Skip to content

Commit d71b931

Browse files
authored
chore(cloudtrail): enforceSSL on trail s3 bucket (#18270)
could pass another bucket, but automatically created buckets are convenient/popular, so worth improving defaults https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-cloudtrail.Trail.html https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-s3.Bucket.html --- ```sh # updated integ snapshots packages/@aws-cdk/aws-cloudtrail $ /workspace/aws-cdk/tools/\@aws-cdk/cdk-integ-tools/bin/cdk-integ --dry-run packages/@aws-cdk/aws-codepipeline-actions $ /workspace/aws-cdk/tools/\@aws-cdk/cdk-integ-tools/bin/cdk-integ --dry-run ``` --- ```sh # eslint fix /workspace/aws-cdk/node_modules/eslint/bin/eslint.js packages/@aws-cdk/aws-cloudtrail/test/ --ext=.ts --fix ``` ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 9226714 commit d71b931

File tree

4 files changed

+134
-2
lines changed

4 files changed

+134
-2
lines changed

packages/@aws-cdk/aws-cloudtrail/lib/cloudtrail.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ export class Trail extends Resource {
209209

210210
const cloudTrailPrincipal = new iam.ServicePrincipal('cloudtrail.amazonaws.com');
211211

212-
this.s3bucket = props.bucket || new s3.Bucket(this, 'S3', { encryption: s3.BucketEncryption.UNENCRYPTED });
212+
this.s3bucket = props.bucket || new s3.Bucket(this, 'S3', { encryption: s3.BucketEncryption.UNENCRYPTED, enforceSSL: true });
213213

214214
this.s3bucket.addToResourcePolicy(new iam.PolicyStatement({
215215
resources: [this.s3bucket.bucketArn],

packages/@aws-cdk/aws-cloudtrail/test/cloudtrail.test.ts

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,36 @@ import { ManagementEventSources, ReadWriteType, Trail } from '../lib';
1212
const ExpectedBucketPolicyProperties = {
1313
PolicyDocument: {
1414
Statement: [
15+
{
16+
Action: 's3:*',
17+
Condition: {
18+
Bool: { 'aws:SecureTransport': 'false' },
19+
},
20+
Effect: 'Deny',
21+
Principal: {
22+
AWS: '*',
23+
},
24+
Resource: [
25+
{
26+
'Fn::GetAtt': [
27+
'MyAmazingCloudTrailS3A580FE27',
28+
'Arn',
29+
],
30+
},
31+
{
32+
'Fn::Join': [
33+
'',
34+
[{
35+
'Fn::GetAtt': [
36+
'MyAmazingCloudTrailS3A580FE27',
37+
'Arn',
38+
],
39+
},
40+
'/*'],
41+
],
42+
},
43+
],
44+
},
1545
{
1646
Action: 's3:GetBucketAcl',
1747
Effect: 'Allow',
@@ -154,6 +184,40 @@ describe('cloudtrail', () => {
154184
Bucket: { Ref: 'TrailS30071F172' },
155185
PolicyDocument: {
156186
Statement: [
187+
{
188+
Action: 's3:*',
189+
Condition: {
190+
Bool: {
191+
'aws:SecureTransport': 'false',
192+
},
193+
},
194+
Effect: 'Deny',
195+
Principal: {
196+
AWS: '*',
197+
},
198+
Resource: [
199+
{
200+
'Fn::GetAtt': [
201+
'TrailS30071F172',
202+
'Arn',
203+
],
204+
},
205+
{
206+
'Fn::Join': [
207+
'',
208+
[
209+
{
210+
'Fn::GetAtt': [
211+
'TrailS30071F172',
212+
'Arn',
213+
],
214+
},
215+
'/*',
216+
],
217+
],
218+
},
219+
],
220+
},
157221
{
158222
Action: 's3:GetBucketAcl',
159223
Effect: 'Allow',
@@ -611,4 +675,4 @@ describe('cloudtrail', () => {
611675
});
612676
});
613677
});
614-
});
678+
});

packages/@aws-cdk/aws-cloudtrail/test/integ.cloudtrail.lit.expected.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,40 @@
9797
},
9898
"PolicyDocument": {
9999
"Statement": [
100+
{
101+
"Action": "s3:*",
102+
"Condition": {
103+
"Bool": {
104+
"aws:SecureTransport": "false"
105+
}
106+
},
107+
"Effect": "Deny",
108+
"Principal": {
109+
"AWS": "*"
110+
},
111+
"Resource": [
112+
{
113+
"Fn::GetAtt": [
114+
"TrailS30071F172",
115+
"Arn"
116+
]
117+
},
118+
{
119+
"Fn::Join": [
120+
"",
121+
[
122+
{
123+
"Fn::GetAtt": [
124+
"TrailS30071F172",
125+
"Arn"
126+
]
127+
},
128+
"/*"
129+
]
130+
]
131+
}
132+
]
133+
},
100134
{
101135
"Action": "s3:GetBucketAcl",
102136
"Effect": "Allow",

packages/@aws-cdk/aws-codepipeline-actions/test/integ.lambda-pipeline.expected.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,40 @@
669669
},
670670
"PolicyDocument": {
671671
"Statement": [
672+
{
673+
"Action": "s3:*",
674+
"Condition": {
675+
"Bool": {
676+
"aws:SecureTransport": "false"
677+
}
678+
},
679+
"Effect": "Deny",
680+
"Principal": {
681+
"AWS": "*"
682+
},
683+
"Resource": [
684+
{
685+
"Fn::GetAtt": [
686+
"CloudTrailS310CD22F2",
687+
"Arn"
688+
]
689+
},
690+
{
691+
"Fn::Join": [
692+
"",
693+
[
694+
{
695+
"Fn::GetAtt": [
696+
"CloudTrailS310CD22F2",
697+
"Arn"
698+
]
699+
},
700+
"/*"
701+
]
702+
]
703+
}
704+
]
705+
},
672706
{
673707
"Action": "s3:GetBucketAcl",
674708
"Effect": "Allow",

0 commit comments

Comments
 (0)