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(core): add docker security option to asset bundling #15204

Merged
merged 2 commits into from
Jul 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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