Configuring public access to a bucket
Object Storage incorporates several access management mechanisms. To learn how these mechanisms interact, see Access management methods in Object Storage: Overview.
By default, bucket access is restricted. You can enable public access:
- To read objects in a bucket.
- To view the list of objects in a bucket.
- To read settings:
Public access to each operation is granted separately. This means, if you have granted only read access to your objects, anonymous users cannot get the list of objects and bucket settings.
Enabling public access
Warning
Public access is granted to an unlimited number of anonymous users. Use it only when other access grant mechanisms are not available.
- In the management console
, open a folder. - Navigate to Object Storage.
- Select the bucket to configure public access for.
- In the left-hand panel, select
Settings. - Select the General tab.
- Enable public access for the operation types you need.
- Click Save.
If you do not have the Yandex Cloud CLI yet, install and initialize it.
The folder used by default is the one specified when creating the CLI profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also specify a different folder for any command using --folder-name or --folder-id. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.
-
See the description of the CLI command for updating a bucket:
yc storage bucket update --help -
Get a list of buckets in the default folder:
yc storage bucket listResult:
+------------------+----------------------+-------------+-----------------------+---------------------+ | NAME | FOLDER ID | MAX SIZE | DEFAULT STORAGE CLASS | CREATED AT | +------------------+----------------------+-------------+-----------------------+---------------------+ | first-bucket | b1gmit33ngp6******** | 53687091200 | STANDARD | 2022-12-16 13:58:18 | +------------------+----------------------+-------------+-----------------------+---------------------+ -
Save the name (from the
NAMEcolumn) of the bucket to which you want to enable public access. -
Enable public access to bucket operations:
yc storage bucket update \ --name <bucket_name> \ --public-read \ --public-list \ --public-config-readWhere:
--name: Name of the bucket to which you need to enable public access.--public-read: Flag to enable public read access to bucket objects.--public-list: Flag to enable public view access to the list of bucket objects.--public-config-read: Flag to enable public read access to the bucket configuration.
name: This is a required setting. Other parameters are optional. By default, public access to the bucket is disabled.Result:
name: first-bucket folder_id: b1gmit33ngp6******** anonymous_access_flags: read: true list: true config_read: true default_storage_class: STANDARD versioning: VERSIONING_DISABLED max_size: "53687091200" acl: {} created_at: "2022-12-16T13:58:18.933814Z"
Note
If you access Object Storage via Terraform under a service account, assign to the service account the relevant role, e.g., storage.admin, for the folder you are going to create the resources in.
With Terraform
Terraform is distributed under the Business Source License
For more information about the provider resources, see the relevant documentation on the Terraform
If you do not have Terraform yet, install it and configure the Yandex Cloud provider.
To open public access to bucket operations:
-
Open the Terraform configuration file and add the
anonymous_access_flagssection to the bucket description.resource "yandex_storage_bucket" "log_bucket" { access_key = "<static_key_ID>" secret_key = "<secret_key>" bucket = "<bucket_name>" anonymous_access_flags { read = true list = true config_read = true } }Where:
-
access_key: Static access key ID.Note
In addition to static access keys, you can use an IAM token for authentication in Object Storage. For more details, see Creating a bucket and the relevant provider documentation.
-
secret_key: Secret access key value. -
bucket: Name of the bucket to which you need to enable public access. -
anonymous_access_flags: Public access parameters:read: Public read access to bucket objects.list: Public access to the list of bucket objects.config_read: Public read access to the bucket configuration.
For more information about the
yandex_storage_bucketproperties in Terraform, see this provider guide. -
-
Validate your configuration files.
-
In the terminal, navigate to the directory where you created your configuration file.
-
Run a check using the following command:
terraform plan
If your configuration is correct, the terminal will display a list of the resources to be created and their settings. Otherwise, Terraform will show any detected errors.
-
-
Deploy the cloud resources.
-
If the configuration is correct, run this command:
terraform apply -
Confirm creating the resources: type
yesand press Enter.This will create all the resources you need in the specified folder. You can check the new resources and their settings using the management console
.
-
To open public access to bucket operations, use the update REST API method for the Bucket resource or the BucketService/Update gRPC API call.
Note
You will not be able to open public access if a restrictive access policy is configured for the bucket.
Disabling public access
- In the management console
, select any folder. - Navigate to Object Storage.
- Select the bucket to disable public access for.
- In the left-hand panel, select
Settings. - Select the General tab.
- Enable restricted access for the operation types you need.
- Click Save.
If you do not have the Yandex Cloud CLI yet, install and initialize it.
The folder used by default is the one specified when creating the CLI profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also specify a different folder for any command using --folder-name or --folder-id. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.
-
See the description of the CLI command for updating a bucket:
yc storage bucket update --help -
Get a list of buckets in the default folder:
yc storage bucket listResult:
+------------------+----------------------+-------------+-----------------------+---------------------+ | NAME | FOLDER ID | MAX SIZE | DEFAULT STORAGE CLASS | CREATED AT | +------------------+----------------------+-------------+-----------------------+---------------------+ | first-bucket | b1gmit33ngp6******** | 53687091200 | STANDARD | 2022-12-16 13:58:18 | +------------------+----------------------+-------------+-----------------------+---------------------+ -
Save the name (from the
NAMEcolumn) of the bucket to which you want to disable public access. -
Disable public access to bucket operations:
yc storage bucket update \ --name <bucket_name> \ --public-read=false \ --public-list=false \ --public-config-read=falseWhere:
--name: Name of the bucket to which you need to disable public access.--public-read: Flag to manage public read access to bucket objects. To disable public access, set it tofalse.--public-list: Flag to manage public view access to the list of bucket objects. To disable public access, set it tofalse.--public-config-read: Flag to manage public read access to the bucket configuration. To disable public access, set it tofalse.
name: This is a required setting. Other parameters are optional. By default, public access to the bucket is disabled.Result:
name: first-bucket folder_id: b1gmit33ngp6******** anonymous_access_flags: read: false list: false config_read: false default_storage_class: STANDARD versioning: VERSIONING_DISABLED max_size: "53687091200" acl: {} created_at: "2022-12-16T13:58:18.933814Z"
With Terraform
Terraform is distributed under the Business Source License
For more information about the provider resources, see the relevant documentation on the Terraform
If you do not have Terraform yet, install it and configure the Yandex Cloud provider.
To disable public access to bucket operations:
-
Open the Terraform configuration file and add the
anonymous_access_flagssection to the bucket description fragment.resource "yandex_storage_bucket" "log_bucket" { access_key = "<static_key_ID>" secret_key = "<secret_key>" bucket = "<bucket_name>" anonymous_access_flags { read = false list = false config_read = false } }Where:
access_key: Static access key ID.secret_key: Secret access key value.bucket: Name of the bucket to which you need to disable public access.anonymous_access_flags: Public access parameters:read: Public read access to bucket objects.list: Public access to the list of bucket objects.config_read: Public read access to the bucket configuration.
For more information about the
yandex_storage_bucketproperties in Terraform, see this provider guide. -
Validate your configuration files.
-
In the terminal, navigate to the directory where you created your configuration file.
-
Run a check using the following command:
terraform plan
If your configuration is correct, the terminal will display a list of the resources to be created and their settings. Otherwise, Terraform will show any detected errors.
-
-
Deploy the cloud resources.
-
If the configuration is correct, run this command:
terraform apply -
Confirm creating the resources: type
yesand press Enter.This will create all the resources you need in the specified folder. You can check the new resources and their settings using the management console
.
-
To disable public access to bucket operations, use the update REST API method for the Bucket resource or the BucketService/Update gRPC API call.
When disabling public access to your bucket, make sure the All users public group has no viewer, storage.viewer, or higher role assigned for the folder or bucket. Otherwise, the bucket will still be publicly accessible.