-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBuildAccountBaseInfrastructure.yml
92 lines (88 loc) · 2.73 KB
/
BuildAccountBaseInfrastructure.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
AWSTemplateFormatVersion: 2010-09-09
Description: This template sets up the base infrastructure required for a CrossAccount CodePipeline
Parameters:
ProjectName:
Type: String
Description: The name of the project this base infrastructure will support
KeyAdministratorArn:
Type: String
Description: "The arn of the Administrator of this KMS Key"
DevAccountNo:
Type: String
Description: The Account Number of the dev account
ProdAccountNo:
Type: String
Description: The Account Number of the prod account
Resources:
ArtefactKMSKey:
Type: AWS::KMS::Key
Properties:
Description: !Sub 'KMS CMK for ${ProjectName} Artefacts'
Tags:
- Key: Project
Value: !Ref ProjectName
KeyPolicy:
Version: '2012-10-17'
Id: !Sub '${ProjectName}-artefact-key-policy'
Statement:
- Sid: Allow IAM User Permissions
Effect: Allow
Principal:
AWS:
- !Sub 'arn:aws:iam::${AWS::AccountId}:root'
Action: kms:*
Resource: '*'
- Sid: Allow administration of the key
Effect: Allow
Principal:
AWS:
- !Ref KeyAdministratorArn
Action:
- kms:Create*
- kms:Describe*
- kms:Enable*
- kms:List*
- kms:Put*
- kms:Update*
- kms:Revoke*
- kms:Disable*
- kms:Get*
- kms:Delete*
- kms:ScheduleKeyDeletion
- kms:CancelKeyDeletion
Resource: '*'
- Sid: Allow Cross Account Access
Effect: Allow
Principal:
AWS:
- !Sub 'arn:aws:iam::${DevAccountNo}:root'
- !Sub 'arn:aws:iam::${ProdAccountNo}:root'
Action:
- kms:Encrypt
- kms:Decrypt
- kms:ReEncrypt*
- kms:GenerateDataKey*
- kms:DescribeKey
Resource: '*'
- Sid: Allow attachment of persistent resources
Effect: Allow
Principal:
AWS:
- !Sub 'arn:aws:iam::${DevAccountNo}:root'
- !Sub 'arn:aws:iam::${ProdAccountNo}:root'
Action:
- kms:CreateGrant
- kms:ListGrants
- kms:RevokeGrant
Resource: '*'
ArtefactKeyAlias:
Type: AWS::KMS::Alias
Properties:
AliasName: !Sub 'alias/${ProjectName}-ArtefactKey'
TargetKeyId: !Ref ArtefactKMSKey
Outputs:
AretfactKMSKey:
Description: The ARN of the KMS Key to be used for artefacts'
Value: !GetAtt ArtefactKMSKey.Arn
Export:
Name: !Sub '${ProjectName}:ArtefactKMSKey'