-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathcfn-centralized-logging-kms-key-config.yaml
98 lines (93 loc) · 2.99 KB
/
cfn-centralized-logging-kms-key-config.yaml
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
93
94
95
96
97
98
########################################################################
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: MIT-0
########################################################################
---
AWSTemplateFormatVersion: 2010-09-09
Description:
Config centralized KMS key for Config.
Metadata:
AWS::CloudFormation::Interface:
ParameterGroups:
- Label:
default: KMS Key Properties
Parameters:
- pLogArchiveAccountId
- pManagementAccountId
- pConfigKeyAlias
ParameterLabels:
pManagementAccountId:
default: Management Account ID
pLogArchiveAccountId:
default: Log Archive Account ID
pConfigKeyAlias:
default: Organization Config KMS Key Alias
Parameters:
pManagementAccountId:
AllowedPattern: '^\d{12}$'
ConstraintDescription: Must be 12 digits
Description: Management Account ID
Type: String
pLogArchiveAccountId:
AllowedPattern: '^\d{12}$'
ConstraintDescription: Must be 12 digits
Description: Log archive account ID
Type: String
pConfigKeyAlias:
Default: config-org-key
Description: Config KMS Key Alias
Type: String
Resources:
rConfigKey:
Type: AWS::KMS::Key
Properties:
Description: AWS Config KMS Key
EnableKeyRotation: True
KeyPolicy:
Version: 2012-10-17
Id: !Sub ${pConfigKeyAlias}
Statement:
- Sid: Enable IAM User Permissions
Effect: Allow
Principal:
AWS:
- !Sub arn:${AWS::Partition}:iam::${AWS::AccountId}:root
Action: 'kms:*'
Resource: '*'
- Sid: Allow Config to use KMS for encryption
Effect: Allow
Principal:
AWS:
- !Sub arn:${AWS::Partition}:iam::${pManagementAccountId}:root
Action:
- kms:Decrypt
- kms:GenerateDataKey
Resource: '*'
- Sid: Allow alias creation during setup
Effect: Allow
Principal:
AWS:
- !Sub arn:${AWS::Partition}:iam::${AWS::AccountId}:root
Action: kms:CreateAlias
Resource: '*'
Condition:
StringEquals:
kms:CallerAccount: !Sub ${AWS::AccountId}
kms:ViaService: !Sub cloudformation.${AWS::Region}.amazonaws.com
- Sid: Allow Log Archive and Management account access
Effect: Allow
Principal:
AWS:
- !Sub arn:${AWS::Partition}:iam::${pLogArchiveAccountId}:root
- !Sub arn:${AWS::Partition}:iam::${pManagementAccountId}:root
Action: kms:Decrypt
Resource: '*'
rConfigKeyAlias:
Type: AWS::KMS::Alias
Properties:
AliasName: !Sub alias/${pConfigKeyAlias}
TargetKeyId: !Ref rConfigKey
Outputs:
oConfigKeyArn:
Description: Config KMS Key ARN
Value: !GetAtt rConfigKey.Arn