Description
Every bucket policy statement needs an Effect of Allow or Deny. An Allow with both Action: "*" and Principal: "*" can extend access far beyond what a workload needs.
Potential impact
Relaxing other safeguards can expose data for public reading or allow changes and deletions that disrupt services.
Remediation
Name the accounts, roles or services, actions and bucket or object ARNs required. s3:* still covers all S3 actions. Keep Block Public Access for private buckets and test intended and denied requests against all grants, conditions and explicit denies. After unintended public access, restrict access and review logs and policy changes.
Examples
The first example’s DOC-EXAMPLE-BUCKET contains hyphens, which CloudFormation logical IDs cannot contain. The second excerpt requires an S3 bucket resource named ExampleBucket in the same template.
Broad actions for all principals
Resources:
SampleBucketPolicy3:
Type: "AWS::S3::BucketPolicy"
Properties:
Bucket: !Ref DOC-EXAMPLE-BUCKET
PolicyDocument:
Statement:
- Action: "*"
Effect: Allow
Resource: "*"
Principal: "*"
The first statement is written to allow all principals and actions.
Explicit GetObject deny
Resources:
SampleBucketPolicy1:
Type: "AWS::S3::BucketPolicy"
Properties:
Bucket: !Ref ExampleBucket
PolicyDocument:
Statement:
- Action:
- "s3:GetObject"
Effect: Deny
Resource: !Sub '${ExampleBucket.Arn}/*'
Principal: "*"
The second denies s3:GetObject to everyone, including legitimate readers of current objects. Its deny does not cover s3:GetObjectVersion, writes or deletions.