Skip to content

Commit 45c12b6

Browse files
authored
Merge branch 'master' into feature/rds-vpc-endpoint
2 parents 3ff0445 + 6597a09 commit 45c12b6

File tree

7 files changed

+209
-2
lines changed

7 files changed

+209
-2
lines changed

packages/@aws-cdk/aws-ec2/lib/vpc.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1886,6 +1886,7 @@ class LookedUpVpc extends VpcBase {
18861886
availabilityZone: vpcSubnet.availabilityZone,
18871887
subnetId: vpcSubnet.subnetId,
18881888
routeTableId: vpcSubnet.routeTableId,
1889+
ipv4CidrBlock: vpcSubnet.cidr,
18891890
}));
18901891
}
18911892
return ret;

packages/@aws-cdk/aws-ec2/test/vpc.from-lookup.test.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,47 @@ nodeunitShim({
210210

211211
test.done();
212212
},
213+
'subnets in imported VPC has all expected attributes'(test: Test) {
214+
const previous = mockVpcContextProviderWith(test, {
215+
vpcId: 'vpc-1234',
216+
subnetGroups: [
217+
{
218+
name: 'Public',
219+
type: cxapi.VpcSubnetGroupType.PUBLIC,
220+
subnets: [
221+
{
222+
subnetId: 'pub-sub-in-us-east-1a',
223+
availabilityZone: 'us-east-1a',
224+
routeTableId: 'rt-123',
225+
cidr: '10.100.0.0/24',
226+
},
227+
],
228+
},
229+
],
230+
}, options => {
231+
test.deepEqual(options.filter, {
232+
isDefault: 'true',
233+
});
234+
235+
test.equal(options.subnetGroupNameTag, undefined);
236+
});
237+
238+
const stack = new Stack();
239+
const vpc = Vpc.fromLookup(stack, 'Vpc', {
240+
isDefault: true,
241+
});
242+
243+
let subnet = vpc.publicSubnets[0];
244+
245+
test.equal(subnet.availabilityZone, 'us-east-1a');
246+
test.equal(subnet.subnetId, 'pub-sub-in-us-east-1a');
247+
test.equal(subnet.routeTable.routeTableId, 'rt-123');
248+
test.equal(subnet.ipv4CidrBlock, '10.100.0.0/24');
249+
250+
251+
restoreContextProvider(previous);
252+
test.done();
253+
},
213254
},
214255
});
215256

packages/@aws-cdk/aws-kms/lib/key.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ abstract class KeyBase extends Resource implements IKey {
156156
resourceArns: [this.keyArn],
157157
resourceSelfArns: crossEnvironment ? undefined : ['*'],
158158
};
159-
if (this.trustAccountIdentities) {
159+
if (this.trustAccountIdentities && !crossEnvironment) {
160160
return iam.Grant.addToPrincipalOrResource(grantOptions);
161161
} else {
162162
return iam.Grant.addToPrincipalAndResource({

packages/@aws-cdk/aws-kms/test/key.test.ts

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,103 @@ describe('key policies', () => {
245245
});
246246
});
247247

248+
testFutureBehavior('grant for a principal in a different region', flags, cdk.App, (app) => {
249+
const principalStack = new cdk.Stack(app, 'PrincipalStack', { env: { region: 'testregion1' } });
250+
const principal = new iam.Role(principalStack, 'Role', {
251+
assumedBy: new iam.AnyPrincipal(),
252+
roleName: 'MyRolePhysicalName',
253+
});
254+
255+
const keyStack = new cdk.Stack(app, 'KeyStack', { env: { region: 'testregion2' } });
256+
const key = new kms.Key(keyStack, 'Key');
257+
258+
key.grantEncrypt(principal);
259+
260+
expect(keyStack).toHaveResourceLike('AWS::KMS::Key', {
261+
KeyPolicy: {
262+
Statement: arrayWith(
263+
{
264+
Action: [
265+
'kms:Encrypt',
266+
'kms:ReEncrypt*',
267+
'kms:GenerateDataKey*',
268+
],
269+
Effect: 'Allow',
270+
Principal: { AWS: { 'Fn::Join': ['', ['arn:', { Ref: 'AWS::Partition' }, ':iam::', { Ref: 'AWS::AccountId' }, ':role/MyRolePhysicalName']] } },
271+
Resource: '*',
272+
},
273+
),
274+
Version: '2012-10-17',
275+
},
276+
});
277+
expect(principalStack).toHaveResourceLike('AWS::IAM::Policy', {
278+
PolicyDocument: {
279+
Statement: [
280+
{
281+
Action: [
282+
'kms:Encrypt',
283+
'kms:ReEncrypt*',
284+
'kms:GenerateDataKey*',
285+
],
286+
Effect: 'Allow',
287+
Resource: '*',
288+
},
289+
],
290+
Version: '2012-10-17',
291+
},
292+
});
293+
});
294+
295+
testFutureBehavior('grant for a principal in a different account', flags, cdk.App, (app) => {
296+
const principalStack = new cdk.Stack(app, 'PrincipalStack', { env: { account: '0123456789012' } });
297+
const principal = new iam.Role(principalStack, 'Role', {
298+
assumedBy: new iam.AnyPrincipal(),
299+
roleName: 'MyRolePhysicalName',
300+
});
301+
302+
const keyStack = new cdk.Stack(app, 'KeyStack', { env: { account: '111111111111' } });
303+
const key = new kms.Key(keyStack, 'Key');
304+
305+
key.grantEncrypt(principal);
306+
307+
expect(keyStack).toHaveResourceLike('AWS::KMS::Key', {
308+
KeyPolicy: {
309+
Statement: [
310+
{
311+
// Default policy, unmodified
312+
},
313+
{
314+
Action: [
315+
'kms:Encrypt',
316+
'kms:ReEncrypt*',
317+
'kms:GenerateDataKey*',
318+
],
319+
Effect: 'Allow',
320+
Principal: { AWS: { 'Fn::Join': ['', ['arn:', { Ref: 'AWS::Partition' }, ':iam::0123456789012:role/MyRolePhysicalName']] } },
321+
Resource: '*',
322+
},
323+
],
324+
Version: '2012-10-17',
325+
},
326+
});
327+
expect(principalStack).toHaveResourceLike('AWS::IAM::Policy', {
328+
PolicyDocument: {
329+
Statement: [
330+
{
331+
Action: [
332+
'kms:Encrypt',
333+
'kms:ReEncrypt*',
334+
'kms:GenerateDataKey*',
335+
],
336+
Effect: 'Allow',
337+
Resource: '*',
338+
},
339+
],
340+
Version: '2012-10-17',
341+
},
342+
});
343+
});
344+
248345
testFutureBehavior('additional key admins can be specified (with imported/immutable principal)', flags, cdk.App, (app) => {
249346
const stack = new cdk.Stack(app);
250347
const adminRole = iam.Role.fromRoleArn(stack, 'Admin', 'arn:aws:iam::123456789012:role/TrustedAdmin');

packages/@aws-cdk/aws-s3-assets/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ new assets.Asset(this, 'BundledAsset', {
115115
},
116116
// Docker bundling fallback
117117
image: BundlingDockerImage.fromRegistry('alpine'),
118+
entrypoint: ['/bin/sh', '-c'],
118119
command: ['bundle'],
119120
},
120121
});

packages/@aws-cdk/core/lib/bundling.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@ export interface BundlingOptions {
1313
*/
1414
readonly image: BundlingDockerImage;
1515

16+
/**
17+
* The entrypoint to run in the Docker container.
18+
*
19+
* @example ['/bin/sh', '-c']
20+
*
21+
* @see https://docs.docker.com/engine/reference/builder/#entrypoint
22+
*
23+
* @default - run the entrypoint defined in the image
24+
*/
25+
readonly entrypoint?: string[];
26+
1627
/**
1728
* The command to run in the Docker container.
1829
*
@@ -152,7 +163,15 @@ export class BundlingDockerImage {
152163
public run(options: DockerRunOptions = {}) {
153164
const volumes = options.volumes || [];
154165
const environment = options.environment || {};
155-
const command = options.command || [];
166+
const entrypoint = options.entrypoint?.[0] || null;
167+
const command = [
168+
...options.entrypoint?.[1]
169+
? [...options.entrypoint.slice(1)]
170+
: [],
171+
...options.command
172+
? [...options.command]
173+
: [],
174+
];
156175

157176
const dockerArgs: string[] = [
158177
'run', '--rm',
@@ -164,6 +183,9 @@ export class BundlingDockerImage {
164183
...options.workingDirectory
165184
? ['-w', options.workingDirectory]
166185
: [],
186+
...entrypoint
187+
? ['--entrypoint', entrypoint]
188+
: [],
167189
this.image,
168190
...command,
169191
];
@@ -238,6 +260,13 @@ export enum DockerVolumeConsistency {
238260
* Docker run options
239261
*/
240262
export interface DockerRunOptions {
263+
/**
264+
* The entrypoint to run in the container.
265+
*
266+
* @default - run the entrypoint defined in the image
267+
*/
268+
readonly entrypoint?: string[];
269+
241270
/**
242271
* The command to run in the container.
243272
*

packages/@aws-cdk/core/test/bundling.test.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,44 @@ nodeunitShim({
171171
test.done();
172172
},
173173

174+
'custom entrypoint is passed through to docker exec'(test: Test) {
175+
const spawnSyncStub = sinon.stub(child_process, 'spawnSync').returns({
176+
status: 0,
177+
stderr: Buffer.from('stderr'),
178+
stdout: Buffer.from('stdout'),
179+
pid: 123,
180+
output: ['stdout', 'stderr'],
181+
signal: null,
182+
});
183+
184+
const image = BundlingDockerImage.fromRegistry('alpine');
185+
image.run({
186+
entrypoint: ['/cool/entrypoint', '--cool-entrypoint-arg'],
187+
command: ['cool', 'command'],
188+
environment: {
189+
VAR1: 'value1',
190+
VAR2: 'value2',
191+
},
192+
volumes: [{ hostPath: '/host-path', containerPath: '/container-path' }],
193+
workingDirectory: '/working-directory',
194+
user: 'user:group',
195+
});
196+
197+
test.ok(spawnSyncStub.calledWith('docker', [
198+
'run', '--rm',
199+
'-u', 'user:group',
200+
'-v', '/host-path:/container-path:delegated',
201+
'--env', 'VAR1=value1',
202+
'--env', 'VAR2=value2',
203+
'-w', '/working-directory',
204+
'--entrypoint', '/cool/entrypoint',
205+
'alpine',
206+
'--cool-entrypoint-arg',
207+
'cool', 'command',
208+
], { stdio: ['ignore', process.stderr, 'inherit'] }));
209+
test.done();
210+
},
211+
174212
'cp utility copies from an image'(test: Test) {
175213
// GIVEN
176214
const containerId = '1234567890abcdef1234567890abcdef';

0 commit comments

Comments
 (0)