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(codepipeline): generate a Role for every AWS-owned Action used in a Pipeline #3105

Merged
merged 1 commit into from
Jun 28, 2019
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
288 changes: 223 additions & 65 deletions packages/@aws-cdk/app-delivery/test/integ.cicd.expected.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"Resources": {
"ArtifactBucket7410C9EF": {
"DeletionPolicy": "Delete",
"Type": "AWS::S3::Bucket"
"Type": "AWS::S3::Bucket",
"DeletionPolicy": "Delete"
},
"CodePipelineRoleB3A660B4": {
"Type": "AWS::IAM::Role",
Expand Down Expand Up @@ -70,75 +70,22 @@
]
},
{
"Action": "iam:PassRole",
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Resource": {
"Fn::GetAtt": [
"CodePipelineDeployChangeSetRoleF9F2B343",
"CodePipelineDeployExecuteCodePipelineActionRoleAE36AF49",
"Arn"
]
}
},
{
"Action": [
"cloudformation:CreateChangeSet",
"cloudformation:DeleteChangeSet",
"cloudformation:DescribeChangeSet",
"cloudformation:DescribeStacks"
],
"Condition": {
"StringEqualsIfExists": {
"cloudformation:ChangeSetName": "CICD-ChangeSet"
}
},
"Effect": "Allow",
"Resource": {
"Fn::Join": [
"",
[
"arn:",
{
"Ref": "AWS::Partition"
},
":cloudformation:",
{
"Ref": "AWS::Region"
},
":",
{
"Ref": "AWS::AccountId"
},
":stack/CICD/*"
]
]
}
},
{
"Action": "cloudformation:ExecuteChangeSet",
"Condition": {
"StringEquals": {
"cloudformation:ChangeSetName": "CICD-ChangeSet"
}
},
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Resource": {
"Fn::Join": [
"",
[
"arn:",
{
"Ref": "AWS::Partition"
},
":cloudformation:",
{
"Ref": "AWS::Region"
},
":",
{
"Ref": "AWS::AccountId"
},
":stack/CICD/*"
]
"Fn::GetAtt": [
"CodePipelineDeployChangeSetCodePipelineActionRoleB3BCDD8A",
"Arn"
]
}
}
Expand Down Expand Up @@ -202,15 +149,15 @@
},
"Configuration": {
"StackName": "CICD",
"ActionMode": "CHANGE_SET_REPLACE",
"ChangeSetName": "CICD-ChangeSet",
"TemplatePath": "Artifact_CICDGitHubF8BA7ADD::CICD.template.yaml",
"RoleArn": {
"Fn::GetAtt": [
"CodePipelineDeployChangeSetRoleF9F2B343",
"Arn"
]
}
},
"ActionMode": "CHANGE_SET_REPLACE",
"ChangeSetName": "CICD-ChangeSet",
"TemplatePath": "Artifact_CICDGitHubF8BA7ADD::CICD.template.yaml"
},
"InputArtifacts": [
{
Expand All @@ -219,6 +166,12 @@
],
"Name": "ChangeSet",
"OutputArtifacts": [],
"RoleArn": {
"Fn::GetAtt": [
"CodePipelineDeployChangeSetCodePipelineActionRoleB3BCDD8A",
"Arn"
]
},
"RunOrder": 10
},
{
Expand All @@ -236,6 +189,12 @@
"InputArtifacts": [],
"Name": "Execute",
"OutputArtifacts": [],
"RoleArn": {
"Fn::GetAtt": [
"CodePipelineDeployExecuteCodePipelineActionRoleAE36AF49",
"Arn"
]
},
"RunOrder": 999
}
],
Expand All @@ -254,6 +213,205 @@
"CodePipelineRoleB3A660B4"
]
},
"CodePipelineDeployExecuteCodePipelineActionRoleAE36AF49": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"AWS": {
"Fn::Join": [
"",
[
"arn:",
{
"Ref": "AWS::Partition"
},
":iam::",
{
"Ref": "AWS::AccountId"
},
":root"
]
]
}
}
}
],
"Version": "2012-10-17"
}
}
},
"CodePipelineDeployExecuteCodePipelineActionRoleDefaultPolicy2B66E78C": {
"Type": "AWS::IAM::Policy",
"Properties": {
"PolicyDocument": {
"Statement": [
{
"Action": "cloudformation:ExecuteChangeSet",
"Condition": {
"StringEquals": {
"cloudformation:ChangeSetName": "CICD-ChangeSet"
}
},
"Effect": "Allow",
"Resource": {
"Fn::Join": [
"",
[
"arn:",
{
"Ref": "AWS::Partition"
},
":cloudformation:",
{
"Ref": "AWS::Region"
},
":",
{
"Ref": "AWS::AccountId"
},
":stack/CICD/*"
]
]
}
}
],
"Version": "2012-10-17"
},
"PolicyName": "CodePipelineDeployExecuteCodePipelineActionRoleDefaultPolicy2B66E78C",
"Roles": [
{
"Ref": "CodePipelineDeployExecuteCodePipelineActionRoleAE36AF49"
}
]
}
},
"CodePipelineDeployChangeSetCodePipelineActionRoleB3BCDD8A": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"AWS": {
"Fn::Join": [
"",
[
"arn:",
{
"Ref": "AWS::Partition"
},
":iam::",
{
"Ref": "AWS::AccountId"
},
":root"
]
]
}
}
}
],
"Version": "2012-10-17"
}
}
},
"CodePipelineDeployChangeSetCodePipelineActionRoleDefaultPolicy87FA0C1E": {
"Type": "AWS::IAM::Policy",
"Properties": {
"PolicyDocument": {
"Statement": [
{
"Action": "iam:PassRole",
"Effect": "Allow",
"Resource": {
"Fn::GetAtt": [
"CodePipelineDeployChangeSetRoleF9F2B343",
"Arn"
]
}
},
{
"Action": [
"s3:GetObject*",
"s3:GetBucket*",
"s3:List*"
],
"Effect": "Allow",
"Resource": [
{
"Fn::GetAtt": [
"ArtifactBucket7410C9EF",
"Arn"
]
},
{
"Fn::Join": [
"",
[
{
"Fn::GetAtt": [
"ArtifactBucket7410C9EF",
"Arn"
]
},
"/*"
]
]
}
]
},
{
"Action": [
"cloudformation:CreateChangeSet",
"cloudformation:DeleteChangeSet",
"cloudformation:DescribeChangeSet",
"cloudformation:DescribeStacks"
],
"Condition": {
"StringEqualsIfExists": {
"cloudformation:ChangeSetName": "CICD-ChangeSet"
}
},
"Effect": "Allow",
"Resource": {
"Fn::Join": [
"",
[
"arn:",
{
"Ref": "AWS::Partition"
},
":cloudformation:",
{
"Ref": "AWS::Region"
},
":",
{
"Ref": "AWS::AccountId"
},
":stack/CICD/*"
]
]
}
}
],
"Version": "2012-10-17"
},
"PolicyName": "CodePipelineDeployChangeSetCodePipelineActionRoleDefaultPolicy87FA0C1E",
"Roles": [
{
"Ref": "CodePipelineDeployChangeSetCodePipelineActionRoleB3BCDD8A"
}
]
}
},
"CodePipelineDeployChangeSetRoleF9F2B343": {
"Type": "AWS::IAM::Role",
"Properties": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { countResources, expect, haveResource, isSuperObject } from '@aws-cdk/assert';
import { expect, haveResource, isSuperObject } from '@aws-cdk/assert';
import cfn = require('@aws-cdk/aws-cloudformation');
import codebuild = require('@aws-cdk/aws-codebuild');
import codepipeline = require('@aws-cdk/aws-codepipeline');
Expand Down Expand Up @@ -268,9 +268,6 @@ export = nodeunit.testCase({
}));

// THEN //
// there should be 3 policies 1. CodePipeline, 2. Codebuild, 3.
// ChangeSetDeploy Action
expect(pipelineStack).to(countResources('AWS::IAM::Policy', 3));
expect(pipelineStack).to(haveResource('AWS::IAM::Policy', {
PolicyDocument: {
Version: '2012-10-17',
Expand Down
Loading