-
Notifications
You must be signed in to change notification settings - Fork 0
/
ci-iam.yml
179 lines (176 loc) · 6.38 KB
/
ci-iam.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
---
AWSTemplateFormatVersion: 2010-09-09
Description:
IAM permissions for deploying the URL Shortener
Parameters:
ServerlessServiceName:
Type: String
Default: urlshrtnr
Description: Enter the service name from serverless.yml. Must be lowercase.
AllowedPattern: "^[a-z]+$"
HostedZoneId:
Type: AWS::Route53::HostedZone::Id
Description: Target Route53 zone id.
Resources:
ServerlessCloudformationPolicy:
Type: AWS::IAM::ManagedPolicy
Properties:
Description: Policy for Cloudformation Serverless deployments
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- iam:CreateRole
- iam:DeleteRole
- iam:GetRole
- iam:GetRolePolicy
- iam:PutRolePolicy
- iam:DeleteRolePolicy
- iam:PassRole
Resource: !Sub "arn:aws:iam::${AWS::AccountId}:role/${ServerlessServiceName}*"
- Effect: Allow
Action:
- apigateway:POST
Resource: !Sub "arn:aws:apigateway:${AWS::Region}::/restapis"
- Effect: Allow
Action:
- apigateway:DELETE
- apigateway:GET
- apigateway:PATCH
- apigateway:POST
- apigateway:PUT
- apigateway:UpdateRestApiPolicy
Resource: !Sub "arn:aws:apigateway:${AWS::Region}::/restapis/*"
- Effect: Allow
Action:
- dynamodb:CreateTable
- dynamodb:DeleteTable
- dynamodb:DescribeTable
- dynamodb:ListTagsOfResource
- dynamodb:TagResource
Resource: !Sub "arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${ServerlessServiceName}*"
- Effect: Allow
Action:
- lambda:*
Resource: !Sub "arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${ServerlessServiceName}*"
- Effect: Allow
Action:
- logs:DescribeLogGroups
Resource: !Sub "arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group::log-stream:"
- Effect: Allow
Action:
- logs:CreateLogGroup
- logs:DeleteLogGroup
- logs:DescribeLogGroups
Resource: !Sub "arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/${ServerlessServiceName}*"
- Effect: Allow
Action:
- s3:*
Resource:
- !Sub "arn:aws:s3:::${ServerlessServiceName}*"
- !Sub "arn:aws:s3:::${ServerlessServiceName}*/*"
- Effect: Allow
Action:
- states:CreateStateMachine
- states:TagResource
Resource: !Sub "arn:aws:states:${AWS::Region}:${AWS::AccountId}:stateMachine:*"
- Effect: Allow
Action:
- states:*
Resource:
- !Sub "arn:aws:states:${AWS::Region}:${AWS::AccountId}:stateMachine:${ServerlessServiceName}*"
- Effect: Allow
Action:
- cloudfront:CreateDistribution
- cloudfront:CreateDistributionWithTags
- cloudfront:GetDistribution
- cloudfront:UpdateDistribution
- cloudfront:DeleteDistribution
- cloudfront:TagResource
Resource: "*"
- Effect: Allow
Action:
- route53:ListHostedZones
Resource: "*"
- Effect: Allow
Action:
- route53:ChangeResourceRecordSets
- route53:ListResourceRecordSets
Resource: !Sub "arn:aws:route53:::hostedzone/${HostedZoneId}"
- Effect: Allow
Action:
- route53:GetChange
Resource: !Sub "arn:aws:route53:::change/*"
ServerlessCloudformationRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- cloudformation.amazonaws.com
Action:
- sts:AssumeRole
ManagedPolicyArns:
- !Ref ServerlessCloudformationPolicy
ServerlessDeploymentPolicy:
Type: AWS::IAM::ManagedPolicy
Properties:
Description: Policy to start Serverless deployments
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- iam:PassRole
Resource: !GetAtt ServerlessCloudformationRole.Arn
- Effect: Allow
Action:
- cloudformation:DescribeStacks
- cloudformation:ValidateTemplate
Resource: "*"
- Effect: Allow
Action:
- cloudformation:CreateStack
- cloudformation:UpdateStack
- cloudformation:DeleteStack
- cloudformation:DescribeStackEvents
- cloudformation:DescribeStackResource
- cloudformation:ListStackResources
Resource: !Sub "arn:aws:cloudformation:${AWS::Region}:${AWS::AccountId}:stack/${ServerlessServiceName}*"
- Effect: Allow
Action:
- ssm:GetParameter
Resource: !Sub "arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:parameter/${ServerlessServiceName}/*"
- Effect: Allow
Action:
- lambda:*
Resource:
- !Sub "arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${ServerlessServiceName}*"
- Effect: Allow
Action:
- apigateway:GET
Resource:
- !Sub "arn:aws:apigateway:${AWS::Region}::/restapis"
- !Sub "arn:aws:apigateway:${AWS::Region}::/restapis/*"
- Effect: Allow
Action:
- apigateway:PATCH
Resource: !Sub "arn:aws:apigateway:${AWS::Region}::/restapis/*/stages/*"
- Effect: Allow
Action:
- s3:ListBucket
- s3:GetObject
- s3:PutObject
- s3:DeleteObject
Resource:
- !Sub "arn:aws:s3:::${ServerlessServiceName}*"
- !Sub "arn:aws:s3:::${ServerlessServiceName}*/*"
Outputs:
CloudformationDeploymentRoleOutput:
Value: !GetAtt ServerlessCloudformationRole.Arn
Export:
Name: !Sub "${ServerlessServiceName}CloudformationRole"