Description
In an S3 bucket policy’s Allow statement, name the users, roles, accounts or services that need access. A Principal of * can include anonymous requests. If the principal is missing, validate and correct the policy.
Potential impact
Public read access can expose object contents. Writes and deletions require separate permissions.
Remediation
Apply account and bucket Block Public Access for private buckets. For intentional public access, limit the actions and objects. Review conditions and explicit denies with IAM Access Analyzer or a similar tool, then test that only the intended reads succeed.
Examples
The first example uses the fixed name DOC-EXAMPLE-BUCKET in the object ARN even though the stack generates the bucket name.
Before
Resources:
Bucket:
Type: AWS::S3::Bucket
BucketPolicy:
Type: AWS::S3::BucketPolicy
Properties:
Bucket: !Ref Bucket
PolicyDocument:
Statement:
- Effect: Allow
Principal:
AWS:
- "*"
Action: s3:GetObject
Resource: arn:aws:s3:::DOC-EXAMPLE-BUCKET/*
After
Resources:
Bucket:
Type: AWS::S3::Bucket
BucketPolicy:
Type: AWS::S3::BucketPolicy
Properties:
Bucket: !Ref Bucket
PolicyDocument:
Statement:
- Effect: Allow
Principal:
AWS:
- arn:aws:iam::111122223333:user/Alice
- arn:aws:iam::111122223333:user/foo
Action: s3:GetObject
Resource: !Sub '${Bucket.Arn}/*'
The second statement allows two IAM users to perform s3:GetObject on objects in the bucket the stack creates. Substitute existing user ARNs and check for permissions granted by other policies.