(cdk-assets): docker buildkit secrets from environment
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
### Describe the feature
#23778 Introduced the ability to pass secrets within the [build process thanks to BuildKit](https://docs.docker.com/engine/reference/commandline/buildx_build/#secret). Such feature supports secrets from two souces:
1. **File**: docker will read the file and pass the content as the secret
2. **Env**: docker will read the secret from the Environment and pass it
The PR aboved implemented (1) but not (2)
### Use Case
> As a developer,
>
> I want to be able to use the Environment to pass secrets to the Docker build step of CDK,
>
> so I don't have to create ephimeral files from secrets that I already have in the environment. Specifically in Github Action pipelines.
### Proposed Solution
In line with what [is proposed in here](https://github.com/aws/aws-cdk/issues/14395#issuecomment-1157820199), I suggest to
```ts
/**
* buildArgs?: {
* [key: string]: string | undefined;
* };
*/
// Such
const asset = new DockerImageAsset(stack, 'blah', { directory, buildSecrets: { mySecret: undefined } });
```
This way we keep the same interface and we take the `undefined` semantic to fetch the secret from the environment.
Specifically we can modify [this line](https://github.com/aws/aws-cdk/blob/74512fa339e0a2937213f519c109ef1207e9d0c6/packages/cdk-assets/lib/private/docker.ts#L58) such
```ts
// Before
...flatten(Object.entries(options.buildSecrets || {}).map(([k, v]) => ['--secret', `id=${k},${v}`])),
// After
...flatten(Object.entries(options.buildSecrets || {}).map(([k, v]) => ['--secret', v===undefined ? `id=${k}`:`id=${k},${v}`])),
```
Otherwise we can create a new method such
```ts
DockerBuildSecret.fromEnvironment('MY_SECRET')
```
and parse that down the line.
This last method would be more scalable to include other methods such the one mentioned in #14395 (pass secrets from Secrets Manager or SSM)
### Other Information
Relates to #14395 but is a different user need
### Acknowledgements
- [ ] I may be able to implement this feature request
- [ ] This feature might incur a breaking change
### CDK version used
2.69.0
### Environment details (OS name and version, etc.)
MacOS Ventura 13.2.1
Contributor guide
Research direction
Start in packages/cdk-assets/lib/private/docker.ts around the buildSecrets handling near line 58, and compare the existing file-based BuildKit secret behavior with Docker's documented environment-source syntax. Decide how the proposed undefined value or a dedicated method should represent environment secrets while preserving file support; done means CDK can pass an environment-backed secret without an ephemeral file.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, typescript
- Domain
- devops, infrastructure
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100