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

feat(cdk-assets): externally-configured Docker credentials #15290

Merged
merged 6 commits into from
Jun 25, 2021

Conversation

njlynch
Copy link
Contributor

@njlynch njlynch commented Jun 24, 2021

Currently, cdk-assets does a single docker login with credentials fetched
from ECR's getAuthorizationToken API. This enables access to (typically) the
assets in the environment's ECR repo (*--container-assets-*).

A pain point for users today is throttling when using images from other sources,
especially from DockerHub when using unauthenticated calls.

This change introduces a new configuration file at a well-known location (and
overridable via the CDK_DOCKER_CREDS_FILE environment variable), which allows
specifying per-domain login credentials via either the default ECR auth tokens
or via a secret in SecretsManager.

If the credentials file is present, a Docker credential helper
(docker-credential-cdk-assets) will be set up for each of the configured
domains, and used for the docker build commands to enable fetching images from
both DockerHub or configured ECR repos. Then the "normal" credentials will be
assumed for the final publishing step. For backwards compatibility, if no
credentials file is present, the existing docker login will be done prior to
the build step as usual.

This PR will be shortly followed by a corresponding PR for the cdk pipelines
library to enable users to specify registries and credentials to be fed into
this credentials file during various stages of the pipeline (e.g., build/synth,
self-update, and asset publishing).

Two refactorings here:

  • Moved obtainEcrCredentials from docker.ts to docker-credentials-ts.
  • Moved DefaultAwsClient from bin/publish.ts to lib/aws.ts

related #10999
related #11774


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

Currently, `cdk-assets` does a single `docker login` with credentials fetched
from ECR's `getAuthorizationToken` API. This enables access to (typically) the
assets in the environment's ECR repo (`*--container-assets-*`).

A pain point for users today is throttling when using images from other sources,
especially from DockerHub when using unauthenticated calls.

This change introduces a new configuration file at a well-known location (and
overridable via the CDK_DOCKER_CREDS_FILE environment variable), which allows
specifying per-domain login credentials via either the default ECR auth tokens
or via a secret in SecretsManager.

If the credentials file is present, a Docker credential helper
(docker-credential-cdk-assets) will be set up for each of the configured
domains, and used for the `docker build` commands to enable fetching images from
both DockerHub or configured ECR repos. Then the "normal" credentials will be
assumed for the final publishing step. For backwards compatibility, if no
credentials file is present, the existing `docker login` will be done prior to
the build step as usual.

This PR will be shortly followed by a corresponding PR for the cdk pipelines
library to enable users to specify registries and credentials to be fed into
this credentials file during various stages of the pipeline (e.g., build/synth,
self-update, and asset publishing).

related #10999
related #11774
@njlynch njlynch requested review from rix0rrr and a team June 24, 2021 10:52
@njlynch njlynch self-assigned this Jun 24, 2021
@gitpod-io
Copy link

gitpod-io bot commented Jun 24, 2021

@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Jun 24, 2021
@rix0rrr rix0rrr added the pr/do-not-merge This PR should not be merged at this time. label Jun 24, 2021
Copy link
Contributor

@rix0rrr rix0rrr left a comment

Choose a reason for hiding this comment

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

Provisional okeli-dokeli after you've considered my feedback.

@njlynch njlynch requested a review from rix0rrr June 24, 2021 14:00
@njlynch njlynch removed the pr/do-not-merge This PR should not be merged at this time. label Jun 25, 2021
@mergify
Copy link
Contributor

mergify bot commented Jun 25, 2021

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject89A8053A-LhjRyN9kxr8o
  • Commit ID: a6ad9e4
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit e530195 into master Jun 25, 2021
@mergify mergify bot deleted the njlynch/cdk-assets-docker-creds branch June 25, 2021 12:24
@mergify
Copy link
Contributor

mergify bot commented Jun 25, 2021

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

hollanddd pushed a commit to hollanddd/aws-cdk that referenced this pull request Aug 26, 2021
Currently, `cdk-assets` does a single `docker login` with credentials fetched
from ECR's `getAuthorizationToken` API. This enables access to (typically) the
assets in the environment's ECR repo (`*--container-assets-*`).

A pain point for users today is throttling when using images from other sources,
especially from DockerHub when using unauthenticated calls.

This change introduces a new configuration file at a well-known location (and
overridable via the CDK_DOCKER_CREDS_FILE environment variable), which allows
specifying per-domain login credentials via either the default ECR auth tokens
or via a secret in SecretsManager.

If the credentials file is present, a Docker credential helper
(docker-credential-cdk-assets) will be set up for each of the configured
domains, and used for the `docker build` commands to enable fetching images from
both DockerHub or configured ECR repos. Then the "normal" credentials will be
assumed for the final publishing step. For backwards compatibility, if no
credentials file is present, the existing `docker login` will be done prior to
the build step as usual.

This PR will be shortly followed by a corresponding PR for the cdk pipelines
library to enable users to specify registries and credentials to be fed into
this credentials file during various stages of the pipeline (e.g., build/synth,
self-update, and asset publishing).

Two refactorings here:
- Moved obtainEcrCredentials from docker.ts to docker-credentials-ts.
- Moved DefaultAwsClient from bin/publish.ts to lib/aws.ts

related aws#10999
related aws#11774

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution/core This is a PR that came from AWS.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants