Bucket policies
A bucket policy decides who can do what with a bucket and its objects. Use one when you want to make files public, give another S3 user access, allow access only from certain IP addresses, or stop objects being deleted by mistake.
- Create a bucket policy in the web panel or with the API
- Edit or delete a bucket policy
- Copy-paste examples
How policies work
- A policy is a JSON document attached to one bucket. It uses the same language as Amazon S3 bucket policies.
- Only the bucket owner can attach, change or delete the policy. The owner always keeps access to their own bucket.
- Each policy has one or more statements. A statement says whether to Allow or Deny a list of actions on a resource, for a principal (who), optionally under a condition.
- Anything not explicitly allowed is denied. An explicit Deny always wins over an Allow.
- Permissions belong to S3 users, not to individual access keys. To give a tool less access, use a separate S3 user (see Managing access keys).
- Changes take effect within a short time, not instantly. Wait a minute before testing a new policy.
:::warning A policy is not immutability Because the bucket owner can always delete the policy, a Deny rule only protects against mistakes and other users. It can't stop the owner, or someone holding the owner's keys. To make data truly undeletable for a set time, use Object Lock. :::
Policy elements
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "ReadOnlyFromOffice",
"Effect": "Allow",
"Principal": { "AWS": "arn:aws:iam::<domain_id>:<user_id>" },
"Action": ["s3:GetObject"],
"Resource": "arn:aws:s3:::<bucket>/*",
"Condition": { "IpAddress": { "aws:SourceIp": "203.0.113.0/24" } }
}
]
}
| Element | What it means |
|---|---|
Version | Policy language version. Always 2012-10-17. |
Sid | A name for the statement. Letters and numbers only, no spaces. |
Effect | Allow or Deny. |
Principal | Who the statement applies to. "*" means everyone, including anonymous users. A specific S3 user is written as arn:aws:iam::<domain_id>:<user_id>. |
Action | One or more actions from the reference below, e.g. s3:GetObject. |
Resource | arn:aws:s3:::<bucket> for the bucket itself (listing, settings), or arn:aws:s3:::<bucket>/* for objects. Use arn:aws:s3:::<bucket>/<prefix>/* for one folder. |
Condition | Optional limits, e.g. source IP address or TLS version. |
Supported actions
Object Storage supports these actions in bucket policies. Wildcards such as s3:* and s3:Get* also work.
Objects: read
| Action | Allows |
|---|---|
s3:GetObject | Downloading objects and reading their metadata (also used for HEAD requests) |
s3:GetObjectVersion | Downloading a specific older version |
s3:GetObjectAcl | Reading an object's ACL |
s3:GetObjectVersionAcl | Reading the ACL of a specific version |
Objects: write and delete
| Action | Allows |
|---|---|
s3:PutObject | Uploading objects, including multipart uploads and copies |
s3:DeleteObject | Deleting objects. On a versioned bucket this only adds a delete marker; older versions remain. |
s3:DeleteObjectVersion | Permanently deleting a specific version |
s3:AbortMultipartUpload | Cancelling an unfinished multipart upload |
s3:ListMultipartUploadParts | Listing the parts of an unfinished multipart upload |
Bucket: listing and settings
| Action | Allows |
|---|---|
s3:ListBucket | Listing the objects in the bucket |
s3:ListBucketMultipartUploads | Listing unfinished multipart uploads |
s3:GetBucketLocation | Reading the bucket's location |
s3:DeleteBucket | Deleting the (empty) bucket |
s3:GetBucketCORS, s3:PutBucketCORS | Reading and setting CORS rules |
s3:GetBucketWebsite, s3:PutBucketWebsite | Reading and setting static website settings |
s3:GetBucketLogging, s3:PutBucketLogging | Reading and setting access logging |
s3:GetBucketNotification, s3:PutBucketNotification | Reading and setting event notifications |
s3:PutBucketRequestPayment | Setting request payment configuration |
Versioning
| Action | Allows |
|---|---|
s3:GetBucketVersioning | Reading whether versioning is on |
s3:PutBucketVersioning | Turning versioning on or suspending it |
s3:ListBucketVersions | Listing all versions and delete markers |
Object Lock
There are no separate Object Lock actions in bucket policies. Instead, you can use these condition keys on s3:PutObject to control which retention settings uploads may set:
| Condition key | Values |
|---|---|
s3:object-lock-mode | GOVERNANCE or COMPLIANCE |
s3:object-lock-retain-until-date | Date |
s3:object-lock-remaining-retention-days | Number of days |
s3:object-lock-legal-hold | ON or OFF |
Turning on Object Lock and setting retention or legal hold is done with the API. See Object Lock.
Lifecycle
| Action | Allows |
|---|---|
s3:GetLifecycleConfiguration | Reading lifecycle rules |
s3:PutLifecycleConfiguration | Setting or replacing lifecycle rules |
Lifecycle rules are API only.
Replication
| Action | Allows |
|---|---|
s3:GetReplicationConfiguration | Reading the cross-region replication setup |
s3:PutReplicationConfiguration | Setting up cross-region replication |
Policy and ACL management
| Action | Allows |
|---|---|
s3:GetBucketPolicy | Reading the bucket policy |
s3:PutBucketPolicy | Attaching or replacing the bucket policy (bucket owner only) |
s3:DeleteBucketPolicy | Removing the bucket policy (bucket owner only) |
s3:GetBucketAcl, s3:PutBucketAcl | Reading and setting the bucket ACL |
s3:PutObjectAcl, s3:PutObjectVersionAcl | Setting ACLs on objects and versions |
Supported condition keys
These keys work with every action:
| Condition key | Use it to | Values |
|---|---|---|
aws:SourceIp | Allow or deny by client IP address or range | IP or CIDR, e.g. 203.0.113.0/24 |
s3:TlsVersion | Require a minimum TLS version | 1.2, 1.1, 1.0 |
s3:signatureversion | Require a signature version | AWS (V2), AWS4-HMAC-SHA256 (V4) |
s3:signatureAge | Limit how old a request signature can be | Milliseconds |
s3:authType | Allow or deny by authentication method | REST-HEADER, REST-QUERY-STRING (presigned links), POST |
s3:x-amz-content-sha256 | Deny unsigned uploads | UNSIGNED-PAYLOAD |
These keys only work with the actions listed:
| Condition key | Actions | Use it to |
|---|---|---|
s3:prefix, s3:max-keys | s3:ListBucket, s3:ListBucketVersions | Limit listing to a folder, or the number of results |
s3:versionid | Version actions (s3:GetObjectVersion, s3:DeleteObjectVersion, …) | Match a specific version ID |
s3:x-amz-acl, s3:x-amz-grant-* | s3:PutObject, s3:PutObjectAcl, s3:PutObjectVersionAcl, s3:PutBucketAcl | Control which ACLs can be set |
s3:x-amz-storage-class | s3:PutObject, s3:PutObjectAcl, s3:PutObjectVersionAcl | Match the storage class in the request |
s3:x-amz-copy-source | s3:PutObject | Limit which objects can be copied in |
s3:x-amz-website-redirect-location | s3:PutObject | Control website redirects |
s3:object-lock-* | s3:PutObject | See Object Lock above |
Supported condition operators
| Type | Operators |
|---|---|
| String | StringEquals, StringNotEquals, StringEqualsIgnoreCase, StringNotEqualsIgnoreCase, StringLike, StringNotLike (wildcards * and ?) |
| Number | NumericEquals, NumericNotEquals, NumericLessThan, NumericLessThanEquals, NumericGreaterThan, NumericGreaterThanEquals |
| Date | DateEquals, DateNotEquals, DateLessThan, DateLessThanEquals, DateGreaterThan, DateGreaterThanEquals |
| IP address | IpAddress, NotIpAddress |
| Binary | BinaryEquals (base64-encoded value) |
For details on each operator, see the AWS IAM condition operator reference.