Access policies
An access policy (bucket policy) is a way to manage access to the contents and settings of a bucket. Unlike an access control list (ACL), an access policy provides a more predictable and flexible access model.
The joint use of an access policy and an ACL is governed by the bucket parameter OwnershipControls, which has two modes:
BucketOwnerEnforced— only the access policy is used, the ACL is not used (disabled). The recommended way for flexible rights management in one place.BucketOwnerPreferred— access is first checked by the policy, then the ACL is checked. It can be used, for example, to maintain backward compatibility. Enabled by default.
Using BucketOwnerPreferred can cause conflicts between the access policy and the ACL. Where possible, it is recommended to disable the ACL in the bucket settings, after which the OwnershipControls mode will be changed to BucketOwnerEnforced.
Examples of using an access policy:
- managing access to objects within a bucket;
- controlling bucket access for external read or write;
- granting access permissions to individual users or projects;
- restricting access by IP addresses, path prefixes, or other conditions.
The access policy configuration is specified in JSON format, which contains one or more rules.
Structure of the JSON file:
{"Version": "2012-10-17","Id": "","Statement": [{"Sid": "","Action": [""],"Effect": "","Principal": {"AWS":[""]},"Resource": [""],"Condition": {...}},...]}
Here:
Id— a unique identifier (name) of the access policy.Statement— an array of access policy rules.Sid— a unique identifier (name) of the rule.Action— a string or an array of strings with the actions to which the rule applies.Effect— allow or deny for performing the action.Principal— a string or an array of strings with the principals (subjects) to which the rule applies.Condition— defines under which conditions the rule is triggered.Resource— a string or an array of strings in thearn:aws:s3:::<RESOURCE>format specifying the resource for which the rule is set.
Detailed descriptions of the Action, Effect, Principal, Condition, and Resource parameters are provided below.
The Action parameter defines which actions with buckets and objects will be allowed or denied.
| Abort a multipart upload and delete already uploaded parts |
| Request the parts of a multipart upload |
| Request the list of incomplete multipart uploads in a bucket |
| Request (download) the contents of an object |
| Request (download) the contents of a specific version of an object |
| Request the extended attributes of an object |
| Request the extended attributes of a specific version of an object |
| Upload or overwrite an object (with versioning enabled, create a new version) |
| Delete an object |
| Delete a specific version of an object |
| Request the ACL of an object |
| Request the ACL of a specific version of an object |
| Set or overwrite the ACL of an object |
| Set or overwrite the ACL of a specific version of an object |
| Request the tags of an object |
| Set or overwrite the tags of an object |
| Delete the tags of an object |
| Check the status of an object's indefinite (legal) hold |
| Set or remove an object's indefinite (legal) hold |
| Get the status of an object's temporary retention |
| Set or change an object's temporary retention |
| Bypass a temporary retention |
| Request the list of objects in a bucket |
| Request the list of object versions and delete markers |
| Request the ACL of a bucket |
| Set or overwrite the ACL of a bucket |
| Request the access policy of a bucket |
| Set or overwrite the access policy of a bucket |
| Delete the access policy of a bucket |
| Request the bucket status indicating public access |
| Request the access management configuration of a bucket |
| Set or overwrite the access management configuration of a bucket |
| Request the object lock configuration at the bucket level |
| Set or overwrite the object lock configuration at the bucket level |
| Request the CORS configuration of a bucket |
| Set or overwrite the CORS configuration of a bucket |
| Request the static website configuration of a bucket |
| Set or overwrite the static website configuration of a bucket |
| Delete the static website configuration from a bucket |
| Request the notification configuration |
| Set or overwrite the notification configuration |
| Request the versioning status of a bucket |
| Enable or suspend versioning of a bucket |
| Request the lifecycle rules of a bucket |
| Set or overwrite the lifecycle rules of a bucket |
| Get the region of a bucket |
| Delete a bucket |
All actions can be allowed (Allow) or denied (Deny) both implicitly and explicitly.
-
Implicit allow: set automatically by VK Object Storage and applied by default to all internal principals.
-
Implicit deny: set automatically by VK Object Storage and applied by default to all external principals.
-
Explicit allow: set by the user using access policies via the
Effectparameter:..."Effect": "Allow"... -
Explicit deny: set by the user using access policies via the
Effectparameter:..."Effect": "Deny"...
Accordingly:
- internal principals are allowed all actions by default (implicit allow), and access is restricted by explicit denies (explicit deny);
- external principals: all actions are denied by default (implicit deny), and access is expanded through explicit allows (explicit allow).
The Principal parameter defines who exactly is allowed or denied the actions. Several principal options are supported.
-
Public access without authentication (anonymous). For example, for publishing static websites.
..."Principal": "*"... -
Project-based access — the policy applies to the users and service accounts of the VK Cloud project.
..."Principal": {"AWS": "<PROJECT_ID>"}...Here
<PROJECT_ID>is the identifier of the project to which the policy should be applied. It can point to your own project or to another VK Cloud project. -
Granting access to a specific VK Object Storage account.
..."Principal": {"AWS": "arn:aws:iam::<PROJECT_ID>:user/<S3_ACCOUNT>"}...Here:
<PROJECT_ID>— the identifier of the project to which the policy should be applied. It can point to your own project or to another VK Cloud project.<S3_ACCOUNT>— the name of the VK Object Storage account.
-
Access for applications or services using a service account.
..."Principal": {"AWS": "arn:aws:iam::<PROJECT_ID>:user/serviceusers-<SERVICE_USER>"}...Here:
<PROJECT_ID>— the identifier of the project to which the policy should be applied. It can point to your own project or to another VK Cloud project.<SERVICE_USER>— the name of the VK Cloud service user for VK Object Storage.
-
VK Object Storage prefix key:
..."Principal": {"AWS": "arn:aws:iam::<PROJECT_ID>:user/<PREFIX_KEY>"}...Here:
<PROJECT_ID>— the identifier of the project to which the policy should be applied. Only prefix keys bound to one of the buckets in the project are supported.<PREFIX_KEY>— the name of the VK Object Storage prefix key.
The Condition parameter defines under which conditions the rule will be triggered. It is specified using two parameters: an operator and a key.
It is specified inside the Condition block and defines how the values will be checked.
| Check for an exact match of the string value of the condition key against the specified value (or one of the values in the list) |
| Check for the absence of an exact match of the string value of the condition key against the specified value (or none of the values in the list) |
| Check for an exact match of the numeric value of the condition key against the specified number (or one of the numbers in the list) |
| True if the numeric value of the condition key is less than the specified number |
| True if the date and time value equals the specified value in ISO 8601 format |
| True if the IP address of the request source falls within the specified IPv4 or IPv6 CIDR range |
| True if the IP address of the request source does not fall within the specified IPv4 or IPv6 CIDR range |
It is specified inside the operator in key/value format.
| The status of an object's indefinite (legal) hold. Allows or denies operations depending on whether the legal hold is enabled. Possible values: |
| The temporary retention mode of an object. Used to control operations depending on the retention mode. Possible values: |
| The number of days remaining until the object's temporary retention expires. Used to control operations depending on the number of remaining retention days. Numeric values of 0 or greater are supported |
| The date and time until which the object is retained, in ISO 8601 format. Used to control operations depending on the retention end date |
| The IP address of the client from which the request came. Used to restrict access by IPv4 or IPv6 CIDR ranges |
The Resource parameter can contain:
-
a string pointing to a bucket:
"Resource": "arn:aws:s3:::<BUCKET_NAME>" -
a string pointing to an object:
"Resource": "arn:aws:s3:::<BUCKET_NAME>/<OBJECT_KEY>" -
a string with a
*(wildcard) mask pointing to objects with a specific object key prefix:"Resource": "arn:aws:s3:::<BUCKET_NAME>/<PART_OF_OBJECT_KEY>/*"or
"Resource": "arn:aws:s3:::<BUCKET_NAME>/<PART_OF_OBJECT_KEY>*" -
a string with a
*(wildcard) mask pointing to objects with a specific object key suffix:"Resource": "arn:aws:s3:::<BUCKET_NAME>/*<PART_OF_OBJECT_KEY>" -
an array of strings with several resources:
"Resource": ["arn:aws:s3:::<BUCKET_NAME>","arn:aws:s3:::<BUCKET_NAME>/<OBJECT_KEY>"]In this case, actions for buckets will be applied only to buckets, and actions for objects — only to objects.
-
Allow anonymous users (external principals) to download objects only from the specified IP address range:
{"Version": "2012-10-17","Statement": [{"Sid": "AllowGetOnlyFromCIDR","Effect": "Allow","Principal": "*","Action": "s3:GetObject","Resource": ["arn:aws:s3:::my-bucket/*"],"Condition": {"IpAddress": {"aws:SourceIp": ["203.0.113.0/24", "198.51.100.0/24"]}}}]} -
Deny a specific user (an internal principal) to download objects from the specified IP address:
{"Version": "2012-10-17","Statement": [{"Sid": "DenyGetFromSingleIP","Effect": "Deny","Principal": {"AWS": "arn:aws:iam::mcs1234567890:user/user-internal-b"},"Action": "s3:GetObject","Resource": ["arn:aws:s3:::my-bucket/*"],"Condition": {"IpAddress": {"aws:SourceIp": "198.51.100.10/32"}}}]} -
Grant some users (external principals from another project
mcs9876543210) full access to objects with a specific prefix:{"Version": "2012-10-17","Statement": [{"Sid": "UserAFullAccessToFolderA","Effect": "Allow","Principal": {"AWS": "arn:aws:iam::mcs9876543210:user/user-external-a"},"Action": ["s3:GetObject","s3:GetObjectAttributes","s3:PutObject","s3:DeleteObject","s3:GetObjectTagging","s3:PutObjectTagging","s3:DeleteObjectTagging","s3:GetObjectAcl","s3:PutObjectAcl","s3:AbortMultipartUpload","s3:ListMultipartUploadParts"],"Resource": ["arn:aws:s3:::my-bucket/folder-a/*"]},{"Sid": "UserBFullAccessToFolderB","Effect": "Allow","Principal": {"AWS": "arn:aws:iam::mcs9876543210:user/user-external-b"},"Action": ["s3:GetObject","s3:GetObjectAttributes","s3:PutObject","s3:DeleteObject","s3:GetObjectTagging","s3:PutObjectTagging","s3:DeleteObjectTagging","s3:GetObjectAcl","s3:PutObjectAcl","s3:AbortMultipartUpload","s3:ListMultipartUploadParts"],"Resource": ["arn:aws:s3:::my-bucket/folder-b/*"]}]} -
Grant users or service accounts (external principals from another project
mcs9876543210) full access to objects with a specific prefix:{"Version": "2012-10-17","Statement": [{"Sid": "ProjectFullAccessToSharedFolder","Effect": "Allow","Principal": {"AWS": "mcs9876543210"},"Action": ["s3:GetObject","s3:GetObjectAttributes","s3:PutObject","s3:DeleteObject","s3:GetObjectTagging","s3:PutObjectTagging","s3:DeleteObjectTagging","s3:GetObjectAcl","s3:PutObjectAcl","s3:AbortMultipartUpload","s3:ListMultipartUploadParts"],"Resource": ["arn:aws:s3:::my-bucket/shared/*"]}]} -
Allow users or service accounts (external principals from another project
mcs9876543210) to write objects only from specific IP addresses:{"Version": "2012-10-17","Statement": [{"Sid": "AllowPutOnlyFromCIDR","Effect": "Allow","Principal": {"AWS": "mcs9876543210"},"Action": "s3:PutObject","Resource": ["arn:aws:s3:::my-bucket/*"],"Condition": {"IpAddress": {"aws:SourceIp": ["203.0.113.0/24"]}}}]} -
Deny a specific user (an internal principal) to download any objects and prevent bypassing this denial:
{"Version": "2012-10-17","Statement": [{"Sid": "DenyDownloadObjectAndVersions","Effect": "Deny","Principal": {"AWS": "arn:aws:iam::mcs1234567890:user/user-internal-b"},"Action": ["s3:GetObject","s3:GetObjectVersion"],"Resource": ["arn:aws:s3:::my-bucket/*"]},{"Sid": "DenyBypassPrevention","Effect": "Deny","Principal": {"AWS": "arn:aws:iam::mcs1234567890:user/user-internal-b"},"Action": ["s3:PutBucketPolicy","s3:DeleteBucketPolicy"],"Resource": ["arn:aws:s3:::my-bucket"]}]} -
Deny a specific user (an internal principal) to delete any objects and prevent bypassing this denial:
{"Version": "2012-10-17","Statement": [{"Sid": "DenyDeleteObjectAndVersions","Effect": "Deny","Principal": {"AWS": "arn:aws:iam::mcs1234567890:user/user-internal-a"},"Action": ["s3:DeleteObject","s3:DeleteObjectVersion"],"Resource": ["arn:aws:s3:::my-bucket/*"]},{"Sid": "DenyBypassPreventionObject","Effect": "Deny","Principal": {"AWS": "arn:aws:iam::mcs1234567890:user/user-internal-a"},"Action": ["s3:PutObject"],"Resource": ["arn:aws:s3:::my-bucket/*"]},{"Sid": "DenyBypassPreventionBucket","Effect": "Deny","Principal": {"AWS": "arn:aws:iam::mcs1234567890:user/user-internal-a"},"Action": ["s3:PutLifecycleConfiguration","s3:PutBucketPolicy","s3:DeleteBucketPolicy","s3:PutBucketVersioning"],"Resource": ["arn:aws:s3:::my-bucket"]}]} -
Allow a specific user (an external principal from another project
mcs9876543210) to set or change the object lock retention period, provided the requested period does not exceed 10 days:{"Version": "2012-10-17","Statement": [{"Sid": "AllowShortRetention","Effect": "Allow","Principal": {"AWS": "arn:aws:iam::mcs9876543210:user/user-external-a"},"Action": ["s3:PutObjectRetention"],"Resource": ["arn:aws:s3:::my-bucket/*"],"Condition": {"NumericLessThan": {"s3:object-lock-remaining-retention-days": 11}}}]} -
Completely deny a user (an internal principal) access to the bucket:
{"Version": "2012-10-17","Statement": [{"Sid": "ExplicitDenyInternalUser","Effect": "Deny","Principal": {"AWS": "arn:aws:iam::mcs1234567890:user/user-internal-a"},"Action": "s3:*","Resource": ["arn:aws:s3:::my-bucket","arn:aws:s3:::my-bucket/*"]}]} -
Allow a user (an external principal from another project
mcs9876543210) to only view the list of versions (history) of the bucket itself:{"Version": "2012-10-17","Statement": [{"Sid": "AllowExternalUserListBucket","Effect": "Allow","Principal": {"AWS": "arn:aws:iam::mcs9876543210:user/user-external-a"},"Action": ["s3:ListBucket","s3:ListBucketVersions",],"Resource": ["arn:aws:s3:::my-bucket"]}]} -
Set a set of rules for a specific bucket, object, or prefix for external and internal principals:
{"Version": "2012-10-17","Statement": [{"Sid": "Allow list-object to anonymous users","Effect": "Allow","Principal": "*","Action": "s3:ListBucket","Resource": ["arn:aws:s3:::my-bucket"]},{"Sid": "Deny viewing, editing, and deleting the object my-object-1 to the internal user user-internal-a","Effect": "Deny","Principal": {"AWS": "arn:aws:iam::mcs1234567890:user/user-internal-a"},"Action": ["s3:GetObject","s3:GetObjectVersion","s3:PutObject","s3:DeleteObject","s3:DeleteObjectVersion"],"Resource": ["arn:aws:s3:::my-bucket/my-object-1"]},{"Sid": "Deny changing the bucket and its objects lifecycle rules to the internal user user-internal-a","Effect": "Deny","Principal": {"AWS": "arn:aws:iam::mcs1234567890:user/user-internal-a"},"Action": ["s3:PutLifecycleConfiguration"],"Resource": ["arn:aws:s3:::my-bucket"]},{"Sid": "Deny changing and deleting the my-bucket bucket policy to the internal user user-internal-a","Effect": "Deny","Principal": {"AWS": "arn:aws:iam::mcs1234567890:user/user-internal-a"},"Action": ["s3:PutBucketPolicy","s3:DeleteBucketPolicy"],"Resource": ["arn:aws:s3:::my-bucket"]},{"Sid": "Allow list-bucket for get-object of objects only with the 'directory' prefix to external users from another project mcs9876543210","Effect": "Allow","Principal": {"AWS": "mcs9876543210"},"Action": ["s3:ListBucket"],"Resource": ["arn:aws:s3:::my-bucket"]},{"Sid": "Allow get-object of objects only with the 'directory' prefix to external users from another project mcs9876543210","Effect": "Allow","Principal": {"AWS": "mcs9876543210"},"Action": ["s3:GetObject"],"Resource": ["arn:aws:s3:::my-bucket/directory/*"]}]} -
Deny a specific user (an internal principal) to change the indefinite object lock, if it is enabled:
{"Version": "2012-10-17","Statement": [{"Sid": "DenyPutLegalHold","Effect": "Deny","Principal": {"AWS": "arn:aws:iam::mcs1234567890:user/user-internal-a"},"Action": ["s3:PutObjectLegalHold"],"Resource": ["arn:aws:s3:::my-bucket/*"],"Condition": {"StringEquals": {"s3:object-lock-legal-hold": "ON"}}}]} -
Deny a specific user (an internal principal) to change the temporary object lock, where the
GOVERNANCEmode is set:{"Version": "2012-10-17","Statement": [{"Sid": "DenyPutObjectRetention","Effect": "Deny","Principal": {"AWS": "arn:aws:iam::mcs1234567890:user/user-internal-a"},"Action": ["s3:PutObjectRetention","s3:BypassGovernanceRetention"],"Resource": ["arn:aws:s3:::test-bucket-1/*"],"Condition": {"StringEquals": {"s3:object-lock-mode": "COMPLIANCE"}}}]} -
Allow users (external principals from another project
mcs9876543210) to set the object retention period, provided the requested date is2026-09-17:{"Version": "2012-10-17","Statement": [{"Sid": "ExplicitAllowForExternalPrincipals","Effect": "Allow","Principal": {"AWS": "mcs9876543210"},"Action": ["s3:PutObjectRetention","s3:BypassGovernanceRetention"],"Resource": ["arn:aws:s3:::test-bucket-1/*"],"Condition": {"DateEquals": {"s3:object-lock-retain-until-date": "2026-09-17T00:00:00Z"}}}]}