forked from aws-samples/aws-iam-credential-report
-
Notifications
You must be signed in to change notification settings - Fork 0
/
iam-credential-report-kms-key.yaml
111 lines (101 loc) · 3.18 KB
/
iam-credential-report-kms-key.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
99
100
101
102
103
104
105
106
107
108
109
110
111
AWSTemplateFormatVersion: "2010-09-09"
Description: Creates the Customer Managed AWS KMS Key for the IAM Credential Report Blog Post
Metadata:
AWS::CloudFormation::Interface:
ParameterGroups:
- Label:
default: KMS Key Attributes
Parameters:
- pIAMCredentialReportKeyAlias
- pManagementAccountId
- pLoggingAccountId
- pTagKey1
- pTagValue1
ParameterLabels:
pIAMCredentialReportKeyAlias:
default: IAM Credential Report Delivery KMS Key Alias
pManagementAccountId:
default: Organization Management Account ID
pLoggingAccountId:
default: Log Archive Account ID
pTagKey1:
default: Tag Key
pTagValue1:
default: Tag Value
Parameters:
pIAMCredentialReportKeyAlias:
Type: String
Description: IAM Credential Report Delivery KMS Key Alias
Default: IAMCredsReportDeliveryKMSKey
pManagementAccountId:
Type: String
Description: Organization management account ID
pLoggingAccountId:
Type: String
Description: Organization log archive account ID
pTagKey1:
Type: String
Description: Tag key
Default: managed-by
pTagValue1:
Type: String
Description: Tag key value
Default: credential-cfn
Resources:
rIAMCredentialReportKey:
Type: AWS::KMS::Key
Metadata:
cfn_nag:
rules_to_suppress:
- id: F76
reason: The principal is restricted by the condition statement
Properties:
Description: "IAM Credential Report Delivery Key"
EnableKeyRotation: True
KeyPolicy:
Version: "2012-10-17"
Id: !Sub ${pIAMCredentialReportKeyAlias}
Statement:
- Sid: "Enable IAM User Permissions"
Effect: "Allow"
Principal:
AWS:
- !Sub "arn:aws:iam::${AWS::AccountId}:root"
Action: "kms:*"
Resource: "*"
- Sid: "Allow alias creation during setup"
Effect: "Allow"
Principal:
AWS: "*"
Action: "kms:CreateAlias"
Resource: "*"
Condition:
StringEquals:
"kms:CallerAccount": !Sub ${AWS::AccountId}
"kms:ViaService": "cloudformation.us-east-1.amazonaws.com"
- Sid: "Allow log archive account access"
Effect: "Allow"
Principal:
AWS:
- !Sub "arn:aws:iam::${pLoggingAccountId}:root"
- !Sub "arn:aws:iam::${pManagementAccountId}:root"
Action:
- "kms:DescribeKey"
- "kms:Encrypt"
- "kms:Decrypt"
- "kms:ReEncrypt*"
- "kms:GenerateDataKey"
- "kms:GenerateDataKeyWithoutPlaintext"
Resource: "*"
Tags:
- Key: !Ref pTagKey1
Value: !Ref pTagValue1
rIAMCredentialReportKeyAlias:
Type: AWS::KMS::Alias
Properties:
AliasName: !Sub alias/${pIAMCredentialReportKeyAlias}
TargetKeyId: !Ref rIAMCredentialReportKey
Outputs:
oIAMCredentialReportKeyArn:
Description: IAM Credential Report Delivery KMS Key ARN
Value: !GetAtt rIAMCredentialReportKey.Arn