S3 bucket policy uses a wildcard principal

Review wildcard principals in S3 bucket policies alongside actions, conditions, explicit denies, and Block Public Access.

Description

An S3 bucket policy with Principal: "*" can include anonymous requests and other AWS accounts. Check which actions the statement allows on which resources.

Potential impact

Read access can expose files and backups. Write or delete access can change or remove data.

Remediation

Name the accounts, roles or services that need access. If a wildcard is necessary, check the condition keys, operators and values. For private buckets, check account and bucket Block Public Access settings and explicit denies, then verify that only the required external integrations work.

Examples

The first example uses ${aws_sqs_queue.q.arn}, an SQS reference that cannot identify a resource in an S3 bucket policy.

Before

yaml
- name: Create a simple s3 bucket with a policy
  amazon.aws.s3_bucket:
    name: mys3bucket
    policy:
      Version: "2012-10-17"
      Id: "sqspolicy"
      Statement:
        - Sid: First
          Effect: Allow
          Principal: "*"
          Action: "*"
          Resource: ${aws_sqs_queue.q.arn}

After

yaml
- name: Create a simple s3 bucket with a policy
  amazon.aws.s3_bucket:
    name: mys3bucket
    policy:
      Version: "2012-10-17"
      Id: "bucket-policy"
      Statement:
        - Sid: AllowReadFromSpecificRole
          Effect: Allow
          Principal:
            AWS: "arn:aws:iam::123456789012:role/app-bucket-reader"
          Action:
            - "s3:GetObject"
          Resource: "arn:aws:s3:::mys3bucket/*"

The second statement grants app-bucket-reader the s3:GetObject action on objects in mys3bucket. Substitute the actual bucket name and role ARN and check the role’s other permissions.

References