@aws/nx-plugin 0.1.6 → 0.2.0

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