qcs:ip
限制用户访问 IP,适用于所有请求。192.168.1.0/24
网段和 IP 为 101.226.100.185
或 101.226.100.186
时,拥有上传对象和下载对象的权限。{"version": "2.0","principal": {"qcs": ["qcs::cam::uin/100000000001:uin/100000000002"]},"statement": [{"effect": "allow","action": ["name/cos:PutObject","name/cos:GetObject"],"resource": ["qcs::cos:ap-guangzhou:uid/1250000000:examplebucket-gz-1250000000/exampleobject"],"condition": {"ip_equal": {"qcs:ip": ["192.168.1.0/24","101.226.100.185","101.226.100.186"]}}}]}
{"statement": [{"action": ["name/cos:*"],"condition": {"string_equal": {"vpc:requester_vpc": ["vpc-aqp5jrc1"]}},"effect": "allow","principal": {"qcs": ["qcs::cam::uin/100000000001:uin/100000000002"]},"resource": ["qcs::cos:ap-beijing:uid/1250000000:examplebucket-1250000000/*"]}],"version": "2.0"}
versionid
表示对象的版本号,关于版本控制相关内容可查看 版本控制概述。您可以在下载对象(GetObject)、删除对象(DeleteObject)时使用请求参数 versionid
指定需要操作的对象版本。versionid
请求参数时,请求默认作用于对象的最新版本。versionid
请求参数为一个空字符串时,等同于不带 versionid
请求参数时。versionid
请求参数为字符串 "null"
的情况。对于一个存储桶在开启版本控制之前上传的对象,开启版本控制后,这批对象的版本号统一是字符串 "null"
。cos:versionid
用于限制请求参数 versionid
。{"version":"2.0","statement":[{"principal":{"qcs":["qcs::cam::uin/100000000001:uin/100000000002"]},"effect":"allow","action":["name/cos:GetObject"],"condition":{"string_equal":{"cos:versionid":"MTg0NDUxNTc1NjIzMTQ1MDAwODg"}},"resource":["qcs::cos:ap-guangzhou:uid/1250000000:examplebucket-1250000000/*"]}]}
{"statement":[{"principal":{"qcs":["qcs::cam::uin/100000000001:uin/100000000002"]},"effect":"allow","action":["name/cos:GetObject"],"condition":{"string_equal":{"cos:versionid":"MTg0NDUxNTc1NjIzMTQ1MDAwODg"}},"resource":["qcs::cos:ap-guangzhou:uid/1250000000:examplebucket-1250000000/*"]},{"principal":{"qcs":["qcs::cam::uin/100000000001:uin/100000000002"]},"effect":"deny","action":["name/cos:GetObject"],"condition":{"string_not_equal_if_exist":{"cos:versionid":"MTg0NDUxNTc1NjIzMTQ1MDAwODg"}},"resource":["qcs::cos:ap-guangzhou:uid/1250000000:examplebucket-1250000000/*"]}],"version":"2.0"}
versionid
或 versionid
为空字符串时,GetObject 默认获取最新版本的对象。因此,我们可以在条件中使用 string_equal_if_exsit:“”
,同样会命中 allow 策略,只对获取最新版本的对象的请求进行授权。"condition": {"string_equal_if_exist": {"cos:versionid": ""}}
{"statement":[{"principal":{"qcs":["qcs::cam::uin/100000000001:uin/100000000002"]},"effect":"allow","action":["name/cos:GetObject"],"condition":{"string_equal_if_exist":{"cos:versionid":""}},"resource":["qcs::cos:ap-guangzhou:uid/1250000000:examplebucket-1250000000/*"]},{"principal":{"qcs":["qcs::cam::uin/100000000001:uin/100000000002"]},"effect":"deny","action":["name/cos:GetObject"],"condition":{"string_not_equal":{"cos:versionid":""}},"resource":["qcs::cos:ap-guangzhou:uid/1250000000:examplebucket-1250000000/*"]}],"version":"2.0"}
{"statement":[{"principal":{"qcs":["qcs::cam::uin/100000000001:uin/100000000002"]},"effect":"allow","action":["name/cos:DeleteObject"],"resource":["qcs::cos:ap-guangzhou:uid/1250000000:examplebucket-1250000000/*"]},{"principal":{"qcs":["qcs::cam::uin/100000000001:uin/100000000002"]},"effect":"deny","action":["name/cos:DeleteObject"],"condition":{"string_equal":{"cos:versionid":"null"}},"resource":["qcs::cos:ap-guangzhou:uid/1250000000:examplebucket-1250000000/*"]}],"version":"2.0"}
cos:content-length
限制请求头部 Content-Length
,进而限制上传对象的文件大小,以方便您更加灵活管理存储空间,避免上传过大、过小文件浪费存储空间与网络带宽。cos:content-length
条件键限制子用户(uin:100000000002)上传请求的 Content-Length 头的大小。{"version":"2.0","statement":[{"principal":{"qcs":["qcs::cam::uin/100000000001:uin/100000000002"]},"effect":"allow","action":["name/cos:PutObject","name/cos:PostObject"],"resource":["qcs::cos:ap-guangzhou:uid/1250000000:examplebucket-1250000000/*"],"condition":{"numeric_less_than_equal":{"cos:content-length":10}}},{"principal":{"qcs":["qcs::cam::uin/100000000001:uin/100000000002"]},"effect":"deny","action":["name/cos:PutObject","name/cos:PostObject"],"resource":["qcs::cos:ap-guangzhou:uid/1250000000:examplebucket-1250000000/*"],"condition":{"numeric_greater_than_if_exist":{"cos:content-length":10}}}]}
{"version":"2.0","statement":[{"principal":{"qcs":["qcs::cam::uin/100000000001:uin/100000000002"]},"effect":"allow","action":["name/cos:PutObject","name/cos:PostObject"],"resource":["qcs::cos:ap-guangzhou:uid/1250000000:examplebucket-1250000000/*"],"condition":{"numeric_greater_than_equal":{"cos:content-length":2}}},{"principal":{"qcs":["qcs::cam::uin/100000000001:uin/100000000002"]},"effect":"deny","action":["name/cos:PutObject","name/cos:PostObject"],"resource":["qcs::cos:ap-guangzhou:uid/1250000000:examplebucket-1250000000/*"],"condition":{"numeric_less_than_if_exist":{"cos:content-length":2}}}]}
cos:content-type
可以对请求的 Content-Type
头部进行限制。cos:content-type
条件键限制子用户(uin:100000000002)上传请求的 Content-Type 头的具体内容。{"version":"2.0","statement":[{"principal":{"qcs":["qcs::cam::uin/100000000001:uin/100000000002"]},"effect":"allow","action":["name/cos:PutObject"],"resource":["qcs::cos:ap-guangzhou:uid/1250000000:examplebucket-1250000000/*"],"condition":{"string_equal":{"cos:content-type":"image/jpeg"}}},{"principal":{"qcs":["qcs::cam::uin/100000000001:uin/100000000002"]},"effect":"deny","action":["name/cos:PutObject"],"resource":["qcs::cos:ap-guangzhou:uid/1250000000:examplebucket-1250000000/*"],"condition":{"string_not_equal_if_exist":{"cos:content-type":"image/jpeg"}}}]}
response-content-type
,用于设置响应中 Content-Type 头部的值。cos:response-content-type
,您可以对请求的是否必须携带请求参数 response-content-type
参数值做限制。response-content-type
是请求参数,发起请求时需要经过 urlencode,即 response-content-type=image%2Fjpeg
,所以在设置 Policy 时,“image/jpeg”也需要经过 urlencode 填写"image%2Fjpeg"。{"version":"2.0","statement":[{"principal":{"qcs":["qcs::cam::uin/100000000001:uin/100000000002"]},"effect":"allow","action":["name/cos:GetObject"],"resource":["qcs::cos:ap-guangzhou:uid/1250000000:examplebucket-1250000000/*"],"condition":{"string_equal":{"cos:response-content-type":"image%2Fjpeg"}}},{"principal":{"qcs":["qcs::cam::uin/100000000001:uin/100000000002"]},"effect":"deny","action":["name/cos:GetObject"],"resource":["qcs::cos:ap-guangzhou:uid/1250000000:examplebucket-1250000000/*"],"condition":{"string_not_equal_if_exist":{"cos:response-content-type":"image%2Fjpeg"}}}]}
cos:secure-transport
限制请求必须使用 HTTPS 协议{"version":"2.0","statement":[{"principal":{"qcs":["qcs::cam::uin/100000000001:uin/100000000002"]},"effect":"allow","action":["name/cos:GetObject"],"resource":["qcs::cos:ap-guangzhou:uid/1250000000:examplebucket-1250000000/*"],"condition":{"bool_equal":{"cos:secure-transport":"true"}}}]}
{"version":"2.0","statement":[{"principal":{"qcs":["qcs::cam::uin/100000000001:uin/100000000002"]},"effect":"deny","action":["*"],"resource":["qcs::cos:ap-guangzhou:uid/1250000000:examplebucket-1250000000/*"],"condition":{"bool_equal":{"cos:secure-transport":"false"}}}]}
x-cos-storage-class
在上传对象时指定存储类型或修改对象的存储类型。cos:x-cos-storage-class
限制请求头部 x-cos-storage-class
,进而限制可能修改存储类型的请求。STANDARD
、MAZ_STANDARD
, STANDARD_IA
、MAZ_STANDARD_IA
、INTELLIGENT_TIERING
、MAZ_INTELLIGENT_TIERING
、ARCHIVE
、DEEP_ARCHIVE
。STANDARD
。{"version":"2.0","statement":[{"principal":{"qcs":["qcs::cam::uin/100000000001:uin/100000000002"]},"effect":"allow","action":["name/cos:PutObject"],"resource":["qcs::cos:ap-guangzhou:uid/1250000000:examplebucket-1250000000/*"],"condition":{"string_equal":{"cos:x-cos-storage-class":"STANDARD"}}},{"principal":{"qcs":["qcs::cam::uin/100000000001:uin/100000000002"]},"effect":"deny","action":["name/cos:PutObject"],"resource":["qcs::cos:ap-guangzhou:uid/1250000000:examplebucket-1250000000/*"],"condition":{"string_not_equal_if_exist":{"cos:x-cos-storage-class":"STANDARD"}}}]}
private
、public-read
、public-read-write
、authenticated-read
。default
、private
、public-read
、authenticated-read
、bucket-owner-read
、bucket-owner-full-control
。cos:x-cos-acl
限制请求的头部 x-cos-acl
,进而限制可能修改对象或存储桶 ACL 的请求。private
。{"version":"2.0","statement":[{"principal":{"qcs":["qcs::cam::uin/100000000001:uin/100000000002"]},"effect":"allow","action":["name/cos:PutObject"],"resource":["qcs::cos:ap-guangzhou:uid/1250000000:examplebucket-1250000000/*"],"condition":{"string_equal":{"cos:x-cos-acl":"private"}}},{"principal":{"qcs":["qcs::cam::uin/100000000001:uin/100000000002"]},"effect":"deny","action":["name/cos:PutObject"],"resource":["qcs::cos:ap-guangzhou:uid/1250000000:examplebucket-1250000000/*"],"condition":{"string_not_equal_if_exist":{"cos:x-cos-acl":"private"}}}]}
cos:prefix
限制请求参数 prefix。/
等),写入存储桶策略前需要先经过 urlencode。{"statement":[{"principal":{"qcs":["qcs::cam::uin/100000000001:uin/100000000002"]},"effect":"allow","action":["name/cos:GetBucket"],"resource":["qcs::cos:ap-guangzhou:uid/1250000000:examplebucket-1250000000/*"],"condition":{"string_equal":{"cos:prefix":"folder1"}}},{"principal":{"qcs":["qcs::cam::uin/100000000001:uin/100000000002"]},"effect":"deny","action":["name/cos:GetBucket"],"resource":["qcs::cos:ap-guangzhou:uid/1250000000:examplebucket-1250000000/*"],"condition":{"string_equal_if_exist":{"cos:prefix":"folder1"}}}],"version":"2.0"}
cos:tls-version
限制 HTTPS 请求的 TLS 版本,该条件键为 Numric 类型,支持输入浮点数,例如 1.0、1.1、1.2 等。请求场景 | 预期 |
HTTPS 请求,TLS 版本为1.0 | 403,失败 |
HTTPS 请求,TLS 版本为1.2 | 200,成功 |
{"version":"2.0","statement":[{"principal":{"qcs":["qcs::cam::uin/100000000001:uin/100000000002"]},"effect":"allow","action":["*"],"resource":["qcs::cos:ap-guangzhou:uid/1250000000:examplebucket-1250000000/*"],"condition":{"numeric_equal":{"cos:tls-version":1.2}}}]}
请求场景 | 预期 |
HTTPS 请求,TLS 版本为1.0 | 403,失败 |
HTTPS 请求,TLS 版本为1.2 | 200,成功 |
{"version":"2.0","statement":[{"principal":{"qcs":["qcs::cam::uin/100000000001:uin/100000000002"]},"effect":"allow","action":["*"],"resource":["qcs::cos:ap-guangzhou:uid/1250000000:examplebucket-1250000000/*"],"condition":{"numeric_greater_than_equal":{"cos:tls-version":1.2}}},{"principal":{"qcs":["qcs::cam::uin/100000000001:uin/100000000002"]},"effect":"deny","action":["*"],"resource":["qcs::cos:ap-guangzhou:uid/1250000000:examplebucket-1250000000/*"],"condition":{"numeric_less_than_if_exist":{"cos:tls-version":1.2}}}]}
qcs:request_tag
限制用户发起请求 PutBucket、PutBucketTagging 必须携带指定的存储桶标签。<a,b>
和 <c,d>
,才能获得授权。for_any_value:string_equal
表示 A 和 B 存在交集时生效。for_all_value:string_equal
表示 A 是 B 的子集时生效。for_any_value:string_equal
时,对应的策略和请求表现如下:请求场景 | 预期 |
PutBucket,请求头部 x-cos-tagging: a=b&c=d | 200,成功 |
PutBucket,请求头部 x-cos-tagging: a=b | 200,成功 |
PutBucket,请求头部 x-cos-tagging: a=b&c=d&e=f | 200,成功 |
{"version": "2.0","statement": [{"principal": {"qcs": ["qcs::cam::uin/100000000001:uin/100000000002"]},"effect": "allow","action": ["name/cos:PutBucket"],"resource": "*","condition": {"for_any_value:string_equal": {"qcs:request_tag": ["a&b","c&d"]}}}]}
for_all_value:string_equal
时,对应的策略和请求表现如下:请求场景 | 预期 |
PutBucket,请求头部 x-cos-tagging: a=b&c=d | 200,成功 |
PutBucket,请求头部 x-cos-tagging: a=b | 200,成功 |
PutBucket,请求头部 x-cos-tagging: a=b&c=d&e=f | 403,失败 |
{"version": "2.0","statement": [{"principal": {"qcs": ["qcs::cam::uin/100000000001:uin/100000000002"]},"effect": "allow","action": ["name/cos:PutBucket"],"resource": "*","condition": {"for_all_value:string_equal": {"qcs:request_tag": ["a&b","c&d"]}}}]}
本页内容是否解决了您的问题?