Back to Checks
iac

Ensure a log metric filter and alarm exist for S3 bucket policy changes

AWS-0154
Service: cloudwatchSeverity: low
OfficialBuilt-inVerified

You can do real-time monitoring of API calls by directing CloudTrail logs to CloudWatch Logs and establishing corresponding metric filters and alarms. CIS recommends that you create a metric filter and alarm for changes to S3 bucket policies. Monitoring these changes might reduce time to detect and correct permissive policies on sensitive S3 buckets.

Run this check with Prowler

Run in Prowler Cloud
Run
prowler iac --checks AWS-0154

Recommendation

Create an alarm to alert on S3 Bucket policy changes

Check Code

# METADATA
# title: Ensure a log metric filter and alarm exist for S3 bucket policy changes
# description: |
#   You can do real-time monitoring of API calls by directing CloudTrail logs to CloudWatch Logs and establishing corresponding metric filters and alarms.
#   CIS recommends that you create a metric filter and alarm for changes to S3 bucket policies. Monitoring these changes might reduce time to detect and correct permissive policies on sensitive S3 buckets.
# scope: package
# schemas:
#   - input: schema["cloud"]
# related_resources:
#   - https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudwatch-alarms-for-cloudtrail.html
# custom:
#   id: AWS-0154
#   long_id: aws-cloudwatch-require-s3-bucket-policy-change-alarm
#   aliases:
#     - AVD-AWS-0154
#     - require-s3-bucket-policy-change-alarm
#     - aws-cloudwatch-require-s3-bucket-policy-change-alarm
#   provider: aws
#   service: cloudwatch
#   severity: LOW
#   recommended_action: Create an alarm to alert on S3 Bucket policy changes
#   frameworks:
#     cis-aws-1.2:
#       - "3.8"
#     cis-aws-1.4:
#       - "4.8"
#   input:
#     selector:
#       - type: cloud
#         subtypes:
#           - service: cloudwatch
#             provider: aws
package builtin.aws.cloudwatch.aws0154

import rego.v1

import data.lib.aws.trails

pattern := `{($.eventSource=s3.amazonaws.com) && (($.eventName=PutBucketAcl) || ($.eventName=PutBucketPolicy) || ($.eventName=PutBucketCors) || ($.eventName=PutBucketLifecycle) || ($.eventName=PutBucketReplication) || ($.eventName=DeleteBucketPolicy) || ($.eventName=DeleteBucketCors) || ($.eventName=DeleteBucketLifecycle) || ($.eventName=DeleteBucketReplication))}`

deny contains res if {
	some trail in trails.trails_without_filter(pattern)
	res := result.new("Cloudtrail has no S3 bucket policy change log filter", trail)
}

deny contains res if {
	some trail in trails.trails_without_alarm_for_filter(pattern)
	res := result.new("Cloudtrail has no S3 bucket policy change alarm", trail)
}