Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add aws uri field #407

Merged
merged 1 commit into from
Dec 3, 2024
Merged

add aws uri field #407

merged 1 commit into from
Dec 3, 2024

Conversation

refaelm92
Copy link
Contributor

@refaelm92 refaelm92 commented Dec 3, 2024

PR Type

enhancement


Description

  • Updated the AWSImageRegistry struct to replace the Registry field with RegistryURI.
  • Modified methods to use registryURI instead of registry.
  • Added validation logic for registryURI to ensure it follows the expected AWS ECR format.
  • Implemented extractRegionFromAWSRegistryURI to derive the region from the registryURI.

Changes walkthrough 📝

Relevant files
Enhancement
registrymethods.go
Update AWSImageRegistry to use registryURI and validate it

armotypes/registrymethods.go

  • Changed registry to registryURI in several methods.
  • Added validation for registryURI format and extraction of region.
  • Introduced extractRegionFromAWSRegistryURI function.
  • +23/-8   
    registrytypes.go
    Rename Registry to RegistryURI in AWSImageRegistry             

    armotypes/registrytypes.go

    • Renamed Registry field to RegistryURI in AWSImageRegistry.
    +1/-1     

    💡 PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

    Copy link

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Error Handling
    The new region extraction logic doesn't validate if the extracted region is a valid AWS region format. Should add validation to ensure extracted region follows AWS region pattern.

    Missing Validation
    The cleanRegistryURL function is called but its implementation is not shown. Need to verify it properly sanitizes the registry URI input.

    Backwards Compatibility
    Changing from Registry to RegistryURI may break existing configurations. Should verify migration path for existing users.

    Copy link

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Possible issue
    Add validation to ensure extracted AWS region follows the correct format pattern

    The region extraction logic assumes a specific URI format but doesn't validate the
    region string itself. Add validation to ensure the extracted region follows AWS
    region format (e.g., us-east-1, eu-west-2).

    armotypes/registrymethods.go [104-105]

     region := parts[3]
    +if !regexp.MustCompile(`^[a-z]{2}-[a-z]+-\d+$`).MatchString(region) {
    +    return "", errors.New("invalid AWS region format")
    +}
     return region, nil
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: The suggestion addresses a significant validation gap that could allow invalid AWS region formats to pass through, potentially causing issues downstream. Adding regex validation would prevent invalid region formats early.

    8
    Security
    Prevent potential panic by adding proper array bounds checking before accessing elements

    The URI parsing logic is vulnerable to index out of range panic if the URI contains
    dots but fewer than 5 parts. Move the array access inside a bounds check.

    armotypes/registrymethods.go [100-104]

     parts := strings.Split(uri, ".")
     if len(parts) < 5 {
         return "", errors.New("unexpected URI structure")
     }
    +if len(parts) <= 3 {
    +    return "", errors.New("invalid URI format: missing region part")
    +}
     region := parts[3]
    • Apply this suggestion
    Suggestion importance[1-10]: 3

    Why: While the suggestion aims to prevent a potential panic, it's redundant since the code already has a length check for < 5 parts which would catch the same issue. The additional check doesn't provide meaningful protection.

    3

    💡 Need additional feedback ? start a PR chat

    @refaelm92 refaelm92 merged commit d966767 into main Dec 3, 2024
    3 checks passed
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    2 participants