Skip to content

Commit

Permalink
feat(core): add docker security option to asset bundling (#15204)
Browse files Browse the repository at this point in the history
Allow users to add [Docker security option](https://docs.docker.com/engine/reference/run/#security-configuration) when setting their [BundlingOptions](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.BundlingOptions.html).

Improvement on PR [14682](#14682), related to issue #14681

Last PR [14682](#14682) only addressed [DockerRunOptions](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.DockerRunOptions.html)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
maafk authored Jul 5, 2021
1 parent 0419356 commit cbee18a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/@aws-cdk/core/lib/asset-staging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ export class AssetStaging extends CoreConstruct {
volumes,
environment: options.environment,
workingDirectory: options.workingDirectory ?? AssetStaging.BUNDLING_INPUT_DIR,
securityOpt: options.securityOpt ?? '',
});
}
} catch (err) {
Expand Down
10 changes: 9 additions & 1 deletion packages/@aws-cdk/core/lib/bundling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ export interface BundlingOptions {
*
*/
readonly outputType?: BundlingOutput;

/**
* [Security configuration](https://docs.docker.com/engine/reference/run/#security-configuration)
* when running the docker container.
*
* @default - no security options
*/
readonly securityOpt?: string;
}

/**
Expand Down Expand Up @@ -413,7 +421,7 @@ export interface DockerRunOptions {
* [Security configuration](https://docs.docker.com/engine/reference/run/#security-configuration)
* when running the docker container.
*
* @default - no secutiy options
* @default - no security options
*/
readonly securityOpt?: string;
}
Expand Down
28 changes: 28 additions & 0 deletions packages/@aws-cdk/core/test/staging.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,34 @@ nodeunitShim({
test.done();
},


'bundling with docker security option'(test: Test) {
// GIVEN
const app = new App();
const stack = new Stack(app, 'stack');
const directory = path.join(__dirname, 'fs', 'fixtures', 'test1');

// WHEN
const asset = new AssetStaging(stack, 'Asset', {
sourcePath: directory,
bundling: {
image: BundlingDockerImage.fromRegistry('alpine'),
command: [DockerStubCommand.SUCCESS],
securityOpt: 'no-new-privileges',
},
assetHashType: AssetHashType.BUNDLE,
});

// THEN
test.equal(
readDockerStubInput(),
`run --rm --security-opt no-new-privileges ${USER_ARG} -v /input:/asset-input:delegated -v /output:/asset-output:delegated -w /asset-input alpine DOCKER_STUB_SUCCESS`,
);
test.equal(asset.assetHash, '33cbf2cae5432438e0f046bc45ba8c3cef7b6afcf47b59d1c183775c1918fb1f');

test.done();
},

'bundling with OUTPUT asset hash type'(test: Test) {
// GIVEN
const app = new App();
Expand Down

0 comments on commit cbee18a

Please sign in to comment.