How to configure a bucket policy
Before you begin, make sure that you have a bucket. If you do not have one, create a bucket.- CLI
- Terraform
To configure a list of rules in a bucket policy, run the following command:The
--bucket-policy-rules parameter contains a list of rules for a bucket policy. Every rule has the following parameters:-
paths: Paths to objects that the rule applies to. If you use*, the rule provides access to all objects. Examples of supported paths:prefix_1/key_1: Rule applies to the object with the set prefix and key.prefix_1/*: Rule applies to any object with theprefix_1prefix.key_1: Rule applies to the object with thekey_1key.*: Rule applies to all objects in a bucket.
*symbol only at the end of the path and only once in a path. For example, you can specifyprefix_1/*, but you cannot useprefix*1orpre*fix*. -
roles: Object Storage roles granted to the specified IAM group to access objects in a bucket. You can grant read-only roles or editor roles. -
group_id: ID of the IAM group to which the rule applies. To get the group ID, go to theAdministration → IAM page in the web console. The list of groups and their IDs is displayed on the Groups tab.
Anonymous access
Anonymous access allows you to access a bucket without authentication. For instance, you can use acurl command without any authentication data.
To configure anonymous access:
- Instead of the
group_idparameter, specify"anonymous": {}in a CLI command oranonymous = {}in Terraform configuration. - Only use the
storage.viewer,storage.object-viewerandstorage.object-listerroles in the rule, as anonymous access only works for read-only permissions.
Examples
- CLI
- Terraform
-
Allow access to all objects in a bucket:
The
storage.viewerrole enables one to view buckets, to list and download objects. -
Allow access to objects with the
allowed1andallowed2prefixes: -
Allow access to the object with the
allowed_keykey: -
Allow anonymous access to all objects in a bucket:
-
Apply two rules simultaneously:
- Assign the
storage.viewerrole to theprefix_1/key_1object. - Assign the
storage.editorrole to objects with theprefix_2prefix.
- Assign the
How to delete all bucket policy rules
If you specify an empty list of rules for a bucket policy, no policy applies.- CLI
- Terraform
To delete all rules, run the following command:
Limitations
- The IAM group and the bucket must be in the same tenant.
- The maximum number of rules per bucket is 10.
- The maximum number of paths per rule is 10.
- The maximum path length is 1024 symbols (the same as the maximum length of an object key).
Access permits and bucket policies
If you have assigned a bucket policy or an access permit to a bucket, both of them grant access to the bucket and its objects. For example:
- If a bucket policy grants the
storage.object-listerrole and an access permit grants thestorage.object-viewerrole to the same IAM group, both of the roles apply to the group. As a result, members of this group can both list objects and view them.- If a bucket policy grants the
storage.viewerrole and an access permit grants thestorage.editorrole to the same IAM group, members of this group have editor rights as a result although they still have rights of thestorage.viewerrole.