forked from aws/aws-cdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(codebuild): Project lacks permissions to its log destinations
In aws#11444, we added the option of setting the logging configuration of the Project. Unfortuantely, the Project's Role was not given permissions to write into that destination, which means executing the Project's build would fail. Fixes aws#12179
- Loading branch information
Showing
4 changed files
with
253 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
223 changes: 223 additions & 0 deletions
223
packages/@aws-cdk/aws-codebuild/test/integ.project-logging.expected.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,223 @@ | ||
{ | ||
"Resources": { | ||
"LogingGroupE599B53B": { | ||
"Type": "AWS::Logs::LogGroup", | ||
"Properties": { | ||
"RetentionInDays": 731 | ||
}, | ||
"UpdateReplacePolicy": "Delete", | ||
"DeletionPolicy": "Delete" | ||
}, | ||
"LoggingBucket1E5A6F3B": { | ||
"Type": "AWS::S3::Bucket", | ||
"UpdateReplacePolicy": "Delete", | ||
"DeletionPolicy": "Delete" | ||
}, | ||
"ProjectRole4CCB274E": { | ||
"Type": "AWS::IAM::Role", | ||
"Properties": { | ||
"AssumeRolePolicyDocument": { | ||
"Statement": [ | ||
{ | ||
"Action": "sts:AssumeRole", | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Service": "codebuild.amazonaws.com" | ||
} | ||
} | ||
], | ||
"Version": "2012-10-17" | ||
} | ||
} | ||
}, | ||
"ProjectRoleDefaultPolicy7F29461B": { | ||
"Type": "AWS::IAM::Policy", | ||
"Properties": { | ||
"PolicyDocument": { | ||
"Statement": [ | ||
{ | ||
"Action": [ | ||
"s3:DeleteObject*", | ||
"s3:PutObject*", | ||
"s3:Abort*" | ||
], | ||
"Effect": "Allow", | ||
"Resource": [ | ||
{ | ||
"Fn::GetAtt": [ | ||
"LoggingBucket1E5A6F3B", | ||
"Arn" | ||
] | ||
}, | ||
{ | ||
"Fn::Join": [ | ||
"", | ||
[ | ||
{ | ||
"Fn::GetAtt": [ | ||
"LoggingBucket1E5A6F3B", | ||
"Arn" | ||
] | ||
}, | ||
"/*" | ||
] | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"Action": [ | ||
"logs:CreateLogStream", | ||
"logs:PutLogEvents" | ||
], | ||
"Effect": "Allow", | ||
"Resource": { | ||
"Fn::GetAtt": [ | ||
"LogingGroupE599B53B", | ||
"Arn" | ||
] | ||
} | ||
}, | ||
{ | ||
"Action": [ | ||
"logs:CreateLogGroup", | ||
"logs:CreateLogStream", | ||
"logs:PutLogEvents" | ||
], | ||
"Effect": "Allow", | ||
"Resource": [ | ||
{ | ||
"Fn::Join": [ | ||
"", | ||
[ | ||
"arn:", | ||
{ | ||
"Ref": "AWS::Partition" | ||
}, | ||
":logs:", | ||
{ | ||
"Ref": "AWS::Region" | ||
}, | ||
":", | ||
{ | ||
"Ref": "AWS::AccountId" | ||
}, | ||
":log-group:/aws/codebuild/", | ||
{ | ||
"Ref": "ProjectC78D97AD" | ||
} | ||
] | ||
] | ||
}, | ||
{ | ||
"Fn::Join": [ | ||
"", | ||
[ | ||
"arn:", | ||
{ | ||
"Ref": "AWS::Partition" | ||
}, | ||
":logs:", | ||
{ | ||
"Ref": "AWS::Region" | ||
}, | ||
":", | ||
{ | ||
"Ref": "AWS::AccountId" | ||
}, | ||
":log-group:/aws/codebuild/", | ||
{ | ||
"Ref": "ProjectC78D97AD" | ||
}, | ||
":*" | ||
] | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"Action": [ | ||
"codebuild:CreateReportGroup", | ||
"codebuild:CreateReport", | ||
"codebuild:UpdateReport", | ||
"codebuild:BatchPutTestCases", | ||
"codebuild:BatchPutCodeCoverages" | ||
], | ||
"Effect": "Allow", | ||
"Resource": { | ||
"Fn::Join": [ | ||
"", | ||
[ | ||
"arn:", | ||
{ | ||
"Ref": "AWS::Partition" | ||
}, | ||
":codebuild:", | ||
{ | ||
"Ref": "AWS::Region" | ||
}, | ||
":", | ||
{ | ||
"Ref": "AWS::AccountId" | ||
}, | ||
":report-group/", | ||
{ | ||
"Ref": "ProjectC78D97AD" | ||
}, | ||
"-*" | ||
] | ||
] | ||
} | ||
} | ||
], | ||
"Version": "2012-10-17" | ||
}, | ||
"PolicyName": "ProjectRoleDefaultPolicy7F29461B", | ||
"Roles": [ | ||
{ | ||
"Ref": "ProjectRole4CCB274E" | ||
} | ||
] | ||
} | ||
}, | ||
"ProjectC78D97AD": { | ||
"Type": "AWS::CodeBuild::Project", | ||
"Properties": { | ||
"Artifacts": { | ||
"Type": "CODEPIPELINE" | ||
}, | ||
"Environment": { | ||
"ComputeType": "BUILD_GENERAL1_SMALL", | ||
"Image": "aws/codebuild/standard:1.0", | ||
"ImagePullCredentialsType": "CODEBUILD", | ||
"PrivilegedMode": false, | ||
"Type": "LINUX_CONTAINER" | ||
}, | ||
"ServiceRole": { | ||
"Fn::GetAtt": [ | ||
"ProjectRole4CCB274E", | ||
"Arn" | ||
] | ||
}, | ||
"Source": { | ||
"Type": "CODEPIPELINE" | ||
}, | ||
"EncryptionKey": "alias/aws/s3", | ||
"LogsConfig": { | ||
"CloudWatchLogs": { | ||
"GroupName": { | ||
"Ref": "LogingGroupE599B53B" | ||
}, | ||
"Status": "ENABLED" | ||
}, | ||
"S3Logs": { | ||
"Location": { | ||
"Ref": "LoggingBucket1E5A6F3B" | ||
}, | ||
"Status": "ENABLED" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
packages/@aws-cdk/aws-codebuild/test/integ.project-logging.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import * as logs from '@aws-cdk/aws-logs'; | ||
import * as s3 from '@aws-cdk/aws-s3'; | ||
import * as cdk from '@aws-cdk/core'; | ||
import * as codebuild from '../lib'; | ||
|
||
const app = new cdk.App(); | ||
|
||
const stack = new cdk.Stack(app, 'aws-cdk-codebuild-logging'); | ||
|
||
new codebuild.PipelineProject(stack, 'Project', { | ||
logging: { | ||
cloudWatch: { | ||
logGroup: new logs.LogGroup(stack, 'LogingGroup', { | ||
removalPolicy: cdk.RemovalPolicy.DESTROY, | ||
}), | ||
}, | ||
s3: { | ||
bucket: new s3.Bucket(stack, 'LoggingBucket', { | ||
removalPolicy: cdk.RemovalPolicy.DESTROY, | ||
}), | ||
}, | ||
}, | ||
}); | ||
|
||
app.synth(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters