Skip to content

Commit cb68120

Browse files
author
jradtilbrook
committed
Change lambda managed policies to explicit policy
1 parent a2b1cb8 commit cb68120

File tree

1 file changed

+28
-17
lines changed

1 file changed

+28
-17
lines changed

templates/aws-stack.yml

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ Parameters:
110110
Type: String
111111
Default: ""
112112

113+
BuildkiteAgentTokenParameterStoreKMSKey:
114+
Description: AWS KMS key ID used to encrypt the SSM parameter (if encrypted)
115+
Type: String
116+
Default: ""
117+
113118
BuildkiteAgentTags:
114119
Description: Additional tags seperated by commas to provide to the agent. E.g os=linux,llamas=always
115120
Type: String
@@ -272,11 +277,6 @@ Parameters:
272277
Description: Optional - Comma separated list of managed IAM policy ARNs to attach to the instance role
273278
Default: ""
274279

275-
LambdaManagedPolicyARN:
276-
Type: CommaDelimitedList
277-
Description: Optional - Comma separated list of managed IAM policy ARNs to attach to the autoscaling lambda
278-
Default: ""
279-
280280
InstanceRoleName:
281281
Type: String
282282
Description: Optional - A name for the IAM Role attached to the Instance Profile
@@ -426,15 +426,15 @@ Conditions:
426426
UseManagedPolicyARN:
427427
!Not [ !Equals [ !Join [ "", !Ref ManagedPolicyARN ], "" ] ]
428428

429-
UseLambdaManagedPolicyARN:
430-
!Not [ !Equals [ !Join [ "", !Ref LambdaManagedPolicyARN ], "" ] ]
431-
432429
UseECR:
433430
!Not [ !Equals [ !Ref ECRAccessPolicy, "none" ] ]
434431

435432
UseSSMAgentToken:
436433
!Not [ !Equals [ !Ref BuildkiteAgentTokenParameterStorePath, "" ] ]
437434

435+
AgentTokenEncrypted:
436+
!Not [ !Equals [ !Ref BuildkiteAgentTokenParameterStoreKMSKey, "" ] ]
437+
438438
HasVariableSize:
439439
!Not [ !Equals [ !Ref MaxSize, !Ref MinSize ] ]
440440

@@ -916,15 +916,7 @@ Resources:
916916
Action:
917917
- sts:AssumeRole
918918
ManagedPolicyArns: !Split
919-
- ','
920-
- !Join
921-
- ','
922-
- - arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
923-
- !If
924-
- UseLambdaManagedPolicyARN
925-
- !Ref 'AWS::NoValue'
926-
- !Join [ ',', !Ref LambdaManagedPolicyARN ] ]
927-
- !Ref 'AWS::NoValue'
919+
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
928920
Policies:
929921
- PolicyName: AutoScalingGroups
930922
PolicyDocument:
@@ -935,6 +927,25 @@ Resources:
935927
- autoscaling:DescribeAutoScalingGroups
936928
- autoscaling:SetDesiredCapacity
937929
Resource: '*'
930+
- !If
931+
- AgentTokenEncrypted
932+
- - PolicyName: DecryptAgentToken
933+
PolicyDocument:
934+
Version: '2012-10-17'
935+
Statement:
936+
- Effect: Allow
937+
Action:
938+
- kms:Decrypt
939+
Resource: !Sub arn:aws:kms:${AWS::Region}:${AWS::AccountId}:key/${BuildkiteAgentTokenParameterStoreKMSKey}
940+
- PolicyName: ReadAgentToken
941+
PolicyDocument:
942+
Version: '2012-10-17'
943+
Statement:
944+
- Effect: Allow
945+
Action:
946+
- ssm:GetParameter
947+
Resource: !Sub arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:parameter/${BuildkiteAgentTokenParameterStorePath}
948+
- !Ref 'AWS::NoValue'
938949
- PolicyName: WriteCloudwatchMetrics
939950
PolicyDocument:
940951
Version: '2012-10-17'

0 commit comments

Comments
 (0)