Description
Check wildcards in both Action and Principal. s3:* matches every S3 action and s3:Get* matches a subset. An object ARN covers object-level operations.
Potential impact
Unneeded reads can disclose contents. Writes and deletions can change published content or cause data loss and outages.
Remediation
Limit the principals, actions and ARNs. Check account and bucket Block Public Access, conditions and explicit denies. Even where reads are public, restrict and test writes and administration separately. S3 module 3.7.0 requires attach_policy = true for a custom policy.
Legacy policy examples
For a new bucket, use an available unique name in both the bucket configuration and the policy’s object ARN. For an existing bucket, keep its name and Terraform resource address when editing the policy. The excerpts give the same bucket different resource addresses. Check Object Ownership and Block Public Access. AWS provider 4.2.0 treats policy and acl as read-only on this resource, so define the policy as a separate resource with that version.
Allow all object actions
resource "aws_s3_bucket" "open_bucket" {
bucket = "example-s3b-181355"
acl = "private"
policy = <<EOF
{
"Id": "id113",
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"s3:*"
],
"Effect": "Allow",
"Resource": "arn:aws:s3:::example-s3b-181355/*",
"Principal": "*"
}
]
}
EOF
}
The first statement allows every S3 action applicable to the named objects for any principal. A private ACL does not cancel that grant.
Narrow only the action to object writes
resource "aws_s3_bucket" "restricted_bucket" {
bucket = "example-s3b-181355"
acl = "private"
policy = <<EOF
{
"Id": "id113",
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"s3:putObject"
],
"Effect": "Allow",
"Resource": "arn:aws:s3:::example-s3b-181355/*",
"Principal": "*"
}
]
}
EOF
}
The second still allows s3:putObject for every principal. Action names are case-insensitive. Limit uploads to approved callers and object ARNs.
References
- CWE-250
- AWS S3 bucket resource
- AWS policy Action element
- AWS policy Principal element
- AWS policy Effect element
- Permissions and resource types for S3 operations
- S3 Block Public Access
- S3 bucket naming rules
- S3 bucket attributes in AWS provider 4.2.0
- Policy handling in S3 module 3.7.0
- Input defaults in S3 module 3.7.0