@aws/nx-plugin 0.1.6 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. package/LICENSE-THIRD-PARTY +114 -244
  2. package/generators.json +1 -7
  3. package/package.json +1 -1
  4. package/src/cloudscape-website/app/README.md +84 -48
  5. package/src/cloudscape-website/app/__snapshots__/generator.spec.ts.snap +157 -218
  6. package/src/cloudscape-website/app/files/app/README.md.template +44 -0
  7. package/src/cloudscape-website/app/files/app/src/layouts/App/index.tsx.template +40 -43
  8. package/src/cloudscape-website/app/files/app/src/layouts/App/navitems.ts.template +3 -3
  9. package/src/cloudscape-website/app/files/app/src/layouts/Routes/index.tsx.template +4 -6
  10. package/src/cloudscape-website/app/files/app/src/main.tsx.template +7 -10
  11. package/src/cloudscape-website/app/files/app/src/pages/Home/index.tsx.template +0 -2
  12. package/src/cloudscape-website/app/files/common/constructs/src/app/static-websites/__websiteNameKebabCase__.ts.template +13 -0
  13. package/src/cloudscape-website/app/files/common/constructs/src/{__websiteNameKebabCase__ → core}/static-website.ts.template +74 -144
  14. package/src/cloudscape-website/app/generator.js +74 -64
  15. package/src/cloudscape-website/app/generator.js.map +1 -1
  16. package/src/cloudscape-website/app/schema.d.ts +3 -4
  17. package/src/cloudscape-website/app/schema.json +1 -24
  18. package/src/cloudscape-website/cognito-auth/README.md +53 -32
  19. package/src/cloudscape-website/cognito-auth/__snapshots__/generator.spec.ts.snap +161 -125
  20. package/src/cloudscape-website/cognito-auth/files/app/components/CognitoAuth/index.tsx.template +53 -39
  21. package/src/cloudscape-website/cognito-auth/files/common/constructs/src/core/user-identity.ts.template +168 -0
  22. package/src/cloudscape-website/cognito-auth/generator.js +129 -46
  23. package/src/cloudscape-website/cognito-auth/generator.js.map +1 -1
  24. package/src/cloudscape-website/cognito-auth/schema.d.ts +1 -0
  25. package/src/cloudscape-website/cognito-auth/schema.json +7 -1
  26. package/src/cloudscape-website/runtime-config/__snapshots__/generator.spec.ts.snap +15 -17
  27. package/src/cloudscape-website/runtime-config/files/app/components/RuntimeConfig/index.tsx.template +7 -10
  28. package/src/cloudscape-website/runtime-config/files/app/hooks/useRuntimeConfig.tsx.template +13 -0
  29. package/src/cloudscape-website/runtime-config/generator.js +3 -1
  30. package/src/cloudscape-website/runtime-config/generator.js.map +1 -1
  31. package/src/infra/app/README.md +71 -46
  32. package/src/infra/app/__snapshots__/generator.spec.ts.snap +114 -252
  33. package/src/infra/app/files/app/README.md.template +76 -0
  34. package/src/infra/app/files/app/src/main.ts.template +18 -0
  35. package/src/infra/app/files/common/constructs/src/core/cfn-guard-rules/aws-prototyping.guard +1282 -0
  36. package/src/infra/app/files/common/constructs/src/core/cfn-guard-rules/cfn-nag.guard +6839 -0
  37. package/src/infra/app/files/common/constructs/src/core/cfn-guard-rules/hipaa-security.guard +2807 -0
  38. package/src/infra/app/files/common/constructs/src/core/cfn-guard-rules/nist-csf.guard +2585 -0
  39. package/src/infra/app/files/common/constructs/src/core/cfn-guard-rules/pci-dss-3-2-1.guard +2236 -0
  40. package/src/infra/app/files/common/constructs/src/core/cfn-guard-rules/wa-reliability-pillar.guard +885 -0
  41. package/src/infra/app/files/common/constructs/src/core/cfn-guard-rules/wa-security-pillar.guard +2205 -0
  42. package/src/infra/app/files/common/constructs/src/core/cfn-guard.ts.template +63 -0
  43. package/src/infra/app/generator.js +17 -3
  44. package/src/infra/app/generator.js.map +1 -1
  45. package/src/infra/app/schema.d.ts +10 -1
  46. package/src/infra/app/schema.json +16 -8
  47. package/src/trpc/backend/README.md +102 -80
  48. package/src/trpc/backend/__snapshots__/generator.spec.ts.snap +37 -17
  49. package/src/trpc/backend/files/backend/README.md.template +33 -0
  50. package/src/trpc/backend/files/common/constructs/src/app/trpc-apis/__apiNameKebabCase__.ts.template +18 -0
  51. package/src/trpc/backend/files/common/constructs/src/{__apiNameKebabCase__/index.ts.template → core/trpc-api.ts.template} +12 -16
  52. package/src/trpc/backend/files/schema/README.md.template +33 -0
  53. package/src/trpc/backend/generator.js +29 -43
  54. package/src/trpc/backend/generator.js.map +1 -1
  55. package/src/trpc/backend/schema.d.ts +3 -1
  56. package/src/trpc/backend/schema.json +8 -13
  57. package/src/trpc/react/README.md +46 -66
  58. package/src/trpc/react/__snapshots__/generator.spec.ts.snap +104 -65
  59. package/src/trpc/react/files/src/components/TrpcClients/IsolatedTrpcProvider.tsx.template +75 -0
  60. package/src/trpc/react/files/src/components/TrpcClients/TrpcApis.tsx.template +1 -0
  61. package/src/trpc/react/files/src/components/TrpcClients/TrpcClientProviders.tsx.template +10 -0
  62. package/src/trpc/react/files/src/components/TrpcClients/index.tsx.template +5 -0
  63. package/src/trpc/react/files/src/hooks/useSigV4.tsx.template +38 -0
  64. package/src/trpc/react/files/src/hooks/use__apiNameClassName__.tsx.template +3 -0
  65. package/src/trpc/react/generator.js +123 -24
  66. package/src/trpc/react/generator.js.map +1 -1
  67. package/src/trpc/react/schema.json +2 -2
  68. package/src/ts/cjs-to-esm/generator.js.map +1 -1
  69. package/src/ts/lib/eslint.d.ts +1 -1
  70. package/src/ts/lib/eslint.js +59 -11
  71. package/src/ts/lib/eslint.js.map +1 -1
  72. package/src/ts/lib/files/README.md.template +33 -0
  73. package/src/ts/lib/generator.js +11 -4
  74. package/src/ts/lib/generator.js.map +1 -1
  75. package/src/ts/lib/schema.d.ts +1 -3
  76. package/src/ts/lib/schema.json +2 -15
  77. package/src/ts/lib/ts-project-utils.js.map +1 -1
  78. package/src/ts/lib/vitest.js +14 -0
  79. package/src/ts/lib/vitest.js.map +1 -1
  80. package/src/utils/ast.d.ts +13 -0
  81. package/src/utils/ast.js +102 -0
  82. package/src/utils/ast.js.map +1 -0
  83. package/src/utils/files/common/constructs/src/app/index.ts.template +0 -0
  84. package/src/utils/files/common/constructs/src/{runtime-config → core}/runtime-config.ts.template +3 -5
  85. package/src/utils/files/common/constructs/src/index.ts.template +2 -1
  86. package/src/utils/files/common/readme/README.md.template +33 -0
  87. package/src/utils/files/common/types/src/runtime-config.ts.template +1 -13
  88. package/src/utils/format.js.map +1 -1
  89. package/src/utils/names.d.ts +2 -0
  90. package/src/utils/names.js +27 -0
  91. package/src/utils/names.js.map +1 -0
  92. package/src/utils/npm-scope.js.map +1 -1
  93. package/src/utils/paths.js.map +1 -1
  94. package/src/utils/shared-constructs.js +37 -4
  95. package/src/utils/shared-constructs.js.map +1 -1
  96. package/src/utils/versions.d.ts +15 -9
  97. package/src/utils/versions.js +14 -8
  98. package/src/utils/versions.js.map +1 -1
  99. package/src/cloudscape-website/app/files/common/constructs/src/__websiteNameKebabCase__/cloudfront-web-acl.ts.template +0 -317
  100. package/src/cloudscape-website/app/files/common/constructs/src/__websiteNameKebabCase__/index.ts.template +0 -4
  101. package/src/cloudscape-website/app/files/common/constructs/src/__websiteNameKebabCase__/webacl_event_handler/index.ts.template +0 -301
  102. package/src/cloudscape-website/cognito-auth/files/common/constructs/src/identity/index.ts.template +0 -4
  103. package/src/cloudscape-website/cognito-auth/files/common/constructs/src/identity/user-identity.ts.template +0 -66
  104. package/src/cloudscape-website/cognito-auth/files/common/constructs/src/identity/userpool-with-mfa.ts.template +0 -70
  105. package/src/gitlab/generator.d.ts +0 -8
  106. package/src/gitlab/generator.js +0 -16
  107. package/src/gitlab/generator.js.map +0 -1
  108. package/src/gitlab/schema.d.ts +0 -9
  109. package/src/gitlab/schema.json +0 -52
  110. package/src/infra/app/files/src/main.ts.template +0 -37
  111. package/src/trpc/react/files/src/components/TRPCClientProvider/index.tsx.template +0 -34
  112. package/src/trpc/react/files/src/hooks/useTrpc.tsx.template +0 -5
  113. /package/src/infra/app/files/{cdk.json → app/cdk.json} +0 -0
  114. /package/src/infra/app/files/{src → app/src}/stacks/application-stack.ts.template +0 -0
  115. /package/src/utils/files/common/constructs/src/{runtime-config → core}/index.ts.template +0 -0
@@ -0,0 +1,2236 @@
1
+ #
2
+ #####################################
3
+ ## Gherkin ##
4
+ #####################################
5
+ # Rule Identifier:
6
+ # DMS_REPLICATION_NOT_PUBLIC
7
+ #
8
+ # Description:
9
+ # Checks whether AWS Database Migration Service replication instances are not set to allow public.
10
+ #
11
+ # Reports on:
12
+ # AWS::DMS::ReplicationInstance
13
+ #
14
+ # Evaluates:
15
+ # AWS CloudFormation
16
+ #
17
+ # Rule Parameters:
18
+ # NA
19
+ #
20
+ # Scenarios:
21
+ # a) SKIP: when there is no DMS Replication Instance present
22
+ # b) FAIL: When DMS Replication Instance is present and PubliclyAccessible property is set to true
23
+ # c) PASS: When DMS Replication Instance is present and PubliclyAccessible property is set to false
24
+ # c) PASS: When DMS Replication Instance is present and PubliclyAccessible property is not set
25
+ # d) SKIP: when metada has rule suppression for DMS_REPLICATION_NOT_PUBLIC
26
+
27
+ #
28
+ # Select all Redshift cluster resources from incoming template
29
+ #
30
+
31
+ let dms_replication_instances = Resources.*[ Type == 'AWS::DMS::ReplicationInstance'
32
+ Metadata.guard.SuppressedRules not exists or
33
+ Metadata.guard.SuppressedRules.* != "DMS_REPLICATION_NOT_PUBLIC"
34
+ ]
35
+
36
+ rule DMS_REPLICATION_NOT_PUBLIC when %dms_replication_instances !empty {
37
+ %dms_replication_instances.Properties.PubliclyAccessible exists
38
+ %dms_replication_instances.Properties.PubliclyAccessible == false
39
+ <<
40
+ Guard Rule Set: PCI-DSS-3-2-1
41
+ Controls: 1.2,1.2.1,1.3,1.3.1,1.3.2,1.3.4,1.3.6,2.2.2
42
+ Violation: AWS Database Migration Service replication instances should not be public.
43
+ Fix: Set the DMS Replication Instance property PubliclyAccessible parameter to true.
44
+ >>
45
+ }
46
+ #
47
+ #####################################
48
+ ## Gherkin ##
49
+ #####################################
50
+ # Rule Identifier:
51
+ # EC2_INSTANCE_NO_PUBLIC_IP
52
+ #
53
+ # Description:
54
+ # Checks whether Amazon Elastic Compute Cloud (Amazon EC2) instances have a public IP association.
55
+ #
56
+ # Reports on:
57
+ # AWS::EC2::Instance
58
+ #
59
+ # Evaluates:
60
+ # AWS CloudFormation
61
+ #
62
+ # Rule Parameters:
63
+ # NA
64
+ #
65
+ # Scenarios:
66
+ # a) SKIP: when no EC2 Instance resources are present
67
+ # b) SKIP: when no EC2 Instances have network interfaces defined
68
+ # c) PASS: when no EC2 Instances with network interfaces have associated public IP addresses
69
+ # d) FAIL: when any EC2 Instances with network interfaces have associated public IP addresses
70
+ # e) SKIP: hen metadata includes the suppression for rule EC2_INSTANCE_NO_PUBLIC_IP
71
+
72
+ #
73
+ # Select all EC2 Instance resources from incoming template (payload)
74
+ #
75
+ let ec2_instances_no_public_ip = Resources.*[Type == 'AWS::EC2::Instance'
76
+ Properties.NetworkInterfaces[*] !empty
77
+ Metadata.guard.SuppressedRules not exists or
78
+ Metadata.guard.SuppressedRules.* != "EC2_INSTANCE_NO_PUBLIC_IP"
79
+ ]
80
+
81
+ rule EC2_INSTANCE_NO_PUBLIC_IP when %ec2_instances_no_public_ip !empty {
82
+ %ec2_instances_no_public_ip.Properties.NetworkInterfaces[*] {
83
+ AssociatePublicIpAddress !exists OR
84
+ AssociatePublicIpAddress == false
85
+ <<
86
+ Guard Rule Set: PCI-DSS-3-2-1
87
+ Controls: 1.2,1.2.1,1.3,1.3.1,1.3.2,1.3.4,1.3.6,2.2.2
88
+ Violation: EC2 Instances cannot have public IP addresses associated with their network interfaces
89
+ Fix: remove the AssociatePublicIpAddress property from NetworkInterfaces list or set it to false
90
+ >>
91
+ }
92
+ }
93
+
94
+
95
+ #
96
+ #####################################
97
+ ## Gherkin ##
98
+ #####################################
99
+ # Rule Identifier:
100
+ # ELASTICSEARCH_IN_VPC_ONLY
101
+ #
102
+ # Description:
103
+ # Elasticsearch domains must be in a VPC
104
+ #
105
+ # Reports on:
106
+ # AWS::Elasticsearch::Domain
107
+ #
108
+ # Evaluates:
109
+ # AWS CloudFormation
110
+ #
111
+ # Rule Parameters:
112
+ # NA
113
+ #
114
+ # Scenarios:
115
+ # a) SKIP: when there is no elasticsearch domain present
116
+ # b) FAIL: when elasticsearch domain does not have VPCOptions or Endpoint properties
117
+ # c) PASS: when elasticsearch domain has VPCOptions or Endpoint properties
118
+ # d) SKIP: when metada has rule suppression for ELASTICSEARCH_IN_VPC_ONLY
119
+
120
+ #
121
+ # Select all elasticsearch domains from incoming template
122
+ #
123
+ let elasticsearch_domains_vpc_required = Resources.*[ Type == 'AWS::Elasticsearch::Domain'
124
+ Metadata.guard.SuppressedRules not exists or
125
+ Metadata.guard.SuppressedRules.* != "ELASTICSEARCH_IN_VPC_ONLY"
126
+ ]
127
+
128
+ rule ELASTICSEARCH_IN_VPC_ONLY when %elasticsearch_domains_vpc_required !empty {
129
+ %elasticsearch_domains_vpc_required.Properties.VPCOptions EXISTS
130
+ <<
131
+ Guard Rule Set: PCI-DSS-3-2-1
132
+ Controls: 1.2,1.2.1,1.3,1.3.1,1.3.2,1.3.4,1.3.6,2.2.2
133
+ Violation: Elasticsearch domains must be in a VPC.
134
+ Fix: Provide VPCOptions object to enable opensearch to function in a VPC.
135
+ >>
136
+ }
137
+ ## Config Rule Name : emr-master-no-public-ip
138
+ ## Config Rule URL: https://docs.aws.amazon.com/config/latest/developerguide/emr-master-no-public-ip.html"
139
+
140
+ #
141
+ #####################################
142
+ ## Gherkin ##
143
+ #####################################
144
+ # Rule Identifier:
145
+ # INCOMING_SSH_DISABLED
146
+ #
147
+ # Description:
148
+ # Checks if the incoming SSH traffic for the security groups is accessible.
149
+ #
150
+ # Reports on:
151
+ # AWS::EC2::SecurityGroup
152
+ #
153
+ # Evaluates:
154
+ # AWS CloudFormation
155
+ #
156
+ # Rule Parameters:
157
+ # NA
158
+ #
159
+ # Scenarios:
160
+ # a) SKIP: when no Security Group resources are present
161
+ # b) SKIP: when no SSH ingress is defined (port 22)
162
+ # c) PASS: when all Security Groups resources restrict the IP address of the incoming SSH traffic
163
+ # d) FAIL: when a Security Group allows SSH traffic from any IP address (0.0.0.0/0).
164
+ # e) SKIP: hen metadata includes the suppression for rule INCOMING_SSH_DISABLED
165
+
166
+ #
167
+ # Select all Security Group resources from incoming template (payload)
168
+ #
169
+ let aws_security_groups_restricted_ssh = Resources.*[
170
+ Type == 'AWS::EC2::SecurityGroup'
171
+ some Properties.SecurityGroupIngress[*] {
172
+ ToPort == 22
173
+ FromPort == 22
174
+ IpProtocol == "tcp"
175
+ }
176
+ Metadata.guard.SuppressedRules not exists or
177
+ Metadata.guard.SuppressedRules.* != "INCOMING_SSH_DISABLED"
178
+ ]
179
+
180
+ rule INCOMING_SSH_DISABLED when %aws_security_groups_restricted_ssh !empty {
181
+ %aws_security_groups_restricted_ssh.Properties.SecurityGroupIngress[*] != {CidrIp:"0.0.0.0/0", ToPort:22, FromPort:22, IpProtocol:"tcp"}
182
+ <<
183
+ Guard Rule Set: PCI-DSS-3-2-1
184
+ Controls: 1.2,1.2.1,1.3,1.3.1,1.3.2,2.2,2.2.2
185
+ Violation: IP addresses of the incoming SSH traffic in the security groups are restricted (CIDR other than 0.0.0.0/0)
186
+ Fix: set SecurityGroupIngress.CidrIp property to a more restrictive CIDR than 0.0.0.0/0
187
+ >>
188
+ }
189
+ #
190
+ #####################################
191
+ ## Gherkin ##
192
+ #####################################
193
+ # Rule Identifier:
194
+ # EC2_INSTANCES_IN_VPC
195
+ #
196
+ # Description:
197
+ # Checks if your EC2 instances belong to a virtual private cloud (VPC).
198
+ #
199
+ # Reports on:
200
+ # AWS::EC2::Instance
201
+ #
202
+ # Evaluates:
203
+ # AWS CloudFormation
204
+ #
205
+ # Rule Parameters:
206
+ # NA
207
+ #
208
+ # Scenarios:
209
+ # a) SKIP: when there are no EC2 resource present
210
+ # b) PASS: when all EC2 resources have the SubnetId property set
211
+ # c) FAIL: when any EC2 resources do not have the SubnetId property set
212
+ # d) SKIP: when metadata includes the suppression for rule EC2_INSTANCES_IN_VPC
213
+
214
+ #
215
+ # Select all ECS Instance resources from incoming template (payload)
216
+ #
217
+ let ec2_instances_in_vpc = Resources.*[ Type == 'AWS::EC2::Instance'
218
+ Metadata.guard.SuppressedRules not exists or
219
+ Metadata.guard.SuppressedRules.* != "EC2_INSTANCES_IN_VPC"
220
+ ]
221
+
222
+ rule EC2_INSTANCES_IN_VPC when %ec2_instances_in_vpc !empty {
223
+ %ec2_instances_in_vpc.Properties.SubnetId !empty
224
+ <<
225
+ Guard Rule Set: PCI-DSS-3-2-1
226
+ Controls: 1.2,1.2.1,1.3,1.3.1,1.3.2,1.3.4,1.3.6,2.2.2
227
+ Violation: EC2 Instances must belong to a VPC
228
+ Fix: set the SubnetId property to a subnet ID
229
+ >>
230
+ }
231
+ #
232
+ #####################################
233
+ ## Gherkin ##
234
+ #####################################
235
+ # Rule Identifier:
236
+ # LAMBDA_FUNCTION_PUBLIC_ACCESS_PROHIBITED
237
+ #
238
+ # Description:
239
+ # Checks if the AWS Lambda function policy attached to the Lambda resource prohibits public access.
240
+ #
241
+ # Reports on:
242
+ # AWS::Lambda::Permission
243
+ # AWS::Lambda::LayerVersionPermission
244
+ #
245
+ # Evaluates:
246
+ # AWS CloudFormation
247
+ #
248
+ # Rule Parameters:
249
+ # NA
250
+ #
251
+ # Scenarios:
252
+ # a) SKIP: when no AWS Lambda permission policies are present
253
+ # b) PASS: when all AWS Lambda permission policies prohibit public access
254
+ # c) FAIL: when any AWS Lambda permission policies allow public access
255
+ # d) SKIP: hen metadata includes the suppression for rule LAMBDA_FUNCTION_PUBLIC_ACCESS_PROHIBITED
256
+
257
+ #
258
+ # Select all AWS Lambda Permission resources from incoming template (payload)
259
+ #
260
+ let aws_lambda_permissions_public_access_prohibited = Resources.*[
261
+ Type in [ /AWS::Lambda::Permission/,
262
+ /AWS::Lambda::LayerVersionPermission/ ]
263
+ Metadata.guard.SuppressedRules not exists or
264
+ Metadata.guard.SuppressedRules.* != "LAMBDA_FUNCTION_PUBLIC_ACCESS_PROHIBITED"
265
+ ]
266
+
267
+ rule LAMBDA_FUNCTION_PUBLIC_ACCESS_PROHIBITED when %aws_lambda_permissions_public_access_prohibited !empty {
268
+
269
+ # Lambda permission policy where principal is an account id
270
+ %aws_lambda_permissions_public_access_prohibited {
271
+ Type == 'AWS::Lambda::Permission'
272
+ Properties {
273
+ Principal in [ /^\d{12}$/, "AWS::AccountId" ]
274
+ OR Principal > 0
275
+ }
276
+ }
277
+
278
+ # Lambda permission policy where principal is a service (not s3)
279
+ OR %aws_lambda_permissions_public_access_prohibited {
280
+ Type == 'AWS::Lambda::Permission'
281
+ Properties {
282
+ Principal != 's3.amazonaws.com'
283
+ PrincipalOrgID !empty
284
+ OR SourceAccount exists
285
+ OR SourceArn !empty
286
+ <<
287
+ Guard Rule Set: PCI-DSS-3-2-1
288
+ Controls: 1.2,1.2.1,1.3,1.3.1,1.3.2,1.3.4,2.2.2
289
+ Violation: All Lambda permission policies attached to Lambda resources must prohibit public access.
290
+ Fix: Limit permission policies by setting the Principal property to an account ID,
291
+ or limiting a service principal by setting the SourceArn, SourceAccount, or PrincipalOrgID properties.
292
+ >>
293
+ }
294
+ }
295
+
296
+ # Lambda permission policy where principal is s3 service
297
+ OR %aws_lambda_permissions_public_access_prohibited {
298
+ Type == 'AWS::Lambda::Permission'
299
+ Properties {
300
+ Principal == 's3.amazonaws.com'
301
+ PrincipalOrgID !empty
302
+ OR SourceAccount exists
303
+ <<
304
+ Guard Rule Set: PCI-DSS-3-2-1
305
+ Controls: 1.2,1.2.1,1.3,1.3.1,1.3.2,1.3.4,2.2.2
306
+ Violation: All Lambda permission policies attached to Lambda resources must prohibit public access.
307
+ Fix: Limit permission policies by setting the Principal property to an account ID,
308
+ or for S3 as the principal specify either a SourceAccount or PrincipalOrgID.
309
+ Note: It is possible for an S3 bucket to be deleted by its owner and recreated by another account.
310
+ >>
311
+ }
312
+ }
313
+
314
+ # Lambda layer version permission policies
315
+ OR %aws_lambda_permissions_public_access_prohibited {
316
+ Type == 'AWS::Lambda::LayerVersionPermission'
317
+ Properties {
318
+ OrganizationId !empty
319
+ OR Principal in [ /^\d{12}$/, "AWS::AccountId" ]
320
+ OR Principal > 0
321
+ <<
322
+ Guard Rule Set: PCI-DSS-3-2-1
323
+ Controls: 1.2,1.2.1,1.3,1.3.1,1.3.2,1.3.4,2.2.2
324
+ Violation: All Lambda permission policies attached to Lambda resources must prohibit public access.
325
+ Fix: For Lambda layer version permission policies, either limit permissions by the OrganizationId property
326
+ or set the Principal property to an account ID rather than using a wildcard (*).
327
+ >>
328
+ }
329
+ }
330
+ }
331
+
332
+ #
333
+ #####################################
334
+ ## Gherkin ##
335
+ #####################################
336
+ # Rule Identifier:
337
+ # LAMBDA_INSIDE_VPC
338
+ #
339
+ # Description:
340
+ # Checks whether an AWS Lambda function is allowed access to an Amazon Virtual Private Cloud.
341
+ #
342
+ # Reports on:
343
+ # AWS::Lambda::Function
344
+ #
345
+ # Evaluates:
346
+ # AWS CloudFormation
347
+ #
348
+ # Rule Parameters:
349
+ # NA
350
+ #
351
+ # Scenarios:
352
+ # a) SKIP: when no AWS Lambda functions are present
353
+ # b) PASS: when all AWS Lambda functions are VPC enabled
354
+ # c) FAIL: when any AWS Lambda functions are not VPC enabled
355
+ # d) SKIP: hen metadata includes the suppression for rule LAMBDA_INSIDE_VPC
356
+
357
+ #
358
+ # Select all AWS Lambda Function resources from incoming template (payload)
359
+ #
360
+ let aws_lambda_functions_inside_vpc = Resources.*[ Type == 'AWS::Lambda::Function'
361
+ Metadata.guard.SuppressedRules not exists or
362
+ Metadata.guard.SuppressedRules.* != "LAMBDA_INSIDE_VPC"
363
+ ]
364
+
365
+ rule LAMBDA_INSIDE_VPC when %aws_lambda_functions_inside_vpc !empty {
366
+ %aws_lambda_functions_inside_vpc.Properties.VpcConfig.SecurityGroupIds !empty
367
+ %aws_lambda_functions_inside_vpc.Properties.VpcConfig.SubnetIds !empty
368
+ <<
369
+ Guard Rule Set: PCI-DSS-3-2-1
370
+ Controls: 1.2,1.2.1,1.3,1.3.1,1.3.2,1.3.4,2.2.2
371
+ Violation: All AWS Lambda Functions must be configured with access to a VPC
372
+ Fix: set the VpcConfig.SecurityGroupIds and VpcConfig.SubnetIds parameters with a list of security groups and subnets.
373
+ Lambda creates an elastic network interface for each combination of security group and subnet in the function's VPC configuration.
374
+ >>
375
+ }
376
+ #
377
+ #####################################
378
+ ## Gherkin ##
379
+ #####################################
380
+ # Rule Identifier:
381
+ # RDS_INSTANCE_PUBLIC_ACCESS_CHECK
382
+ #
383
+ # Description:
384
+ # Checks if an RDS instances has Publicly Accessible not set.
385
+ #
386
+ # Reports on:
387
+ # AWS::RDS::DBInstance
388
+ #
389
+ # Evaluates:
390
+ # AWS CloudFormation
391
+ #
392
+ # Rule Parameters:
393
+ # NA
394
+ #
395
+ # Scenarios:
396
+ # a) SKIP: when there are no RDS instances present
397
+ # b) PASS: when all RDS instances have PubliclyAccessible set to true
398
+ # c) FAIL: when all RDS instances have PubliclyAccessible set to false
399
+ # d) FAIL: when there are RDS instances with PubliclyAccessible property is not present
400
+ # e) SKIP: when metadata includes the suppression for rule RDS_INSTANCE_PUBLIC_ACCESS_CHECK
401
+
402
+ #
403
+ # Select all RDS instance resources from incoming template (payload)
404
+ #
405
+ let aws_rds_instances_not_public = Resources.*[ Type == 'AWS::RDS::DBInstance'
406
+ Metadata.guard.SuppressedRules not exists or
407
+ Metadata.guard.SuppressedRules.* != "RDS_INSTANCE_PUBLIC_ACCESS_CHECK"
408
+ ]
409
+
410
+ rule RDS_INSTANCE_PUBLIC_ACCESS_CHECK when %aws_rds_instances_not_public !empty {
411
+ # ALL RDS instances must have PubliclyAccessible set to false
412
+ %aws_rds_instances_not_public.Properties.PubliclyAccessible == false
413
+ <<
414
+ Guard Rule Set: PCI-DSS-3-2-1
415
+ Controls: 1.2,1.2.1,1.3,1.3.1,1.3.2,1.3.4,1.3.6,2.2.2
416
+ Violation: All RDS instances must not be publicly accessible.
417
+ Fix: Set the PubliclyAccessible to false.
418
+ >>
419
+ }
420
+
421
+ #
422
+ #####################################
423
+ ## Gherkin ##
424
+ #####################################
425
+ # Rule Identifier:
426
+ # REDSHIFT_CLUSTER_PUBLIC_ACCESS_CHECK
427
+ #
428
+ # Description:
429
+ # Redshift cluster should not be publicly accessible on the internet.
430
+ #
431
+ # Reports on:
432
+ # AWS::EKS::Cluster
433
+ #
434
+ # Evaluates:
435
+ # AWS CloudFormation
436
+ #
437
+ # Rule Parameters:
438
+ # NA
439
+ #
440
+ # Scenarios:
441
+ # a) SKIP: when there is no Redshift cluster present
442
+ # b) PASS: when Redshift Cluster resources do not have the publiclyAccessible property set (default false)
443
+ # c) PASS: when Redshift Cluster resources have the PubliclyAccessible property set to false
444
+ # d) FAIL: when any Redshift Cluster resources have the PubliclyAccessible property set to true
445
+ # e) SKIP: when metada includes the suppression for rule REDSHIFT_CLUSTER_PUBLIC_ACCESS_CHECK
446
+
447
+ #
448
+ # Select all Redshift cluster resources from incoming template
449
+ #
450
+
451
+ let aws_redshift_clusters_resources_public_access_check = Resources.*[ Type == 'AWS::Redshift::Cluster'
452
+ Metadata.guard.SuppressedRules not exists or
453
+ Metadata.guard.SuppressedRules.* != "REDSHIFT_CLUSTER_PUBLIC_ACCESS_CHECK"
454
+ ]
455
+
456
+
457
+ rule REDSHIFT_CLUSTER_PUBLIC_ACCESS_CHECK when %aws_redshift_clusters_resources_public_access_check !empty {
458
+ %aws_redshift_clusters_resources_public_access_check.Properties.PubliclyAccessible not exists or
459
+ %aws_redshift_clusters_resources_public_access_check.Properties.PubliclyAccessible == false
460
+
461
+ <<
462
+ Guard Rule Set: PCI-DSS-3-2-1
463
+ Controls: 1.2,1.2.1,1.3,1.3.1,1.3.2,1.3.4,1.3.6,2.2.2
464
+ Violation: Redshift cluster should not be available to public.
465
+ Fix: Set the Redshift property PubliclyAccessible parameter to false.
466
+ >>
467
+ }
468
+
469
+ #
470
+ #####################################
471
+ ## Gherkin ##
472
+ #####################################
473
+ # Rule Identifier:
474
+ # RESTRICTED_INCOMING_TRAFFIC
475
+ #
476
+ # Description:
477
+ # Checks if the security groups in use do not allow unrestricted incoming TCP traffic to the specified ports.
478
+ #
479
+ # Reports on:
480
+ # AWS::EC2::SecurityGroup
481
+ #
482
+ # Evaluates:
483
+ # AWS CloudFormation
484
+ #
485
+ # Rule Parameters:
486
+ # NA
487
+ #
488
+ # Scenarios:
489
+ # a) SKIP: when there are no Security Groups resource present
490
+ # b) SKIP when there are no TCP or UDP ingress rules
491
+ # c) PASS: when all Security Groups do no allow any of the restricted common ports
492
+ # d) FAIL: when a Security Group allows any of the restricted common ports
493
+ # e) SKIP: when metadata includes the suppression for rule RESTRICTED_INCOMING_TRAFFIC
494
+
495
+ #
496
+ # Select all Security Group resources from incoming template (payload)
497
+ #
498
+ let aws_security_groups_restricted_incoming_traffic = Resources.*[ Type == 'AWS::EC2::SecurityGroup'
499
+ some Properties.SecurityGroupIngress[*] {
500
+ IpProtocol in ['tcp', 'udp']
501
+ }
502
+ Metadata.guard.SuppressedRules not exists or
503
+ Metadata.guard.SuppressedRules.* != "RESTRICTED_INCOMING_TRAFFIC"
504
+ ]
505
+
506
+ rule RESTRICTED_INCOMING_TRAFFIC when %aws_security_groups_restricted_incoming_traffic !empty {
507
+ let violations = Resources.*[
508
+ Type == 'AWS::EC2::SecurityGroup'
509
+ some Properties.SecurityGroupIngress[*] {
510
+ FromPort in [ 20, 21, 3389, 3306, 4333 ]
511
+ ToPort in [ 20, 21, 3389, 3306, 4333 ]
512
+ }
513
+ ]
514
+ %violations empty
515
+ <<
516
+ Guard Rule Set: PCI-DSS-3-2-1
517
+ Controls: 1.2,1.2.1,1.3,1.3.1,1.3.2,2.2,2.2.2
518
+ Violation: Security groups must not allow unrestricted incoming TCP/UDP traffic to the specified ports [20, 21, 3389, 3306, 4333].
519
+ Fix: change the FromPort and ToPort properties in the SecurityGroupIngress list
520
+ >>
521
+ }
522
+ #
523
+ #####################################
524
+ ## Gherkin ##
525
+ #####################################
526
+ # Rule Identifier:
527
+ # S3_BUCKET_PUBLIC_READ_PROHIBITED
528
+ #
529
+ # Description:
530
+ # Checks if your Amazon S3 buckets do not allow public read access. The rule checks the Block Public
531
+ # Access settings, the bucket policy, and the bucket access control list (ACL).
532
+ #
533
+ # Reports on:
534
+ # AWS::S3::Bucket
535
+ #
536
+ # Evaluates:
537
+ # AWS CloudFormation
538
+ #
539
+ # Rule Parameters:
540
+ # NA
541
+ #
542
+ # Scenarios:
543
+ # a) SKIP: when there are no S3 resource present
544
+ # b) PASS: when all S3 resources Public Access Block Configuration element is present and properties are set to true
545
+ # c) FAIL: when all S3 resources do not have the Public Access Block Configuration element present or all properties set to true
546
+ # d) SKIP: when metadata includes the suppression for rule S3_BUCKET_PUBLIC_READ_PROHIBITED
547
+
548
+ #
549
+ # Select all S3 resources from incoming template (payload)
550
+ #
551
+ let s3_bucket_public_read_prohibited = Resources.*[ Type == 'AWS::S3::Bucket'
552
+ Metadata.guard.SuppressedRules not exists or
553
+ Metadata.guard.SuppressedRules.* != "S3_BUCKET_PUBLIC_READ_PROHIBITED"
554
+ ]
555
+
556
+ rule S3_BUCKET_PUBLIC_READ_PROHIBITED when %s3_bucket_public_read_prohibited !empty {
557
+ %s3_bucket_public_read_prohibited.Properties.PublicAccessBlockConfiguration exists
558
+ %s3_bucket_public_read_prohibited.Properties.PublicAccessBlockConfiguration.BlockPublicAcls == true
559
+ %s3_bucket_public_read_prohibited.Properties.PublicAccessBlockConfiguration.BlockPublicPolicy == true
560
+ %s3_bucket_public_read_prohibited.Properties.PublicAccessBlockConfiguration.IgnorePublicAcls == true
561
+ %s3_bucket_public_read_prohibited.Properties.PublicAccessBlockConfiguration.RestrictPublicBuckets == true
562
+ <<
563
+ Guard Rule Set: PCI-DSS-3-2-1
564
+ Controls: 1.2,1.2.1,1.3,1.3.1,1.3.2,1.3.4,1.3.6,2.2,2.2.2
565
+ Violation: S3 Bucket Public Write Access controls need to be restricted.
566
+ Fix: Set S3 Bucket PublicAccessBlockConfiguration properties for BlockPublicAcls, BlockPublicPolicy, IgnorePublicAcls, RestrictPublicBuckets parameters to true.
567
+ >>
568
+ }
569
+ #
570
+ #####################################
571
+ ## Gherkin ##
572
+ #####################################
573
+ # Rule Identifier:
574
+ # S3_BUCKET_PUBLIC_WRITE_PROHIBITED
575
+ #
576
+ # Description:
577
+ # Checks if your Amazon S3 buckets do not allow public write access. The rule checks the Block Public
578
+ # Access settings, the bucket policy, and the bucket access control list (ACL).
579
+ #
580
+ # Reports on:
581
+ # AWS::S3::Bucket
582
+ #
583
+ # Evaluates:
584
+ # AWS CloudFormation
585
+ #
586
+ # Rule Parameters:
587
+ # NA
588
+ #
589
+ # Scenarios:
590
+ # a) SKIP: when there are no S3 resource present
591
+ # b) PASS: when all S3 resources Public Access Block Configuration element is present and properties are set to true
592
+ # c) FAIL: when all S3 resources do not have the Public Access Block Configuration element present or all properties set to true
593
+ # d) SKIP: when metadata includes the suppression for rule S3_BUCKET_PUBLIC_WRITE_PROHIBITED
594
+
595
+ #
596
+ # Select all S3 resources from incoming template (payload)
597
+ #
598
+ let s3_buckets_public_write_prohibited = Resources.*[ Type == 'AWS::S3::Bucket'
599
+ Metadata.guard.SuppressedRules not exists or
600
+ Metadata.guard.SuppressedRules.* != "S3_BUCKET_PUBLIC_WRITE_PROHIBITED"
601
+ ]
602
+
603
+ rule S3_BUCKET_PUBLIC_WRITE_PROHIBITED when %s3_buckets_public_write_prohibited !empty {
604
+ %s3_buckets_public_write_prohibited.Properties.PublicAccessBlockConfiguration exists
605
+ %s3_buckets_public_write_prohibited.Properties.PublicAccessBlockConfiguration.BlockPublicAcls == true
606
+ %s3_buckets_public_write_prohibited.Properties.PublicAccessBlockConfiguration.BlockPublicPolicy == true
607
+ %s3_buckets_public_write_prohibited.Properties.PublicAccessBlockConfiguration.IgnorePublicAcls == true
608
+ %s3_buckets_public_write_prohibited.Properties.PublicAccessBlockConfiguration.RestrictPublicBuckets == true
609
+ <<
610
+ Guard Rule Set: PCI-DSS-3-2-1
611
+ Controls: 1.2,1.2.1,1.3,1.3.1,1.3.2,1.3.4,1.3.6,2.2,2.2.2
612
+ Violation: S3 Bucket Public Write Access controls need to be restricted.
613
+ Fix: Set S3 Bucket PublicAccessBlockConfiguration properties for BlockPublicAcls, BlockPublicPolicy, IgnorePublicAcls, RestrictPublicBuckets parameters to true.
614
+ >>
615
+ }
616
+ ## Config Rule Name : sagemaker-notebook-no-direct-internet-access
617
+ ## Config Rule URL: https://docs.aws.amazon.com/config/latest/developerguide/sagemaker-notebook-no-direct-internet-access.html"
618
+
619
+ #
620
+ #####################################
621
+ ## Gherkin ##
622
+ #####################################
623
+ # Rule Identifier:
624
+ # SUBNET_AUTO_ASSIGN_PUBLIC_IP_DISABLED
625
+ #
626
+ # Description:
627
+ # Checks if Amazon Virtual Private Cloud (Amazon VPC) subnets are assigned a public IP address.
628
+ #
629
+ # Reports on:
630
+ # AWS::EC2::Subnet
631
+ #
632
+ # Evaluates:
633
+ # AWS CloudFormation
634
+ #
635
+ # Rule Parameters:
636
+ # NA
637
+ #
638
+ # Scenarios:
639
+ # a) SKIP: when there are no EC2 Subnet resource present
640
+ # b) PASS: when all EC2 Subnet resources have the MapPublicIpOnLaunch property set to false or it is missing (default false)
641
+ # c) FAIL: when any EC2 Subnet resources have the MapPublicIpOnLaunch property set to true
642
+ # d) SKIP: hen metadata includes the suppression for rule SUBNET_AUTO_ASSIGN_PUBLIC_IP_DISABLED
643
+
644
+ #
645
+ # Select all EC2 Subnet resources from incoming template (payload)
646
+ #
647
+ let ec2_subnets_auto_assign_public_ip_disabled = Resources.*[ Type == 'AWS::EC2::Subnet'
648
+ Metadata.guard.SuppressedRules not exists or
649
+ Metadata.guard.SuppressedRules.* != "SUBNET_AUTO_ASSIGN_PUBLIC_IP_DISABLED"
650
+ ]
651
+
652
+ rule SUBNET_AUTO_ASSIGN_PUBLIC_IP_DISABLED when %ec2_subnets_auto_assign_public_ip_disabled !empty {
653
+ %ec2_subnets_auto_assign_public_ip_disabled.Properties.MapPublicIpOnLaunch !exists
654
+ OR %ec2_subnets_auto_assign_public_ip_disabled.Properties.MapPublicIpOnLaunch == false
655
+ <<
656
+ Guard Rule Set: PCI-DSS-3-2-1
657
+ Controls: 1.2,1.2.1,1.3,1.3.1,1.3.2,1.3.4,1.3.6,2.2.2
658
+ Violation: VPCs should not have subnets that are assigned a public IP address.
659
+ Fix: remove the MapPublicIpOnLaucnh property or set it to false
660
+ >>
661
+ }
662
+ #
663
+ #####################################
664
+ ## Gherkin ##
665
+ #####################################
666
+ # Rule Identifier:
667
+ # S3_BUCKET_LEVEL_PUBLIC_ACCESS_PROHIBITED
668
+ #
669
+ # Description:
670
+ # Checks if Amazon Simple Storage Service (Amazon S3) buckets are publicly accessible.
671
+ #
672
+ # Reports on:
673
+ # AWS::S3::Bucket
674
+ #
675
+ # Evaluates:
676
+ # AWS CloudFormation
677
+ #
678
+ # Rule Parameters:
679
+ # NA
680
+ #
681
+ # Scenarios:
682
+ # a) SKIP: when there are no S3 resource present
683
+ # b) PASS: when all S3 resources Public Access Block Configuration element is present and properties are set to true
684
+ # c) FAIL: when all S3 resources do not have the Public Access Block Configuration element present or all properties set to true
685
+ # d) SKIP: when metada has rule suppression for S3_BUCKET_LEVEL_PUBLIC_ACCESS_PROHIBITED
686
+
687
+ #
688
+ # Select all S3 resources from incoming template (payload)
689
+ #
690
+ let s3_buckets_level_public_access_prohibited = Resources.*[ Type == 'AWS::S3::Bucket'
691
+ Metadata.guard.SuppressedRules not exists or
692
+ Metadata.guard.SuppressedRules.* != "S3_BUCKET_LEVEL_PUBLIC_ACCESS_PROHIBITED"
693
+ ]
694
+
695
+ rule S3_BUCKET_LEVEL_PUBLIC_ACCESS_PROHIBITED when %s3_buckets_level_public_access_prohibited !empty {
696
+ %s3_buckets_level_public_access_prohibited.Properties.PublicAccessBlockConfiguration exists
697
+ %s3_buckets_level_public_access_prohibited.Properties.PublicAccessBlockConfiguration.BlockPublicAcls == true
698
+ %s3_buckets_level_public_access_prohibited.Properties.PublicAccessBlockConfiguration.BlockPublicPolicy == true
699
+ %s3_buckets_level_public_access_prohibited.Properties.PublicAccessBlockConfiguration.IgnorePublicAcls == true
700
+ %s3_buckets_level_public_access_prohibited.Properties.PublicAccessBlockConfiguration.RestrictPublicBuckets == true
701
+ <<
702
+ Guard Rule Set: PCI-DSS-3-2-1
703
+ Controls: 1.2,1.2.1,1.3,1.3.1,1.3.2,1.3.4,1.3.6,2.2.2
704
+ Violation: S3 Bucket Public Access controls need to be restricted.
705
+ Fix: Set S3 Bucket PublicAccessBlockConfiguration properties for BlockPublicAcls, BlockPublicPolicy, IgnorePublicAcls, RestrictPublicBuckets parameters to true.
706
+ >>
707
+ }
708
+ #
709
+ #####################################
710
+ ## Gherkin ##
711
+ #####################################
712
+ # Rule Identifier:
713
+ # NO_UNRESTRICTED_ROUTE_TO_IGW
714
+ #
715
+ # Description:
716
+ # Checks if there are public routes in the route table to an Internet Gateway (IGW).
717
+ #
718
+ # Reports on:
719
+ # AWS::EC2::Route
720
+ #
721
+ # Evaluates:
722
+ # AWS CloudFormation
723
+ #
724
+ # Rule Parameters:
725
+ # NA
726
+ #
727
+ # Scenarios:
728
+ # a) SKIP: when no EC2 Route resources are present
729
+ # b) SKIP: when there are no EC2 Routes to an Internet Gateway (no GatewayId property)
730
+ # c) PASS: when all EC2 Routes to an Internet Gateway have a restricted destination CIDR block (not '0.0.0.0/0' or '::/0')
731
+ # d) FAIL: when any EC2 Routes to an Internet Gateway have a destination CIDR block of '0.0.0.0/0' or '::/0'
732
+ # e) SKIP: hen metadata includes the suppression for rule NO_UNRESTRICTED_ROUTE_TO_IGW
733
+
734
+ #
735
+ # Select all EC2 Route resources from incoming template (payload)
736
+ #
737
+ let routes_no_unrestricted_to_igw = Resources.*[ Type == 'AWS::EC2::Route'
738
+ Properties.GatewayId exists
739
+ Metadata.guard.SuppressedRules not exists or
740
+ Metadata.guard.SuppressedRules.* != "NO_UNRESTRICTED_ROUTE_TO_IGW"
741
+ ]
742
+
743
+ rule NO_UNRESTRICTED_ROUTE_TO_IGW when %routes_no_unrestricted_to_igw !empty {
744
+ %routes_no_unrestricted_to_igw {
745
+ Properties {
746
+ DestinationCidrBlock not in ['0.0.0.0/0', '::/0']
747
+ <<
748
+ Guard Rule Set: PCI-DSS-3-2-1
749
+ Controls: 1.2,1.2.1,1.3,1.3.1,1.3.2,2.2.2
750
+ Violation: EC2 Routes to an IGW cannot have a destination CIDR block of '0.0.0.0/0' or '::/0'
751
+ Fix: Remove routes to an IGW (with the GatewayId property defined) or modify the DestinationCidrBlock property to a more restricted CIDR block
752
+ >>
753
+ }
754
+ }
755
+ }
756
+ ## Config Rule Name : autoscaling-launch-config-public-ip-disabled
757
+ ## Config Rule URL: https://docs.aws.amazon.com/config/latest/developerguide/AUTOSCALING_LAUNCH_CONFIG_PUBLIC_IP_DISABLED.html"
758
+
759
+ ####################################
760
+ ## Gherkin ##
761
+ #####################################
762
+ # Rule Identifier:
763
+ # REDSHIFT_ENHANCED_VPC_ROUTING_ENABLED
764
+ #
765
+ # Description:
766
+ # Checks if Amazon Redshift cluster has 'enhancedVpcRouting' enabled.
767
+ #
768
+ # Reports on:
769
+ # AWS::Redshift::Cluster
770
+ #
771
+ # Evaluates:
772
+ # AWS CloudFormation
773
+ #
774
+ # Rule Parameters:
775
+ # NA
776
+ #
777
+ # Scenarios:
778
+ # a) SKIP: when there are no Redshift Cluster resource present
779
+ # b) PASS: when Redshift Cluster resources have property EnhancedVpcRouting set to true
780
+ # c) FAIL: when any Redshift Cluster resources do not have EnhancedVpcRouting property set (defualt false)
781
+ # d) FAIL: when any Redshift Cluster resources have EnhancedVpcRouting property set to false
782
+ # e) SKIP: when metadata includes the suppression for rule REDSHIFT_ENHANCED_VPC_ROUTING_ENABLED
783
+
784
+ #
785
+ # Select all Redshift Cluster resources from incoming template (payload)
786
+ #
787
+ let redhshift_enhanced_vpc_routing_enabled_clusters = Resources.*[ Type == 'AWS::Redshift::Cluster'
788
+ Metadata.guard.SuppressedRules not exists or
789
+ Metadata.guard.SuppressedRules.* != "REDSHIFT_ENHANCED_VPC_ROUTING_ENABLED"
790
+ ]
791
+
792
+ rule REDSHIFT_ENHANCED_VPC_ROUTING_ENABLED when %redhshift_enhanced_vpc_routing_enabled_clusters !empty {
793
+ %redhshift_enhanced_vpc_routing_enabled_clusters.Properties.EnhancedVpcRouting == true
794
+
795
+ <<
796
+ Guard Rule Set: PCI-DSS-3-2-1
797
+ Controls: 1.2,1.3,1.3.1,1.3.2
798
+ Violation: Enhanced VPC Routing must be enabled on Redshift clusters
799
+ Fix: set the EnhancedVpcRouting property to true
800
+ >>
801
+ }
802
+ ## Config Rule Name : autoscaling-group-elb-healthcheck-required
803
+ ## Config Rule URL: https://docs.aws.amazon.com/config/latest/developerguide/autoscaling-group-elb-healthcheck-required.html"
804
+ #
805
+ #####################################
806
+ ## Gherkin ##
807
+ #####################################
808
+ # Rule Identifier:
809
+ # AUTOSCALING_GROUP_ELB_HEALTHCHECK_REQUIRED
810
+ #
811
+ # Description:
812
+ # Checks whether your Auto Scaling groups that are associated with a load balancer are using Elastic Load Balancing health checks.
813
+ #
814
+ # Reports on:
815
+ # AWS::AutoScaling::AutoScalingGroup
816
+ #
817
+ # Evaluates:
818
+ # AWS CloudFormation
819
+ #
820
+ # Rule Parameters:
821
+ # NA
822
+ #
823
+ # Scenarios:
824
+ # a) SKIP: when there are no S3 resource present
825
+ # b) PASS: when all S3 resources ObjectLockEnabled property is set to true
826
+ # c) FAIL: when all S3 resources do not have the ObjectLockEnabled property is set to true or is missing
827
+ # d) SKIP: when metada has rule suppression for S3_BUCKET_DEFAULT_LOCK_ENABLED
828
+
829
+ #
830
+ # Select all S3 resources from incoming template (payload)
831
+ #
832
+ #
833
+ #####################################
834
+ ## Gherkin ##
835
+ #####################################
836
+ # Rule Identifier:
837
+ # CLOUD_TRAIL_CLOUD_WATCH_LOGS_ENABLED
838
+ #
839
+ # Description:
840
+ # Checks whether AWS CloudTrail trails are configured to send logs to Amazon CloudWatch logs.
841
+ # The trail is non-compliant if the CloudWatchLogsLogGroupArn property of the trail is empty.
842
+ #
843
+ # Reports on:
844
+ # AWS::CloudTrail::Trail
845
+ #
846
+ # Evaluates:
847
+ # AWS CloudFormation
848
+ #
849
+ # Rule Parameters:
850
+ # NA
851
+ #
852
+ # Scenarios:
853
+ # a) SKIP: when there are no CloudTrail Trails present
854
+ # b) PASS: when all CloudTrail Trails have CloudWatchLogsLogGroupArn parameter set
855
+ # c) FAIL: when there are CloudTrail Trails with CloudWatchLogsLogGroupArn property not present
856
+ # d) SKIP: when metada has rule suppression for CLOUD_TRAIL_CLOUD_WATCH_LOGS_ENABLED
857
+
858
+ #
859
+ # Select all CloudTrail Trail resources from incoming template (payload)
860
+ #
861
+ let cloudtrail_trails_cw_logs_enabled = Resources.*[ Type == 'AWS::CloudTrail::Trail'
862
+ Metadata.guard.SuppressedRules not exists or
863
+ Metadata.guard.SuppressedRules.* != "CLOUD_TRAIL_CLOUD_WATCH_LOGS_ENABLED"
864
+ ]
865
+
866
+ rule CLOUD_TRAIL_CLOUD_WATCH_LOGS_ENABLED when %cloudtrail_trails_cw_logs_enabled !empty {
867
+ %cloudtrail_trails_cw_logs_enabled.Properties.CloudWatchLogsLogGroupArn exists
868
+ <<
869
+ Guard Rule Set: PCI-DSS-3-2-1
870
+ Controls: 2.2,10.1,10.2.1,10.2.2,10.2.3,10.2.5,10.3.1,10.3.2,10.3.3,10.3.4,10.3.5,10.3.6,10.5.3,10.5.4
871
+ Violation: CloudTrail Trail should have logs exported to cloudwatch logs.
872
+ Fix: Set the CloudWatchLogsLogGroupArn parameter to enable exporting to CloudWatch Logs.
873
+ >>
874
+ }
875
+ #
876
+ #####################################
877
+ ## Gherkin ##
878
+ #####################################
879
+ # Rule Identifier:
880
+ # CLOUD_TRAIL_ENCRYPTION_ENABLED
881
+ #
882
+ # Description:
883
+ # Checks if AWS CloudTrail is configured to use the server side encryption (SSE)
884
+ # AWS Key Management Service KMS key encryption.
885
+ #
886
+ # Reports on:
887
+ # AWS::CloudTrail::Trail
888
+ #
889
+ # Evaluates:
890
+ # AWS CloudFormation
891
+ #
892
+ # Rule Parameters:
893
+ # NA
894
+ #
895
+ # Scenarios:
896
+ # a) SKIP: when there are no CloudTrail Trails present
897
+ # b) PASS: when all CloudTrail Trails have KMSKeyId parameter set
898
+ # c) FAIL: when there are CloudTrail Trails with KMSKeyId property not present
899
+ # d) SKIP: when metada has rule suppression for CLOUD_TRAIL_ENCRYPTION_ENABLED
900
+
901
+ #
902
+ # Select all CloudTrail Trail resources from incoming template (payload)
903
+ #
904
+ let cloudtrail_trails_encryption = Resources.*[ Type == 'AWS::CloudTrail::Trail'
905
+ Metadata.guard.SuppressedRules not exists or
906
+ Metadata.guard.SuppressedRules.* != "CLOUD_TRAIL_ENCRYPTION_ENABLED"
907
+ ]
908
+
909
+ rule CLOUD_TRAIL_ENCRYPTION_ENABLED when %cloudtrail_trails_encryption !empty {
910
+ %cloudtrail_trails_encryption.Properties.KMSKeyId EXISTS
911
+ %cloudtrail_trails_encryption.Properties.KMSKeyId is_string
912
+ <<
913
+ Guard Rule Set: PCI-DSS-3-2-1
914
+ Controls: 2.2,3.4,10.5
915
+ Violation: CloudTrail Trail should be used to encrypt logs delivered by CloudTrail.
916
+ Fix: Set the KMSKeyId parameter to enable encryption. The value can be an alias name prefixed by "alias/", a fully specified ARN to an alias, a fully specified ARN to a key, or a globally unique identifier.
917
+ >>
918
+ }
919
+ #
920
+ #####################################
921
+ ## Gherkin ##
922
+ #####################################
923
+ # Rule Identifier:
924
+ # CLOUD_TRAIL_LOG_FILE_VALIDATION_ENABLED
925
+ #
926
+ # Description:
927
+ # Checks whether AWS CloudTrail creates a signed digest file with logs.
928
+ #
929
+ # Reports on:
930
+ # AWS::CloudTrail::Trail
931
+ #
932
+ # Evaluates:
933
+ # AWS CloudFormation
934
+ #
935
+ # Rule Parameters:
936
+ # NA
937
+ #
938
+ # Scenarios:
939
+ # a) SKIP: when there are no CloudTrail Trails present
940
+ # b) PASS: when all CloudTrail Trails have EnableLogFileValidation parameter set true
941
+ # c) FAIL: when there are CloudTrail Trails with the EnableLogFileValidation parameter is set to false
942
+ # d) FAIL: when there are CloudTrail Trails with EnableLogFileValidation property not present
943
+ # e) SKIP: when metada has rule suppression for CLOUD_TRAIL_LOG_FILE_VALIDATION_ENABLED
944
+
945
+
946
+ #
947
+ # Select all CloudTrail Trail resources from incoming template (payload)
948
+ #
949
+ let cloudtrail_trails_log_validation = Resources.*[ Type == 'AWS::CloudTrail::Trail'
950
+ Metadata.guard.SuppressedRules not exists or
951
+ Metadata.guard.SuppressedRules.* != "CLOUD_TRAIL_LOG_FILE_VALIDATION_ENABLED"
952
+ ]
953
+
954
+ rule CLOUD_TRAIL_LOG_FILE_VALIDATION_ENABLED when %cloudtrail_trails_log_validation !empty {
955
+ %cloudtrail_trails_log_validation.Properties.EnableLogFileValidation EXISTS
956
+ %cloudtrail_trails_log_validation.Properties.EnableLogFileValidation == true
957
+ <<
958
+ Guard Rule Set: PCI-DSS-3-2-1
959
+ Controls: 2.2,10.5.2,10.5,10.5.5,11.5
960
+ Violation: CloudTrail Trail should have Log File Validation enabled.
961
+ Fix: Set the EnableLogFileValidation parameter to true.
962
+ >>
963
+ }
964
+ #
965
+ #####################################
966
+ ## Gherkin ##
967
+ #####################################
968
+ # Rule Identifier:
969
+ # CLOUDTRAIL_S3_DATAEVENTS_ENABLED
970
+ #
971
+ # Description:
972
+ # Checks whether at least one AWS CloudTrail trail is logging Amazon S3 data events for all S3 buckets.
973
+ #
974
+ # Reports on:
975
+ # AWS::CloudTrail::Trail
976
+ #
977
+ # Evaluates:
978
+ # AWS CloudFormation
979
+ #
980
+ # Rule Parameters:
981
+ # NA
982
+ #
983
+ # Scenarios:
984
+ # a) SKIP: when there are no CloudTrail Trails present
985
+ # b) PASS: when all CloudTrail Trails have EventSelectors parameter set
986
+ # c) FAIL: when there are CloudTrail Trails with EventSelectors property not present
987
+ # d) SKIP: when metada has rule suppression for CLOUDTRAIL_S3_DATAEVENTS_ENABLED
988
+
989
+ #
990
+ # Select all CloudTrail Trail resources from incoming template (payload)
991
+ #
992
+ let cloudtrail_trails_dataevents = Resources.*[ Type == 'AWS::CloudTrail::Trail'
993
+ Metadata.guard.SuppressedRules not exists or
994
+ Metadata.guard.SuppressedRules.* != "CLOUDTRAIL_S3_DATAEVENTS_ENABLED"
995
+ ]
996
+
997
+ rule CLOUDTRAIL_S3_DATAEVENTS_ENABLED when %cloudtrail_trails_dataevents !empty {
998
+ %cloudtrail_trails_dataevents.Properties.EventSelectors EXISTS
999
+ some %cloudtrail_trails_dataevents.Properties.EventSelectors.* == {DataResources:[{Type:'AWS::S3::Object',Values:['arn:aws:s3:::']}],IncludeManagementEvents:true,ReadWriteType:'All'}
1000
+ <<
1001
+ Guard Rule Set: PCI-DSS-3-2-1
1002
+ Controls: 2.2,10.1,10.2.1,10.2.2,10.2.3,10.2.5,10.3.1,10.3.2,10.3.3,10.3.4,10.3.5,10.3.6
1003
+ Violation: CloudTrail Trail should have data events being logged.
1004
+ Fix: Set the EventSelectors parameter to enable encryption. The value can be an alias name prefixed by "alias/", a fully specified ARN to an alias, a fully specified ARN to a key, or a globally unique identifier.
1005
+ >>
1006
+ }
1007
+ ## Config Rule Name : cmk-backing-key-rotation-enabled
1008
+ ## Config Rule URL: https://docs.aws.amazon.com/config/latest/developerguide/cmk-backing-key-rotation-enabled.html"
1009
+
1010
+ #
1011
+ #####################################
1012
+ ## Gherkin ##
1013
+ #####################################
1014
+ # Rule Identifier:
1015
+ # EC2_EBS_ENCRYPTION_BY_DEFAULT
1016
+ #
1017
+ # Description:
1018
+ # Check that Amazon Elastic Block Store (EBS) encryption is enabled by default
1019
+ # Reports on:
1020
+ # AWS::EC2::Volume
1021
+ #
1022
+ # Evaluates:
1023
+ # AWS CloudFormation
1024
+ #
1025
+ # Rule Parameters:
1026
+ # NA
1027
+ #
1028
+ # Scenarios:
1029
+ # a) SKIP: when no EC2 Volume resources are present
1030
+ # b) PASS: when all EC2 Volume resources have the Encrypted property set to true
1031
+ # c) FAIL: when any EC2 Volumes resources do not have the Encrypted property set to true
1032
+ # e) SKIP: when metadata includes the suppression for rule EC2_EBS_ENCRYPTION_BY_DEFAULT
1033
+
1034
+ #
1035
+ # Select all EC2 Volume resources from incoming template (payload)
1036
+ #
1037
+ let ec2_ebs_volumes_encrypted_by_default = Resources.*[ Type == 'AWS::EC2::Volume'
1038
+ Metadata.guard.SuppressedRules not exists or
1039
+ Metadata.guard.SuppressedRules.* != "EC2_EBS_ENCRYPTION_BY_DEFAULT"
1040
+ ]
1041
+
1042
+ rule EC2_EBS_ENCRYPTION_BY_DEFAULT when %ec2_ebs_volumes_encrypted_by_default !empty {
1043
+ %ec2_ebs_volumes_encrypted_by_default.Properties.Encrypted == true
1044
+ <<
1045
+ Guard Rule Set: PCI-DSS-3-2-1
1046
+ Controls: 2.2,3.4,8.2.1
1047
+ Violation: All EBS Volumes should be encryped
1048
+ Fix: Set Encrypted property to true
1049
+ >>
1050
+ }
1051
+ #
1052
+ #####################################
1053
+ ## Gherkin ##
1054
+ #####################################
1055
+ # Rule Identifier:
1056
+ # ENCRYPTED_VOLUMES
1057
+ #
1058
+ # Description:
1059
+ # Checks if the EBS volumes that are in an attached state are encrypted.
1060
+ #
1061
+ # Reports on:
1062
+ # AWS::EC2::Volume
1063
+ #
1064
+ # Evaluates:
1065
+ # AWS CloudFormation
1066
+ #
1067
+ # Rule Parameters:
1068
+ # NA
1069
+ #
1070
+ # Scenarios:
1071
+ # a) SKIP: when there are no EBS volume resources present
1072
+ # b) PASS: when all EBS volumes have the KmsKeyId property set or the Encrypted property set to true
1073
+ # c) FAIL: when any EC2 volumes do not have the KmsKeyId or Encrypted property set
1074
+ # e) SKIP: hen metadata includes the suppression for rule ENCRYPTED_VOLUMES
1075
+
1076
+ #
1077
+ # Select all EC2 Instance resources from incoming template (payload)
1078
+ #
1079
+ let ebs_volumes_encrypted = Resources.*[ Type == 'AWS::EC2::Volume'
1080
+ Metadata.guard.SuppressedRules not exists or
1081
+ Metadata.guard.SuppressedRules.* != "ENCRYPTED_VOLUMES"
1082
+ ]
1083
+
1084
+ rule ENCRYPTED_VOLUMES when %ebs_volumes_encrypted !empty {
1085
+ %ebs_volumes_encrypted.Properties.KmsKeyId !empty
1086
+ OR %ebs_volumes_encrypted.Properties.Encrypted == true
1087
+ <<
1088
+ Guard Rule Set: PCI-DSS-3-2-1
1089
+ Controls: 2.2,3.4,8.2.1
1090
+ Violation: EBS volumes in an attached state must encrypted.
1091
+ Fix: either set the KmsKeyId property to a key ID, key alias, key ARN, or alias ARN
1092
+ or set the Encrypted property to true to encrypt the volume with the account default key or AWS managed key.
1093
+ >>
1094
+ }
1095
+ #
1096
+ #####################################
1097
+ ## Gherkin ##
1098
+ #####################################
1099
+ # Rule Identifier:
1100
+ # IAM_NO_INLINE_POLICY_CHECK
1101
+ #
1102
+ # Description:
1103
+ # Checks that inline policy feature is not in use.
1104
+ #
1105
+ # Reports on:
1106
+ # AWS::IAM::User
1107
+ # AWS::IAM::Role
1108
+ # AWS::IAM::Group
1109
+ #
1110
+ # Evaluates:
1111
+ # AWS CloudFormation
1112
+ #
1113
+ # Rule Parameters:
1114
+ # NA
1115
+ #
1116
+ # Scenarios:
1117
+ # a) SKIP: when there are no IAM Users, Roles, or Groups present
1118
+ # b) PASS: when all IAM Users, Roles, or Groups present have no inline policies listed
1119
+ # c) FAIL: when any IAM Users, Roles, or Groups present have inline policies listed
1120
+ # d) SKIP: when metada has rule suppression for IAM_NO_INLINE_POLICY_CHECK
1121
+
1122
+ #
1123
+ # Select all IAM User, Role, and Group resources from incoming template (payload)
1124
+ #
1125
+ let aws_iam_entities_no_inline_policy = Resources.*[
1126
+ Type in [ /AWS::IAM::User/,
1127
+ /AWS::IAM::Role/,
1128
+ /AWS::IAM::Group/ ]
1129
+ Metadata.guard.SuppressedRules not exists or
1130
+ Metadata.guard.SuppressedRules.* != "IAM_NO_INLINE_POLICY_CHECK"
1131
+ ]
1132
+
1133
+ rule IAM_NO_INLINE_POLICY_CHECK when %aws_iam_entities_no_inline_policy !empty {
1134
+ %aws_iam_entities_no_inline_policy.Properties.Policies empty
1135
+ <<
1136
+ Guard Rule Set: PCI-DSS-3-2-1
1137
+ Controls: 2.2,7.1.2,7.1.3,7.2.1,7.2.2
1138
+ Violation: Inline policies are not allowed on IAM Users, Roles, or Groups.
1139
+ Fix: Remove the Policies list property from any IAM Users, Roles, or Groups.
1140
+ >>
1141
+ }
1142
+
1143
+ #
1144
+ #####################################
1145
+ ## Gherkin ##
1146
+ #####################################
1147
+ # Rule Identifier:
1148
+ # IAM_POLICY_NO_STATEMENTS_WITH_ADMIN_ACCESS
1149
+ #
1150
+ # Description:
1151
+ # Checks the IAM policies that you create for Allow statements that grant permissions to all actions on all resources.
1152
+ #
1153
+ # Reports on:
1154
+ # AWS::IAM::Policy
1155
+ #
1156
+ # Evaluates:
1157
+ # AWS CloudFormation
1158
+ #
1159
+ # Rule Parameters:
1160
+ # NA
1161
+ #
1162
+ # Scenarios:
1163
+ # a) SKIP: when there are no IAM Policies present
1164
+ # b) PASS: when all IAM Policies do not grant permissions to all actions on all resources
1165
+ # c) FAIL: when any IAM Policies grant permissions to all actions on all resources
1166
+ # d) SKIP: when metada has rule suppression for IAM_POLICY_NO_STATEMENTS_WITH_ADMIN_ACCESS
1167
+
1168
+ #
1169
+ # Select all IAM Policy resources from incoming template (payload)
1170
+ #
1171
+ let aws_iam_policies_no_statements_with_admin_access = Resources.*[ Type == 'AWS::IAM::Policy'
1172
+ Metadata.guard.SuppressedRules not exists or
1173
+ Metadata.guard.SuppressedRules.* != "IAM_POLICY_NO_STATEMENTS_WITH_ADMIN_ACCESS"
1174
+ ]
1175
+
1176
+ rule IAM_POLICY_NO_STATEMENTS_WITH_ADMIN_ACCESS when %aws_iam_policies_no_statements_with_admin_access !empty {
1177
+ let violations = Resources.*[
1178
+ Type == 'AWS::IAM::Policy'
1179
+ some Properties.PolicyDocument.Statement[*] {
1180
+ some Action[*] == "*"
1181
+ Effect == "Allow"
1182
+ Resource == "*"
1183
+ }
1184
+ ]
1185
+ %violations empty
1186
+ <<
1187
+ Guard Rule Set: PCI-DSS-3-2-1
1188
+ Controls: 2.2,7.1.2,7.1.3,7.2.1,7.2.2
1189
+ Violation: One or more IAM policies contain allow statements that grant permissions to all actions on all resources
1190
+ Fix: Remove policy statements that match {"Effect": "Allow", "Action": "*", "Resource": "*"}
1191
+ >>
1192
+ }
1193
+
1194
+
1195
+
1196
+ #
1197
+ #####################################
1198
+ ## Gherkin ##
1199
+ #####################################
1200
+ # Rule Identifier:
1201
+ # IAM_USER_NO_POLICIES_CHECK
1202
+ #
1203
+ # Description:
1204
+ # Checks that none of your IAM users have policies attached. IAM users must inherit permissions from IAM groups or roles.
1205
+ #
1206
+ # Reports on:
1207
+ # AWS::IAM::User
1208
+ #
1209
+ # Evaluates:
1210
+ # AWS CloudFormation
1211
+ #
1212
+ # Rule Parameters:
1213
+ # NA
1214
+ #
1215
+ # Scenarios:
1216
+ # a) SKIP: when there are no IAM Users present
1217
+ # b) PASS: when all IAM Users do not have policies attached
1218
+ # c) FAIL: when any IAM User have policies attached
1219
+ # d) SKIP: when metada has rule suppression for IAM_USER_NO_POLICIES_CHECK
1220
+
1221
+ #
1222
+ # Select all IAM User resources from incoming template (payload)
1223
+ #
1224
+ let aws_iam_users_no_policies = Resources.*[ Type == 'AWS::IAM::User'
1225
+ Metadata.guard.SuppressedRules not exists or
1226
+ Metadata.guard.SuppressedRules.* != "IAM_USER_NO_POLICIES_CHECK"
1227
+ ]
1228
+
1229
+ rule IAM_USER_NO_POLICIES_CHECK when %aws_iam_users_no_policies !empty {
1230
+ %aws_iam_users_no_policies.Properties.Policies empty
1231
+ <<
1232
+ Guard Rule Set: PCI-DSS-3-2-1
1233
+ Controls: 2.2,7.1.2,7.1.3,7.2.1,7.2.2
1234
+ Violation: Inline policies are not allowed on IAM Users. IAM users must inherit permissions from IAM groups or roles.
1235
+ Fix: Remove the Policies list property from any IAM Users.
1236
+ >>
1237
+ }
1238
+
1239
+ #
1240
+ #####################################
1241
+ ## Gherkin ##
1242
+ #####################################
1243
+ # Rule Identifier:
1244
+ # S3_BUCKET_LOGGING_ENABLED
1245
+ #
1246
+ # Description:
1247
+ # Checks whether logging is enabled for your S3 buckets.
1248
+ #
1249
+ # Reports on:
1250
+ # AWS::S3::Bucket
1251
+ #
1252
+ # Evaluates:
1253
+ # AWS CloudFormation
1254
+ #
1255
+ # Rule Parameters:
1256
+ # NA
1257
+ #
1258
+ # Scenarios:
1259
+ # a) SKIP: when there are no S3 resource present
1260
+ # b) PASS: when all S3 resources Logging Configuration exists
1261
+ # c) FAIL: when all S3 resources have Logging Configuration is not set
1262
+ # d) SKIP: when metadata includes the suppression for rule S3_BUCKET_LOGGING_ENABLED
1263
+
1264
+ #
1265
+ # Select all S3 resources from incoming template (payload)
1266
+ #
1267
+
1268
+ let s3_buckets_bucket_logging_enabled = Resources.*[ Type == 'AWS::S3::Bucket'
1269
+ Metadata.guard.SuppressedRules not exists or
1270
+ Metadata.guard.SuppressedRules.* != "S3_BUCKET_LOGGING_ENABLED"
1271
+ ]
1272
+
1273
+ rule S3_BUCKET_LOGGING_ENABLED when %s3_buckets_bucket_logging_enabled !empty {
1274
+ %s3_buckets_bucket_logging_enabled.Properties.LoggingConfiguration exists
1275
+ <<
1276
+ Guard Rule Set: PCI-DSS-3-2-1
1277
+ Controls: 2.2,10.1,10.2.1,10.2.2,10.2.3,10.2.4,10.2.5,10.2.7,10.3.1,10.3.2,10.3.3,10.3.4,10.3.5,10.3.6
1278
+ Violation: S3 Bucket Logging needs to be configured to enable logging.
1279
+ Fix: Set the S3 Bucket property LoggingConfiguration to start logging into S3 bucket.
1280
+ >>
1281
+ }
1282
+ #
1283
+ #####################################
1284
+ ## Gherkin ##
1285
+ #####################################
1286
+ # Rule Identifier:
1287
+ # S3_BUCKET_REPLICATION_ENABLED
1288
+ #
1289
+ # Description:
1290
+ # Checks whether the Amazon S3 buckets have cross-region replication enabled.
1291
+ #
1292
+ # Reports on:
1293
+ # AWS::S3::Bucket
1294
+ #
1295
+ # Evaluates:
1296
+ # AWS CloudFormation
1297
+ #
1298
+ # Rule Parameters:
1299
+ # NA
1300
+ #
1301
+ # Scenarios:
1302
+ # a) SKIP: when there are no S3 resource present
1303
+ # b) PASS: when all S3 resources replication configuration set status is set to Enabled
1304
+ # c) FAIL: when all S3 resources have Versioning Configuration status property not set or set to Suspended
1305
+ # d) SKIP: when metadata includes the suppression for rule S3_BUCKET_REPLICATION_ENABLED
1306
+
1307
+ #
1308
+ # Select all S3 resources from incoming template (payload)
1309
+ #
1310
+
1311
+ let s3_buckets_replication_enabled = Resources.*[ Type == 'AWS::S3::Bucket'
1312
+ Metadata.guard.SuppressedRules not exists or
1313
+ Metadata.guard.SuppressedRules.* != "S3_BUCKET_REPLICATION_ENABLED"
1314
+ ]
1315
+
1316
+ rule S3_BUCKET_REPLICATION_ENABLED when %s3_buckets_replication_enabled !empty {
1317
+ %s3_buckets_replication_enabled.Properties.ReplicationConfiguration exists
1318
+ <<
1319
+ Guard Rule Set: PCI-DSS-3-2-1
1320
+ Controls: 2.2,10.5.3
1321
+ Violation: S3 Bucket replication should be enabled.
1322
+ Fix: Set S3 Bucket ReplicationConfiguration to another S3 Bucket.
1323
+ >>
1324
+ ## TODO regex to identify cross-region
1325
+ }
1326
+ #
1327
+ #####################################
1328
+ ## Gherkin ##
1329
+ #####################################
1330
+ # Rule Identifier:
1331
+ # S3_BUCKET_SERVER_SIDE_ENCRYPTION_ENABLED
1332
+ #
1333
+ # Description:
1334
+ # Checks if your Amazon S3 bucket either has the Amazon S3 default encryption enabled or that the Amazon S3 bucket policy
1335
+ # explicitly denies put-object requests without server side encryption that uses AES-256 or AWS Key Management Service.
1336
+ #
1337
+ # Reports on:
1338
+ # AWS::S3::Bucket
1339
+ #
1340
+ # Evaluates:
1341
+ # AWS CloudFormation
1342
+ #
1343
+ # Rule Parameters:
1344
+ # NA
1345
+ #
1346
+ # Scenarios:
1347
+ # a) SKIP: when there are no S3 resource present
1348
+ # b) PASS: when all S3 resources Bucket Encryption ServerSideEncryptionByDefault is set to either "aws:kms" or "AES256"
1349
+ # c) FAIL: when all S3 resources have Bucket Encryption ServerSideEncryptionByDefault is not set or does not have "aws:kms" or "AES256" configurations
1350
+ # d) SKIP: when metadata includes the suppression for rule S3_BUCKET_SERVER_SIDE_ENCRYPTION_ENABLED
1351
+
1352
+ #
1353
+ # Select all S3 resources from incoming template (payload)
1354
+ #
1355
+
1356
+ let s3_buckets_server_side_encryption = Resources.*[ Type == 'AWS::S3::Bucket'
1357
+ Metadata.guard.SuppressedRules not exists or
1358
+ Metadata.guard.SuppressedRules.* != "S3_BUCKET_SERVER_SIDE_ENCRYPTION_ENABLED"
1359
+ ]
1360
+
1361
+ rule S3_BUCKET_SERVER_SIDE_ENCRYPTION_ENABLED when %s3_buckets_server_side_encryption !empty {
1362
+ %s3_buckets_server_side_encryption.Properties.BucketEncryption exists
1363
+ %s3_buckets_server_side_encryption.Properties.BucketEncryption.ServerSideEncryptionConfiguration[*].ServerSideEncryptionByDefault.SSEAlgorithm in ["aws:kms","AES256"]
1364
+ <<
1365
+ Guard Rule Set: PCI-DSS-3-2-1
1366
+ Controls: 2.2,3.4,8.2.1,10.5
1367
+ Violation: S3 Bucket must enable server-side encryption.
1368
+ Fix: Set the S3 Bucket property BucketEncryption.ServerSideEncryptionConfiguration.ServerSideEncryptionByDefault.SSEAlgorithm to either "aws:kms" or "AES256"
1369
+ >>
1370
+ }
1371
+
1372
+ #
1373
+ #####################################
1374
+ ## Gherkin ##
1375
+ #####################################
1376
+ # Rule Identifier:
1377
+ # S3_BUCKET_SSL_REQUESTS_ONLY
1378
+ #
1379
+ # Description:
1380
+ # Checks if Amazon S3 buckets have policies that require requests to use Secure Socket Layer (SSL).
1381
+ #
1382
+ # Reports on:
1383
+ # AWS::S3::BucketPolicy
1384
+ #
1385
+ # Evaluates:
1386
+ # AWS CloudFormation
1387
+ #
1388
+ # Rule Parameters:
1389
+ # NA
1390
+ #
1391
+ # Scenarios:
1392
+ # a) SKIP: when there are no S3 Bucket Policy Document resource present
1393
+ # b) PASS: when all S3 Bucket Policy Document set to deny if condition SecureTransport not true
1394
+ # c) FAIL: when all S3 Bucket Policy Document does not have deny on insecure transport actions
1395
+ # d) SKIP: when metadata includes the suppression for rule S3_BUCKET_SSL_REQUESTS_ONLY
1396
+
1397
+ #
1398
+ # Select all S3 resources from incoming template (payload)
1399
+ #
1400
+ let s3_buckets_policies_ssl_requests_only = Resources.*[ Type == 'AWS::S3::BucketPolicy'
1401
+ Metadata.guard.SuppressedRules not exists or
1402
+ Metadata.guard.SuppressedRules.* != "S3_BUCKET_SSL_REQUESTS_ONLY"
1403
+ ]
1404
+
1405
+ rule S3_BUCKET_SSL_REQUESTS_ONLY when %s3_buckets_policies_ssl_requests_only !empty {
1406
+ some %s3_buckets_policies_ssl_requests_only.Properties.PolicyDocument.Statement.* == {"Action":"s3:*","Effect":"Deny","Principal":"*","Resource":"*","Condition":{"Bool":{"aws:SecureTransport":false}}}
1407
+ <<
1408
+ Guard Rule Set: PCI-DSS-3-2-1
1409
+ Controls: 2.2,4.1,8.2.1
1410
+ Violation: Bucket policies must feature a statement to enforce TLS usage.
1411
+ Fix: Set a bucket policy statement to '"Action":"s3:*","Effect":"Deny","Principal":"*","Resource":"*","Condition":{"Bool":{"aws:SecureTransport":false}}' .
1412
+ >>
1413
+ }
1414
+ #
1415
+ #####################################
1416
+ ## Gherkin ##
1417
+ #####################################
1418
+ # Rule Identifier:
1419
+ # EC2_INSTANCE_PROFILE_ATTACHED
1420
+ #
1421
+ # Description:
1422
+ # Checks if an Amazon Elastic Compute Cloud (Amazon EC2) instance has an Identity and Access Management (IAM) profile attached to it.
1423
+ #
1424
+ # Reports on:
1425
+ # AWS::EC2::Instance
1426
+ #
1427
+ # Evaluates:
1428
+ # AWS CloudFormation
1429
+ #
1430
+ # Rule Parameters:
1431
+ # NA
1432
+ #
1433
+ # Scenarios:
1434
+ # a) SKIP: when no EC2 Instance resources are present
1435
+ # b) PASS: when all EC2 Instace resources have an associated IAM instance profile
1436
+ # d) FAIL: when any EC2 Instace resources do not have an associated IAM instance profile
1437
+ # e) SKIP: hen metadata includes the suppression for rule EC2_INSTANCE_PROFILE_ATTACHED
1438
+
1439
+ #
1440
+ # Select all EC2 Instance resources from incoming template (payload)
1441
+ #
1442
+ let ec2_instances_profile_attached = Resources.*[ Type == 'AWS::EC2::Instance'
1443
+ Metadata.guard.SuppressedRules not exists or
1444
+ Metadata.guard.SuppressedRules.* != "EC2_INSTANCE_PROFILE_ATTACHED"
1445
+ ]
1446
+
1447
+ rule EC2_INSTANCE_PROFILE_ATTACHED when %ec2_instances_profile_attached !empty {
1448
+ %ec2_instances_profile_attached.Properties.IamInstanceProfile EXISTS
1449
+ <<
1450
+ Guard Rule Set: PCI-DSS-3-2-1
1451
+ Controls: 2.2,7.1.1,7.2.1
1452
+ Violation: EC2 Instances must have IAM profile attached to it.
1453
+ Fix: Associate the EC2 Instance property IamInstanceProfile with an IAM Instance Profile.
1454
+ >>
1455
+ }
1456
+
1457
+ ## Config Rule Name : alb-http-to-https-redirection-check
1458
+ ## Config Rule URL: https://docs.aws.amazon.com/config/latest/developerguide/alb-http-to-https-redirection-check.html"
1459
+
1460
+ # Rule Intent: Checks if HTTP to HTTPS redirection is configured on all HTTP listeners of Application Load Balancers.
1461
+
1462
+ # Expectations:
1463
+ # a) SKIP: when there are no ALB resources present
1464
+ # b) PASS: when one or more HTTP listeners have forwarding to an HTTPS listener
1465
+ # c) FAIL: when one of more HTTP listeners have forwarding to an HTTP listener instead of redirection.
1466
+ # d) FAIL: when one or more HTTP listeners of Application Load Balancer do not have HTTP to HTTPS redirection configured.
1467
+
1468
+
1469
+
1470
+ #
1471
+ # Select all ALB resources from incoming template (payload)
1472
+ #
1473
+
1474
+ ## Config Rule Name : api-gw-ssl-enabled
1475
+ ## Config Rule URL: https://docs.aws.amazon.com/config/latest/developerguide/api-gw-ssl-enabled.html"
1476
+
1477
+ ## Config Rule Name : elb-predefined-security-policy-ssl-check
1478
+ ## Config Rule URL: https://docs.aws.amazon.com/config/latest/developerguide/elb-predefined-security-policy-ssl-check.html"
1479
+
1480
+ ## Config Rule Name : elb-tls-https-listeners-only
1481
+ ## Config Rule URL: https://docs.aws.amazon.com/config/latest/developerguide/elb-tls-https-listeners-only.html"
1482
+
1483
+ #
1484
+ #####################################
1485
+ ## Gherkin ##
1486
+ #####################################
1487
+ # Rule Identifier:
1488
+ # CW_LOGGROUP_RETENTION_PERIOD_CHECK
1489
+ #
1490
+ # Description:
1491
+ # Checks whether Amazon CloudWatch LogGroup retention
1492
+ # period is set to specific number of days.
1493
+ #
1494
+ # Reports on:
1495
+ # AWS::Logs::LogGroup
1496
+ #
1497
+ # Evaluates:
1498
+ # AWS CloudFormation
1499
+ #
1500
+ # Rule Parameters:
1501
+ # NA
1502
+ #
1503
+ # Scenarios:
1504
+ # a) SKIP: when there are no cloudwatch logs log group resources present
1505
+ # b) PASS: when all cloudwatch logs log group resources property RetentionInDays is set
1506
+ # c) FAIL: when all cloudwatch logs log group resources property RetentionInDays is not set with valid value
1507
+ # d) SKIP: when metada has rule suppression for CW_LOGGROUP_RETENTION_PERIOD_CHECK
1508
+
1509
+ #
1510
+ # Select all cloudwatch logs log group resources from incoming template (payload)
1511
+ #
1512
+ let cloudwatch_logs_retention_period = Resources.*[ Type == 'AWS::Logs::LogGroup'
1513
+ Metadata.guard.SuppressedRules not exists or
1514
+ Metadata.guard.SuppressedRules.* != "CW_LOGGROUP_RETENTION_PERIOD_CHECK"
1515
+ ]
1516
+
1517
+ rule CW_LOGGROUP_RETENTION_PERIOD_CHECK when %cloudwatch_logs_retention_period !empty {
1518
+ %cloudwatch_logs_retention_period.Properties.RetentionInDays IN [1, 3, 5, 7, 14, 30, 60, 90, 120, 150, 180, 365, 400, 545, 731, 1827, 3653]
1519
+ <<
1520
+ Guard Rule Set: PCI-DSS-3-2-1
1521
+ Controls: 3.1,10.7
1522
+ Violation: CloudWatch Log LogsGroup does not have RetentionInDays set.
1523
+ Fix: Set the RetentionInDays parameter to a value of 1, 3, 5, 7, 14, 30, 60, 90, 120, 150, 180, 365, 400, 545, 731, 1827, or 3653.
1524
+ >>
1525
+ }
1526
+ ## Config Rule Name : api-gw-cache-enabled-and-encrypted
1527
+ ## Config Rule URL: https://docs.aws.amazon.com/config/latest/developerguide/api-gw-cache-enabled-and-encrypted.html"
1528
+
1529
+ #
1530
+ #####################################
1531
+ ## Gherkin ##
1532
+ #####################################
1533
+ # Rule Identifier:
1534
+ # CLOUDWATCH_LOG_GROUP_ENCRYPTED
1535
+ #
1536
+ # Description:
1537
+ # Checks if a log group in Amazon CloudWatch Logs is encrypted with a
1538
+ # AWS Key Management Service (KMS) managed Customer Master Keys (CMK).
1539
+ #
1540
+ # Reports on:
1541
+ # AWS::Logs::LogGroup
1542
+ #
1543
+ # Evaluates:
1544
+ # AWS CloudFormation
1545
+ #
1546
+ # Rule Parameters:
1547
+ # NA
1548
+ #
1549
+ # Scenarios:
1550
+ # a) SKIP: when there are no cloudwatch logs log group resources present
1551
+ # b) PASS: when all cloudwatch logs log group resources property KmsKeyId is set
1552
+ # c) FAIL: when all cloudwatch logs log group resources property KmsKeyId is not set with valid value
1553
+ # d) SKIP: when metada has rule suppression for CLOUDWATCH_LOG_GROUP_ENCRYPTED
1554
+
1555
+ #
1556
+ # Select all cloudwatch logs log group resources from incoming template (payload)
1557
+ #
1558
+ let cloudwatch_logs = Resources.*[ Type == 'AWS::Logs::LogGroup'
1559
+ Metadata.guard.SuppressedRules not exists or
1560
+ Metadata.guard.SuppressedRules.* != "CLOUDWATCH_LOG_GROUP_ENCRYPTED"
1561
+ ]
1562
+
1563
+ rule CLOUDWATCH_LOG_GROUP_ENCRYPTED when %cloudwatch_logs !empty {
1564
+ %cloudwatch_logs.Properties.KmsKeyId exists
1565
+ <<
1566
+ Guard Rule Set: PCI-DSS-3-2-1
1567
+ Controls: 3.4
1568
+ Violation: CloudWatch Log LogsGroup does not have KmsKeyId set.
1569
+ Fix: Set the KmsKeyId parameter to a ARN.
1570
+ >>
1571
+ }
1572
+
1573
+ ## Config Rule Name : dynamodb-table-encrypted-kms
1574
+ ## Config Rule URL: https://docs.aws.amazon.com/config/latest/developerguide/dynamodb-table-encrypted-kms.html"
1575
+
1576
+ #
1577
+ #####################################
1578
+ ## Gherkin ##
1579
+ #####################################
1580
+ # Rule Identifier:
1581
+ # EFS_ENCRYPTED_CHECK
1582
+ #
1583
+ # Description:
1584
+ # Checks if Amazon Elastic File System (Amazon EFS) is configured to encrypt the file data
1585
+ # using AWS Key Management Service (AWS KMS). The rule is NON_COMPLIANT if the encrypted
1586
+ # key is set to false on DescribeFileSystems or if the KmsKeyId key on DescribeFileSystems
1587
+ # does not match the KmsKeyId parameter.
1588
+ #
1589
+ # Reports on:
1590
+ # AWS::EFS::FileSystem
1591
+ #
1592
+ # Evaluates:
1593
+ # AWS CloudFormation
1594
+ #
1595
+ # Rule Parameters:
1596
+ # NA
1597
+ #
1598
+ # Scenarios:
1599
+ # a) SKIP: when there are no EFS resource present
1600
+ # b) PASS: when all EFS resources have encrypted key property set to true
1601
+ # c) FAIL: when all EFS resources have encrypted key property not set or set to false
1602
+ # d) SKIP: when guard metadata states EFS_ENCRYPTED_CHECK to be suppressed
1603
+
1604
+ #
1605
+ # Select all EFS resources from incoming template (payload)
1606
+ #
1607
+ let efs_file_systems_encrypted_check = Resources.*[ Type == 'AWS::EFS::FileSystem'
1608
+ Metadata.guard.SuppressedRules not exists or
1609
+ Metadata.guard.SuppressedRules.* != "EFS_ENCRYPTED_CHECK"
1610
+ ]
1611
+
1612
+ rule EFS_ENCRYPTED_CHECK when %efs_file_systems_encrypted_check !empty {
1613
+ %efs_file_systems_encrypted_check.Properties.Encrypted == true
1614
+ <<
1615
+ Guard Rule Set: PCI-DSS-3-2-1
1616
+ Controls: 3.4,8.2.1
1617
+ Violation: EFS filesystem must be encrypted.
1618
+ Fix: Set the EFS Filesystem property Encrypted parameter to true.
1619
+ >>
1620
+ }
1621
+ #
1622
+ #####################################
1623
+ ## Gherkin ##
1624
+ #####################################
1625
+ # Rule Identifier:
1626
+ # ELASTICSEARCH_ENCRYPTED_AT_REST
1627
+ #
1628
+ # Description:
1629
+ # Elasticsearch domains must enforce server side encryption
1630
+ #
1631
+ # Reports on:
1632
+ # AWS::Elasticsearch::Domain
1633
+ #
1634
+ # Evaluates:
1635
+ # AWS CloudFormation
1636
+ #
1637
+ # Rule Parameters:
1638
+ # NA
1639
+ #
1640
+ # Scenarios:
1641
+ # a) SKIP: when there is no elasticsearch domain present
1642
+ # b) FAIL: when elasticsearch domain has server side encryption set to false
1643
+ # c) PASS: when elasticsearch domain has server side encryption set to true
1644
+ # d) FAIL: when elasticsearch domain has server side encryption property is missing
1645
+ # e) SKIP: when metada has rule suppression for ELASTICSEARCH_ENCRYPTED_AT_REST
1646
+
1647
+ #
1648
+ # Select all elasticsearch domains from incoming template
1649
+ #
1650
+ let elasticsearch_domains_encrypted = Resources.*[ Type == 'AWS::Elasticsearch::Domain'
1651
+ Metadata.guard.SuppressedRules not exists or
1652
+ Metadata.guard.SuppressedRules.* != "ELASTICSEARCH_ENCRYPTED_AT_REST"
1653
+ ]
1654
+
1655
+ rule ELASTICSEARCH_ENCRYPTED_AT_REST when %elasticsearch_domains_encrypted !empty {
1656
+ %elasticsearch_domains_encrypted.Properties.EncryptionAtRestOptions.Enabled == true
1657
+ <<
1658
+ Guard Rule Set: PCI-DSS-3-2-1
1659
+ Controls: 3.4,8.2.1
1660
+ Violation: Elasticsearch domains must enforce server side encryption.
1661
+ Fix: Set the EncryptionAtRestOptions.Enabled parameter to true.
1662
+ >>
1663
+ }
1664
+ #
1665
+ #####################################
1666
+ ## Gherkin ##
1667
+ #####################################
1668
+ # Rule Identifier:
1669
+ # RDS_SNAPSHOT_ENCRYPTED
1670
+ #
1671
+ # Description:
1672
+ # Checks whether Amazon Relational Database Service (Amazon RDS) DB snapshots are encrypted.
1673
+ #
1674
+ #
1675
+ # Reports on:
1676
+ # AWS::RDS::DBInstance
1677
+ #
1678
+ # Evaluates:
1679
+ # AWS CloudFormation
1680
+ #
1681
+ # Rule Parameters:
1682
+ # NA
1683
+ #
1684
+ # Scenarios:
1685
+ # a) SKIP: when there are no RDS instances present
1686
+ # b) PASS: when all RDS instances have StorageEncrypted set to true
1687
+ # c) FAIL: when all RDS instances have StorageEncrypted set to false
1688
+ # d) FAIL: when there are RDS instances with StorageEncrypted property is not present
1689
+ # e) SKIP: when metadata includes the suppression for rule RDS_SNAPSHOT_ENCRYPTED
1690
+
1691
+ #
1692
+ # Select all RDS instance resources from incoming template (payload)
1693
+ #
1694
+ let aws_rds_instances_snapshot_encrypted = Resources.*[ Type == 'AWS::RDS::DBInstance'
1695
+ Metadata.guard.SuppressedRules not exists or
1696
+ Metadata.guard.SuppressedRules.* != "RDS_SNAPSHOT_ENCRYPTED"
1697
+ ]
1698
+
1699
+
1700
+ rule RDS_SNAPSHOT_ENCRYPTED when %aws_rds_instances_snapshot_encrypted !empty {
1701
+ %aws_rds_instances_snapshot_encrypted.Properties.StorageEncrypted EXISTS
1702
+ %aws_rds_instances_snapshot_encrypted.Properties.StorageEncrypted == true
1703
+ <<
1704
+ Guard Rule Set: PCI-DSS-3-2-1
1705
+ Controls: 3.4,8.2.1
1706
+ Violation: All RDS instances must have snapshots encrypted.
1707
+ Fix: Set the StorageEncrypted parameter to true so by default all snapshots are encrypted.
1708
+ >>
1709
+ }
1710
+
1711
+ #
1712
+ #####################################
1713
+ ## Gherkin ##
1714
+ #####################################
1715
+ # Rule Identifier:
1716
+ # RDS_STORAGE_ENCRYPTED
1717
+ #
1718
+ # Description:
1719
+ # Checks whether storage encryption is enabled for your RDS DB instances.
1720
+ #
1721
+ #
1722
+ # Reports on:
1723
+ # AWS::RDS::DBInstance
1724
+ #
1725
+ # Evaluates:
1726
+ # AWS CloudFormation
1727
+ #
1728
+ # Rule Parameters:
1729
+ # NA
1730
+ #
1731
+ # Scenarios:
1732
+ # a) SKIP: when there are no RDS instances present
1733
+ # b) PASS: when all RDS instances have StorageEncrypted set to true
1734
+ # c) FAIL: when all RDS instances have StorageEncrypted set to false
1735
+ # d) FAIL: when there are RDS instances with StorageEncrypted property is not present
1736
+ # e) SKIP: when metadata includes the suppression for rule RDS_STORAGE_ENCRYPTED
1737
+
1738
+ #
1739
+ # Select all RDS instance resources from incoming template (payload)
1740
+ #
1741
+ let aws_rds_instances_storage_encrypted = Resources.*[ Type == 'AWS::RDS::DBInstance'
1742
+ Metadata.guard.SuppressedRules not exists or
1743
+ Metadata.guard.SuppressedRules.* != "RDS_STORAGE_ENCRYPTED"
1744
+ ]
1745
+
1746
+
1747
+ rule RDS_STORAGE_ENCRYPTED when %aws_rds_instances_storage_encrypted !empty {
1748
+ %aws_rds_instances_storage_encrypted.Properties.StorageEncrypted EXISTS
1749
+ %aws_rds_instances_storage_encrypted.Properties.StorageEncrypted == true
1750
+ <<
1751
+ Guard Rule Set: PCI-DSS-3-2-1
1752
+ Controls: 3.4,8.2.1
1753
+ Violation: All RDS instances must have encrypted storage.
1754
+ Fix: Set the StorageEncrypted parameter to true.
1755
+ >>
1756
+ }
1757
+
1758
+ ####################################
1759
+ ## Gherkin ##
1760
+ #####################################
1761
+ # Rule Identifier:
1762
+ # REDSHIFT_CLUSTER_CONFIGURATION_CHECK
1763
+ #
1764
+ # Description:
1765
+ # Checks whether Amazon Redshift clusters have the specified settings (Encrypted Only)
1766
+ #
1767
+ # Reports on:
1768
+ # AWS::Redshift::Cluster
1769
+ #
1770
+ # Evaluates:
1771
+ # AWS CloudFormation
1772
+ #
1773
+ # Rule Parameters:
1774
+ # NA
1775
+ #
1776
+ # Scenarios:
1777
+ # a) SKIP: when there are no Redshift Cluster resource present
1778
+ # b) PASS: when Redshift Cluster resources have the Encrypted property set to true
1779
+ # c) FAIL: when any Redshift Cluster resources do not have Encrypted property set (default false)
1780
+ # d) FAIL: when any Redshift Cluster resources have Encrypted property set to false
1781
+ # e) SKIP: when metadata includes the suppression for rule REDSHIFT_CLUSTER_CONFIGURATION_CHECK
1782
+
1783
+ #
1784
+ # Select all Redshift Cluster resources from incoming template (payload)
1785
+ #
1786
+ let redhshift_clusters_configuration_check = Resources.*[ Type == 'AWS::Redshift::Cluster'
1787
+ Metadata.guard.SuppressedRules not exists or
1788
+ Metadata.guard.SuppressedRules.* != "REDSHIFT_CLUSTER_CONFIGURATION_CHECK"
1789
+ ]
1790
+
1791
+ rule REDSHIFT_CLUSTER_CONFIGURATION_CHECK when %redhshift_clusters_configuration_check !empty {
1792
+ %redhshift_clusters_configuration_check.Properties.Encrypted == true
1793
+
1794
+ <<
1795
+ Guard Rule Set: PCI-DSS-3-2-1
1796
+ Controls: 3.4,8.2.1,10.1,10.2.1,10.2.2,10.2.3,10.2.4,10.2.5,10.3.1,10.3.2,10.3.3,10.3.4,10.3.5,10.3.6
1797
+ Violation: Amazon Redshift configuration should have encryption enabled
1798
+ Fix: Set the Encrypted property to true
1799
+ >>
1800
+ }
1801
+ #
1802
+ #####################################
1803
+ ## Gherkin ##
1804
+ #####################################
1805
+ # Rule Identifier:
1806
+ # S3_DEFAULT_ENCRYPTION_KMS
1807
+ #
1808
+ # Description:
1809
+ # Checks whether the Amazon S3 buckets are encrypted with AWS Key Management Service(AWS KMS).
1810
+ # The rule is NON_COMPLIANT if the Amazon S3 bucket is not encrypted with AWS KMS key.
1811
+ #
1812
+ # Reports on:
1813
+ # AWS::S3::Bucket
1814
+ #
1815
+ # Evaluates:
1816
+ # AWS CloudFormation
1817
+ #
1818
+ # Rule Parameters:
1819
+ # NA
1820
+ #
1821
+ # Scenarios:
1822
+ # a) SKIP: when there are no S3 resource present
1823
+ # b) PASS: when all S3 resources have ServerSideEncryptionConfiguration property set with values of "aws:kms" or "AES256"
1824
+ # c) FAIL: when all S3 resources have ServerSideEncryptionConfiguration property not set or values are not "aws:kms" or "AES256"
1825
+ # d) SKIP: when metadata includes the suppression for rule S3_DEFAULT_ENCRYPTION_KMS
1826
+
1827
+ #
1828
+ # Assignments
1829
+ #
1830
+ let s3_buckets_s3_default_encryption = Resources.*[ Type == 'AWS::S3::Bucket'
1831
+ Metadata.guard.SuppressedRules not exists or
1832
+ Metadata.guard.SuppressedRules.* != "S3_DEFAULT_ENCRYPTION_KMS"
1833
+ ]
1834
+
1835
+ rule S3_DEFAULT_ENCRYPTION_KMS when %s3_buckets_s3_default_encryption !empty {
1836
+ %s3_buckets_s3_default_encryption.Properties.BucketEncryption exists
1837
+ %s3_buckets_s3_default_encryption.Properties.BucketEncryption.ServerSideEncryptionConfiguration[*].ServerSideEncryptionByDefault.SSEAlgorithm in ["aws:kms","AES256"]
1838
+ <<
1839
+ Guard Rule Set: PCI-DSS-3-2-1
1840
+ Controls: 3.4,8.2.1,10.5
1841
+ Violation: S3 Bucket default encryption must be set.
1842
+ Fix: Set the S3 Bucket property BucketEncryption.ServerSideEncryptionConfiguration.ServerSideEncryptionByDefault.SSEAlgorithm to either "aws:kms" or "AES256"
1843
+ >>
1844
+ }
1845
+
1846
+ ## Config Rule Name : sagemaker-endpoint-configuration-kms-key-configured
1847
+ ## Config Rule URL: https://docs.aws.amazon.com/config/latest/developerguide/sagemaker-endpoint-configuration-kms-key-configured.html"
1848
+
1849
+ ## Config Rule Name : sagemaker-notebook-instance-kms-key-configured
1850
+ ## Config Rule URL: https://docs.aws.amazon.com/config/latest/developerguide/sagemaker-notebook-instance-kms-key-configured.html"
1851
+
1852
+ ## Config Rule Name : secretsmanager-using-cmk
1853
+ ## Config Rule URL: https://docs.aws.amazon.com/config/latest/developerguide/secretsmanager-using-cmk.html"
1854
+
1855
+ ## Config Rule Name : kms-cmk-not-scheduled-for-deletion
1856
+ ## Config Rule URL: https://docs.aws.amazon.com/config/latest/developerguide/kms-cmk-not-scheduled-for-deletion.html"
1857
+
1858
+ ## Config Rule Name : acm-certificate-expiration-check
1859
+ ## Config Rule URL: https://docs.aws.amazon.com/config/latest/developerguide/acm-certificate-expiration-check.html"
1860
+
1861
+ ## Config Rule Name : alb-http-drop-invalid-header-enabled
1862
+ ## Config Rule URL: https://docs.aws.amazon.com/config/latest/developerguide/alb-http-drop-invalid-header-enabled.html"
1863
+
1864
+ #
1865
+ #####################################
1866
+ ## Gherkin ##
1867
+ #####################################
1868
+ # Rule Identifier:
1869
+ # ELASTICSEARCH_NODE_TO_NODE_ENCRYPTION_CHECK
1870
+ #
1871
+ # Description:
1872
+ # Elasticsearch domains must enforce Node-to-Node Encryption
1873
+ #
1874
+ # Reports on:
1875
+ # AWS::Elasticsearch::Domain
1876
+ #
1877
+ # Evaluates:
1878
+ # AWS CloudFormation
1879
+ #
1880
+ # Rule Parameters:
1881
+ # NA
1882
+ #
1883
+ # Scenarios:
1884
+ # a) SKIP: when there is no elasticsearch domain present
1885
+ # b) FAIL: when elasticsearch domain has Node-to-Node encryption set to false
1886
+ # c) PASS: when elasticsearch domain has Node-to-Node encryption set to true
1887
+ # d) FAIL: when elasticsearch domain has Node-to-Node encryption property missing
1888
+ # e) SKIP: when metada has rule suppression for ELASTICSEARCH_NODE_TO_NODE_ENCRYPTION_CHECK
1889
+
1890
+ #
1891
+ # Select all elasticsearch domains from incoming template
1892
+ #
1893
+
1894
+ let elasticsearch_domains_node2node_encrpytion = Resources.*[ Type == 'AWS::Elasticsearch::Domain'
1895
+ Metadata.guard.SuppressedRules not exists or
1896
+ Metadata.guard.SuppressedRules.* != "ELASTICSEARCH_NODE_TO_NODE_ENCRYPTION_CHECK"
1897
+ ]
1898
+
1899
+ rule ELASTICSEARCH_NODE_TO_NODE_ENCRYPTION_CHECK when %elasticsearch_domains_node2node_encrpytion !empty {
1900
+ %elasticsearch_domains_node2node_encrpytion.Properties.NodeToNodeEncryptionOptions.Enabled == true
1901
+ <<
1902
+ Guard Rule Set: PCI-DSS-3-2-1
1903
+ Controls: 4.1
1904
+ Violation: Elasticsearch domains must enforce Node-to-Node Encryption.
1905
+ Fix: Set the NodeToNodeEncryptionOptions.Enabled parameter to true.
1906
+ >>
1907
+ }
1908
+
1909
+ ## Config Rule Name : elb-acm-certificate-required
1910
+ ## Config Rule URL: https://docs.aws.amazon.com/config/latest/developerguide/elb-acm-certificate-required.html"
1911
+
1912
+ ## Config Rule Name : elbv2-acm-certificate-required
1913
+ ## Config Rule URL: https://docs.aws.amazon.com/config/latest/developerguide/elbv2-acm-certificate-required.html"
1914
+
1915
+ #
1916
+ #####################################
1917
+ ## Gherkin ##
1918
+ #####################################
1919
+ # Rule Identifier:
1920
+ # RDS_AUTOMATIC_MINOR_VERSION_UPGRADE_ENABLED
1921
+ #
1922
+ # Description:
1923
+ # Checks whether storage encryption is enabled for your RDS DB instances
1924
+ #
1925
+ # Reports on:
1926
+ # AWS::RDS::DBInstance
1927
+ #
1928
+ # Evaluates:
1929
+ # AWS CloudFormation
1930
+ #
1931
+ # Rule Parameters:
1932
+ # NA
1933
+ #
1934
+ # Scenarios:
1935
+ # a) SKIP: when there are no RDS instances present
1936
+ # b) PASS: when all RDS instances have AutoMinorVersionUpgrade set to true
1937
+ # c) FAIL: when all RDS instances have AutoMinorVersionUpgrade set to false
1938
+ # d) FAIL: when there are RDS instances with AutoMinorVersionUpgrade property is not present
1939
+ # e) SKIP: when metadata includes the suppression for rule RDS_AUTOMATIC_MINOR_VERSION_UPGRADE_ENABLED
1940
+
1941
+ #
1942
+ # Select all RDS instance resources from incoming template (payload)
1943
+ #
1944
+
1945
+ let aws_rds_instances_minor_version_upgrade_enabled = Resources.*[ Type == 'AWS::RDS::DBInstance'
1946
+ Metadata.guard.SuppressedRules not exists or
1947
+ Metadata.guard.SuppressedRules.* != "RDS_AUTOMATIC_MINOR_VERSION_UPGRADE_ENABLED"
1948
+ ]
1949
+
1950
+
1951
+ rule RDS_AUTOMATIC_MINOR_VERSION_UPGRADE_ENABLED when %aws_rds_instances_minor_version_upgrade_enabled !empty {
1952
+ %aws_rds_instances_minor_version_upgrade_enabled.Properties.AutoMinorVersionUpgrade EXISTS
1953
+ %aws_rds_instances_minor_version_upgrade_enabled.Properties.AutoMinorVersionUpgrade == true
1954
+ <<
1955
+ Guard Rule Set: PCI-DSS-3-2-1
1956
+ Controls: 6.2
1957
+ Violation: All RDS instances must have automatic minor version upgrade enabled.
1958
+ Fix: Set the AutoMinorVersionUpgrade parameter to true.
1959
+ >>
1960
+ }
1961
+
1962
+ ####################################
1963
+ ## Gherkin ##
1964
+ #####################################
1965
+ # Rule Identifier:
1966
+ # REDSHIFT_CLUSTER_MAINTENANCESETTINGS_CHECK
1967
+ #
1968
+ # Description:
1969
+ # Checks whether Amazon Redshift clusters have the specified maintenance settings (AllowVersionUpgrade, PreferredMaintenanceWindow, AutomatedSnapshotRetentionPeriod)
1970
+ #
1971
+ # Reports on:
1972
+ # AWS::Redshift::Cluster
1973
+ #
1974
+ # Evaluates:
1975
+ # AWS CloudFormation
1976
+ #
1977
+ # Rule Parameters:
1978
+ # NA
1979
+ #
1980
+ # Scenarios:
1981
+ # a) SKIP: when there are no Redshift Cluster resource present
1982
+ # b) PASS: when Redshift Cluster resources have properties PreferredMaintenanceWindow set, AllowVersionUpgrade either not set (default true) or set to true, and AutomatedSnapshotRetentionPeriod either not set (default 1 day) or set to greated than 0.
1983
+ # c) FAIL: when any Redshift Cluster resources do not have PreferredMaintenanceWindow property set
1984
+ # d) FAIL: when any Redshift Cluster resources have AllowVersionUpgrade property set to false
1985
+ # e) FAIL: when any Redshift Cluster resources have AutomatedSnapshotRetentionPeriod property set to 0
1986
+ # f) SKIP: when metadata includes the suppression for rule REDSHIFT_CLUSTER_MAINTENANCESETTINGS_CHECK
1987
+
1988
+ #
1989
+ # Select all Redshift Cluster resources from incoming template (payload)
1990
+ #
1991
+ let redhshift_clusters_maintenancesettings_check = Resources.*[ Type == 'AWS::Redshift::Cluster'
1992
+ Metadata.guard.SuppressedRules not exists or
1993
+ Metadata.guard.SuppressedRules.* != "REDSHIFT_CLUSTER_MAINTENANCESETTINGS_CHECK"
1994
+ ]
1995
+
1996
+ rule REDSHIFT_CLUSTER_MAINTENANCESETTINGS_CHECK when %redhshift_clusters_maintenancesettings_check !empty {
1997
+ %redhshift_clusters_maintenancesettings_check.Properties.PreferredMaintenanceWindow exists
1998
+
1999
+ %redhshift_clusters_maintenancesettings_check.Properties.AllowVersionUpgrade not exists or
2000
+ %redhshift_clusters_maintenancesettings_check.Properties.AllowVersionUpgrade == true
2001
+
2002
+
2003
+ %redhshift_clusters_maintenancesettings_check.Properties.AutomatedSnapshotRetentionPeriod not exists or
2004
+ %redhshift_clusters_maintenancesettings_check.Properties.AutomatedSnapshotRetentionPeriod > 0
2005
+
2006
+ <<
2007
+ Guard Rule Set: PCI-DSS-3-2-1
2008
+ Controls: 6.2
2009
+ Violation: Amazon Redshift maintenance settings must be configured
2010
+ Fix: set the PreferredMaintenanceWindow property, remove the AllowVersionUpgrade property (default true) or set it to true, and remove the AutomatedSnapshotRetentionPeriod property (default 1 day) or set it to greated than 0.
2011
+ >>
2012
+ }
2013
+ ## Config Rule Name : alb-waf-enabled
2014
+ ## Config Rule URL: https://docs.aws.amazon.com/config/latest/developerguide/alb-waf-enabled.html"
2015
+
2016
+ ## Config Rule Name : api-gw-associated-with-waf
2017
+ ## Config Rule URL: https://docs.aws.amazon.com/config/latest/developerguide/API_GW_ASSOCIATED_WITH_WAF.html"
2018
+
2019
+ #
2020
+ #####################################
2021
+ ## Gherkin ##
2022
+ #####################################
2023
+ # Rule Identifier:
2024
+ # IAM_POLICY_NO_STATEMENTS_WITH_FULL_ACCESS
2025
+ #
2026
+ # Description:
2027
+ # Checks if AWS Identity and Access Management (IAM) policies grant permissions to all actions on individual AWS resources.
2028
+ #
2029
+ # Reports on:
2030
+ # AWS::IAM::ManagedPolicy
2031
+ #
2032
+ # Evaluates:
2033
+ # AWS CloudFormation
2034
+ #
2035
+ # Rule Parameters:
2036
+ # NA
2037
+ #
2038
+ # Scenarios:
2039
+ # a) SKIP: when there are no IAM Managed Policies present
2040
+ # b) PASS: when all IAM Managed Policies do not allows full access to at least 1 AWS service
2041
+ # c) FAIL: when any IAM Managed Policies allows full access to at least 1 AWS service.
2042
+ # d) SKIP: when metada has rule suppression for IAM_POLICY_NO_STATEMENTS_WITH_FULL_ACCESS
2043
+
2044
+ #
2045
+ # Select all IAM Managed Policy resources from incoming template (payload)
2046
+ #
2047
+ let aws_iam_managed_policies_no_statements_with_full_access = Resources.*[ Type == 'AWS::IAM::ManagedPolicy'
2048
+ Metadata.guard.SuppressedRules not exists or
2049
+ Metadata.guard.SuppressedRules.* != "IAM_POLICY_NO_STATEMENTS_WITH_FULL_ACCESS"
2050
+ ]
2051
+
2052
+ rule IAM_POLICY_NO_STATEMENTS_WITH_FULL_ACCESS when %aws_iam_managed_policies_no_statements_with_full_access !empty {
2053
+ let violations = Resources.*[
2054
+ Type == 'AWS::IAM::ManagedPolicy'
2055
+ some Properties.PolicyDocument.Statement[*] {
2056
+ some Action[*] in ["*", /^[a-zA-Z0-9]*:\*$/]
2057
+ Effect == "Allow"
2058
+ Resource == "*"
2059
+ }
2060
+ ]
2061
+ %violations empty
2062
+ <<
2063
+ Guard Rule Set: PCI-DSS-3-2-1
2064
+ Controls: 7.1.2,7.1.3,7.2.1,7.2.2
2065
+ Violation: One or more IAM Managed Policies allow full access to at least 1 AWS service
2066
+ Fix: Remove policy statements that match {"Effect": "Allow", "Action": "<service-name>:*" ... } or {"Effect": "Allow", "Action": "*" ... }
2067
+ >>
2068
+ }
2069
+ ## Config Rule Name : emr-kerberos-enabled
2070
+ ## Config Rule URL: https://docs.aws.amazon.com/config/latest/developerguide/EMR_KERBEROS_ENABLED.html"
2071
+
2072
+ ## Config Rule Name : s3-bucket-policy-grantee-check
2073
+ ## Config Rule URL: https://docs.aws.amazon.com/config/latest/developerguide/s3-bucket-policy-grantee-check.html
2074
+
2075
+ # Rule Intent: Checks that the access granted by the Amazon S3 bucket is restricted by any of the AWS principals, federated users, service principals, IP addresses, or VPCs that you provide.
2076
+
2077
+ ## Config Rule Name : ecs-task-definition-user-for-host-mode-check
2078
+ ## Config Rule URL: https://docs.aws.amazon.com/config/latest/developerguide/ECS_TASK_DEFINITION_USER_FOR_HOST_MODE_CHECK.html"
2079
+
2080
+ ## Config Rule Name : codebuild-project-envvar-awscred-check
2081
+ ## Config Rule URL: https://docs.aws.amazon.com/config/latest/developerguide/codebuild-project-envvar-awscred-check.html"
2082
+
2083
+ ## Config Rule Name : codebuild-project-source-repo-url-check
2084
+ ## Config Rule URL: https://docs.aws.amazon.com/config/latest/developerguide/codebuild-project-source-repo-url-check.html"
2085
+
2086
+ ## Config Rule Name : sns-encrypted-kms
2087
+ ## Config Rule URL: https://docs.aws.amazon.com/config/latest/developerguide/sns-encrypted-kms.html"
2088
+
2089
+ ## Config Rule Name : api-gw-execution-logging-enabled
2090
+ ## Config Rule URL: https://docs.aws.amazon.com/config/latest/developerguide/api-gw-execution-logging-enabled.html"
2091
+
2092
+ ## Config Rule Name : elb-logging-enabled
2093
+ ## Config Rule URL: https://docs.aws.amazon.com/config/latest/developerguide/elb-logging-enabled.html"
2094
+
2095
+ #
2096
+ #####################################
2097
+ ## Gherkin ##
2098
+ #####################################
2099
+ # Rule Identifier:
2100
+ # RDS_INSTANCE_LOGGING_ENABLED
2101
+ #
2102
+ # Description:
2103
+ # Checks if log types exported to Amazon CloudWatch for an Amazon Relational
2104
+ # Database Service (Amazon RDS) instance are enabled.
2105
+ #
2106
+ # Reports on:
2107
+ # AWS::RDS::DBInstance
2108
+ #
2109
+ # Evaluates:
2110
+ # AWS CloudFormation
2111
+ #
2112
+ # Rule Parameters:
2113
+ # NA
2114
+ #
2115
+ # Scenarios:
2116
+ # a) SKIP: when there are no RDS instances present
2117
+ # b) PASS: when all RDS instances have EnableCloudwatchLogsExports set to true
2118
+ # c) FAIL: when all RDS instances have EnableCloudwatchLogsExports set to false
2119
+ # d) FAIL: when there are RDS instances with EnableCloudwatchLogsExports property is not present
2120
+ # e) SKIP: when metadata includes the suppression for rule RDS_INSTANCE_LOGGING_ENABLED
2121
+
2122
+ #
2123
+ # Select all RDS instance resources from incoming template (payload)
2124
+ #
2125
+
2126
+ let aws_rds_instances_logging_enabled = Resources.*[ Type == 'AWS::RDS::DBInstance'
2127
+ Metadata.guard.SuppressedRules not exists or
2128
+ Metadata.guard.SuppressedRules.* != "RDS_INSTANCE_LOGGING_ENABLED"
2129
+ ]
2130
+
2131
+
2132
+ rule RDS_INSTANCE_LOGGING_ENABLED when %aws_rds_instances_logging_enabled !empty {
2133
+ %aws_rds_instances_logging_enabled.Properties.EnableCloudwatchLogsExports EXISTS
2134
+ <<
2135
+ Guard Rule Set: PCI-DSS-3-2-1
2136
+ Controls: 10.1,10.2.1,10.2.2,10.2.3,10.2.4,10.2.5,10.3.1,10.3.2,10.3.3,10.3.4,10.3.5,10.3.6
2137
+ Violation: Enable CloudWatch Logs Exports for monitoring and logging.
2138
+ Fix: Provide EnableCloudWatchLogsExports object to start exporting cloudwatch logs.
2139
+ >>
2140
+ }
2141
+
2142
+
2143
+ ## Config Rule Name : wafv2-logging-enabled
2144
+ ## Config Rule URL: https://docs.aws.amazon.com/config/latest/developerguide/wafv2-logging-enabled.html"
2145
+
2146
+ #
2147
+ #####################################
2148
+ ## Gherkin ##
2149
+ #####################################
2150
+ # Rule Identifier:
2151
+ # ELASTICSEARCH_LOGS_TO_CLOUDWATCH
2152
+ #
2153
+ # Description:
2154
+ # Checks if Amazon OpenSearch Service (OpenSearch Service) domains are
2155
+ # configured to send logs to Amazon CloudWatch Logs.
2156
+ #
2157
+ # Reports on:
2158
+ # AWS::Elasticsearch::Domain
2159
+ #
2160
+ # Evaluates:
2161
+ # AWS CloudFormation
2162
+ #
2163
+ # Rule Parameters:
2164
+ # NA
2165
+ #
2166
+ # Scenarios:
2167
+ # a) SKIP: when there is no elasticsearch domain present
2168
+ # b) FAIL: when elasticsearch domain does not have LogPublishingOptions or Enabled parameter is set to false for all available keys
2169
+ # c) PASS: when elasticsearch domain has LogPublishingOptions with Enabled parameter is set to true on one key
2170
+ # d) SKIP: when metada has rule suppression for ELASTICSEARCH_LOGS_TO_CLOUDWATCH
2171
+
2172
+ #
2173
+ # Select all elasticsearch domains from incoming template
2174
+ #
2175
+
2176
+ let elasticsearch_domains_logs_cloudwatch = Resources.*[ Type == 'AWS::Elasticsearch::Domain'
2177
+ Metadata.guard.SuppressedRules not exists or
2178
+ Metadata.guard.SuppressedRules.* != "ELASTICSEARCH_LOGS_TO_CLOUDWATCH"
2179
+ ]
2180
+
2181
+ rule ELASTICSEARCH_LOGS_TO_CLOUDWATCH when %elasticsearch_domains_logs_cloudwatch !empty {
2182
+
2183
+ %elasticsearch_domains_logs_cloudwatch.Properties.LogPublishingOptions EXISTS
2184
+ %elasticsearch_domains_logs_cloudwatch.Properties.LogPublishingOptions.ES_APPLICATION_LOGS.Enabled == true OR
2185
+ %elasticsearch_domains_logs_cloudwatch.Properties.LogPublishingOptions.SEARCH_SLOW_LOGS.Enabled == true OR
2186
+ %elasticsearch_domains_logs_cloudwatch.Properties.LogPublishingOptions.INDEX_SLOW_LOGS.Enabled == true
2187
+ <<
2188
+ Guard Rule Set: PCI-DSS-3-2-1
2189
+ Controls: 10.1,10.2.1,10.2.2,10.2.3,10.2.4,10.2.5,10.3.1,10.3.2,10.3.3,10.3.4,10.3.5,10.3.6
2190
+ Violation: Elasticsearch domain must have logging configured to send logs to CloudWatch Logs.
2191
+ Fix: Set a LogPublishingOptions object to have the property "Enabled" parameter set to true for keys "ES_APPLICATION_LOGS", "SEARCH_SLOW_LOGS", or "INDEX_SLOW_LOGS".
2192
+ >>
2193
+ }
2194
+ #
2195
+ #####################################
2196
+ ## Gherkin ##
2197
+ #####################################
2198
+ # Rule Identifier:
2199
+ # S3_BUCKET_VERSIONING_ENABLED
2200
+ #
2201
+ # Description:
2202
+ # Checks if versioning is enabled for your S3 buckets.
2203
+ #
2204
+ # Reports on:
2205
+ # AWS::S3::Bucket
2206
+ #
2207
+ # Evaluates:
2208
+ # AWS CloudFormation
2209
+ #
2210
+ # Rule Parameters:
2211
+ # NA
2212
+ #
2213
+ # Scenarios:
2214
+ # a) SKIP: when there are no S3 resource present
2215
+ # b) PASS: when all S3 resources Versioning Configuration status is set to Enabled
2216
+ # c) FAIL: when all S3 resources have Versioning Configuration status property not set or set to Suspended
2217
+ # d) SKIP: when metadata includes the suppression for rule S3_BUCKET_VERSIONING_ENABLED
2218
+
2219
+ #
2220
+ # Select all S3 resources from incoming template (payload)
2221
+ #
2222
+ let s3_buckets_versioning_enabled = Resources.*[ Type == 'AWS::S3::Bucket'
2223
+ Metadata.guard.SuppressedRules not exists or
2224
+ Metadata.guard.SuppressedRules.* != "S3_BUCKET_VERSIONING_ENABLED"
2225
+ ]
2226
+
2227
+ rule S3_BUCKET_VERSIONING_ENABLED when %s3_buckets_versioning_enabled !empty {
2228
+ %s3_buckets_versioning_enabled.Properties.VersioningConfiguration exists
2229
+ %s3_buckets_versioning_enabled.Properties.VersioningConfiguration.Status == 'Enabled'
2230
+ <<
2231
+ Guard Rule Set: PCI-DSS-3-2-1
2232
+ Controls: 10.5.3
2233
+ Violation: S3 Bucket Versioning must be enabled.
2234
+ Fix: Set the S3 Bucket property VersioningConfiguration.Status to 'Enabled' .
2235
+ >>
2236
+ }