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 regex to support ECR as OCI Helm registry #362

Merged
merged 1 commit into from
Sep 29, 2022

Conversation

bnsfrt
Copy link
Contributor

@bnsfrt bnsfrt commented Sep 26, 2022

This change adds a new regex to parse AWS ECR OCI URLs when to allow URLs that point to the root of an AWS account's ECR registry, instead of forcing all repositories to contain a "/" character.

When accepted this will resolve fluxcd/source-controller#905.

I've verified this change resolves the issue by rebuilding the source-controller image and deploying it to a Kubernetes cluster and verifying it can properly authenticate and pull from AWS ECR when given a URL like oci://<account>.dkr.ecr.<region>.amazonaws.com in a HelmRepository object.


oci/auth/aws/auth.go Outdated Show resolved Hide resolved
registryParts = registryPartRe.FindAllStringSubmatch(image, -1)
if len(registryParts) < 1 || len(registryParts[0]) < 3 {
return "", "", false
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went on to find some background on why this function parses image and not registry like it's done for GCP and Azure.
The image parsing and the regex was introduced in fluxcd/image-reflector-controller#174 , which later was refactored into a package and moved to this repository.
Based on the above PR, I don't see any specific reason to have it different from the other providers. For GCP and Azure, only the registry host is checked to be valid. We should be able to do something similar for AWS.
I think the reason for the name to be specific to image is that it was added in image-reflector-controller, where the input is expected to be an image. Now that this is becoming more generic, we should be able to relax the parsing and make it about registry only. The information that's extracted after parsing are the account ID and region, which are still present in a registry URL.
Based on the above reasoning, I think we should rename the function to ParseRegistry(), then replace the old regex with the new ECR registry pattern, update login.go to use aws.ParseRegistry() and anywhere else where it's used, and update the old tests accordingly.
I think this change would be backwards compatible because we are relaxing the parser, shouldn't break any existing behavior.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, with this ImageRegistryProvider() can just accept a name.Reference and the registry string can be passed to aws.ParseRegistry(), similar to how it's passed to the ValidHost() methods for other providers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for digging up that background, @darkowlzz . I went ahead and tried refactoring ParseImage into ParseRegistry and relaxed the parsing. I believe I've gotten all the pieces you've mentioned and the updated tests are passing locally. Would you give it another look?

Copy link
Contributor

@darkowlzz darkowlzz Sep 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for updating. The changes look good to me. I'll run the integration tests with cloud providers to make sure it still works.
And please rebase and squash your commits.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran the integration tests in this repo and in image-reflector-controller against AWS with these changes and they continue to work.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are about to do a release today. So, I'll just rebase and squash the commits myself. Hope that's okay. The new source-controller in this release will have this fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@darkowlzz darkowlzz added the area/oci OCI related issues and pull requests label Sep 28, 2022
This change replaces ParseImage with ParseRegistry to allow URLs that
point to the root of an AWS account's ECR registry, instead of
forcing all repositories to contain a "/" character.
This enables support for using ECR repositories at root level to be used
as OCI Helm Repository.

Signed-off-by: Ben <benjamin.seifert@niche.com>
Copy link
Contributor

@darkowlzz darkowlzz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!
Ran the cloud provider integration tests against the three providers and also verified that image-reflector-controller and source-controller is able to perform contextual login with this change.

@darkowlzz darkowlzz merged commit 640a3ab into fluxcd:main Sep 29, 2022
@bnsfrt bnsfrt deleted the fix-ecr-oci-registry branch September 29, 2022 14:12
@austinorth
Copy link

This fix did not work on our end, for the record, after bnsfrt@f7c66eb. Still unable to pull Helm charts from root ECR repo.

@darkowlzz
Copy link
Contributor

@austinorth can you provide some more information? Error string, registry address, etc. Because this change also updates the test case for the code that was causing the failure for the initially reported issue.
A new issue with all the necessary details about what you tried, what you observed, version of flux controllers, etc would also be very helpful.

@cep21
Copy link

cep21 commented Nov 8, 2022

@austinorth @darkowlzz
We are in the same boat: Cannot pull from private ECR repositories for helm charts.

@darkowlzz
Copy link
Contributor

darkowlzz commented Nov 9, 2022

@cep21 you seem to have a different issue in fluxcd/source-controller#951 . This fix was for invalid chart reference, which you did had initially in your issue. But now, you've authentication issue, which is not related to this PR.
You may have to follow the registry login IRSA setup instructions for using service account https://fluxcd.io/flux/components/source/ocirepositories/#aws . And also make sure to restart source-controller after that to ensure it's using the new token.

@romitzz1
Copy link

romitzz1 commented Dec 9, 2022

@darkowlzz I added opened #429 to add context that @austinorth is pointing out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/oci OCI related issues and pull requests
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

OCI HelmRepository doesn't support charts at the root of AWS ECR
6 participants