> ## Documentation Index
> Fetch the complete documentation index at: https://docs.nebius.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Bucket policies in Object Storage

A *bucket policy* enables you to configure fine-grained access to objects within a bucket. In particular, you can allow access to objects with certain [prefixes or keys](https://docs.nebius.com/object-storage/overview.md#keys-prefixes-and-object-hierarchy) for a certain [IAM group](https://docs.nebius.com/iam/authorization/groups/index.md). In a policy, you specify what permissions the group obtains and what objects it can access.

## Prerequisites

> [tab] CLI
>
> [Install and configure](https://docs.nebius.com/cli/install.md) the Nebius AI Cloud CLI.

> [tab] Terraform
>
> [Install and configure](https://docs.nebius.com/terraform-provider/install.md) the Nebius AI Cloud provider for Terraform.

> [tab] Go SDK
>
> [Install and initialize the Nebius SDK for Go](https://docs.nebius.com/sdk/go/install-auth.md).

> [tab] Python SDK
>
> [Install and initialize the Nebius SDK for Python](https://docs.nebius.com/sdk/python/install-auth.md).

> [tab] JavaScript SDK
>
> [Install and initialize the Nebius SDK for JavaScript](https://docs.nebius.com/sdk/javascript/install-auth.md).

## 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](https://docs.nebius.com/object-storage/buckets/manage.md#how-to-create-buckets).

> [tab] CLI
>
> To configure a list of rules in a bucket policy, run the following command:
>
> ```bash theme={null}
> nebius storage bucket update \
>   --id <bucket_ID> \
>   --bucket-policy-rules "[{\"paths\": [\"<paths>\"], \"roles\": [\"<list_of_roles>\"], \"group_id\": \"<group_ID>\"}]"
> ```
>
> > [!WARNING]
> >
> > In the command, specify all the rules that the bucket should have. If you add a new rule to a list of existing rules, specify the existing rules as well. Otherwise, they will be deleted.
>
> 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. Each path is either a full object key or a prefix ending with a single `*` wildcard character. If you use `*`, the rule provides access to all objects. A path may also contain one or more `?` placeholders. Each `?` character matches a single character at that position in the string.
>
>   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 the `prefix_1` prefix.
>   * `allowed?/*`: Rule applies to objects with prefixes like `allowed1/`, `allowed2/` or `allowedA/`. A single `?` matches exactly one character, so neither `allowed/` nor `allowed10/` matches.
>   * `key_1`: Rule applies to the object with the `key_1` key.
>   * `*`: Rule applies to all objects in a bucket.
>
>   You can use the `*` symbol only at the end of the path and only once in a path. For example, you can specify `prefix_1/*`, but you cannot use `prefix*1` or `pre*fix*`.
>
> * `roles`: [Object Storage roles](https://docs.nebius.com/iam/authorization/roles.md#object-storage) 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 the  [Administration → IAM](https://console.nebius.com/iam/groups) page in the web console. The list of groups and their IDs is displayed on the **Groups** tab.

> [tab] Terraform
>
> To configure a list of rules in a bucket policy, use the `bucket_policy` parameter in a bucket configuration:
>
> ```hcl theme={null}
> resource nebius_storage_v1_bucket "<bucket_name>" {
>   bucket_policy = {
>     rules = [
>       {
>         paths      = [<paths>]
>         roles      = [<list_of_roles>]
>         group_id = "<group_ID>"
>       }
>     ]
>   }
>   ...
> }
> ```
>
> The `rules` parameter contains a list of rules for the bucket policy. Every rule has the following parameters:
>
> * `paths`: Paths to objects that the rule applies to. Each path is either a full object key or a prefix ending with a single `*` wildcard character. If you use `*`, the rule provides access to all objects. A path may also contain one or more `?` placeholders. Each `?` character matches a single character at that position in the string.
>
>   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 the `prefix_1` prefix.
>   * `allowed?/*`: Rule applies to objects with prefixes like `allowed1/`, `allowed2/` or `allowedA/`. A single `?` matches exactly one character, so neither `allowed/` nor `allowed10/` matches.
>   * `key_1`: Rule applies to the object with the `key_1` key.
>   * `*`: Rule applies to all objects in a bucket.
>
>   You can use the `*` symbol only at the end of the path and only once in a path. For example, you can specify `prefix_1/*`, but you cannot use `prefix*1` or `pre*fix*`.
>
> * `roles`: [Object Storage roles](https://docs.nebius.com/iam/authorization/roles.md#object-storage) 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 the  [Administration → IAM](https://console.nebius.com/iam/groups) page in the web console. The list of groups and their IDs is displayed on the **Groups** tab.

> [tab] Go SDK
>
> Configure a list of rules in a bucket policy:
>
> ```go theme={null}
> policySvc := sdk.Services().Storage().V1().Bucket()
> policyBucket, err := policySvc.Get(
>     ctx,
>     &storage.GetBucketRequest{
>         Id: "<bucket_ID>",
>     },
> )
> if err != nil {
>     return err
> }
> policyBucket.Spec.BucketPolicy = &storage.BucketPolicy{
>     Rules: []*storage.BucketPolicy_Rule{
>         {
>             Paths: []string{"<paths>"},
>             Roles: []string{"<list_of_roles>"},
>             Subject: &storage.BucketPolicy_Rule_GroupId{
>                 GroupId: "<group_ID>",
>             },
>         },
>     },
> }
> policyOp, err := policySvc.Update(
>     ctx,
>     &storage.UpdateBucketRequest{
>         Metadata: policyBucket.Metadata,
>         Spec:     policyBucket.Spec,
>     },
> )
> if err != nil {
>     return err
> }
> if _, err = policyOp.Wait(ctx); err != nil {
>     return err
> }
> ```
>
> > [!WARNING]
> >
> > In the code, specify all the rules that the bucket should have. If you add a new rule to a list of existing rules, specify the existing rules as well. Otherwise, they will be deleted.
>
> In the code, set the following parameters:
>
> * `Id`: Bucket ID.
> * `Paths`: Paths to objects that the rule applies to. Each path is an object key, a prefix ending with `*`, or a pattern with `?` placeholders. `*` matches all objects and can appear only once, at the end of a path.
> * `Roles`: [Object Storage roles](https://docs.nebius.com/iam/authorization/roles.md#object-storage) granted for those objects.
> * `GroupId`: ID of the IAM group that receives the roles.

> [tab] Python SDK
>
> Configure a list of rules in a bucket policy:
>
> ```python theme={null}
> bucket_service = BucketServiceClient(sdk)
> bucket = await bucket_service.get(
>     GetBucketRequest(id="<bucket_ID>"),
> )
> bucket.spec.bucket_policy = BucketPolicy(
>     rules=[
>         BucketPolicy__Rule(
>             paths=["<paths>"],
>             roles=["<list_of_roles>"],
>             group_id="<group_ID>",
>         ),
>     ],
> )
> operation = await bucket_service.update(
>     UpdateBucketRequest(
>         metadata=bucket.metadata,
>         spec=bucket.spec,
>     ),
> )
> await operation.wait()
> ```
>
> > [!WARNING]
> >
> > In the code, specify all the rules that the bucket should have. If you add a new rule to a list of existing rules, specify the existing rules as well. Otherwise, they will be deleted.
>
> In the code, set the following parameters:
>
> * `id`: Bucket ID.
> * `paths`: Paths to objects that the rule applies to. Each path is an object key, a prefix ending with `*`, or a pattern with `?` placeholders. `*` matches all objects and can appear only once, at the end of a path.
> * `roles`: [Object Storage roles](https://docs.nebius.com/iam/authorization/roles.md#object-storage) granted for those objects.
> * `group_id`: ID of the IAM group that receives the roles.

> [tab] JavaScript SDK
>
> Configure a list of rules in a bucket policy:
>
> ```ts theme={null}
> const policyService = new BucketService(sdk);
> const policyBucket = await policyService.get(
>   GetBucketRequest.create({ id: "<bucket_ID>" }),
> ).result;
> policyBucket.spec.bucketPolicy = BucketPolicy.create({
>   rules: [
>     BucketPolicy_Rule.create({
>       paths: ["<paths>"],
>       roles: ["<list_of_roles>"],
>       subject: {
>         $case: "groupId",
>         groupId: "<group_ID>",
>       },
>     }),
>   ],
> });
> const policyOperation = await policyService.update(
>   UpdateBucketRequest.create({
>     metadata: policyBucket.metadata,
>     spec: policyBucket.spec,
>   }),
> ).result;
> await policyOperation.wait();
> ```
>
> > [!WARNING]
> >
> > In the code, specify all the rules that the bucket should have. If you add a new rule to a list of existing rules, specify the existing rules as well. Otherwise, they will be deleted.
>
> In the code, set the following parameters:
>
> * `id`: Bucket ID.
> * `paths`: Paths to objects that the rule applies to. Each path is an object key, a prefix ending with `*`, or a pattern with `?` placeholders. `*` matches all objects and can appear only once, at the end of a path.
> * `roles`: [Object Storage roles](https://docs.nebius.com/iam/authorization/roles.md#object-storage) granted for those objects.
> * `groupId`: ID of the IAM group that receives the roles.

Rules within a single policy don't conflict with each other. All of them apply with an equal priority.

For more information about how to configure a bucket policy, see [Examples](#examples).

### Anonymous access

Anonymous access allows you to access a bucket without authentication. For instance, you can use a `curl` command without any authentication data.

To configure anonymous access:

* Don't set a group ID. Grant access without an IAM group instead. The examples below show the parameter for each interface.
* Only use the `storage.viewer`, `storage.object-viewer` and `storage.object-lister` roles in the rule, as anonymous access only works for read-only permissions.

For more information, see the examples below.

### Examples

> [tab] CLI
>
> * Allow access to all objects in a bucket:
>
>   ```bash theme={null}
>   nebius storage bucket update \
>     --id storagebucket-e00*** \
>     --bucket-policy-rules "[{\"paths\": [\"*\"], \"roles\": [\"storage.viewer\"], \"group_id\": \"group-e00***\"}]"
>   ```
>
>   The `storage.viewer` role enables one to view buckets, and to list and download objects.
>
> * Allow full read access (including multipart uploads) to objects with the `allowed1` and `allowed2` prefixes:
>
>   ```bash theme={null}
>   nebius storage bucket update \
>     --id storagebucket-e00*** \
>     --bucket-policy-rules "[{\"paths\": [\"allowed1/*\", \"allowed2/*\"], \"roles\": [\"storage.viewer\"], \"group_id\": \"group-e00***\"}]"
>   ```
>
> * Allow partial read access (without multipart uploads) to objects with the `allowed1` and `allowed2` prefixes:
>
>   ```bash theme={null}
>   nebius storage bucket update \
>     --id storagebucket-e00*** \
>     --bucket-policy-rules "[{\"paths\": [\"allowed1/*\", \"allowed2/*\"], \"roles\": [\"storage.object-lister\", \"storage.object-viewer\"], \"group_id\": \"group-e00***\"}]"
>   ```
>
> * Allow access to objects with prefixes like `allowed1/`, `allowed2/`, `allowedA/`, and so on, by using a placeholder:
>
>   ```bash theme={null}
>   nebius storage bucket update \
>     --id storagebucket-e00*** \
>     --bucket-policy-rules "[{\"paths\": [\"allowed?/*\"], \"roles\": [\"storage.object-lister\", \"storage.object-viewer\"], \"group_id\": \"group-e00***\"}]"
>   ```
>
> * Allow access to the object with the `allowed_key` key:
>
>   ```bash theme={null}
>   nebius storage bucket update \
>     --id storagebucket-e00*** \
>     --bucket-policy-rules "[{\"paths\": [\"allowed_key\"], \"roles\": [\"storage.viewer\"], \"group_id\": \"group-e00***\"}]"
>   ```
>
> * Allow anonymous access to all objects in a bucket:
>
>   ```bash theme={null}
>   nebius storage bucket update \
>     --id storagebucket-e00*** \
>     --bucket-policy-rules "[{\"paths\": [\"*\"], \"roles\": [\"storage.viewer\"], \"anonymous\": {} }]"
>   ```
>
> * Apply two rules simultaneously:
>
>   * Assign the `storage.viewer` role to the `prefix_1/key_1` object.
>   * Assign the `storage.editor` role to objects with the `prefix_2` prefix.
>
>   ```bash theme={null}
>   nebius storage bucket update \
>     --id storagebucket-e00*** \
>     --bucket-policy-rules "[{\"paths\": [\"prefix_1/key_1\"], \"roles\": [\"storage.viewer\"], \"group_id\": \"group-e00***\"},
>       {\"paths\": [\"prefix_2/*\"], \"roles\": [\"storage.editor\"], \"group_id\": \"group-e00***\"}]"
>   ```

> [tab] Terraform
>
> * Allow access to all objects in a bucket:
>
>   ```hcl theme={null}
>   resource nebius_storage_v1_bucket "bucket1" {
>     bucket_policy = {
>       rules = [
>         {
>           paths    = ["*"]
>           roles    = ["storage.viewer"]
>           group_id = "group-e00***"
>         }
>       ]
>     }
>     ...
>   }
>   ```
>
> * Allow full read access (including multipart uploads) to objects with the `allowed1` and `allowed2` prefixes:
>
>   ```hcl theme={null}
>   resource nebius_storage_v1_bucket "bucket1" {
>     bucket_policy = {
>       rules = [
>         {
>           paths    = ["allowed1/*", "allowed2/*"]
>           roles    = ["storage.viewer"]
>           group_id = "group-e00***"
>         }
>       ]
>     }
>     ...
>   }
>   ```
>
> * Allow partial read access (without multipart uploads) to objects with the `allowed1` and `allowed2` prefixes:
>
>   ```hcl theme={null}
>   resource nebius_storage_v1_bucket "bucket1" {
>     bucket_policy = {
>       rules = [
>         {
>           paths    = ["allowed1/*", "allowed2/*"]
>           roles    = ["storage.object-lister", "storage.object-viewer"]
>           group_id = "group-e00***"
>         }
>       ]
>     }
>     ...
>   }
>   ```
>
> * Allow access to objects with prefixes like `allowed1/`, `allowed2/`, `allowedA/`, and so on, by using a placeholder. A single `?` matches exactly one character, so neither `allowed/` nor `allowed10/` matches this rule:
>
>   ```hcl theme={null}
>   resource nebius_storage_v1_bucket "bucket1" {
>     bucket_policy = {
>       rules = [
>         {
>           paths    = ["allowed?/*"]
>           roles    = ["storage.viewer"]
>           group_id = "group-e00***"
>         }
>       ]
>     }
>     ...
>   }
>   ```
>
> * Allow access to the object with the `allowed_key` key:
>
>   ```hcl theme={null}
>   resource nebius_storage_v1_bucket "bucket1" {
>     bucket_policy = {
>       rules = [
>         {
>           paths    = ["allowed_key"]
>           roles    = ["storage.viewer"]
>           group_id = "group-e00***"
>         }
>       ]
>     }
>     ...
>   }
>   ```
>
> * Allow anonymous access to all objects in a bucket:
>
>   ```hcl theme={null}
>   resource nebius_storage_v1_bucket "bucket1" {
>     bucket_policy = {
>       rules = [
>         {
>           paths     = ["*"]
>           roles     = ["storage.viewer"]
>           anonymous = {}
>         }
>       ]
>     }
>     ...
>   }
>   ```
>
> * Apply two rules simultaneously:
>
>   * Assign the `storage.viewer` role to the `prefix_1/key_1` object.
>   * Assign the `storage.editor` role to objects with the `prefix_2` prefix.
>
>   ```hcl theme={null}
>   resource nebius_storage_v1_bucket "bucket1" {
>     bucket_policy = {
>       rules = [
>         {
>           paths    = ["prefix_1/key_1"]
>           roles    = ["storage.viewer"]
>           group_id = "group-e00***"
>         },
>         {
>           paths    = ["prefix_2/*"]
>           roles    = ["storage.editor"]
>           group_id = "group-e00***"
>         }
>       ]
>     }
>     ...
>   }
>   ```

> [tab] Go SDK
>
> * Allow access to all objects in a bucket:
>
>   ```go theme={null}
>   allSvc := sdk.Services().Storage().V1().Bucket()
>   allBucket, err := allSvc.Get(
>       ctx,
>       &storage.GetBucketRequest{
>           Id: "storagebucket-e00***",
>       },
>   )
>   if err != nil {
>       return err
>   }
>   allBucket.Spec.BucketPolicy = &storage.BucketPolicy{
>       Rules: []*storage.BucketPolicy_Rule{
>           {
>               Paths: []string{"*"},
>               Roles: []string{"storage.viewer"},
>               Subject: &storage.BucketPolicy_Rule_GroupId{
>                   GroupId: "group-e00***",
>               },
>           },
>       },
>   }
>   allOp, err := allSvc.Update(
>       ctx,
>       &storage.UpdateBucketRequest{
>           Metadata: allBucket.Metadata,
>           Spec:     allBucket.Spec,
>       },
>   )
>   if err != nil {
>       return err
>   }
>   if _, err = allOp.Wait(ctx); err != nil {
>       return err
>   }
>   ```
>
>   The `storage.viewer` role enables one to view buckets, and to list and download objects.
>
> * Allow full read access (including multipart uploads) to objects with the `allowed1` and `allowed2` prefixes:
>
>   ```go theme={null}
>   prefixSvc := sdk.Services().Storage().V1().Bucket()
>   prefixBucket, err := prefixSvc.Get(
>       ctx,
>       &storage.GetBucketRequest{
>           Id: "storagebucket-e00***",
>       },
>   )
>   if err != nil {
>       return err
>   }
>   prefixBucket.Spec.BucketPolicy = &storage.BucketPolicy{
>       Rules: []*storage.BucketPolicy_Rule{
>           {
>               Paths: []string{"allowed1/*", "allowed2/*"},
>               Roles: []string{"storage.viewer"},
>               Subject: &storage.BucketPolicy_Rule_GroupId{
>                   GroupId: "group-e00***",
>               },
>           },
>       },
>   }
>   prefixOp, err := prefixSvc.Update(
>       ctx,
>       &storage.UpdateBucketRequest{
>           Metadata: prefixBucket.Metadata,
>           Spec:     prefixBucket.Spec,
>       },
>   )
>   if err != nil {
>       return err
>   }
>   if _, err = prefixOp.Wait(ctx); err != nil {
>       return err
>   }
>   ```
>
> * Allow partial read access (without multipart uploads) to objects with the `allowed1` and `allowed2` prefixes:
>
>   ```go theme={null}
>   listSvc := sdk.Services().Storage().V1().Bucket()
>   listBucket, err := listSvc.Get(
>       ctx,
>       &storage.GetBucketRequest{
>           Id: "storagebucket-e00***",
>       },
>   )
>   if err != nil {
>       return err
>   }
>   listBucket.Spec.BucketPolicy = &storage.BucketPolicy{
>       Rules: []*storage.BucketPolicy_Rule{
>           {
>               Paths: []string{"allowed1/*", "allowed2/*"},
>               Roles: []string{
>                   "storage.object-lister",
>                   "storage.object-viewer",
>               },
>               Subject: &storage.BucketPolicy_Rule_GroupId{
>                   GroupId: "group-e00***",
>               },
>           },
>       },
>   }
>   listOp, err := listSvc.Update(
>       ctx,
>       &storage.UpdateBucketRequest{
>           Metadata: listBucket.Metadata,
>           Spec:     listBucket.Spec,
>       },
>   )
>   if err != nil {
>       return err
>   }
>   if _, err = listOp.Wait(ctx); err != nil {
>       return err
>   }
>   ```
>
> * Allow access to objects with prefixes like `allowed1/`, `allowed2/`, `allowedA/`, and so on, by using a placeholder:
>
>   ```go theme={null}
>   placeholderSvc := sdk.Services().Storage().V1().Bucket()
>   placeholderBucket, err := placeholderSvc.Get(
>       ctx,
>       &storage.GetBucketRequest{
>           Id: "storagebucket-e00***",
>       },
>   )
>   if err != nil {
>       return err
>   }
>   placeholderBucket.Spec.BucketPolicy = &storage.BucketPolicy{
>       Rules: []*storage.BucketPolicy_Rule{
>           {
>               Paths: []string{"allowed?/*"},
>               Roles: []string{
>                   "storage.object-lister",
>                   "storage.object-viewer",
>               },
>               Subject: &storage.BucketPolicy_Rule_GroupId{
>                   GroupId: "group-e00***",
>               },
>           },
>       },
>   }
>   placeholderOp, err := placeholderSvc.Update(
>       ctx,
>       &storage.UpdateBucketRequest{
>           Metadata: placeholderBucket.Metadata,
>           Spec:     placeholderBucket.Spec,
>       },
>   )
>   if err != nil {
>       return err
>   }
>   if _, err = placeholderOp.Wait(ctx); err != nil {
>       return err
>   }
>   ```
>
> * Allow access to the object with the `allowed_key` key:
>
>   ```go theme={null}
>   keySvc := sdk.Services().Storage().V1().Bucket()
>   keyBucket, err := keySvc.Get(
>       ctx,
>       &storage.GetBucketRequest{
>           Id: "storagebucket-e00***",
>       },
>   )
>   if err != nil {
>       return err
>   }
>   keyBucket.Spec.BucketPolicy = &storage.BucketPolicy{
>       Rules: []*storage.BucketPolicy_Rule{
>           {
>               Paths: []string{"allowed_key"},
>               Roles: []string{"storage.viewer"},
>               Subject: &storage.BucketPolicy_Rule_GroupId{
>                   GroupId: "group-e00***",
>               },
>           },
>       },
>   }
>   keyOp, err := keySvc.Update(
>       ctx,
>       &storage.UpdateBucketRequest{
>           Metadata: keyBucket.Metadata,
>           Spec:     keyBucket.Spec,
>       },
>   )
>   if err != nil {
>       return err
>   }
>   if _, err = keyOp.Wait(ctx); err != nil {
>       return err
>   }
>   ```
>
> * Allow anonymous access to all objects in a bucket:
>
>   ```go theme={null}
>   anonymousSvc := sdk.Services().Storage().V1().Bucket()
>   anonymousBucket, err := anonymousSvc.Get(
>       ctx,
>       &storage.GetBucketRequest{
>           Id: "storagebucket-e00***",
>       },
>   )
>   if err != nil {
>       return err
>   }
>   anonymousBucket.Spec.BucketPolicy = &storage.BucketPolicy{
>       Rules: []*storage.BucketPolicy_Rule{
>           {
>               Paths: []string{"*"},
>               Roles: []string{"storage.viewer"},
>               Subject: &storage.BucketPolicy_Rule_Anonymous{
>                   Anonymous: &storage.BucketPolicy_Rule_AnonymousAccess{
>                   },
>               },
>           },
>       },
>   }
>   anonymousOp, err := anonymousSvc.Update(
>       ctx,
>       &storage.UpdateBucketRequest{
>           Metadata: anonymousBucket.Metadata,
>           Spec:     anonymousBucket.Spec,
>       },
>   )
>   if err != nil {
>       return err
>   }
>   if _, err = anonymousOp.Wait(ctx); err != nil {
>       return err
>   }
>   ```
>
> * Apply two rules simultaneously:
>
>   * Assign the `storage.viewer` role to the `prefix_1/key_1` object.
>   * Assign the `storage.editor` role to objects with the `prefix_2` prefix.
>
>   ```go theme={null}
>   twoRulesSvc := sdk.Services().Storage().V1().Bucket()
>   twoRulesBucket, err := twoRulesSvc.Get(
>       ctx,
>       &storage.GetBucketRequest{
>           Id: "storagebucket-e00***",
>       },
>   )
>   if err != nil {
>       return err
>   }
>   twoRulesBucket.Spec.BucketPolicy = &storage.BucketPolicy{
>       Rules: []*storage.BucketPolicy_Rule{
>           {
>               Paths: []string{"prefix_1/key_1"},
>               Roles: []string{"storage.viewer"},
>               Subject: &storage.BucketPolicy_Rule_GroupId{
>                   GroupId: "group-e00***",
>               },
>           },
>           {
>               Paths: []string{"prefix_2/*"},
>               Roles: []string{"storage.editor"},
>               Subject: &storage.BucketPolicy_Rule_GroupId{
>                   GroupId: "group-e00***",
>               },
>           },
>       },
>   }
>   twoRulesOp, err := twoRulesSvc.Update(
>       ctx,
>       &storage.UpdateBucketRequest{
>           Metadata: twoRulesBucket.Metadata,
>           Spec:     twoRulesBucket.Spec,
>       },
>   )
>   if err != nil {
>       return err
>   }
>   if _, err = twoRulesOp.Wait(ctx); err != nil {
>       return err
>   }
>   ```

> [tab] Python SDK
>
> * Allow access to all objects in a bucket:
>
>   ```python theme={null}
>   bucket_service = BucketServiceClient(sdk)
>   bucket = await bucket_service.get(
>       GetBucketRequest(id="storagebucket-e00***"),
>   )
>   bucket.spec.bucket_policy = BucketPolicy(
>       rules=[
>           BucketPolicy__Rule(
>               paths=["*"],
>               roles=["storage.viewer"],
>               group_id="group-e00***",
>           ),
>       ],
>   )
>   operation = await bucket_service.update(
>       UpdateBucketRequest(
>           metadata=bucket.metadata,
>           spec=bucket.spec,
>       ),
>   )
>   await operation.wait()
>   ```
>
>   The `storage.viewer` role enables one to view buckets, and to list and download objects.
>
> * Allow full read access (including multipart uploads) to objects with the `allowed1` and `allowed2` prefixes:
>
>   ```python theme={null}
>   bucket_service = BucketServiceClient(sdk)
>   bucket = await bucket_service.get(
>       GetBucketRequest(id="storagebucket-e00***"),
>   )
>   bucket.spec.bucket_policy = BucketPolicy(
>       rules=[
>           BucketPolicy__Rule(
>               paths=["allowed1/*", "allowed2/*"],
>               roles=["storage.viewer"],
>               group_id="group-e00***",
>           ),
>       ],
>   )
>   operation = await bucket_service.update(
>       UpdateBucketRequest(
>           metadata=bucket.metadata,
>           spec=bucket.spec,
>       ),
>   )
>   await operation.wait()
>   ```
>
> * Allow partial read access (without multipart uploads) to objects with the `allowed1` and `allowed2` prefixes:
>
>   ```python theme={null}
>   bucket_service = BucketServiceClient(sdk)
>   bucket = await bucket_service.get(
>       GetBucketRequest(id="storagebucket-e00***"),
>   )
>   bucket.spec.bucket_policy = BucketPolicy(
>       rules=[
>           BucketPolicy__Rule(
>               paths=["allowed1/*", "allowed2/*"],
>               roles=[
>                   "storage.object-lister",
>                   "storage.object-viewer",
>               ],
>               group_id="group-e00***",
>           ),
>       ],
>   )
>   operation = await bucket_service.update(
>       UpdateBucketRequest(
>           metadata=bucket.metadata,
>           spec=bucket.spec,
>       ),
>   )
>   await operation.wait()
>   ```
>
> * Allow access to objects with prefixes like `allowed1/`, `allowed2/`, `allowedA/`, and so on, by using a placeholder:
>
>   ```python theme={null}
>   bucket_service = BucketServiceClient(sdk)
>   bucket = await bucket_service.get(
>       GetBucketRequest(id="storagebucket-e00***"),
>   )
>   bucket.spec.bucket_policy = BucketPolicy(
>       rules=[
>           BucketPolicy__Rule(
>               paths=["allowed?/*"],
>               roles=[
>                   "storage.object-lister",
>                   "storage.object-viewer",
>               ],
>               group_id="group-e00***",
>           ),
>       ],
>   )
>   operation = await bucket_service.update(
>       UpdateBucketRequest(
>           metadata=bucket.metadata,
>           spec=bucket.spec,
>       ),
>   )
>   await operation.wait()
>   ```
>
> * Allow access to the object with the `allowed_key` key:
>
>   ```python theme={null}
>   bucket_service = BucketServiceClient(sdk)
>   bucket = await bucket_service.get(
>       GetBucketRequest(id="storagebucket-e00***"),
>   )
>   bucket.spec.bucket_policy = BucketPolicy(
>       rules=[
>           BucketPolicy__Rule(
>               paths=["allowed_key"],
>               roles=["storage.viewer"],
>               group_id="group-e00***",
>           ),
>       ],
>   )
>   operation = await bucket_service.update(
>       UpdateBucketRequest(
>           metadata=bucket.metadata,
>           spec=bucket.spec,
>       ),
>   )
>   await operation.wait()
>   ```
>
> * Allow anonymous access to all objects in a bucket:
>
>   ```python theme={null}
>   bucket_service = BucketServiceClient(sdk)
>   bucket = await bucket_service.get(
>       GetBucketRequest(id="storagebucket-e00***"),
>   )
>   bucket.spec.bucket_policy = BucketPolicy(
>       rules=[
>           BucketPolicy__Rule(
>               paths=["*"],
>               roles=["storage.viewer"],
>               anonymous=BucketPolicy__Rule__AnonymousAccess(),
>           ),
>       ],
>   )
>   operation = await bucket_service.update(
>       UpdateBucketRequest(
>           metadata=bucket.metadata,
>           spec=bucket.spec,
>       ),
>   )
>   await operation.wait()
>   ```
>
> * Apply two rules simultaneously:
>
>   * Assign the `storage.viewer` role to the `prefix_1/key_1` object.
>   * Assign the `storage.editor` role to objects with the `prefix_2` prefix.
>
>   ```python theme={null}
>   bucket_service = BucketServiceClient(sdk)
>   bucket = await bucket_service.get(
>       GetBucketRequest(id="storagebucket-e00***"),
>   )
>   bucket.spec.bucket_policy = BucketPolicy(
>       rules=[
>           BucketPolicy__Rule(
>               paths=["prefix_1/key_1"],
>               roles=["storage.viewer"],
>               group_id="group-e00***",
>           ),
>           BucketPolicy__Rule(
>               paths=["prefix_2/*"],
>               roles=["storage.editor"],
>               group_id="group-e00***",
>           ),
>       ],
>   )
>   operation = await bucket_service.update(
>       UpdateBucketRequest(
>           metadata=bucket.metadata,
>           spec=bucket.spec,
>       ),
>   )
>   await operation.wait()
>   ```

> [tab] JavaScript SDK
>
> * Allow access to all objects in a bucket:
>
>   ```ts theme={null}
>   const allService = new BucketService(sdk);
>   const allBucket = await allService.get(
>     GetBucketRequest.create({ id: "storagebucket-e00***" }),
>   ).result;
>   allBucket.spec.bucketPolicy = BucketPolicy.create({
>     rules: [
>       BucketPolicy_Rule.create({
>         paths: ["*"],
>         roles: ["storage.viewer"],
>         subject: {
>           $case: "groupId",
>           groupId: "group-e00***",
>         },
>       }),
>     ],
>   });
>   const allOperation = await allService.update(
>     UpdateBucketRequest.create({
>       metadata: allBucket.metadata,
>       spec: allBucket.spec,
>     }),
>   ).result;
>   await allOperation.wait();
>   ```
>
>   The `storage.viewer` role enables one to view buckets, and to list and download objects.
>
> * Allow full read access (including multipart uploads) to objects with the `allowed1` and `allowed2` prefixes:
>
>   ```ts theme={null}
>   const prefixService = new BucketService(sdk);
>   const prefixBucket = await prefixService.get(
>     GetBucketRequest.create({ id: "storagebucket-e00***" }),
>   ).result;
>   prefixBucket.spec.bucketPolicy = BucketPolicy.create({
>     rules: [
>       BucketPolicy_Rule.create({
>         paths: ["allowed1/*", "allowed2/*"],
>         roles: ["storage.viewer"],
>         subject: {
>           $case: "groupId",
>           groupId: "group-e00***",
>         },
>       }),
>     ],
>   });
>   const prefixOperation = await prefixService.update(
>     UpdateBucketRequest.create({
>       metadata: prefixBucket.metadata,
>       spec: prefixBucket.spec,
>     }),
>   ).result;
>   await prefixOperation.wait();
>   ```
>
> * Allow partial read access (without multipart uploads) to objects with the `allowed1` and `allowed2` prefixes:
>
>   ```ts theme={null}
>   const listService = new BucketService(sdk);
>   const listBucket = await listService.get(
>     GetBucketRequest.create({ id: "storagebucket-e00***" }),
>   ).result;
>   listBucket.spec.bucketPolicy = BucketPolicy.create({
>     rules: [
>       BucketPolicy_Rule.create({
>         paths: ["allowed1/*", "allowed2/*"],
>         roles: [
>           "storage.object-lister",
>           "storage.object-viewer",
>         ],
>         subject: {
>           $case: "groupId",
>           groupId: "group-e00***",
>         },
>       }),
>     ],
>   });
>   const listOperation = await listService.update(
>     UpdateBucketRequest.create({
>       metadata: listBucket.metadata,
>       spec: listBucket.spec,
>     }),
>   ).result;
>   await listOperation.wait();
>   ```
>
> * Allow access to objects with prefixes like `allowed1/`, `allowed2/`, `allowedA/`, and so on, by using a placeholder:
>
>   ```ts theme={null}
>   const placeholderService = new BucketService(sdk);
>   const placeholderBucket = await placeholderService.get(
>     GetBucketRequest.create({ id: "storagebucket-e00***" }),
>   ).result;
>   placeholderBucket.spec.bucketPolicy = BucketPolicy.create({
>     rules: [
>       BucketPolicy_Rule.create({
>         paths: ["allowed?/*"],
>         roles: [
>           "storage.object-lister",
>           "storage.object-viewer",
>         ],
>         subject: {
>           $case: "groupId",
>           groupId: "group-e00***",
>         },
>       }),
>     ],
>   });
>   const placeholderOperation = await placeholderService.update(
>     UpdateBucketRequest.create({
>       metadata: placeholderBucket.metadata,
>       spec: placeholderBucket.spec,
>     }),
>   ).result;
>   await placeholderOperation.wait();
>   ```
>
> * Allow access to the object with the `allowed_key` key:
>
>   ```ts theme={null}
>   const keyService = new BucketService(sdk);
>   const keyBucket = await keyService.get(
>     GetBucketRequest.create({ id: "storagebucket-e00***" }),
>   ).result;
>   keyBucket.spec.bucketPolicy = BucketPolicy.create({
>     rules: [
>       BucketPolicy_Rule.create({
>         paths: ["allowed_key"],
>         roles: ["storage.viewer"],
>         subject: {
>           $case: "groupId",
>           groupId: "group-e00***",
>         },
>       }),
>     ],
>   });
>   const keyOperation = await keyService.update(
>     UpdateBucketRequest.create({
>       metadata: keyBucket.metadata,
>       spec: keyBucket.spec,
>     }),
>   ).result;
>   await keyOperation.wait();
>   ```
>
> * Allow anonymous access to all objects in a bucket:
>
>   ```ts theme={null}
>   const anonymousService = new BucketService(sdk);
>   const anonymousBucket = await anonymousService.get(
>     GetBucketRequest.create({ id: "storagebucket-e00***" }),
>   ).result;
>   anonymousBucket.spec.bucketPolicy = BucketPolicy.create({
>     rules: [
>       BucketPolicy_Rule.create({
>         paths: ["*"],
>         roles: ["storage.viewer"],
>         subject: {
>           $case: "anonymous",
>           anonymous: BucketPolicy_Rule_AnonymousAccess.create({}),
>         },
>       }),
>     ],
>   });
>   const anonymousOperation = await anonymousService.update(
>     UpdateBucketRequest.create({
>       metadata: anonymousBucket.metadata,
>       spec: anonymousBucket.spec,
>     }),
>   ).result;
>   await anonymousOperation.wait();
>   ```
>
> * Apply two rules simultaneously:
>
>   * Assign the `storage.viewer` role to the `prefix_1/key_1` object.
>   * Assign the `storage.editor` role to objects with the `prefix_2` prefix.
>
>   ```ts theme={null}
>   const twoRulesService = new BucketService(sdk);
>   const twoRulesBucket = await twoRulesService.get(
>     GetBucketRequest.create({ id: "storagebucket-e00***" }),
>   ).result;
>   twoRulesBucket.spec.bucketPolicy = BucketPolicy.create({
>     rules: [
>       BucketPolicy_Rule.create({
>         paths: ["prefix_1/key_1"],
>         roles: ["storage.viewer"],
>         subject: {
>           $case: "groupId",
>           groupId: "group-e00***",
>         },
>       }),
>       BucketPolicy_Rule.create({
>         paths: ["prefix_2/*"],
>         roles: ["storage.editor"],
>         subject: {
>           $case: "groupId",
>           groupId: "group-e00***",
>         },
>       }),
>     ],
>   });
>   const twoRulesOperation = await twoRulesService.update(
>     UpdateBucketRequest.create({
>       metadata: twoRulesBucket.metadata,
>       spec: twoRulesBucket.spec,
>     }),
>   ).result;
>   await twoRulesOperation.wait();
>   ```

## How to delete all bucket policy rules

If you specify an empty list of rules for a bucket policy, no policy applies.

> [tab] CLI
>
> To delete all rules, run the following command:
>
> ```bash theme={null}
> nebius storage bucket update \
>   --id storagebucket-e00*** \
>   --bucket-policy-rules '[]'
> ```

> [tab] Terraform
>
> To delete all rules, delete the `bucket_policy` parameter from the Terraform configuration.

> [tab] Go SDK
>
> Delete all rules:
>
> ```go theme={null}
> clearSvc := sdk.Services().Storage().V1().Bucket()
> clearBucket, err := clearSvc.Get(
>     ctx,
>     &storage.GetBucketRequest{
>         Id: "storagebucket-e00***",
>     },
> )
> if err != nil {
>     return err
> }
> clearBucket.Spec.BucketPolicy = &storage.BucketPolicy{
>     Rules: []*storage.BucketPolicy_Rule{},
> }
> clearOp, err := clearSvc.Update(
>     ctx,
>     &storage.UpdateBucketRequest{
>         Metadata: clearBucket.Metadata,
>         Spec:     clearBucket.Spec,
>     },
> )
> if err != nil {
>     return err
> }
> if _, err = clearOp.Wait(ctx); err != nil {
>     return err
> }
> ```
>
> In the code, set `Id` to the bucket ID and `Rules` to an empty list.

> [tab] Python SDK
>
> Delete all rules:
>
> ```python theme={null}
> bucket_service = BucketServiceClient(sdk)
> bucket = await bucket_service.get(
>     GetBucketRequest(id="storagebucket-e00***"),
> )
> bucket.spec.bucket_policy = BucketPolicy(rules=[])
> operation = await bucket_service.update(
>     UpdateBucketRequest(
>         metadata=bucket.metadata,
>         spec=bucket.spec,
>     ),
> )
> await operation.wait()
> ```
>
> In the code, set `id` to the bucket ID and `rules` to an empty list.

> [tab] JavaScript SDK
>
> Delete all rules:
>
> ```ts theme={null}
> const clearService = new BucketService(sdk);
> const clearBucket = await clearService.get(
>   GetBucketRequest.create({ id: "storagebucket-e00***" }),
> ).result;
> clearBucket.spec.bucketPolicy = BucketPolicy.create({
>   rules: [],
> });
> const clearOperation = await clearService.update(
>   UpdateBucketRequest.create({
>     metadata: clearBucket.metadata,
>     spec: clearBucket.spec,
>   }),
> ).result;
> await clearOperation.wait();
> ```
>
> In the code, set `id` to the bucket ID and `rules` to an empty list.

## 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](https://docs.nebius.com/iam/authorization/groups.md#custom-groups) to a bucket, both of them grant access to the bucket and its objects. For example:

> * If a bucket policy grants the `storage.object-lister` role and an access permit grants the `storage.object-viewer` role 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.viewer` role and an access permit grants the `storage.editor` role to the same IAM group, members of this group have editor rights as a result although they still have rights of the `storage.viewer` role.
