Description
The PUT Bucket encryption API is used to set the default encryption configuration for a specified bucket.
To execute this API, PutBucketEncryption permission is required. By default, the owner of the bucket has permission to use this API directly, and the bucket owner can also grant permission to other users.
Request
Request Sample
PUT /?encryption HTTP 1.1
Host: <BucketName-APPID>.<Endpoint>
Date: GMT Date
Authorization: Auth String
Note:
<BucketName-APPID>is the bucket name with APPID as the suffix, for example, examplebucket-1250000000.- Authorization: Auth String (For details, refer to Request Signature).
Request Parameters
This API has no request parameters.
Request Headers
This API only uses common request headers. For details, see Common Request Headers documentation.
Request Body
Users use XML language in the request body to set bucket default encryption configuration information. Encryption configuration information mainly consists of encryption items.
The following is the request body used to set SSE-COS:
<ServerSideEncryptionConfiguration>
<Rule>
<ApplyServerSideEncryptionByDefault>
<SSEAlgorithm>AES256|KMS</SSEAlgorithm>
<KMSMasterKeyID>String</KMSMasterKeyID>
</ApplyServerSideEncryptionByDefault>
</Rule>
</ServerSideEncryptionConfiguration>
Specific elements are as follows:
| Element Name | Parent Node | Description | Type | Required |
|---|---|---|---|---|
| ServerSideEncryptionConfiguration | No | Configuration parameters including default encryption | Container | Yes |
| Rule | ServerSideEncryptionConfiguration | Default server-side encryption configuration rules | Container | Yes |
| ApplyServerSideEncryptionByDefault | ServerSideEncryptionConfiguration.Rule | Default configuration information for server-side encryption | Container | Yes |
| SSEAlgorithm | ServerSideEncryptionConfiguration.Rule. ApplyServerSideEncryptionByDefault |
Supported enumeration values are AES256 and KMS. AES256 indicates that the SSE-COS mode is used and the encryption algorithm is AES256. KMS indicates the SSE-KMS mode. | String | Yes |
| KMSMasterKeyID | ServerSideEncryptionConfiguration.Rule. ApplyServerSideEncryptionByDefault |
CMK of the KMS when the value of SSEAlgorithm is KMS. If it is not specified, the CMK created by COS by default is used. For details, see SSE-KMS Encryption. | String | Yes |
Response
Response Headers
This API only returns common response headers. For details, please refer to the Public Response Headers document.
Response Body
The response body for this request is empty.
Error Codes
This API follows unified error response and error codes. For details, please refer to the Error Codes document.
Practical Case
Request
The following example demonstrates setting SSE-COS encryption for the bucket examplebucket-1250000000.
PUT /?encryption HTTP 1.1
Host: examplebucket-1250000000.cos.city.yfm4.fsphere.cn
Date: Mon, 17 Jun 2019 08:37:35 GMT
Authorization: signatureValue
<ServerSideEncryptionConfiguration>
<Rule>
<ApplyServerSideEncryptionByDefault>
<SSEAlgorithm>AES256</SSEAlgorithm>
</ApplyServerSideEncryptionByDefault>
</Rule>
</ServerSideEncryptionConfiguration>
Response
HTTP/1.1 200 OK
Content-Type: application/xml
Content-Length: 0
Date: Mon, 17 Jun 2019 08:37:36 GMT
x-cos-request-id: NWQwNzUxNTBfMzdiMDJhMDlfOWM0Nl85NDFk****