-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcicd-dependencies.template.yml
More file actions
179 lines (173 loc) · 6.62 KB
/
cicd-dependencies.template.yml
File metadata and controls
179 lines (173 loc) · 6.62 KB
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
AWSTemplateFormatVersion: 2010-09-09
Transform: AWS::Serverless-2016-10-31
Description: AiProxy CI/CD dependencies
Resources:
# The Artifact Store holds artifacts from codebuild/pipeline so they can be passed
# from one stage of a pipeline to the next, or so artifacts can be reviewed.
# We use a single bucket, though multiple instances of the pipeline may exist.
ArtifactStore:
Type: AWS::S3::Bucket
# This role will be used by CodeBuild to execute the CI build. Here we have
# the common policy rules required. Since we may want to create multiple
# codebuild projects for different branches, we can append policies when those
# stack resources are created (in "2-cicd/cicd.template.yml")
CodeBuildRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Statement:
- Action: ['sts:AssumeRole']
Effect: Allow
Principal:
Service:
- codebuild.amazonaws.com
- codepipeline.amazonaws.com
Version: '2012-10-17'
Path: /service-role/
Policies:
- PolicyName: AiProxyPassRole
PolicyDocument:
Statement:
- Effect: Allow
Action: iam:PassRole
Resource: !Sub arn:aws:iam::${AWS::AccountId}:role/admin/CloudFormationService
- PolicyName: AiProxyCodePipelinePolicy
PolicyDocument:
Statement:
- Effect: Allow
Action:
- "cloudformation:DescribeStacks"
- "cloudformation:DescribeStackEvents"
- "cloudformation:CreateStack"
- "cloudformation:UpdateStack"
Resource: "*" # TODO scope to specific stacks
- PolicyName: CodeBuildResourcesAccess
PolicyDocument:
Statement:
- Effect: Allow
Action:
- "logs:CreateLogGroup"
- "logs:CreateLogStream"
- "logs:PutLogEvents"
Resource:
- !Sub "arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/codebuild/*"
- Effect: Allow
Action:
- s3:GetBucketAcl
- s3:GetBucketLocation
Resource:
- !GetAtt ArtifactStore.Arn
- Effect: Allow
Action:
- s3:PutObject
- s3:PutObjectAcl
- s3:GetObject
- s3:GetObjectVersion
Resource:
- !Sub ${ArtifactStore.Arn}/*
- Effect: Allow
Action:
- ecr:GetAuthorizationToken
Resource: '*' # TODO scope to specific ECR repos
- Effect: Allow
Action: codestar-connections:UseConnection
Resource:
- !Sub arn:aws:codestar-connections:us-east-1:${AWS::AccountId}:connection/*
- PolicyName: CodeBuildSecretsAccess
PolicyDocument:
Statement:
- Effect: Allow
Action:
- "secretsmanager:GetSecretValue"
Resource:
- !Sub arn:aws:secretsmanager:${AWS::Region}:${AWS::AccountId}:secret:cicd/*
# This role will be used by CodeBuild to verify pull requests. As such it has
# very limited permissions, as any GitHub user can create a Pull Requests.
# Since we may want to create multiple codebuild projects for different
# branches, we can append policies when those stack resources are created
# (in "2-cicd/cicd.template.yml")
PublicCodeBuildRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Statement:
- Action: ['sts:AssumeRole']
Effect: Allow
Principal:
Service:
- codebuild.amazonaws.com
Version: '2012-10-17'
Path: /service-role/
Policies:
- PolicyName: PublicCodeBuildSecretsAccess
PolicyDocument:
Statement:
- Effect: Allow
Action:
- "secretsmanager:GetSecretValue"
Resource:
- !Sub arn:aws:secretsmanager:${AWS::Region}:${AWS::AccountId}:secret:cicd/docker-hub/username-ITBwTx
- !Sub arn:aws:secretsmanager:${AWS::Region}:${AWS::AccountId}:secret:cicd/docker-hub/read-only-token-SsbSj7
# This would ideally be defined in 3-app/aiproxy/template.yml, but we do
# not allow the CloudFormationServiceRole permission to CreateRole, so we
# have to define it here. TODO: Tweak permissions for the role used to create
# the cloudformation stack.
ECSTaskExecutionRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
Service:
- ecs-tasks.amazonaws.com
Action:
- sts:AssumeRole
Policies:
- PolicyName: ECRPolicy
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- ecr:GetAuthorizationToken
- ecr:BatchCheckLayerAvailability
- ecr:GetDownloadUrlForLayer
- ecr:BatchGetImage
Resource: "*"
- PolicyName: LogsPolicy
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Resource: "*"
Outputs:
CodeBuildArtifactBucket:
Description: AiProxy CodeBuild Artifact Bucket Name
Value: !Ref ArtifactStore
Export: {Name: AiProxyCodeBuildArtifactBucket}
CodeBuildRoleArn:
Description: AiProxy CodeBuild Role ARN
Value: !GetAtt CodeBuildRole.Arn
Export: {Name: AiProxyCodeBuildRoleArn}
CodeBuildRoleName:
Description: AiProxy CodeBuild Role Name
Value: !Ref CodeBuildRole
Export: {Name: AiProxyCodeBuildRoleName}
PublicCodeBuildRoleArn:
Description: AiProxy Pull Request CodeBuild Role ARN
Value: !GetAtt PublicCodeBuildRole.Arn
Export: {Name: AiProxyPublicCodeBuildRoleArn}
PublicCodeBuildRoleName:
Description: AiProxy Pull Request CodeBuild Role Name
Value: !Ref PublicCodeBuildRole
Export: {Name: AiProxyPublicCodeBuildRoleName}
ECSTaskExecutionRoleArn:
Description: AiProxy ECS Task Execution Role ARN
Value: !GetAtt ECSTaskExecutionRole.Arn
Export: {Name: AiProxyECSTaskExecutionRoleArn}