@aws/nx-plugin 0.1.6 → 0.2.1

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