All Products
Search
Document Center

Object Storage Service:put-bucket-public-access-block

Last Updated:Mar 19, 2026

Enables or disables Block Public Access for a bucket.

Prerequisites

Before you begin, ensure that you have:

  • The oss:PutBucketPublicAccessBlock permission, if operating as a RAM user or using Security Token Service (STS). Alibaba Cloud accounts have this permission by default. For setup instructions, see Attach a custom policy to a RAM user

Syntax

ossutil api put-bucket-public-access-block --bucket <value> --public-access-block-configuration <value> [flags]
ParameterTypeDescription
--bucketstringName of the bucket
--public-access-block-configurationstringBlock Public Access configuration
Note: This command maps to the PutBucketPublicAccessBlock API operation. For all supported global flags, see Command-line options.

--public-access-block-configuration

The --public-access-block-configuration parameter accepts XML or JSON. To load the configuration from a file, prefix the file path with file://.

XML format:

<PublicAccessBlockConfiguration>
  <BlockPublicAccess>true</BlockPublicAccess>
</PublicAccessBlockConfiguration>

JSON format:

{
  "BlockPublicAccess": "string"
}

Examples

The following examples enable Block Public Access for examplebucket.

Using an XML configuration file:

  1. Create public-access-block-configuration.xml with the following content:

    <?xml version="1.0" encoding="UTF-8"?>
    <PublicAccessBlockConfiguration>
      <BlockPublicAccess>true</BlockPublicAccess>
    </PublicAccessBlockConfiguration>
  2. Run the command:

    ossutil api put-bucket-public-access-block --bucket examplebucket --public-access-block-configuration file://public-access-block-configuration.xml

Using a JSON configuration file:

  1. Create public-access-block-configuration.json with the following content:

    {
      "BlockPublicAccess": "true"
    }
  2. Run the command:

    ossutil api put-bucket-public-access-block --bucket examplebucket --public-access-block-configuration file://public-access-block-configuration.json

Using inline JSON:

ossutil api put-bucket-public-access-block --bucket examplebucket --public-access-block-configuration "{\"BlockPublicAccess\":\"true\"}"