-
Notifications
You must be signed in to change notification settings - Fork 0
/
pipeline-iam-roles.yaml
141 lines (140 loc) · 4.32 KB
/
pipeline-iam-roles.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
AWSTemplateFormatVersion: 2010-09-09
Description: "Account IAM Roles Deployment Needed for CI/CD Pipeline for Infrastructure Deployment"
Metadata:
AWS::CloudFormation::Interface:
ParameterGroups:
- Label:
default: Account Configuration
Parameters:
- pToolingAccountId
Parameters:
pToolingAccountId:
Type: String
Description: "The AWS Account ID that will be used as the Tooling Account."
AllowedPattern: '^[0-9]{12}$'
ConstraintDescription: "This must be a 12 character string."
MinLength: 12
MaxLength: 12
Resources:
# IAM Roles
rIamRoleCloudFormationAdmin:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Principal:
Service:
- "cloudformation.amazonaws.com"
Action:
- "sts:AssumeRole"
Path: "/"
ManagedPolicyArns:
- "arn:aws:iam::aws:policy/AdministratorAccess"
- !Ref rIamPolicyCrossAccountS3
RoleName: "CloudFormation-Admin"
rIamRolePipelineCrossAccountAccessRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Principal:
AWS:
- !Sub "arn:aws:iam::${pToolingAccountId}:root"
Action:
- "sts:AssumeRole"
Path: "/"
ManagedPolicyArns:
- !Ref rIamPolicyPipelineCrossAccountAccessRole
- "arn:aws:iam::aws:policy/AWSCodeDeployRoleForECS"
RoleName: "Pipeline-Cross-Account-Access"
rIamRoleEcsTaskExecution:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Principal:
Service:
- "ecs-tasks.amazonaws.com"
Action:
- "sts:AssumeRole"
Path: "/"
ManagedPolicyArns:
- "arn:aws:iam::aws:policy/AdministratorAccess"
- !Ref rIamPolicyEcsTaskExecution
RoleName: "ECS-Task-Execution"
# IAM Policies
rIamPolicyPipelineCrossAccountAccessRole:
Type: AWS::IAM::ManagedPolicy
Properties:
ManagedPolicyName: "Pipeline-Cross-Account-Access"
Path: "/"
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Action:
- "kms:DescribeKey"
- "kms:GenerateDataKey*"
- "kms:Encrypt"
- "kms:ReEncrypt*"
- "kms:Decrypt"
Resource:
- !Sub "arn:aws:kms:eu-west-2:${pToolingAccountId}:key/*"
- Effect: "Allow"
Action:
- "cloudformation:*"
- "codedeploy:*"
- "ecs:*"
- "iam:PassRole"
- "lambda:UpdateFunctionCode"
Resource:
- "*"
- Effect: "Allow"
Action:
- "s3:Get*"
- "s3:Put*"
- "s3:ListBucket"
Resource:
- !Sub "arn:aws:s3:::codepipeline-${AWS::Region}-${pToolingAccountId}/*"
- !Sub "arn:aws:s3:::codepipeline-${AWS::Region}-${pToolingAccountId}"
rIamPolicyEcsTaskExecution:
Type: AWS::IAM::ManagedPolicy
Properties:
ManagedPolicyName: "ECS-Task-Execution"
Path: "/"
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Action:
- "ecr:*"
Resource:
- !Sub "arn:aws:ecr:${AWS::Region}:${pToolingAccountId}:repository/*"
- Effect: "Allow"
Action:
- "logs:CreateLogStream"
- "logs:PutLogEvents"
Resource:
- "*"
rIamPolicyCrossAccountS3:
Type: AWS::IAM::ManagedPolicy
Properties:
ManagedPolicyName: "Cross-Account-S3-Access"
Path: "/"
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Action:
- "s3:Get*"
- "s3:Put*"
- "s3:ListBucket"
Resource:
- !Sub "arn:aws:s3:::lambda-resources-${AWS::Region}-${pToolingAccountId}/*"
- !Sub "arn:aws:s3:::lambda-resources-${AWS::Region}-${pToolingAccountId}"