How to let trivy know to use AWS IAM credentials when pulling from IAM protected ECR repositories #264
-
Hello, Is there another way to setup pull images with credentials when the trivy scanner job/pod starts? In particular, local ECR repositories that enforce IAM access rules? |
Beta Was this translation helpful? Give feedback.
Replies: 9 comments 10 replies
-
This is not supported yet, per other discussions. |
Beta Was this translation helpful? Give feedback.
-
@mmerrill3 I have an update on that after playing with AKS and ECR. It seems that it's a matter of configuration. You can try attaching the In the example below the
/cc @lizrice |
Beta Was this translation helpful? Give feedback.
-
I set up IRSA, and my repo is allowing the IAM role for starboard operator to download the images. I still get a 401. Was the repo you used open to anybody? I checked the pod, and I see the projected service account token for IAM. I grabbed the token and decoded it, it appears fine. Here is what got projected: { I see in the code that the service account is copied to the trivy job from the controller (starboard operator). The same service account is passed to the trivy jobs, and the mutating web hook updates those pods (the new trivy pods) with a projected token as well. Does trivy use the AWS SDK and exchange the projected token for an STS identity? |
Beta Was this translation helpful? Give feedback.
-
I just tried running trivy by itself, the latest version, within k8s, using the expected service account that the IRSA mutating web hook is looking for. This is not the CLI mode, but rather mimicking what the operator does (creating a pod for each scan). I don't see any use of the projected token from the AWS mutating web hook. mmerrillmbp:devor0 mmerrill$ kubectl run --serviceaccount k8s-starboard-role --requests cpu=100m,memory=256Mi --limits cpu=100m,memory=256Mi --image aquasec/trivy:0.15.0 -ti --rm --command trivy2 -- sh
This shows the mutate occured: / # env|grep AWS Is this really supported in the starboard operator mode? The docs, and your example, only show the CLI mode. |
Beta Was this translation helpful? Give feedback.
-
I'm still working on this. I'm focused on the use case where the docker socket is not available, and the google container registry library is used by trivy to get the images. This library tries to obtain the manifest first for the ECR image using a GET http command, with basic auth set. The basic auth should be the username "AWS" and the password that comes from the ECR get login token function. I've verified that the IRSA flow works using docker-java and the latest AWS SDK. So, that shows that the assume role flow works for the roles I'm using, and and OIDC provider setup. I was able to download the image from ECR with a token made by the mutating web hook. So, that part is good. I'm focused on this Manifest call and why that is giving a 401. |
Beta Was this translation helpful? Give feedback.
-
Well, if there's any issue with the irsa setup, and getting the STS token, the exceptions are ignored, and the anonymous user is used. This method from the aquasecurity fanal library is used to get the STS token, but any errors are glossed over. It turns out I had an issue with my OIDC provider I setup, and the audience. The audience mismatch exception wasn't being propagated, so the end result was the use of an anonymous authorization for basic auth with the docker repo (ECR). This is the method in question, maybe adding a log statement of the exception would be helpful to quickly point to issues with the STS workflow.
|
Beta Was this translation helpful? Give feedback.
-
@danielpacak this is verified and anwered. |
Beta Was this translation helpful? Give feedback.
-
hey @mmerrill3 it seems after finding out the solution it worked straightforward for you. Thank you for all the information, it helped me a lot enabling IRSA and create the SA in the right way, but now after setting this up the jobs fail with a strange error
Have you seen this before? The error is so generic that I couldn't find much info on the internet about it. Only a few things related to terraform where they stated that the SA needed The operator pod shows logs like it is creating jobs for all images in all namespaces just like I wanted but something is odd |
Beta Was this translation helpful? Give feedback.
-
You might look on the PR: #1103 Cheers |
Beta Was this translation helpful? Give feedback.
@mmerrill3 I have an update on that after playing with AKS and ECR. It seems that it's a matter of configuration. You can try attaching the
AmazonEC2ContainerRegistryReadOnly
policy to thestarboard
(for Starboard CLI) orstarboard-operator
service account.In the example below the
nginx-private
refers to the private image119244888562.dkr.ecr.eu-central-1.amazonaws.com/library/nginx:1.16
. After attaching the policy to the service account I was able to generate VulnerabilityReport.