When you upload an object to a bucket with server-side encryption enabled, Object Storage Service (OSS) encrypts the object before storing it. When you call the GetObject operation to download the object, OSS automatically decrypts the object and returns it. The response includes the x-oss-server-side-encryption header to indicate that the object was encrypted on the server side.
For more information about the x-oss-server-side-encryption response header, see Response headers.
Scenarios
OSS uses server-side encryption to provide data-at-rest protection. This feature is suitable for scenarios with high security or compliance requirements for data storage, such as storing deep learning sample files and online collaborative documents.
Encryption methods
OSS provides two server-side encryption methods for different scenarios. You can select a method based on your requirements.
Encryption method | Description | Scenarios | Notes | Billing |
Server-side encryption with keys managed by Key Management Service (SSE-KMS) | Use the default customer master key (CMK) managed by Key Management Service (KMS) or a specified CMK to encrypt and decrypt data. Data is encrypted and decrypted without being sent over the network to the KMS server. | This method is suitable when you need to use self-managed or user-specified keys to meet security and compliance requirements. |
| You are charged when you call API operations to encrypt or decrypt data using CMKs stored in KMS. For more information, see Billing of KMS. |
Server-side encryption with OSS-managed keys (SSE-OSS) | Use a key that is fully managed by OSS to encrypt each object. For enhanced security, OSS also uses a master key to encrypt the data encryption key itself. | This method is suitable when only basic encryption capabilities are required and you do not need to manage keys. | None. | Free of charge. |
Notes
To upload, download, or access objects in a bucket that is encrypted using SSE-KMS, you must have permissions to use the specified CMK ID, and the request must not be anonymous. Otherwise, the request fails and the
This request is forbidden by kmserror is returned.Objects in a bucket that are retrieved using mirroring-based back-to-origin rules are not encrypted by default.
Enabling or changing the encryption method for a bucket does not affect the encryption configuration of existing objects in the bucket.
An object can be encrypted by only one server-side encryption method at a time.
If you configure encryption for a bucket, you can still configure a separate encryption method for an object when you upload or copy it. The encryption method configured for the object takes precedence. For more information, see PutObject.
Permissions
The following list describes the permissions that a Resource Access Management (RAM) user needs to use server-side encryption in different scenarios.
For more information, see Grant custom permissions to a RAM user.
Set the encryption method for a bucket
Permissions to manage the target bucket.
The
PutBucketEncryptionandGetBucketEncryptionpermissions.If you set the encryption method to SSE-KMS and specify a CMK ID, you also need the
ListKeys,Listalias,ListAliasesByKeyId, andDescribeKeypermissions. The following is an example RAM policy:{ "Version": "1", "Statement": [ { "Effect": "Allow", "Action": [ "kms:List*", "kms:DescribeKey" ], "Resource": [ "acs:kms:*:141661496593****:*" // Allows the use of all KMS keys under this Alibaba Cloud account ID. To allow only a specific CMK, enter its CMK ID. ] } ] }
Upload an object to an encrypted bucket
Permissions to upload objects to the target bucket.
If you set the encryption method to KMS and specify a CMK ID, you also need the
ListKeys,ListAliases,ListAliasesByKeyId,DescribeKey,GenerateDataKey, andDecryptpermissions. The following is an example RAM policy:{ "Version": "1", "Statement": [ { "Effect": "Allow", "Action": [ "kms:List*", "kms:DescribeKey", "kms:GenerateDataKey", "kms:Decrypt" ], "Resource": [ "acs:kms:*:141661496593****:*"// Allows the use of all KMS keys under this Alibaba Cloud account ID. To allow only a specific CMK, enter its CMK ID. ] } ] }
Download an object from an encrypted bucket
Permissions to access objects in the target bucket.
If the encryption method is KMS and a CMK ID is specified, you also need the
Decryptpermission. The following is an example RAM policy:{ "Version": "1", "Statement": [ { "Effect": "Allow", "Action": [ "kms:Decrypt" ], "Resource": [ "acs:kms:*:141661496593****:*"// Grants decryption permissions for all KMS keys under this Alibaba Cloud account ID. To grant decryption permissions for a specific KMS key, enter its CMK ID. ] } ] }
Methods
If you purchased the KMS key rotation value-added service, server-side encryption supports key rotation for KMS keys. After you enable key rotation, the new key is used to encrypt only new objects. The encryption key for existing objects remains unchanged.
If you update a KMS encryption key through OSS, the new key applies only to objects that are written after the update. Existing objects that were written before the key update are still encrypted with the old key. Therefore, do not delete the old key after an update. Otherwise, you cannot access the existing objects.
Use the OSS console
Use Alibaba Cloud SDKs
Use the ossutil command-line tool
Use KMS-managed keys for encryption and decryption
You can use a KMS-managed CMK to generate a data encryption key to encrypt data. The envelope encryption mechanism further prevents unauthorized data access. With KMS, you can focus on business functions such as data encryption, decryption, and digital signature verification without the high cost of ensuring the confidentiality, integrity, and availability of your keys.
The following figure shows the logic of the SSE-KMS encryption method.
When you use the SSE-KMS encryption method, you can use the following keys:
Use the default KMS key managed by OSS
OSS uses the default KMS-managed CMK to generate different keys to encrypt different objects and automatically decrypts the objects when they are downloaded. When you use this method for the first time, OSS creates an OSS-managed CMK on the KMS platform.
Configuration methods:
Configure the bucket encryption method
Set the bucket encryption method to KMS but do not specify a CMK ID. Then, all objects uploaded to this bucket are encrypted.
You can configure the encryption method for the target object.
When you upload an object or modify its metadata, include the
x-oss-server-side-encryptionparameter in the request and set its value toKMS. OSS then uses the default KMS-managed CMK and the AES256 encryption algorithm to encrypt the object. For more information, see PutObject.
Use Bring-Your-Own-Key (BYOK)
After you use BYOK material to generate a CMK in the KMS console, OSS can use the specified KMS CMK to generate different keys to encrypt different objects. The CMK ID of the encrypted object is recorded in the object's metadata. Only users with decryption permissions can decrypt the object when they download it.
There are two sources for BYOK material:
BYOK material provided by Alibaba Cloud: When you create a key on the KMS platform, select Alibaba Cloud KMS as the key material source.
Your own BYOK material: When you create a key on the KMS platform, select External as the key material source and import the external key material as needed. For more information, see Import key material.
Configuration methods:
Configure the bucket encryption method
Set the bucket encryption method to KMS and specify a CMK ID. Then, all objects uploaded to this bucket are encrypted.
You can configure the encryption method for the target object.
When you upload an object or modify its metadata, set the
x-oss-server-side-encryptionparameter toKMSand thex-oss-server-side-encryption-key-idparameter to the specified CMK ID. In this case, OSS uses the specified KMS CMK and the AES256 encryption algorithm to encrypt the object. For more information, see PutObject.
Use OSS-managed keys for encryption and decryption
OSS generates and manages data encryption keys and uses high-strength, multi-factor security measures for protection. Data is encrypted using the industry-standard 256-bit Advanced Encryption Standard (AES-256).
Configuration methods:
Configure the bucket encryption method
Set the bucket encryption method to OSS-managed and specify the encryption algorithm as AES256. Then, all objects uploaded to this bucket are encrypted by default.
Configure the target object's encryption method
To enable server-side encryption using an OSS-managed key, include the
x-oss-server-side-encryptionparameter in your request when you upload an object or modify its metadata. Set the value of this parameter toAES256. For more information, see PutObject.
Related API operations
The preceding operations are based on API calls. If your application has high customization requirements, you can directly call REST API operations. To call a REST API operation, you must manually write code to calculate the signature. For more information, see PutBucketEncryption.
FAQ
After I configure an encryption method for a bucket, does OSS encrypt the existing objects?
OSS encrypts only the objects that are uploaded after the server-side encryption configuration takes effect. It does not encrypt existing objects. To encrypt existing objects, you can use the CopyObject operation to overwrite them.