Note:When granting API access permissions to a sub-user or collaborator, be sure to follow the principle of least privilege and grant the minimum set of permissions necessary to satisfy business needs. There may be data security risks if you grant excessive access to all of your resources
(resource:*)
or all operations(action:*)
.
When using a temporary key to access COS, the operation permissions required vary by API or series of APIs that you specify.
A COS API authorization policy is a JSON string. For example, below is a policy that grants the permission to perform uploads (including simple upload, upload through an HTML form, and multipart upload) for objects prefixed with doc
and downloads for objects prefixed with doc2
for the bucket examplebucket-1250000000
in the region "ap-beijing" under the APPID 1250000000
:
{
"version": "2.0",
"statement": [{
"action": [
// Upload an object by using simple upload
"name/cos:PutObject",
// Upload an object by using an HTML form
"name/cos:PostObject",
// Initialize a multipart upload
"name/cos:InitiateMultipartUpload",
// List all ongoing multipart uploads
"name/cos:ListMultipartUploads",
// List uploaded parts
"name/cos:ListParts",
// Upload parts
"name/cos:UploadPart",
// Complete a multipart upload
"name/cos:CompleteMultipartUpload",
// Abort a multipart upload
"name/cos:AbortMultipartUpload"
],
"effect": "allow",
"resource": [
"qcs::cos:ap-beijing:uid/1250000000:examplebucket-1250000000/doc/*"
]
},
{
"action": [
// Download
"name/cos:GetObject"
],
"effect": "allow",
"resource": [
"qcs::cos:ap-beijing:uid/1250000000:examplebucket-1250000000/doc2/*"
]
}
]
}
Name | Description |
---|---|
version | Policy syntax version, which is 2.0 by default. |
effect | Allow or deny. |
resource | Specific data of the authorized operation, which can be any resources, resources with a specified path prefix, resource in a specified absolute path, or their combination. |
action | COS API. You can specify one, several, or all (* ) COS APIs as needed, such as name/cos:GetService . Note that this value is case-sensitive. |
condition | Optional condition. For more information, see Element Reference. |
Examples of authorization policy settings for each COS API are as listed below.
To grant access to the GET Service
API, the action
field in the policy should be set to name/cos:GetService
, and the resource
field to *
.
The following policy grants the permission to query the bucket list:
{
"version": "2.0",
"statement": [
{
"action": [
"name/cos:GetService"
],
"effect": "allow",
"resource": [
"*"
]
}
]
}
The resource
field for bucket API policies is outlined in further detail below:
resource
field should be set to *
. Use this option with caution as it may present data security risks due to excessive permissions.examplebucket-1250000000
under the APPID 1250000000
in the region ap-beijing
, the resource
field should be set to qcs::cos:ap-beijing:uid/1250000000:*
.examplebucket-1250000000
under the APPID 1250000000
in the region ap-beijing
, the resource
field should be set to qcs::cos:ap-beijing:uid/1250000000:examplebucket-1250000000/*
.The action
field in bucket API policies varies by operation. The following lists several bucket API policies for your reference.
To grant access to the PUT Bucket
API, the action
field in the policy should be set to name/cos:PutBucket.
The following policy grants the user with the APPID 1250000000
permission to create a bucket named examplebucket-1250000000
in Beijing region:
{
"version": "2.0",
"statement": [
{
"action": [
"name/cos:PutBucket"
],
"effect": "allow",
"resource": [
"qcs::cos:ap-beijing:uid/1250000000:examplebucket-1250000000/"
]
}
]
}
Note:For bucket naming rules, see Bucket Overview.
To grant the access to the HEAD Bucket
API, the action
field in the policy should be set to name/cos:HeadBucket
.
The following policy grants the permission to extract only the bucket examplebucket-1250000000
in the region ap-beijing
under the APPID 1250000000
:
{
"version": "2.0",
"statement": [
{
"action": [
"name/cos:HeadBucket"
],
"effect": "allow",
"resource": [
"qcs::cos:ap-beijing:uid/1250000000:examplebucket-1250000000/"
]
}
]
}
To grant access to the GET Bucket
API, the action
field in the policy should be set to name/cos:GetBucket
.
The following policy grants the permission to query only the list of objects in the bucket examplebucket-1250000000
in the region ap-beijing
under the APPID 1250000000
:
{
"version": "2.0",
"statement": [
{
"action": [
"name/cos:GetBucket"
],
"effect": "allow",
"resource": [
"qcs::cos:ap-beijing:uid/1250000000:examplebucket-1250000000/"
]
}
]
}
To grant access to the Delete Bucket
API, the action
field in the policy should be set to name/cos:DeleteBucket
.
The following policy grants the permission to delete only the bucket examplebucket-1250000000
in the region ap-beijing
under the APPID 1250000000
:
{
"version": "2.0",
"statement": [
{
"action": [
"name/cos:DeleteBucket"
],
"effect": "allow",
"resource": [
"qcs::cos:ap-beijing:uid/1250000000:examplebucket-1250000000/"
]
}
]
}
To grant access to the Put Bucket ACL
API, the action
field in the policy should be set to name/cos:PutBucketACL
.
The following policy grants the permission to set an ACL only for the bucket examplebucket-1250000000
in the region ap-beijing
under the APPID 1250000000
:
{
"version": "2.0",
"statement": [
{
"action": [
"name/cos:PutBucketACL"
],
"effect": "allow",
"resource": [
"qcs::cos:ap-beijing:uid/1250000000:examplebucket-1250000000/"
]
}
]
}
To grant access to the GET Bucket acl
API, the action
field in the policy should be set to name/cos:GetBucketACL
.
The following policy grants the permission to get the ACL only of the bucket examplebucket-1250000000
in the region ap-beijing
under the APPID 1250000000
:
{
"version": "2.0",
"statement": [
{
"action": [
"name/cos:GetBucketACL"
],
"effect": "allow",
"resource": [
"qcs::cos:ap-beijing:uid/1250000000:examplebucket-1250000000/"
]
}
]
}
To grant access to the PUT Bucket cors
API, the action
field in the policy should be set to name/cos:PutBucketCORS
.
The following policy grants the permission to set a CORS configuration only for the bucket examplebucket-1250000000
in the region ap-beijing
under the APPID 1250000000
:
{
"version": "2.0",
"statement": [
{
"action": [
"name/cos:PutBucketCORS"
],
"effect": "allow",
"resource": [
"qcs::cos:ap-beijing:uid/1250000000:examplebucket-1250000000/"
]
}
]
}
To grant access to the GET Bucket cors
API, the action
field in the policy should be set to name/cos:GetBucketCORS
.
The following policy grants the permission to query the CORS configuration only of the bucket examplebucket-1250000000
in the region ap-beijing
under the APPID 1250000000
:
{
"version": "2.0",
"statement": [
{
"action": [
"name/cos:GetBucketCORS"
],
"effect": "allow",
"resource": [
"qcs::cos:ap-beijing:uid/1250000000:examplebucket-1250000000/"
]
}
]
}
To grant access to the DELETE Bucket cors
API, the action
field in the policy should be set to name/cos:DeleteBucketCORS
.
The following policy grants the permission to delete the CORS configuration only of the bucket examplebucket-1250000000
in the region ap-beijing
under the APPID 1250000000
:
{
"version": "2.0",
"statement": [
{
"action": [
"name/cos:DeleteBucketCORS"
],
"effect": "allow",
"resource": [
"qcs::cos:ap-beijing:uid/1250000000:examplebucket-1250000000/"
]
}
]
}
To grant access to the PUT Bucket lifecycle
API, the action
field in the policy should be set to name/cos:PutBucketLifecycle
.
The following policy grants the permission to set a lifecycle configuration only for the bucket examplebucket-1250000000
in the region ap-beijing
under the APPID 1250000000
:
{
"version": "2.0",
"statement": [
{
"action": [
"name/cos:PutBucketLifecycle"
],
"effect": "allow",
"resource": [
"qcs::cos:ap-beijing:uid/1250000000:examplebucket-1250000000/"
]
}
]
}
To grant access to the GET Bucket lifecycle
API, the action
field in the policy should be set to name/cos:GetBucketLifecycle
.
The following policy grants the permission to query the lifecycle configuration only of the bucket examplebucket-1250000000
in the region ap-beijing
under the APPID 1250000000
:
{
"version": "2.0",
"statement": [
{
"action": [
"name/cos:GetBucketLifecycle"
],
"effect": "allow",
"resource": [
"qcs::cos:ap-beijing:uid/1250000000:examplebucket-1250000000/"
]
}
]
}
To grant access to the DELETE Bucket lifecycle
API, the action
field in the policy should be set to name/cos:DeleteBucketLifecycle
.
The following policy grants the permission to delete the lifecycle configuration only of the bucket examplebucket-1250000000
in the region ap-beijing
under the APPID 1250000000
:
{
"version": "2.0",
"statement": [
{
"action": [
"name/cos:DeleteBucketLifecycle"
],
"effect": "allow",
"resource": [
"qcs::cos:ap-beijing:uid/1250000000:examplebucket-1250000000/"
]
}
]
}
The resource
field for object API policies is outlined in further detail below:
resource
field should be set to *
.examplebucket-1250000000
in the region ap-beijing
under the APPID 1250000000
, the resource
field should be set to qcs::cos:ap-beijing:uid/1250000000:examplebucket-1250000000/*
.doc
in the bucket examplebucket-1250000000
in the region ap-beijing
under the APPID 1250000000
, the resource
field should be set to qcs::cos:ap-beijing:uid/1250000000:examplebucket-1250000000/doc/*
.doc/audio.mp3
in the bucket examplebucket-1250000000
in the region ap-beijing
under the APPID 1250000000
, the resource
field should be set to qcs::cos:ap-beijing:uid/1250000000:examplebucket-1250000000/doc/audio.mp3
.The action
field in object API policies varies by operation. All object API policies are as listed below.
To grant access to the PUT Object
API, the action
field in the policy should be set to name/cos:PutObject
.
The following policy grants the permission to use simple upload to upload only objects with the path prefix doc
in the bucket examplebucket-1250000000
in the region ap-beijing
under the APPID 1250000000
:
{
"version": "2.0",
"statement": [
{
"action": [
"name/cos:PutObject"
],
"effect": "allow",
"resource": [
"qcs::cos:ap-beijing:uid/1250000000:examplebucket-1250000000/doc/*"
]
}
]
}
Multipart upload APIs include Initiate Multipart Upload
, List Multipart Uploads
, List Parts
, Upload Part
, Complete Multipart Upload
, and Abort Multipart Upload
. To grant access to these APIs, the action
field in the policy should be a collection of "name/cos:InitiateMultipartUpload","name/cos:ListMultipartUploads","name/cos:ListParts","name/cos:UploadPart","name/cos:CompleteMultipartUpload","name/cos:AbortMultipartUpload"
.
The following policy grants the permission to use multipart upload to upload only objects with the path prefix doc
in the bucket examplebucket-1250000000
in the region ap-beijing
under the APPID 1250000000
:
{
"version": "2.0",
"statement": [
{
"action": [
"name/cos:InitiateMultipartUpload",
"name/cos:ListMultipartUploads",
"name/cos:ListParts",
"name/cos:UploadPart",
"name/cos:CompleteMultipartUpload",
"name/cos:AbortMultipartUpload"
],
"effect": "allow",
"resource": [
"qcs::cos:ap-beijing:uid/1250000000:examplebucket-1250000000/doc/*"
]
}
]
}
To grant access to this API, the action
field in the policy should be set to name/cos:ListMultipartUploads
.
The following policy grants the permission to query ongoing multipart uploads only in the bucket examplebucket-1250000000
in the region ap-beijing
under the APPID 1250000000
:
{
"version": "2.0",
"statement": [
{
"action": [
"name/cos:ListMultipartUploads"
],
"effect": "allow",
"resource": [
"qcs::cos:ap-beijing:uid/1250000000:examplebucket-1250000000/"
]
}
]
}
To grant access to the POST Object
API, the action
field in the policy should be set to name/cos:PostObject
.
The following policy grants the permission to use the POST
method to upload only objects with the path prefix doc
in the bucket examplebucket-1250000000
in the region ap-beijing
under the APPID 1250000000
:
{
"version": "2.0",
"statement": [
{
"action": [
"name/cos:PostObject"
],
"effect": "allow",
"resource": [
"qcs::cos:ap-beijing:uid/1250000000:examplebucket-1250000000/doc/*"
]
}
]
}
To grant access to the Append Object
API, the action
field in the policy should be set to name/cos:AppendObject
.
The following policy grants permission to append parts to objects with the path prefix doc
in the bucket examplebucket-1250000000
in the region ap-beijing
under the APPID 1250000000
:
{
"version": "2.0",
"statement": [
{
"action": [
"name/cos:AppendObject"
],
"effect": "allow",
"resource": [
"qcs::cos:ap-beijing:uid/1250000000:examplebucket-1250000000/doc/*"
]
}
]
}
To grant access to the HEAD Object
API, the action
field in the policy should be set to name/cos:HeadObject
.
The following policy grants the permission to query objects only with the path prefix doc
in the bucket examplebucket-1250000000
in the region ap-beijing
under the APPID 1250000000
:
{
"version": "2.0",
"statement": [
{
"action": [
"name/cos:HeadObject"
],
"effect": "allow",
"resource": [
"qcs::cos:ap-beijing:uid/1250000000:examplebucket-1250000000/doc/*"
]
}
]
}
To grant access to the GET Object
API, the action
field in the policy should be set to name/cos:GetObject
.
The following policy grants the permission to download only objects with the path prefix doc
in the bucket examplebucket-1250000000
in the region ap-beijing
under the APPID 1250000000
:
{
"version": "2.0",
"statement": [
{
"action": [
"name/cos:GetObject"
],
"effect": "allow",
"resource": [
"qcs::cos:ap-beijing:uid/1250000000:examplebucket-1250000000/doc/*"
]
}
]
}
To grant access to the Put Object Copy
API, the action
field for the destination object should be set to name/cos:PutObject
, and the action
field for the source object should be set to name/cos:GetObject
.
The following policy grants the permission to use multipart copy to copy objects from the path prefixed with doc
to the path prefixed with doc2
in the bucket examplebucket-1250000000
in the region ap-beijing
under the APPID 1250000000
:
{
"version": "2.0",
"statement": [
{
"action": [
"name/cos:PutObject"
],
"effect": "allow",
"resource": [
"qcs::cos:ap-beijing:uid/1250000000:examplebucket-1250000000/doc/*"
]
},
{
"action": [
"name/cos:GetObject"
],
"effect": "allow",
"resource": [
"qcs::cos:ap-beijing:uid/1250000000:examplebucket-1250000000/doc2/*"
]
}
]
}
Here, "qcs::cos:ap-beijing:uid/1250000000:examplebucket-1250000000/doc2/*"
is the source object.
To grant access to the Upload Part - Copy
API, the action
field for the destination object should be a collection of "name/cos:InitiateMultipartUpload","name/cos:ListMultipartUploads","name/cos:ListParts","name/cos:PutObject","name/cos:CompleteMultipartUpload","name/cos:AbortMultipartUpload"
, and the action
field for the source object should be set to name/cos:GetObject
.
The following policy grants the permission to use multipart copy to copy objects from the path prefixed with doc
to the path prefixed with doc2
in the bucket examplebucket-1250000000
in the region ap-beijing
under the APPID 1250000000
:
{
"version": "2.0",
"statement": [
{
"action": [
"name/cos:InitiateMultipartUpload",
"name/cos:ListMultipartUploads",
"name/cos:ListParts",
"name/cos:PutObject",
"name/cos:CompleteMultipartUpload",
"name/cos:AbortMultipartUpload"
],
"effect": "allow",
"resource": [
"qcs::cos:ap-beijing:uid/1250000000:examplebucket-1250000000/doc/*"
]
},
{
"action": [
"name/cos:GetObject"
],
"effect": "allow",
"resource": [
"qcs::cos:ap-beijing:uid/1250000000:examplebucket-1250000000/doc2/*"
]
}
]
}
Here, "qcs::cos:ap-beijing:uid/1250000000:examplebucket-1250000000/doc2/*"
is the source object.
To grant access to the Put Object ACL
API, the action
field in the policy should be set to name/cos:PutObjectACL
.
The following policy grants the permission to set an ACL only for objects with the path prefix doc
in the bucket examplebucket-1250000000
in the region ap-beijing
under the APPID 1250000000
:
{
"version": "2.0",
"statement": [
{
"action": [
"name/cos:PutObjectACL"
],
"effect": "allow",
"resource": [
"qcs::cos:ap-beijing:uid/1250000000:examplebucket-1250000000/doc/*"
]
}
]
}
To grant access to the Get Object ACL
API, the action
field in the policy should be set to name/cos:GetObjectACL
.
The following policy grants the permission to query the ACL only of objects with the path prefix doc
in the bucket examplebucket-1250000000
in the region ap-beijing
under the APPID 1250000000
:
{
"version": "2.0",
"statement": [
{
"action": [
"name/cos:GetObjectACL"
],
"effect": "allow",
"resource": [
"qcs::cos:ap-beijing:uid/1250000000:examplebucket-1250000000/doc/*"
]
}
]
}
To grant access to the OPTIONS Object
API, the action
field in the policy should be set to name/cos:OptionsObject
.
The following policy grants the permission to send an OPTIONS
request only for objects with the path prefix doc
in the bucket examplebucket-1250000000
in the region ap-beijing
under the APPID 1250000000
:
{
"version": "2.0",
"statement": [
{
"action": [
"name/cos:OptionsObject"
],
"effect": "allow",
"resource": [
"qcs::cos:ap-beijing:uid/1250000000:examplebucket-1250000000/doc/*"
]
}
]
}
To grant access to the Post Object Restore
API, the action
field in the policy should be set to name/cos:PostObjectRestore
.
The following policy grants the permission to restore archived objects only with the path prefix doc
in the bucket examplebucket-1250000000
in the region ap-beijing
under the APPID 1250000000
:
{
"version": "2.0",
"statement": [
{
"action": [
"name/cos:PostObjectRestore"
],
"effect": "allow",
"resource": [
"qcs::cos:ap-beijing:uid/1250000000:examplebucket-1250000000/doc/*"
]
}
]
}
To grant access to the DELETE Object
API, the action
field in the policy should be set to name/cos:DeleteObject
.
The following policy grants the permission to delete only the object audio.mp3
in the bucket examplebucket-1250000000
in the region ap-beijing
under the APPID 1250000000
:
{
"version": "2.0",
"statement": [
{
"action": [
"name/cos:DeleteObject"
],
"effect": "allow",
"resource": [
"qcs::cos:ap-beijing:uid/1250000000:examplebucket-1250000000/audio.mp3"
]
}
]
}
To grant access to the DELETE Multiple Objects
API, the action
field in the policy should be set to name/cos:DeleteObject
.
The following policy grants the permission to batch delete only the objects audio.mp3
and video.mp4
in the bucket examplebucket-1250000000
in the region ap-beijing
under the APPID 1250000000
:
{
"version": "2.0",
"statement": [
{
"action": [
"name/cos:DeleteObject"
],
"effect": "allow",
"resource": [
"qcs::cos:ap-beijing:uid/1250000000:examplebucket-1250000000/audio.mp3",
"qcs::cos:ap-beijing:uid/1250000000:examplebucket-1250000000/video.mp4"
]
}
]
}
The following policy grants full access to all resources:
{
"version": "2.0",
"statement": [
{
"action": [
"*"
],
"effect": "allow",
"resource": [
"*"
]
}
]
}
The following policy grants read-only access to all resources:
{
"version": "2.0",
"statement": [
{
"action": [
"name/cos:HeadObject",
"name/cos:GetObject",
"name/cos:GetBucket",
"name/cos:OptionsObject"
],
"effect": "allow",
"resource": [
"*"
]
}
]
}
The following policy grants the permission to access only files with the path prefix doc
in the bucket examplebucket-1250000000
and does not allow any operations on files in other paths:
{
"version": "2.0",
"statement": [
{
"action": [
"*"
],
"effect": "allow",
"resource": [
"qcs::cos:ap-shanghai:uid/1250000000:examplebucket-1250000000/doc/*"
]
}
]
}
Was this page helpful?