-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcloudFormation.yaml
185 lines (176 loc) · 5.02 KB
/
cloudFormation.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
AWSTemplateFormatVersion: '2010-09-09'
Description: Zesty Kubernetes Template
Parameters:
S3CURBucket:
Description: The bucket created to receive CUR data upon CUR creation.
Type: String
S3BucketResult:
Description: The bucket created to receive Athena query results.
Type: String
AthenaDatabase:
Description: The name of the Athena database.
Type: String
SpotDataFeedBucketName:
Description: Optional. The bucket created to receive spot data feed.
Type: String
AWSSecretManager:
Description: The name of the AWS Secret Manager.
Type: String
Default: "zesty/access-credentials"
ZestyUserName:
Description: The name of the AWS CUR crawler user.
Type: String
ZestyRoleName:
Description: The name of the Zesty IAM role.
Type: String
Conditions:
HasSpotFeedBucketName: !Not [ !Equals [ !Ref SpotDataFeedBucketName, "" ] ]
Resources:
MyKmsKey:
Type: 'AWS::KMS::Key'
Properties:
Description: "KMS key for encrypting AWS Secrets Manager secrets"
EnableKeyRotation: true
KeyPolicy:
Version: "2012-10-17"
Statement:
- Sid: "Enable IAM User Permissions"
Effect: "Allow"
Principal:
AWS: !Sub "arn:aws:iam::${AWS::AccountId}:root"
Action: "kms:*"
Resource: "*"
- Sid: "Allow Secrets Manager Use of the Key"
Effect: "Allow"
Principal:
Service: "secretsmanager.amazonaws.com"
Action:
- "kms:Decrypt"
- "kms:Encrypt"
- "kms:ReEncrypt*"
- "kms:GenerateDataKey*"
Resource: "*"
SpotFeedPolicy:
Type: 'AWS::IAM::Policy'
Condition: HasSpotFeedBucketName
Properties:
Users:
- !Ref ZestyUser
Roles:
- !Ref ZestyRole
PolicyName: 'Zesty-spot-data-feed-access'
PolicyDocument:
Version: '2012-10-17'
Statement:
- Sid: SpotDataAccess
Effect: Allow
Action:
- s3:ListAllMyBuckets
- s3:ListBucket
- s3:HeadBucket
- s3:HeadObject
- s3:List*
- s3:Get*
Resource: "*"
AthenaPolicy:
Type: 'AWS::IAM::Policy'
Properties:
Users:
- !Ref ZestyUser
Roles:
- !Ref ZestyRole
PolicyName: 'Zesty-athena-access'
PolicyDocument:
Version: '2012-10-17'
Statement:
- Sid: AthenaAccess
Effect: Allow
Action:
- athena:*
Resource:
- "*"
- Sid: ReadAccessToAthenaCurDataViaGlue
Effect: Allow
Action:
- glue:GetDatabase*
- glue:GetTable*
- glue:GetPartition*
- glue:GetUserDefinedFunction
- glue:BatchGetPartition
Resource:
- arn:aws:glue:*:*:catalog
- !Sub arn:aws:glue:*:*:database/${AthenaDatabase}*
- !Sub arn:aws:glue:*:*:table/${AthenaDatabase}*/*
- Sid: AthenaQueryResultsOutput
Effect: Allow
Action:
- s3:GetBucketLocation
- s3:GetObject
- s3:ListBucket
- s3:ListBucketMultipartUploads
- s3:ListMultipartUploadParts
- s3:AbortMultipartUpload
- s3:CreateBucket
- s3:PutObject
Resource:
- !Sub arn:aws:s3:::${S3BucketResult}*
- Sid: S3ReadAccessToAwsBillingData
Effect: Allow
Action:
- s3:Get*
- s3:List*
Resource:
- !Sub 'arn:aws:s3:::${S3CURBucket}*'
- Sid: ReadAccessToAccountTags
Effect: Allow
Action:
- organizations:ListAccounts
- organizations:ListTagsForResource
Resource:
- "*"
- Sid: EC2Describe
Effect: Allow
Action:
- ec2:Describe*
Resource: "*"
- Sid: 'AllowEC2DescribeVolumes'
Effect: 'Allow'
Action:
- 'ec2:DescribeVolumes'
Resource: '*'
ZestyRole:
Type: 'AWS::IAM::Role'
Properties:
RoleName: !Ref 'ZestyRoleName'
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service:
- 'ec2.amazonaws.com'
Action:
- 'sts:AssumeRole'
ZestyUser:
Type: 'AWS::IAM::User'
Properties:
UserName: !Ref ZestyUserName
ZestyAccessKey:
Type: 'AWS::IAM::AccessKey'
Properties:
UserName: !Ref ZestyUser
DependsOn: ZestyUser
StoreAWSCredentialsInSecretManager:
Type: 'AWS::SecretsManager::Secret'
Properties:
Name: !Ref AWSSecretManager
Description: "Access credentials for AWS CUR Crawler user"
SecretString: !Join
- ""
- - "{\"AWS_ACCESS_KEY_ID\":\""
- !Ref ZestyAccessKey
- "\",\"AWS_SECRET_ACCESS_KEY\":\""
- !GetAtt ZestyAccessKey.SecretAccessKey
- "\"}"
KmsKeyId: !Ref MyKmsKey
DependsOn: ZestyAccessKey