@@ -9,6 +9,8 @@ Metadata:
9
9
default : Buildkite Configuration
10
10
Parameters :
11
11
- BuildkiteAgentToken
12
+ - BuildkiteAgentTokenParameterStorePath
13
+ - BuildkiteAgentTokenParameterStoreKMSKey
12
14
- BuildkiteQueue
13
15
14
16
- Label :
@@ -102,7 +104,17 @@ Parameters:
102
104
Description : Buildkite agent registration token
103
105
Type : String
104
106
NoEcho : true
105
- MinLength : 1
107
+ Default : " "
108
+
109
+ BuildkiteAgentTokenParameterStorePath :
110
+ Description : AWS SSM path to the Buildkite agent registration token (this takes precedence over BuildkiteAgentToken)
111
+ Type : String
112
+ Default : " "
113
+
114
+ BuildkiteAgentTokenParameterStoreKMSKey :
115
+ Description : AWS KMS key ID used to encrypt the SSM parameter (if encrypted)
116
+ Type : String
117
+ Default : " "
106
118
107
119
BuildkiteAgentTags :
108
120
Description : Additional tags seperated by commas to provide to the agent. E.g os=linux,llamas=always
@@ -418,6 +430,12 @@ Conditions:
418
430
UseECR :
419
431
!Not [ !Equals [ !Ref ECRAccessPolicy, "none" ] ]
420
432
433
+ UseSSMAgentToken :
434
+ !Not [ !Equals [ !Ref BuildkiteAgentTokenParameterStorePath, "" ] ]
435
+
436
+ UseCustomerManagedKeyForParameterStore :
437
+ !Not [ !Equals [ !Ref BuildkiteAgentTokenParameterStoreKMSKey, "" ] ]
438
+
421
439
HasVariableSize :
422
440
!Not [ !Equals [ !Ref MaxSize, !Ref MinSize ] ]
423
441
@@ -771,6 +789,7 @@ Resources:
771
789
$Env:BUILDKITE_SCALE_IN_IDLE_PERIOD="${ScaleInIdlePeriod}"
772
790
$Env:BUILDKITE_SECRETS_BUCKET="${LocalSecretsBucket}"
773
791
$Env:BUILDKITE_AGENT_TOKEN="${BuildkiteAgentToken}"
792
+ $Env:BUILDKITE_AGENT_TOKEN_PATH="${BuildkiteAgentTokenParameterStorePath}"
774
793
$Env:BUILDKITE_AGENTS_PER_INSTANCE="${AgentsPerInstance}"
775
794
$Env:BUILDKITE_AGENT_TAGS="${BuildkiteAgentTags}"
776
795
$Env:BUILDKITE_AGENT_TIMESTAMP_LINES="${BuildkiteAgentTimestampLines}"
@@ -811,6 +830,7 @@ Resources:
811
830
BUILDKITE_SCALE_IN_IDLE_PERIOD=${ScaleInIdlePeriod} \
812
831
BUILDKITE_SECRETS_BUCKET="${LocalSecretsBucket}" \
813
832
BUILDKITE_AGENT_TOKEN="${BuildkiteAgentToken}" \
833
+ BUILDKITE_AGENT_TOKEN_PATH="${BuildkiteAgentTokenParameterStorePath}" \
814
834
BUILDKITE_AGENTS_PER_INSTANCE="${AgentsPerInstance}" \
815
835
BUILDKITE_AGENT_TAGS="${BuildkiteAgentTags}" \
816
836
BUILDKITE_AGENT_TIMESTAMP_LINES="${BuildkiteAgentTimestampLines}" \
@@ -897,7 +917,7 @@ Resources:
897
917
- lambda.amazonaws.com
898
918
Action :
899
919
- sts:AssumeRole
900
- ManagedPolicyArns :
920
+ ManagedPolicyArns : !Split
901
921
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
902
922
Policies :
903
923
- PolicyName : AutoScalingGroups
@@ -909,6 +929,25 @@ Resources:
909
929
- autoscaling:DescribeAutoScalingGroups
910
930
- autoscaling:SetDesiredCapacity
911
931
Resource : ' *'
932
+ - !If
933
+ - UseCustomerManagedKeyForParameterStore
934
+ - - PolicyName : DecryptAgentToken
935
+ PolicyDocument :
936
+ Version : ' 2012-10-17'
937
+ Statement :
938
+ - Effect : Allow
939
+ Action :
940
+ - kms:Decrypt
941
+ Resource : !Sub arn:aws:kms:${AWS::Region}:${AWS::AccountId}:key/${BuildkiteAgentTokenParameterStoreKMSKey}
942
+ - PolicyName : ReadAgentToken
943
+ PolicyDocument :
944
+ Version : ' 2012-10-17'
945
+ Statement :
946
+ - Effect : Allow
947
+ Action :
948
+ - ssm:GetParameter
949
+ Resource : !Sub arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:parameter/${BuildkiteAgentTokenParameterStorePath}
950
+ - !Ref ' AWS::NoValue'
912
951
- PolicyName : WriteCloudwatchMetrics
913
952
PolicyDocument :
914
953
Version : ' 2012-10-17'
@@ -941,7 +980,8 @@ Resources:
941
980
MemorySize : 128
942
981
Environment :
943
982
Variables :
944
- BUILDKITE_AGENT_TOKEN : !Ref BuildkiteAgentToken
983
+ BUILDKITE_AGENT_TOKEN : !If [ UseSSMAgentToken, !Ref 'AWS::NoValue', !Ref BuildkiteAgentToken ]
984
+ BUILDKITE_AGENT_TOKEN_SSM_KEY : !Ref BuildkiteAgentTokenParameterStorePath
945
985
BUILDKITE_QUEUE : !Ref BuildkiteQueue
946
986
AGENTS_PER_INSTANCE : !Ref AgentsPerInstance
947
987
CLOUDWATCH_METRICS : " 1"
0 commit comments