Skip to content

Commit dbc9fbc

Browse files
committed
Pared down IAM role for lambda execution. Now only uses minimal permissions.
1 parent 042e153 commit dbc9fbc

File tree

1 file changed

+44
-15
lines changed

1 file changed

+44
-15
lines changed

managed-gdb-cft.yml

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
AWSTemplateFormatVersion: 2010-09-09
2-
Description: Create supporting resources for automated global database endpoint management.
2+
Description: Creates supporting resources for automated global database endpoint management solution.
33

44
Resources:
55

@@ -159,9 +159,7 @@ Resources:
159159
Targets:
160160
- Arn: !GetAtt gdbmanagedeplambda.Arn
161161
Id: "gdblambdatarget"
162-
# Tags:
163-
# - Key: Name
164-
# Value: gdb-managed-endpoint-event-rule
162+
165163

166164
#Add the lambda permission so it can be invoked by the rule
167165
gdbmanagedeplambdapermission:
@@ -175,7 +173,7 @@ Resources:
175173

176174
#Create the role needed for the lambda function.
177175
gdbmanagedeprole:
178-
Type: AWS::IAM::Role
176+
Type: 'AWS::IAM::Role'
179177
Properties:
180178
RoleName:
181179
Fn::Join:
@@ -190,21 +188,52 @@ Resources:
190188
- Fn::Split:
191189
- /
192190
- Ref: AWS::StackId
193-
Description: Role to permit the Lambda function to interact with relevant AWS APIs.
194191
AssumeRolePolicyDocument:
195192
Version: 2012-10-17
196193
Statement:
197194
- Effect: Allow
198-
Action:
199-
- sts:AssumeRole
200195
Principal:
201-
Service:
202-
- lambda.amazonaws.com
203-
ManagedPolicyArns:
204-
- arn:aws:iam::aws:policy/AmazonRDSFullAccess
205-
- arn:aws:iam::aws:policy/CloudWatchFullAccess
206-
- arn:aws:iam::aws:policy/AmazonDynamoDBFullAccess
207-
- arn:aws:iam::aws:policy/AmazonRoute53FullAccess
196+
Service: lambda.amazonaws.com
197+
Action: sts:AssumeRole
198+
Policies:
199+
- PolicyName: !Sub "${AWS::StackName}-lambda-cw-policy"
200+
PolicyDocument:
201+
Version: 2012-10-17
202+
Statement:
203+
- Effect: Allow
204+
Action:
205+
- 'logs:CreateLogGroup'
206+
- 'logs:CreateLogStream'
207+
- 'logs:PutLogEvents'
208+
Resource: !Sub "arn:aws:logs:${AWS::Region}:${AWS::AccountId}:*"
209+
- PolicyName: !Sub "${AWS::StackName}-lambda-rds-policy"
210+
PolicyDocument:
211+
Version: 2012-10-17
212+
Statement:
213+
- Effect: Allow
214+
Action:
215+
- rds:DescribeGlobalClusters
216+
- rds:DescribeDBInstances
217+
- rds:DescribeDBClusters
218+
- rds:DescribeDBClusterEndpoints
219+
Resource:
220+
- !Sub "arn:aws:rds:*:${AWS::AccountId}:cluster:*"
221+
- !Sub "arn:aws:rds::${AWS::AccountId}:global-cluster:*"
222+
- !Sub "arn:aws:rds:*:${AWS::AccountId}:db:*"
223+
- PolicyName: !Sub "${AWS::StackName}-lambda-r53-policy"
224+
PolicyDocument:
225+
Version: 2012-10-17
226+
Statement:
227+
Effect: Allow
228+
Action: route53:ChangeResourceRecordSets
229+
Resource: "*"
230+
- PolicyName: !Sub "${AWS::StackName}-lambda-ddb-policy"
231+
PolicyDocument:
232+
Version: 2012-10-17
233+
Statement:
234+
Effect: Allow
235+
Action: dynamodb:GetItem
236+
Resource: !Sub "arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${gdbmanagedepddbtbl}"
208237
Tags:
209238
- Key: Name
210239
Value: gdb-managed-endpoint-lambda-role

0 commit comments

Comments
 (0)