@@ -7,6 +7,7 @@ import * as secrets from '@aws-cdk/aws-secretsmanager';
77import * as dynamodb from '@aws-cdk/aws-dynamodb' ;
88import * as sfn from '@aws-cdk/aws-stepfunctions' ;
99import * as tasks from '@aws-cdk/aws-stepfunctions-tasks' ;
10+ import * as s3 from '@aws-cdk/aws-s3' ;
1011import { CdkDeployProject , PrebuiltCdkDeployProject } from '@aws-accelerator/cdk-accelerator/src/codebuild' ;
1112import { AcceleratorStack , AcceleratorStackProps } from '@aws-accelerator/cdk-accelerator/src/core/accelerator-stack' ;
1213import { createRoleName , createName } from '@aws-accelerator/cdk-accelerator/src/core/accelerator-name-generator' ;
@@ -125,6 +126,42 @@ export namespace InitialSetup {
125126 maxSessionDuration : buildTimeout ,
126127 } ) ;
127128
129+ // S3 working bucket
130+ const s3WorkingBucket = new s3 . Bucket ( this , 'WorkingBucket' , {
131+ blockPublicAccess : s3 . BlockPublicAccess . BLOCK_ALL ,
132+ encryption : s3 . BucketEncryption . S3_MANAGED ,
133+ removalPolicy : cdk . RemovalPolicy . RETAIN ,
134+ lifecycleRules : [
135+ {
136+ id : '7DaysDelete' ,
137+ enabled : true ,
138+ expiration : cdk . Duration . days ( 7 ) ,
139+ } ,
140+ ] ,
141+ } ) ;
142+ s3WorkingBucket . addToResourcePolicy (
143+ new iam . PolicyStatement ( {
144+ actions : [ 's3:GetObject*' , 's3:PutObject*' , 's3:DeleteObject*' , 's3:GetBucket*' , 's3:List*' ] ,
145+ resources : [ s3WorkingBucket . arnForObjects ( '*' ) , s3WorkingBucket . bucketArn ] ,
146+ principals : [ pipelineRole ] ,
147+ } ) ,
148+ ) ;
149+ // Allow only https requests
150+ s3WorkingBucket . addToResourcePolicy (
151+ new iam . PolicyStatement ( {
152+ actions : [ 's3:*' ] ,
153+ resources : [ s3WorkingBucket . bucketArn , s3WorkingBucket . arnForObjects ( '*' ) ] ,
154+ principals : [ new iam . AnyPrincipal ( ) ] ,
155+ conditions : {
156+ Bool : {
157+ 'aws:SecureTransport' : 'false' ,
158+ } ,
159+ } ,
160+ effect : iam . Effect . DENY ,
161+ } ) ,
162+ ) ;
163+ //
164+
128165 // Add a suffix to the CodeBuild project so it creates a new project as it's not able to update the `baseImage`
129166 const projectNameSuffix = enablePrebuiltProject ? 'Prebuilt' : '' ;
130167 const projectConstructor = enablePrebuiltProject ? PrebuiltCdkDeployProject : CdkDeployProject ;
@@ -611,6 +648,7 @@ export namespace InitialSetup {
611648 'configCommitId.$' : '$.configCommitId' ,
612649 outputUtilsTableName : outputUtilsTable . tableName ,
613650 accountsTableName : parametersTable . tableName ,
651+ s3WorkingBucket : s3WorkingBucket . bucketName ,
614652 } ) ,
615653 resultPath : 'DISCARD' ,
616654 } ) ;
0 commit comments