Description
A wildcard deletion grant can cover callers outside the intended cleanup roles. Its scope depends on conditions, resource ARNs, explicit denies and Block Public Access. Check object deletion separately from actions that remove a bucket policy or other settings.
Potential impact
In a versioning-enabled bucket, DeleteObject without a version ID creates a delete marker and hides the current object. Permanently deleting a version requires s3:DeleteObjectVersion. Lost data or settings can interrupt a service, and recovery depends on retained versions or backups.
Remediation
- Limit each cleanup role to the actions and bucket or object ARNs it needs. Remove broad grants such as
s3:*and grant version deletion separately. - Check the applied policy. If you use S3 module 3.7.0 to attach a custom policy, set
attach_policy = true. Test authorized cleanup, denied requests and recovery.
Examples
Choose one of these alternative policies for the separately defined aws_s3_bucket.example. Replace the documentation address 203.0.113.10/32 with the actual source range.
Allow deletion with an IP condition
resource "aws_s3_bucket_policy" "delete_open_policy" {
bucket = aws_s3_bucket.example.id
policy = <<POLICY
{
"Version": "2012-10-17",
"Id": "MYBUCKETPOLICY",
"Statement": [
{
"Sid": "IPAllow",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:DeleteObject",
"Resource": "${aws_s3_bucket.example.arn}/*",
"Condition": {
"IpAddress": {"aws:SourceIp": "203.0.113.10/32"}
}
}
]
}
POLICY
}
The grant checks only the source IP, so other principals using that address can also qualify.
Explicit deny with an IP condition
resource "aws_s3_bucket_policy" "delete_restricted_policy" {
bucket = aws_s3_bucket.example.id
policy = <<POLICY
{
"Version": "2012-10-17",
"Id": "MYBUCKETPOLICY",
"Statement": [
{
"Sid": "IPDeny",
"Effect": "Deny",
"Principal": "*",
"Action": "s3:*",
"Resource": "${aws_s3_bucket.example.arn}/*",
"Condition": {
"IpAddress": {"aws:SourceIp": "203.0.113.10/32"}
}
}
]
}
POLICY
}
The explicit deny covers object operations from the specified address and can block legitimate cleanup. Requests from other addresses fall outside this statement. Restrict the grant itself to the required roles.