-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
(core): docker login to deployment account ECR occurs before asset is built #25894
Comments
I had to dig for a while to find the answer to this, we should document this. You're right, login occurs before the asset is built. But that's done intentionally, and there's a way to adjust that default. See the comment in the code here aws-cdk/packages/cdk-assets/lib/private/docker.ts Lines 221 to 225 in 3196cbc
You can configure a file which contains credential information, the CDK expects it to be here aws-cdk/packages/cdk-assets/lib/private/docker-credentials.ts Lines 25 to 28 in 3196cbc
I didn't know we could have a config file for this, cool! I don't think we document this anywhere though |
Interesting - that's helpful that it exists already. I wonder, though, why doesn't it default to |
@blimmer Were you able to resolve the issue with |
Hey @iliapolo , I won't have time to check out the suggested workaround for some time due to a few tight deadlines. The workaround I provided in the description (granting the image publishing role access to the ECR repo) unblocked me for now. I'm still curious to hear the CDK team's response to my question above. Why not default to using system docker credentials vs the publishing role? It feels like the expected behavior is inverted from the reality today. |
It took me awhile to finally find someone with a similar issue to me. Thanks for bringing this issue up. I attempted to solve the The knowledge gap for me was the OIDC authentication, role, policy, and trust relationship I was using for github actions to execute I would like to mention that I had trouble logging what role was attempting to create the dockerized lambda and execute the |
Just wanted to say that CDK_DOCKER_CREDS_FILE does not work. My current work around is to pull the desired image before hitting
|
For me the same. I cannot get it to work with I've tried the DockerCredentials helper, created the file manually, following the structure described here, all without success. Only thing that works is pulling the image before running |
To work around the issue, I had to resort to explicit docker pull (as mentioned above) commands. These commands are specified in the CDK pipeline property This is then run for each of the asset builds! Not ideal... However, it is a workaround for now. |
When testing locally didn't face this issue, only in an azure devops ci/cd pipeline had this error. Adding the export before the cdk deploy worked. aws ecr get-login-password --region $(region) | docker login --username AWS --password-stdin $(account).dkr.ecr.$(region).amazonaws.com
export CDK_DOCKER_CREDS_FILE=~/.docker/config.json
cdk deploy --require-approval never
|
Describe the bug
Given a simple
Dockerfile
that pulls from a private ECR repository in the same account you're deploying to:With a
DockerImageAsset
:The
cdk deploy
will fail with a message that looks like this:So, in other words, the
FROM
in theDockerfile
cannot be resolved. The reason this happens is because the image publishing role (arn:aws:iam::<ACCOUNT>:role/cdk-hnb659fds-image-publishing-role-<ACCOUNT>-<REGION>
) is used to login to docker before the image is built.Therefore, it overrides the existing
docker login
you might have already done via:And then it can't pull using existing credentials you've already set up.
Expected Behavior
I expected the system-level
docker login
to be respected during image build time so it could resolve the image from the private ECR repo.I understand that the
image-publishing-role
needs to be assumed to push to the CDK assets ECR repository, but it feels like those credentials should only be used before callingdocker push
.In other words, the flow looks like:
docker login
happens as a setup step in my CI platformDockerImageAsset
is built using the credentials from step 1.docker login
is backed updocker login
occurs forimage-publishing-role
docker push
the built assetdocker login
credentials from step 3Current Behavior
What's happening now appears to be:
docker login
happens as a setup step in my CI platformdocker login
occurs forimage-publishing-role
DockerImageAsset
is built using the credentials from step 2 (failure becauseimage-publishing-role
can't access the private ECR repo.Reproduction Steps
blimmer/cdk-bug-reports#2 shows an example. You do need to manually push a
latest
tag to the repo to make it technically correct. However, you should still see the error even with an empty repo (you'll get a 403 error).Possible Solution
If possible, system
docker login
s should be used to build the Docker images, not theimage-publishing-role
.It might be challenging, however, to back up docker credentials, since there are a few different ways you can store those values.
Additional Information/Context
You can work around this issue by applying a policy to your private repository that allows the
image-publishing-role
access to the repo.CDK CLI Version
2.83.0
Framework Version
No response
Node.js Version
18
OS
MacOS
Language
Typescript
Language Version
No response
Other information
No response
The text was updated successfully, but these errors were encountered: