
Use custom rules to validate your compliance
Learn how you can built custom rules to validate compliance in your AWS accounts, using AWS Config and cfn-guard.
s3-bucket-logging-enabled
. When you enable the AWS Foundational Security Best Practices v1.0.0 standard in Security Hub it becomes available.- When the resource is not an S3 bucket, we should skip the rule.
- When the resource is the actual logging bucket, we should skip the rule.
- When the resource does not have logging configured, we should fail the rule.
- When the resource has logging configured on a different bucket then the one we want. We should fail the rule.
- When the resource has logging configured with the expected bucket, we should pass the rule.
loggingBucket
. You can reference that value of this parameter using: CONFIG_RULE_PARAMETERS.loggingBucket
.1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
Resources:
S3AccessLogging:
Type: AWS::Config::ConfigRule
Properties:
ConfigRuleName: lz-s3-access-logging
Description: Validate that access logging has been enabled and that the correct logging bucket is used.
EvaluationModes:
- Mode: DETECTIVE
InputParameters:
Fn::Sub: '{"loggingBucket": "s3-access-logs-${AWS::AccountId}-${AWS::Region}"}'
Scope:
ComplianceResourceTypes: ["AWS::S3::Bucket"]
Source:
Owner: CUSTOM_POLICY
SourceDetails:
- EventSource: aws.config
MessageType: ConfigurationItemChangeNotification
- EventSource: aws.config
MessageType: OversizedConfigurationItemChangeNotification
CustomPolicyDetails:
EnableDebugLogDelivery: 'true'
PolicyRuntime: guard-2.x.x
PolicyText: |-
rule s3_logging_configuration when resourceType == "AWS::S3::Bucket" resourceName != CONFIG_RULE_PARAMETERS.loggingBucket {
supplementaryConfiguration.BucketLoggingConfiguration exists
<<
Violation: S3 Bucket needs to have access logging configured
Fix: Configure the destinationBucketName on your S3 bucket
>>
}
rule s3_logging_correct_bucket when s3_logging_configuration {
supplementaryConfiguration.BucketLoggingConfiguration {
destinationBucketName == CONFIG_RULE_PARAMETERS.loggingBucket
<<
Violation: S3 Bucket needs to have access logging configured
Fix: Configure the destinationBucketName on your S3 bucket
>>
}
}
loggingBucket
is configurable via the InputParameters. Next, we will check if the bucket has used the logging bucket for the access logs configured. When the logging configuration exists the destinationBucketName
needs to match the given name.