Skip to content

Commit 28906c4

Browse files
chore(CFN): Add region-limited KMS key policies and roles (#184)
1 parent 33a8c85 commit 28906c4

File tree

1 file changed

+114
-0
lines changed

1 file changed

+114
-0
lines changed

cfn/CI.yaml

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,38 @@ Resources:
256256
- !Sub "arn:aws:kms:*:658956600833:key/*"
257257
- !Sub "arn:aws:kms:*:658956600833:alias/*"
258258

259+
KMSUsageOnlyUsEast1Keys:
260+
Type: "AWS::IAM::ManagedPolicy"
261+
Properties:
262+
ManagedPolicyName: !Sub "${ProjectName}-KMS-only-us-east-1"
263+
PolicyDocument:
264+
Version: '2012-10-17'
265+
Statement:
266+
- Effect: Allow
267+
Action:
268+
- kms:Encrypt
269+
- kms:Decrypt
270+
- kms:GenerateDataKey
271+
Resource:
272+
- !Sub "arn:aws:kms:us-east-1:658956600833:key/*"
273+
- !Sub "arn:aws:kms:us-east-1:658956600833:alias/*"
274+
275+
KMSUsageOnlyEuWest1Keys:
276+
Type: "AWS::IAM::ManagedPolicy"
277+
Properties:
278+
ManagedPolicyName: !Sub "${ProjectName}-KMS-only-eu-west-1"
279+
PolicyDocument:
280+
Version: '2012-10-17'
281+
Statement:
282+
- Effect: Allow
283+
Action:
284+
- kms:Encrypt
285+
- kms:Decrypt
286+
- kms:GenerateDataKey
287+
Resource:
288+
- !Sub "arn:aws:kms:eu-west-1:658956600833:key/*"
289+
- !Sub "arn:aws:kms:eu-west-1:658956600833:alias/*"
290+
259291
GitHubCIRole:
260292
Type: 'AWS::IAM::Role'
261293
Properties:
@@ -291,3 +323,85 @@ Resources:
291323
}
292324
]
293325
}
326+
327+
GithubCIRoleOnlyUsEast1Keys:
328+
Type: 'AWS::IAM::Role'
329+
Properties:
330+
RoleName: !Sub "GitHub-CI-${ProjectName}-Role-only-us-east-1-KMS-keys"
331+
Description: "Access DDB, KMS, & CA Resources for CI from GitHub. Only grants access to use keys in us-east-1 region. Created for use by CI while executing Custom Client Supplier Example."
332+
ManagedPolicyArns:
333+
- Fn::ImportValue: "Polymorph-CA-GitHubCAReadPolicyArn"
334+
- "arn:aws:iam::370957321024:policy/ESDK-Dafny-DDB-ReadWriteDelete-us-west-2"
335+
- "arn:aws:iam::370957321024:policy/Hierarchical-GitHub-KMS-Key-Policy"
336+
- !Ref KMSUsageOnlyUsEast1Keys
337+
- !Ref DDBUsage
338+
AssumeRolePolicyDocument: !Sub |
339+
{
340+
"Version": "2012-10-17",
341+
"Statement": [
342+
{
343+
"Effect": "Allow",
344+
"Principal": { "AWS": "arn:aws:iam::${AWS::AccountId}:role/GitHub-CI-DDBEC-Dafny-Role-us-west-2" },
345+
"Action": "sts:AssumeRole"
346+
},
347+
{
348+
"Effect": "Allow",
349+
"Principal": { "Federated": "arn:aws:iam::${AWS::AccountId}:oidc-provider/token.actions.githubusercontent.com" },
350+
"Action": "sts:AssumeRoleWithWebIdentity",
351+
"Condition": {
352+
"StringEquals": {
353+
"token.actions.githubusercontent.com:aud": "sts.amazonaws.com"
354+
},
355+
"StringLike": {
356+
"token.actions.githubusercontent.com:sub": "repo:${GitHubRepo}:*"
357+
}
358+
}
359+
},
360+
{
361+
"Effect": "Allow",
362+
"Principal": { "AWS": "arn:aws:iam::${AWS::AccountId}:role/ToolsDevelopment" },
363+
"Action": "sts:AssumeRole"
364+
}
365+
]
366+
}
367+
368+
GithubCIRoleOnlyEuWest1Keys:
369+
Type: 'AWS::IAM::Role'
370+
Properties:
371+
RoleName: !Sub "GitHub-CI-${ProjectName}-Role-only-eu-west-1-KMS-keys"
372+
Description: "Access DDB, KMS, & CA Resources for CI from GitHub. Only grants access to use keys in eu-west-1 region. Created for use by CI while executing Custom Client Supplier Example."
373+
ManagedPolicyArns:
374+
- Fn::ImportValue: "Polymorph-CA-GitHubCAReadPolicyArn"
375+
- "arn:aws:iam::370957321024:policy/ESDK-Dafny-DDB-ReadWriteDelete-us-west-2"
376+
- "arn:aws:iam::370957321024:policy/Hierarchical-GitHub-KMS-Key-Policy"
377+
- !Ref KMSUsageOnlyEuWest1Keys
378+
- !Ref DDBUsage
379+
AssumeRolePolicyDocument: !Sub |
380+
{
381+
"Version": "2012-10-17",
382+
"Statement": [
383+
{
384+
"Effect": "Allow",
385+
"Principal": { "AWS": "arn:aws:iam::${AWS::AccountId}:role/GitHub-CI-DDBEC-Dafny-Role-us-west-2" },
386+
"Action": "sts:AssumeRole"
387+
},
388+
{
389+
"Effect": "Allow",
390+
"Principal": { "Federated": "arn:aws:iam::${AWS::AccountId}:oidc-provider/token.actions.githubusercontent.com" },
391+
"Action": "sts:AssumeRoleWithWebIdentity",
392+
"Condition": {
393+
"StringEquals": {
394+
"token.actions.githubusercontent.com:aud": "sts.amazonaws.com"
395+
},
396+
"StringLike": {
397+
"token.actions.githubusercontent.com:sub": "repo:${GitHubRepo}:*"
398+
}
399+
}
400+
},
401+
{
402+
"Effect": "Allow",
403+
"Principal": { "AWS": "arn:aws:iam::${AWS::AccountId}:role/ToolsDevelopment" },
404+
"Action": "sts:AssumeRole"
405+
}
406+
]
407+
}

0 commit comments

Comments
 (0)