Updated on 2026-07-27 GMT+08:00

Configuring Encryption for a Bucket

Function

OBS allows you to create or update the default server-side encryption configuration for a bucket. Once bucket encryption is configured, objects uploaded to this bucket will be encrypted using the bucket's encryption configuration by default. OBS currently supports server-side encryption with KMS-managed keys (SSE-KMS) or OBS-managed keys (SSE-OBS). For more information about bucket encryption configuration, see Server-Side Encryption.

Constraints

  • Only one encryption method can be used each time an object is uploaded. The encryption configuration of an uploaded object cannot be changed.
  • To use SSE-KMS to encrypt a bucket or the objects in it, you must have kms:cmk:get, kms:cmk:list, kms:cmk:create, kms:dek:create, and kms:dek:crypto permissions granted by using IAM, so that you can upload objects to or download objects from this bucket.
  • If server-side encryption is disabled for a bucket, the encrypted objects can only be accessed over HTTPS.
  • A key in use cannot be deleted, or the object encrypted with this key cannot be downloaded.

Authorization

To call this API, you must be the bucket owner or have the permission to configure bucket encryption. You are advised to use IAM or bucket policies for authorization. For details about OBS authorization methods, see Differences Between OBS Permissions Control Methods.

  • If you use IAM for authorization, you need to use either role/policy-based authorization or identity policy-based authorization and configure the required permissions:
    • If you use role/policy-based authorization (IAM v3 APIs in the old IAM version), you must have the obs:bucket:PutEncryptionConfiguration permission. For details, see Creating a Custom IAM Policy.
    • If you use identity policy-based authorization (IAM v5 APIs in the new IAM version), you must have the obs:bucket:putEncryptionConfiguration permission, as shown in the following table. For details, see Creating a Custom IAM Identity Policy.

      Action

      Access Level

      Resource Type (*: Required)

      Condition Key

      Alias

      Dependencies

      obs:bucket:putEncryptionConfiguration

      Write

      bucket *

      -

      -

      -

      • obs:EpochTime
      • obs:SourceIp
      • obs:TlsVersion
      • obs:CustomDomain
      • obs:BucketEncrypted
  • If you use bucket policies for authorization, you must have the obs:bucket:PutEncryptionConfiguration permission. For details, see Creating a Custom Bucket Policy.

URI

PUT /

Calling Method

For details, see Calling APIs. Before calling this API, calculate the API signature and add it to the request.

You can debug this API in API Explorer.

Request Syntax (SSE-KMS AES256)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
PUT /?encryption  HTTP/1.1
User-Agent: curl/7.29.0
Host: bucketname.obs.region.myhuaweicloud.com 
Accept: */*
Date: date 
Authorization: authorization string
Content-Length: length

<ServerSideEncryptionConfiguration>
    <Rule>
        <ApplyServerSideEncryptionByDefault>
            <SSEAlgorithm>kms</SSEAlgorithm>
            <KMSMasterKeyID>kmskeyid-value</KMSMasterKeyID>
        </ApplyServerSideEncryptionByDefault>
        <BucketKeyEnabled>true</BucketKeyEnabled>
        <BucketKeyRotationPeriod>525600</BucketKeyRotationPeriod>
    </Rule>
</ServerSideEncryptionConfiguration>

Request Syntax (SSE-OBS)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
PUT /?encryption HTTP/1.1 
User-Agent: curl/7.29.0 
Host: bucketname.obs.region.myhuaweicloud.com 
Accept: */* 
Date: date  
Authorization: authorization string 
Content-Length: length
 
<ServerSideEncryptionConfiguration> 
    <Rule> 
        <ApplyServerSideEncryptionByDefault> 
            <SSEAlgorithm>AES256</SSEAlgorithm> 
        </ApplyServerSideEncryptionByDefault> 
    </Rule> 
</ServerSideEncryptionConfiguration>

URI Parameters

Table 1 URI parameters

Parameter

Mandatory

Type

Description

encryption

Yes

String

Definition

An identifier that marks this API as related to server-side encryption.

Constraints

When calculating the signature, add /BucketName/?encryption to CanonicalizedResource. For details, see Using an Authorization Header.

Range

encryption

Default Value

N/A

Request Headers

This request uses common headers. For details, see Table 3.

Request Body

In this request, you need to carry the bucket encryption configuration in the request body. The bucket encryption configuration information is uploaded in the XML format. Table 2 lists the configuration elements.

Table 2 Configuration elements of bucket encryption

Parameter

Mandatory

Type

Description

ServerSideEncryptionConfiguration

Yes

Container

Definition

Root element of the default encryption configuration of a bucket. ServerSideEncryptionConfiguration is the parent node of Rule.

Constraints

N/A

Range

N/A

Default Value

N/A

Rule

Yes

Container

Definition

The child element of the default bucket encryption configuration. Rule is the parent node of ApplyServerSideEncryptionByDefault and BucketKeyEnabled.

Constraints

N/A

Range

For details, see Table 3.

Default Value

N/A

Table 3 Rule parameter description

Parameter

Mandatory

Type

Description

ApplyServerSideEncryptionByDefault

Yes

Container

Definition

Child element of the default encryption configuration of a bucket.

Constraints

N/A

Range

For details, see Table 4.

Default Value

N/A

BucketKeyEnabled

No

Boolean

Definition

Whether to enable the OBS bucket key feature.

Constraints

  • This parameter can only be configured when SSEAlgorithm is set to kms, as it applies only to SSE-KMS encryption scenarios.
  • When configuring a POSIX bucket, set this parameter to true and KMSMasterKeyID is mandatory.

Range

  • true: The OBS bucket key feature is enabled.
  • false: The OBS bucket key feature is disabled.

Default Value

false

BucketKeyRotationPeriod

No

Integer

Definition

Bucket key rotation period, in minutes.

Constraints

This parameter can only be configured when SSEAlgorithm is set to kms and BucketKeyEnabled is set to true.

Range

259200–525600

Default Value

525600

Table 4 ApplyServerSideEncryptionByDefault parameters

Parameter

Mandatory

Type

Description

SSEAlgorithm

Yes

String

Definition

Server-side encryption algorithm used for the default encryption configuration of a bucket.

Constraints

N/A

Range

  • kms: SSE-KMS encryption and the AES256 algorithm are used.
  • AES256: SSE-OBS encryption and the AES256 algorithm are used.

Default Value

N/A

KMSMasterKeyID

No

String

Definition

KMS master key ID used in SSE-KMS encryption.

Constraints

  • If this parameter is not specified, the default master key will be used.
  • If BucketKeyEnabled is set to true, the value of KMSMasterKeyID is the ID of the master key created on KMS.

Range

  • regionID:domainID:key/key_id
  • key_id

In the preceding formats:

Default Value

N/A

Response Syntax

1
2
3
HTTP/1.1 status_code
Date: date
Content-Length: length

Response Headers

This response uses common headers. For details, see Table 1.

Response Body

This response does not contain a response body.

Error Responses

No special errors. You can find all errors in Error Code Overview.

Sample Request (SSE-KMS AES256)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
PUT /?encryption HTTP/1.1
User-Agent: curl/7.29.0
Host: examplebucket.obs.region.myhuaweicloud.com
Accept: */*
Date:  Thu, 21 Feb 2019 03:05:34 GMT
Authorization: OBS H4IPJX0TQTHTHEBQQCEC:DpSAlmLX/BTdjxU5HOEwflhM0WI=
Content-Length: 778

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 
<ServerSideEncryptionConfiguration xmlns="http://obs.region.myhuaweicloud.com/doc/2015-06-30/"> 
    <Rule>
        <ApplyServerSideEncryptionByDefault>
            <SSEAlgorithm>kms</SSEAlgorithm>
            <KMSMasterKeyID>4f1cd4de-ab64-4807-920a-47fc42e7f0d0</KMSMasterKeyID>
        </ApplyServerSideEncryptionByDefault>
        <BucketKeyEnabled>true</BucketKeyEnabled>
    </Rule>
</ServerSideEncryptionConfiguration>

Sample Response (SSE-KMS AES256)

1
2
3
4
5
6
HTTP/1.1 200 OK
Server: OBS
x-obs-request-id: BF26000001643670AC06E7B9A7767921
x-obs-id-2: 32AAAQAAEAABSAAgAAEAABAAAQAAEAABCSvK6z8HV6nrJh49gsB5vqzpgtohkiFm
Date: Thu, 21 Feb 2019 03:05:34 GMT
Content-Length: 0

Sample Request (SSE-OBS)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
PUT /?encryption HTTP/1.1 
User-Agent: curl/7.29.0 
Host: bucketname.obs.region.myhuaweicloud.com 
Accept: */*
Date:  Thu, 21 Feb 2019 03:05:34 GMT
Authorization: OBS H4IPJX0TQTHTHEBQQCEC:DpSAlmLX/BTdjxU5HOEwflhM0WI=
Content-Length: 778
 
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 
<ServerSideEncryptionConfiguration xmlns="http://obs.region.myhuaweicloud.com/doc/2015-06-30/"> 
    <Rule> 
        <ApplyServerSideEncryptionByDefault> 
            <SSEAlgorithm>AES256</SSEAlgorithm> 
        </ApplyServerSideEncryptionByDefault> 
    </Rule> 
</ServerSideEncryptionConfiguration>

Sample Response (SSE-OBS)

1
2
3
4
5
6
HTTP/1.1 200 OK
Server: OBS
x-obs-request-id: BF26000001643670AC06E7B9A7767921
x-obs-id-2: 32AAAQAAEAABSAAgAAEAABAAAQAAEAABCSvK6z8HV6nrJh49gsB5vqzpgtohkiFm
Date: Thu, 21 Feb 2019 03:05:34 GMT
Content-Length: 0

Using SDKs to Call APIs

You are advised to use OBS SDKs to call APIs. SDKs encapsulate APIs to simplify development. You can call SDK API functions to access OBS without manually calculating signatures.

To use SDKs to configure server-side encryption, see the following:

Java: not supported

Python: not supported

C

Go

BrowserJS: not supported

.NET

Android

iOS

PHP

Node.js

Helpful Links