S3 bucket policy with Put actions and a wildcard principal

Restrict S3 object writes and configuration changes to required principals and resources to prevent unwanted uploads and modifications.

Description

Grant s3:PutObject to the callers and objects that need uploads. Review other Put actions separately because they can change bucket or object settings.

Potential impact

An upload can create a key or change its current contents, subject to versioning and conditional requests. Unwanted uploads can change published content or processing results and increase storage and request costs.

Remediation

Limit the uploader, object ARNs and conditions. Check explicit denies and Block Public Access, and validate uploaded data and costs in the consuming service. Handle read and delete permissions separately.

Examples

The first policy cannot be applied. Its language version 2020-10-07 is unsupported, PutObject lacks the S3 prefix, and Resource is missing.

Before

yaml
- name: Bucket
  amazon.aws.s3_bucket:
    name: mys3bucket
    state: present
    policy:
      Version: "2020-10-07"
      Statement:
        - Effect: Allow
          Action: PutObject
          Principal: "*"

After

yaml
- name: Bucket
  amazon.aws.s3_bucket:
    name: mys3bucket
    state: present
    policy:
      Version: "2012-10-17"
      Statement:
        - Effect: Allow
          Action: s3:PutObject
          Resource: "arn:aws:s3:::mys3bucket/*"
          Principal:
            AWS: "arn:aws:iam::123456789012:role/upload-service-role"

The second statement grants upload-service-role object writes in mys3bucket. Substitute the actual role and upload path and test both an allowed upload and a rejected one.

References