-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
AWS ECR registry authentication only works in the same/default region as caller #1026
Comments
If you set AWS_DEFAULT_REGION=eu-central-1, does it work? |
yes, @knqyf263 any possibility that you provide some leads on how trivy reads thanks! |
@knqyf263 Specifying a matching region to the image location via I discovered that EKS clusters have a pod-identiy-webhook configured to inject needed environment variables to assume roles via OIDC / web-identity. This also injects
prevents the webhook from inject region environment values: Trivy's auto-detection works as expected. I wasn't able to resolve the issue by creating a But this still fells like some kind of workaround - running Trivy in an EKS cluster to scan ECR images appears to me like a common use-case. The documentation on the ECR integration page reads like this should work out-of-the-box. Is it possible to override the region directly in Trivy? Otherwise, it feels like this pitfall is worth to document. |
This issue is stale because it has been labeled with inactivity. |
I have a workaround in-place (blank |
This issue is stale because it has been labeled with inactivity. |
Situation hasn't changed on my site, but I would prefer a mentation statement regarding option to improve the situation of future users. |
This issue is stale because it has been labeled with inactivity. |
Status remains unchanged. |
Still the same issue |
I ran across this issue in version This is just running Using Using The workaround suggested by @msw-kialo to set However I was able to get it working by installing docker, starting docker daemon, adding the user to the docker group, and installing/enabling config for It would be great if |
This issue is stale because it has been labeled with inactivity. |
While we have a workaround in place, a proper resolution would be great (I am reluctant to try fixing it myself as I am not familiar with the code base). |
@msw-kialo We've added |
@msw-kialo did you try
|
@sinner- I didn't try adding a docker daemon. It is IMO also a workaround. However, it requires much more maintenance attention and further permissions (at least if you run in a Kubernetes cluster). Unsetting a few environments variables is easier. @knqyf263 Based on the PR, the |
Yes, I'm asking if you want the option for image scanning. The CLI flag can overwrite environmental variables injected by webhook. |
Sorry (apparently I skipped over the second sentence). Yes, such an option would be good to have:
The optimal solution would auto-detect the region parameter based on the image registry URL. If it is an AWS managed registry (and only for those this parameter makes sense), the full registry URL will already contain the correct region: e.g., |
OK, it seems like the region is always included. We can take it and fall back into a blank region when it cannot be detected. It could be easy to do that. Here is the ECR logic. |
Apparently, this issue has been fixed in the meantime (either in trivy itself or the use aws libraries). |
This issue still exists with the latest version. setting AWS_REGION and AWS_DEFAULT_REGION to "" fails for multiple regions
By default it uses the EKS region, and overriding it allows us to access an alternative region. In order to scan images from multiple regions we need to modify the code, I have something working and will submit a PR shortly |
I haven't had a chance to upgrade yet, but I'm seeing the issue in 0.48.0. Thought I'd share a workaround: I had one account where trivy was able to only scan in us-east-1 but not eu-west-3 and a several others. For the other accounts, Trivy was able to run just fine. Not sure why. I used a workaround by setting |
Description
Trivy is deployed within an AWS EKS Kubernetes pod. The pod has an AWS role associated to read ECR images. Trivy is executed to scan:
What did you expect to happen?
Trivy is able to scan these three image types. Authentication is handled transparently by Trivy (for all these types). On failure, an available
docker-credential-ecr-login
helper is used/tried, too.What happened instead?
Trivy is unable to scan (public) ECR images in other AWS regions (except the region of the EKS cluster).
The automatic AWS authentication handler injects ECR authentication tokens from the current (default) region, not the region of the ECR image itself.
Having the
docker-credential-ecr-login
helper available and configured does not mitigate the authentication issue (the helper is never used by Trivy; although it would return valid credentials). There is no known configuration option to force Trivy to fall back to using thedocker-credential-ecr-login
helper.In our case, we start Trivy in an EKS cluster in
us-east-1
. It is able to scan private and public ECR images inus-east-1
. Public images in other regions likeeu-central-1
fail (I could not yet test it with private ECR images).Output of run with
-debug
:Output of
trivy -v
:Issue can be reproduced with at least
0.16.0
, too.Additional details (base image name, container registry info...):
Produce same error messages with built-in tools
The error message
Your Authorization Token is invalid.
can be reproduced by providing an AWS authorization token from a different region:Authentication via
docker-credential-ecr-login
would workPreviously, the pod assumed its role via an older
kube2iam
version (0.10.x). Apparently, the AWS API imitated bykube2iam
was not sufficient to convince Trivy to be running in an AWS context. It did not handle the authentication itself. The availabledocker-credential-ecr-login
helper was successfully used for all image types:The text was updated successfully, but these errors were encountered: