此接口用于修改或创建桶策略。如果桶策略已存在,当前请求会覆盖已有桶策略。
PUT /?policy HTTP/1.1 Host: bucketname.tos-cn-beijing.volces.com Date: Fri, 30 Jul 2021 08:05:36 +0000 Authorization: authorization string { "Version": "2012-10-17", "Statement": [{ "Sid": "桶只读策略", "Effect": "Allow", "Principal": [ "210004xxxx/testuser" ], "Action": [ "tos:Get*", "tos:List*" ], "Resource": [ "trn:tos:::bucketname", "trn:tos:::bucketname/*" ], "Condition": { "IpAddress": { "SourceIp": "192.168.0.1" } } }] }
该请求使用的公共请求消息头,请参见公共参数。
名称 | 位置 | 参数类型 | 是否必选 | 示例值 | 说明 |
---|---|---|---|---|---|
policy | Query | String | 是 | - | 代表 PutBucketPolicy 请求的特殊标识。 |
响应元素是符合 JSON 格式的字符串,包含了桶策略的信息,具体请参见桶策略模板及参数说明。
该请求返回的公共响应消息头,请参见公共参数。
该接口不使用响应元素。
向 TOS 账号授予权限
向账号 ID 为 210004xxxx 授予桶的只读权限。
PUT /?policy HTTP/1.1 Host: bucketname.tos-cn-beijing.volces.com Date: Fri, 30 Jul 2021 08:05:36 +0000 Authorization: authorization string { "Version": "2012-10-17", "Statement": [ { "Sid": "桶只读策略", "Effect": "Allow", "Principal": [ "210004xxxx" ], "Action": [ "tos:Get*", "tos:List*" ], "Resource": [ "trn:tos:::bucketname", "trn:tos:::bucketname/*" ] } ] }
HTTP/1.1 204 No Content Date: Fri, 30 Jul 2021 13:53:55 GMT Server: TosServer x-tos-id-2: 1e89f203jld00006-a444fd0 x-tos-request-id: 1e89f203b2d00006-a444ed0
向 TOS 账号的 IAM 用户授予权限
给账号 ID 210004xxxx 下的 IAM 用户 testuser 授予桶的只读权限。
PUT /?policy HTTP/1.1 Host: bucketname.tos-cn-beijing.volces.com Date: Fri, 30 Jul 2021 08:05:36 +0000 Authorization: authorization string { "Version": "2012-10-17", "Statement": [ { "Sid": "桶只读策略", "Effect": "Allow", "Principal": [ "210004xxxx/testuser" ], "Action": [ "tos:Get*", "tos:List*" ], "Resource": [ "trn:tos:::bucketname", "trn:tos:::bucketname/*" ] } ] }
HTTP/1.1 204 No Content Date: Fri, 30 Jul 2021 13:53:55 GMT Server: TosServer x-tos-id-2: 1e89f203jld00006-a444fd0 x-tos-request-id: 1e89f203b2d00006-a444ed0