Skip to main content

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.

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" } }
}
]
}
ElementWhat it means
VersionPolicy language version. Always 2012-10-17.
SidA name for the statement. Letters and numbers only, no spaces.
EffectAllow or Deny.
PrincipalWho the statement applies to. "*" means everyone, including anonymous users. A specific S3 user is written as arn:aws:iam::<domain_id>:<user_id>.
ActionOne or more actions from the reference below, e.g. s3:GetObject.
Resourcearn: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.
ConditionOptional 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​

ActionAllows
s3:GetObjectDownloading objects and reading their metadata (also used for HEAD requests)
s3:GetObjectVersionDownloading a specific older version
s3:GetObjectAclReading an object's ACL
s3:GetObjectVersionAclReading the ACL of a specific version

Objects: write and delete​

ActionAllows
s3:PutObjectUploading objects, including multipart uploads and copies
s3:DeleteObjectDeleting objects. On a versioned bucket this only adds a delete marker; older versions remain.
s3:DeleteObjectVersionPermanently deleting a specific version
s3:AbortMultipartUploadCancelling an unfinished multipart upload
s3:ListMultipartUploadPartsListing the parts of an unfinished multipart upload

Bucket: listing and settings​

ActionAllows
s3:ListBucketListing the objects in the bucket
s3:ListBucketMultipartUploadsListing unfinished multipart uploads
s3:GetBucketLocationReading the bucket's location
s3:DeleteBucketDeleting the (empty) bucket
s3:GetBucketCORS, s3:PutBucketCORSReading and setting CORS rules
s3:GetBucketWebsite, s3:PutBucketWebsiteReading and setting static website settings
s3:GetBucketLogging, s3:PutBucketLoggingReading and setting access logging
s3:GetBucketNotification, s3:PutBucketNotificationReading and setting event notifications
s3:PutBucketRequestPaymentSetting request payment configuration

Versioning​

ActionAllows
s3:GetBucketVersioningReading whether versioning is on
s3:PutBucketVersioningTurning versioning on or suspending it
s3:ListBucketVersionsListing 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 keyValues
s3:object-lock-modeGOVERNANCE or COMPLIANCE
s3:object-lock-retain-until-dateDate
s3:object-lock-remaining-retention-daysNumber of days
s3:object-lock-legal-holdON or OFF

Turning on Object Lock and setting retention or legal hold is done with the API. See Object Lock.

Lifecycle​

ActionAllows
s3:GetLifecycleConfigurationReading lifecycle rules
s3:PutLifecycleConfigurationSetting or replacing lifecycle rules

Lifecycle rules are API only.

Replication​

ActionAllows
s3:GetReplicationConfigurationReading the cross-region replication setup
s3:PutReplicationConfigurationSetting up cross-region replication

Policy and ACL management​

ActionAllows
s3:GetBucketPolicyReading the bucket policy
s3:PutBucketPolicyAttaching or replacing the bucket policy (bucket owner only)
s3:DeleteBucketPolicyRemoving the bucket policy (bucket owner only)
s3:GetBucketAcl, s3:PutBucketAclReading and setting the bucket ACL
s3:PutObjectAcl, s3:PutObjectVersionAclSetting ACLs on objects and versions

Supported condition keys​

These keys work with every action:

Condition keyUse it toValues
aws:SourceIpAllow or deny by client IP address or rangeIP or CIDR, e.g. 203.0.113.0/24
s3:TlsVersionRequire a minimum TLS version1.2, 1.1, 1.0
s3:signatureversionRequire a signature versionAWS (V2), AWS4-HMAC-SHA256 (V4)
s3:signatureAgeLimit how old a request signature can beMilliseconds
s3:authTypeAllow or deny by authentication methodREST-HEADER, REST-QUERY-STRING (presigned links), POST
s3:x-amz-content-sha256Deny unsigned uploadsUNSIGNED-PAYLOAD

These keys only work with the actions listed:

Condition keyActionsUse it to
s3:prefix, s3:max-keyss3:ListBucket, s3:ListBucketVersionsLimit listing to a folder, or the number of results
s3:versionidVersion 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:PutBucketAclControl which ACLs can be set
s3:x-amz-storage-classs3:PutObject, s3:PutObjectAcl, s3:PutObjectVersionAclMatch the storage class in the request
s3:x-amz-copy-sources3:PutObjectLimit which objects can be copied in
s3:x-amz-website-redirect-locations3:PutObjectControl website redirects
s3:object-lock-*s3:PutObjectSee Object Lock above

Supported condition operators​

TypeOperators
StringStringEquals, StringNotEquals, StringEqualsIgnoreCase, StringNotEqualsIgnoreCase, StringLike, StringNotLike (wildcards * and ?)
NumberNumericEquals, NumericNotEquals, NumericLessThan, NumericLessThanEquals, NumericGreaterThan, NumericGreaterThanEquals
DateDateEquals, DateNotEquals, DateLessThan, DateLessThanEquals, DateGreaterThan, DateGreaterThanEquals
IP addressIpAddress, NotIpAddress
BinaryBinaryEquals (base64-encoded value)

For details on each operator, see the AWS IAM condition operator reference.

Was this page helpful?