Description
Grant s3:DeleteObject only to roles that need to remove objects. An allow statement with Principal: "*" can include anonymous requests.
Potential impact
Deleting an unversioned object can remove logs or backups. In a versioning-enabled general purpose bucket, deleting without a version ID adds a delete marker. Permanently deleting a specific version requires s3:DeleteObjectVersion.
Remediation
Limit the role and object ARNs and check conditions, explicit denies and Block Public Access. Review read permissions and retention separately, then verify the deletion and recovery procedure with a test object.
Examples
The first policy cannot be applied. Its language version 2020-10-07 is unsupported, DeleteObject lacks the S3 prefix, and Resource is missing.
Before
- name: Bucket
amazon.aws.s3_bucket:
name: mys3bucket
state: present
policy:
Version: "2020-10-07"
Statement:
- Effect: Allow
Action: DeleteObject
Principal: "*"
After
- name: Bucket
amazon.aws.s3_bucket:
name: mys3bucket
state: present
policy:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action: s3:DeleteObject
Resource: "arn:aws:s3:::mys3bucket/*"
Principal:
AWS: "arn:aws:iam::123456789012:role/ops-bucket-admin"
The second statement allows ops-bucket-admin to delete objects in mys3bucket. Substitute the actual role and object scope and check that unintended callers cannot delete them.