-
Notifications
You must be signed in to change notification settings - Fork 3
/
github_ci_template.yml
257 lines (249 loc) · 9.56 KB
/
github_ci_template.yml
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: MIT-0
---
AWSTemplateFormatVersion: "2010-09-09"
Description: Guidance for Organizations on AWS - GitHub Actions CI/CD
Parameters:
pStackName:
Type: String
Description: Name of the stack to use for this deployment
Default: DO-NOT-DELETE-organization
pGithubOrganization:
Type: String
Description: GitHub Organization or User
pGitHubRepository:
Type: String
Description: GitHub Repository
Default: orgs-prescriptive-guidance
Resources:
rCloudFormationRole:
Type: "AWS::IAM::Role"
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
Effect: Allow
Principal:
Service: !Sub "cloudformation.${AWS::URLSuffix}"
Action: "sts:AssumeRole"
Description: !Sub "DO NOT DELETE - Used by CloudFormation. Created by CloudFormation ${AWS::StackId}"
ManagedPolicyArns:
- !Sub "arn:${AWS::Partition}:iam::aws:policy/AWSOrganizationsFullAccess"
- !Sub "arn:${AWS::Partition}:iam::aws:policy/AWSCloudFormationFullAccess"
- !Sub "arn:${AWS::Partition}:iam::aws:policy/IAMReadOnlyAccess"
- !Sub "arn:${AWS::Partition}:iam::aws:policy/AWSSSOReadOnly"
Policies:
- PolicyName: CloudFormationPolicy
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- "iam:AddUserToGroup"
- "iam:CreateGroup"
- "iam:CreateServiceLinkedRole"
- "iam:CreateRole"
- "iam:CreateUser"
- "iam:DeleteGroup"
- "iam:DeleteRole"
- "iam:DeleteRolePolicy"
- "iam:DeleteUser"
- "iam:DeleteUserPolicy"
- "iam:PutRolePolicy"
- "iam:PutUserPolicy"
- "iam:RemoveUserFromGroup"
- "iam:TagRole"
- "iam:TagUser"
- "kms:CreateGrant"
- "kms:Decrypt"
- "kms:DescribeKey"
- "kms:Encrypt"
- "lambda:ListTags"
- "lambda:TagResource"
- "lambda:CreateFunction"
- "lambda:DeleteFunction"
- "lambda:GetFunction"
- "lambda:GetFunctionCodeSigningConfig"
- "lambda:GetFunctionRecursionConfig"
- "lambda:GetRuntimeManagementConfig"
- "lambda:InvokeFunction"
- "lambda:UpdateFunctionCode"
- "logs:DescribeLogGroups"
- "logs:ListTagsForResource"
- "logs:TagResource"
- "logs:CreateLogGroup"
- "logs:DeleteLogGroup"
- "logs:PutRetentionPolicy"
- "sso:CreatePermissionSet"
- "sso:AttachCustomerManagedPolicyReferenceToPermissionSet"
- "sso:AttachManagedPolicyToPermissionSet"
- "sso:DeleteInlinePolicyFromPermissionSet"
- "sso:DeletePermissionSet"
- "sso:DeletePermissionsBoundaryFromPermissionSet"
- "sso:DeletePermissionsPolicy"
- "sso:ProvisionPermissionSet"
- "sso:PutInlinePolicyToPermissionSet"
- "sso:PutPermissionsBoundaryToPermissionSet"
- "sso:PutPermissionsPolicy"
- "sso:StartSSO"
- "sso:TagResource"
- "sso:UntagResource"
- "sso:UpdatePermissionSet"
Resource: "*"
- Effect: Allow
Action: "s3:GetObject"
Resource: !Sub "${rArtifactBucket.Arn}/*"
- Effect: Allow
Action: "iam:PassRole"
Resource: "*"
Condition:
StringEquals:
"iam:PassedToService": "lambda.amazonaws.com"
Tags:
- Key: "aws-cloudformation:stack-name"
Value: !Ref "AWS::StackName"
- Key: "aws-cloudformation:stack-id"
Value: !Ref "AWS::StackId"
- Key: "aws-cloudformation:logical-id"
Value: rCloudFormationRole
rGitHubRole:
Type: "AWS::IAM::Role"
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
Effect: Allow
Principal:
Federated: !Ref rGitHubProvider
Action: "sts:AssumeRoleWithWebIdentity"
Condition:
StringEquals:
"token.actions.githubusercontent.com:aud": "sts.amazonaws.com"
StringLike:
"token.actions.githubusercontent.com:sub": !Sub "repo:${pGithubOrganization}/${pGitHubRepository}:*"
Description: !Sub "DO NOT DELETE - Used by GitHub Actions. Created by CloudFormation ${AWS::StackId}"
ManagedPolicyArns:
- !Sub "arn:${AWS::Partition}:iam::aws:policy/AWSCloudFormationReadOnlyAccess"
Policies:
- PolicyName: GitHubPolicy
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action: "iam:PassRole"
Resource: !GetAtt rCloudFormationRole.Arn
Condition:
StringEquals:
"aws:ResourceAccount": "${aws:PrincipalAccount}"
"iam:PassedToService": !Sub "cloudformation.${AWS::URLSuffix}"
- Effect: Allow
Action:
- "cloudformation:ContinueUpdateRollback"
- "cloudformation:CreateChangeSet"
- "cloudformation:CreateStack"
- "cloudformation:DeleteStack"
- "cloudformation:RollbackStack"
- "cloudformation:UpdateStack"
Resource: !Sub "arn:${AWS::Partition}:cloudformation:*:${AWS::AccountId}:stack/${pStackName}*"
Condition:
ArnLike:
"cloudformation:RoleArn": !GetAtt rCloudFormationRole.Arn
"Null":
"cloudformation:ImportResourceTypes": true
- Effect: Allow
Action:
- "cloudformation:CancelUpdateStack"
- "cloudformation:DeleteChangeSet"
- "cloudformation:DetectStackDrift"
- "cloudformation:DetectStackResourceDrift"
- "cloudformation:ExecuteChangeSet"
- "cloudformation:TagResource"
- "cloudformation:UntagResource"
- "cloudformation:UpdateTerminationProtection"
Resource: !Sub "arn:${AWS::Partition}:cloudformation:*:${AWS::AccountId}:stack/${pStackName}*"
- Effect: Allow
Action:
- "cloudformation:ValidateTemplate"
- "cloudformation:EstimateTemplateCost"
Resource: "*"
- Effect: Allow
Action:
- "s3:GetObject"
- "s3:GetObjectVersion"
- "s3:PutObject"
Resource: !Sub "${rArtifactBucket.Arn}/*"
- Effect: Allow
Action:
- "s3:ListBucket"
- "s3:GetBucketPolicy"
- "s3:GetBucketVersioning"
- "s3:GetBucketLocation"
Resource: !GetAtt rArtifactBucket.Arn
rGitHubProvider:
Type: "AWS::IAM::OIDCProvider"
Properties:
ClientIdList:
- "sts.amazonaws.com"
Tags:
- Key: "aws-cloudformation:stack-name"
Value: !Ref "AWS::StackName"
- Key: "aws-cloudformation:stack-id"
Value: !Ref "AWS::StackId"
- Key: "aws-cloudformation:logical-id"
Value: rGitHubProvider
Url: https://token.actions.githubusercontent.com
rArtifactBucket:
Type: "AWS::S3::Bucket"
UpdateReplacePolicy: Delete
DeletionPolicy: RetainExceptOnCreate
Properties:
BucketEncryption:
ServerSideEncryptionConfiguration:
- ServerSideEncryptionByDefault:
SSEAlgorithm: AES256
LifecycleConfiguration:
Rules:
- ExpirationInDays: 30
Id: ExpireAfter30Days
Status: Enabled
- AbortIncompleteMultipartUpload:
DaysAfterInitiation: 1
Id: ExpireNonCurrentAndIncompleteMultipartUpload
NoncurrentVersionExpiration:
NoncurrentDays: 1
Status: Enabled
OwnershipControls:
Rules:
- ObjectOwnership: BucketOwnerEnforced
PublicAccessBlockConfiguration:
BlockPublicAcls: true
BlockPublicPolicy: true
IgnorePublicAcls: true
RestrictPublicBuckets: true
VersioningConfiguration:
Status: Enabled
rArtifactBucketPolicy:
Type: "AWS::S3::BucketPolicy"
Properties:
Bucket: !Ref rArtifactBucket
PolicyDocument:
Statement:
- Effect: Deny
Principal: "*"
Action: "s3:*"
Resource:
- !Sub "${rArtifactBucket.Arn}/*"
- !GetAtt rArtifactBucket.Arn
Condition:
Bool:
"aws:SecureTransport": false
Outputs:
oCloudFormationRoleArn:
Description: CloudFormation IAM Role ARN
Value: !GetAtt rCloudFormationRole.Arn
oGitHubRoleArn:
Description: GitHub Actions IAM Role ARN
Value: !GetAtt rGitHubRole.Arn
oArtifactBucket:
Description: Artifact Bucket Name
Value: !Ref rArtifactBucket