forked from aws-cloudformation/cfn-lint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresources_circular_dependency.yaml
261 lines (261 loc) · 8.01 KB
/
resources_circular_dependency.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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
---
AWSTemplateFormatVersion: "2010-09-09"
Parameters:
myVpcId:
Description: MyVpc Id
Type: AWS::EC2::VPC::Id
myBucketName:
Type: String
Description: "Name of the S3 bucket."
KeyAdminRole:
Type: String
Description: "Name of the role that will act as Key Administrator for the KMS CMK created in this stack."
Ec2ImageId:
Type: AWS::EC2::Image::Id
Description: "ImageId to use when launching the Linux EC2 instance"
Ec2SubnetId:
Type: AWS::EC2::Subnet::Id
Description: "Subnet to associate myInstance EC2 Instance with."
Ec2SecurityGroupId:
Type: AWS::EC2::SecurityGroup::Id
Description: "Existing Security Group that allows SSH access from your machine."
Resources:
mySecurityGroupVpc1:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: "Security Group Vpc 1"
VpcId: !Ref myVpcId
SecurityGroupIngress:
- IpProtocol: 1
SourceSecurityGroupId: "sg-1234567"
- IpProtocol: 1
SourceSecurityGroupId: !Sub "${mySecurityGroupVpc2.GroupId}"
mySecurityGroupVpc2:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: "Security Group Vpc 2"
VpcId: !Ref myVpcId
SecurityGroupIngress:
- IpProtocol: 1
SourceSecurityGroupId: !GetAtt mySecurityGroupVpc1.GroupId
mySecurityGroupVpc3:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: "Security Group Vpc 3"
VpcId: !Ref myVpcId
SecurityGroupIngress:
- IpProtocol: 1
SourceSecurityGroupId: !Ref mySecurityGroupVpc3
myInstance:
Type: AWS::EC2::Instance
DependsOn: myInstanceProfile
Properties:
IamInstanceProfile: !Ref myInstanceProfile
ImageId: !Ref Ec2ImageId
InstanceType: t2.micro
NetworkInterfaces:
- AssociatePublicIpAddress: true
GroupSet:
- !Ref Ec2SecurityGroupId
SubnetId: !Ref Ec2SubnetId
DeviceIndex: 0
myBucket:
Type: AWS::S3::Bucket
DependsOn: myKms
Properties:
BucketEncryption:
ServerSideEncryptionConfiguration:
- ServerSideEncryptionByDefault:
KMSMasterKeyID: !Ref myKms
SSEAlgorithm: aws:kms
BucketName: !Ref myBucketName
myBucketPolicy:
Type: AWS::S3::BucketPolicy
Properties:
Bucket: !Ref myBucket
PolicyDocument:
Version: "2012-10-17"
Id: PutObjPolicy
Statement:
- Sid: DenyIncorrectEncryptionHeader
Effect: Deny
Principal: "*"
Action: s3:PutObject
Resource: !Sub arn:aws:s3:::${myBucketName}/*
Condition:
StringNotEquals:
s3:x-amz-server-side-encryption: aws:kms
- Sid: DenyUnEncryptedObjectUploads
Effect: Deny
Principal: "*"
Action: s3:PutObject
Resource: !Sub arn:aws:s3:::${myBucketName}/*
Condition:
"Null":
s3:x-amz-server-side-encryption: true
myRoleToWriteToS3:
Type: AWS::IAM::Role
DependsOn: myKms
Properties:
RoleName: WriteToS3
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Principal:
Service:
- "ec2.amazonaws.com"
Action:
- "sts:AssumeRole"
Path: "/"
Policies:
- PolicyName: !Sub AllowWriteTo${myBucketName}
PolicyDocument:
Version: "2012-10-17"
Statement:
- Sid: AllowPutObjectOnlyWithmyKms
Effect: Allow
Action: s3:PutObject
Resource: arn:aws:s3:::*/*
Condition:
StringEquals:
s3:x-amz-server-side-encryption: aws:kms
s3:x-amz-server-side-encryption-aws-kms-key-id: !Ref myKms
- Sid: AllowWriteToBucket
Effect: Allow
Action:
- s3:GetObjectAcl
- s3:GetObject
- s3:AbortMultipartUpload
- s3:PutObjectVersionTagging
- s3:ListBucket
- s3:PutObjectTagging
- s3:GetBucketAcl
- s3:GetObjectVersion
Resource:
- arn:aws:s3:::testbucket
- arn:aws:s3:::*/*
- Sid: AllowListBuckets
Effect: Allow
Action:
- s3:ListAllMyBuckets
- s3:HeadBucket
- s3:ListObjects
Resource: "*"
myInstanceProfile:
Type: AWS::IAM::InstanceProfile
DependsOn: myRoleToWriteToS3
Properties:
InstanceProfileName: InstanceProfile
Path: "/"
Roles:
- !Ref myRoleToWriteToS3
myKms:
Type: AWS::KMS::Key
Properties:
Description: "Key used to encrypt objects on S3"
EnableKeyRotation: true
KeyPolicy:
Version: "2012-10-17"
Id: KmsKeyPolicy
Statement:
- Sid: Enable IAM User Permissions
Effect: Allow
Principal:
AWS: !Sub arn:aws:iam::${AWS::AccountId}:root
Action: kms:*
Resource: "*"
- Sid: Allow access for Key Administrators
Effect: Allow
Principal:
AWS: !Sub arn:aws:iam::${AWS::AccountId}:role/${KeyAdminRole}
Action:
- kms:Create*
- kms:Describe*
- kms:Enable*
- kms:List*
- kms:Put*
- kms:Update*
- kms:Revoke*
- kms:Disable*
- kms:Get*
- kms:Delete*
- kms:TagResource
- kms:UntagResource
- kms:ScheduleKeyDeletion
- kms:CancelKeyDeletion
Resource: "*"
- Sid: Allow use of the key
Effect: Allow
Principal:
AWS:
- !Sub arn:aws:iam::${AWS::AccountId}:role/${KeyAdminRole}
- !Sub arn:aws:iam::${AWS::AccountId}:instanceprofile/${myInstanceProfile}
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::${AWS::AccountId}:role/${KeyAdminRole}
Action:
- kms:CreateGrant
- kms:ListGrants
- kms:RevokeGrant
Resource: "*"
Condition:
Bool:
kms:GrantIsForAWSResource: "True"
myInstanceSub:
Type: AWS::EC2::Instance
Properties:
ImageId: String
UserData:
Fn::Sub:
Test: bad configuration
taskdefinition:
Type: AWS::ECS::TaskDefinition
Properties:
RequiresCompatibilities:
- "EC2"
- "FARGATE"
ContainerDefinitions:
- Name: "my-app"
MountPoints:
- SourceVolume: "my-vol"
ContainerPath: "/var/www/my-vol"
Image: "amazon/amazon-ecs-sample"
Cpu: 10
EntryPoint:
- "/usr/sbin/apache2"
- "-D"
- "FOREGROUND"
Memory: 500
Essential: true
Environment:
- Name: key
Value: value
- Name: "busybox"
Image: "busybox"
Cpu: 10
EntryPoint:
- "sh"
- "-c"
Memory: 500
Command:
- '/bin/sh -c "while true; do /bin/date > /var/www/my-vol/date; sleep 1; done"'
Essential: false
# Don't break the graph code by picking up a DependsOn
DependsOn:
- ContainerName: my-app
Condition: START
VolumesFrom:
- SourceContainer: "my-app"
Volumes:
- Host:
SourcePath: "/var/lib/docker/vfs/dir/"
Name: "my-vol"