Set a table policy

更新时间:
复制 MD 格式

Attaches a resource policy to a table to enforce table-level access control.

Usage notes

  • The --resource-policy parameter takes a JSON-formatted policy string. The policy must follow the Alibaba Cloud resource policy specification and include the Version and Statement fields.

  • Setting a new policy overwrites the existing policy on the table. To update an existing policy, first retrieve it with get-table-policy, make your changes, then reapply the updated policy.

  • Pass the JSON string directly on the command line, or load it from a local file using the file:// prefix.

Syntax

ossutil tables-api put-table-policy --table-bucket-arn value --namespace value --name value --resource-policy value [flags]

Parameter

Type

Description

--name

string

The table name. Required.

--namespace

string

The name of the namespace that contains the table. Required.

--resource-policy

string

The resource policy JSON string. You can pass the JSON string directly or specify a local file path using the file:// prefix. Required. Example policy JSON:

{"Version":"1","Statement":[{"Effect":"Allow","Principal":["acs:ram::1234567890:root"],"Action":["osstables:GetTable","osstables:GetTableMetadataLocation"],"Resource":["acs:osstables:cn-hangzhou:1234567890:bucket/my-table-bucket/namespace/my_namespace/table/my_table"]}]}

--table-bucket-arn

string

The ARN of the Table Bucket, in the format acs:osstables:{region}:{uid}:bucket/{bucket-name}. Required.

Note
  • The put-table-policy command corresponds to the PutTablePolicy API operation. See the PutTablePolicy documentation for parameter details.

  • For supported global command-line options, see ossutil global options.

Examples

  • Allow a specified account to read table information and metadata location.

    ossutil tables-api put-table-policy --table-bucket-arn acs:osstables:cn-hangzhou:1234567890:bucket/my-table-bucket --namespace my_namespace --name my_table --resource-policy '{"Version":"1","Statement":[{"Effect":"Allow","Principal":["acs:ram::9876543210:root"],"Action":["osstables:GetTable","osstables:GetTableMetadataLocation"],"Resource":["acs:osstables:cn-hangzhou:1234567890:bucket/my-table-bucket/namespace/my_namespace/table/my_table"]}]}'
  • Load and apply a resource policy from a local file.

    ossutil tables-api put-table-policy --table-bucket-arn acs:osstables:cn-hangzhou:1234567890:bucket/my-table-bucket --namespace my_namespace --name my_table --resource-policy file://policy.json
  • Deny all principals from deleting a table.

    ossutil tables-api put-table-policy --table-bucket-arn acs:osstables:cn-hangzhou:1234567890:bucket/my-table-bucket --namespace my_namespace --name my_table --resource-policy '{"Version":"1","Statement":[{"Effect":"Deny","Principal":["*"],"Action":["osstables:DeleteTable"],"Resource":["acs:osstables:cn-hangzhou:1234567890:bucket/my-table-bucket/namespace/my_namespace/table/my_table"]}]}'