If client-side encryption is enabled, objects are locally encrypted before they are uploaded to Object Storage Service (OSS). Only the holder of the customer master key (CMK) can decrypt the objects. This way, data security is enhanced during transmission and storage.
Disclaimer
-
When you use client-side encryption, you must ensure the integrity and validity of the CMK. If the CMK is incorrectly used or lost due to improper maintenance, you are responsible for all losses and consequences caused by decryption failures.
-
When you copy or migrate encrypted data, you are responsible for the integrity and validity of object metadata. If the encrypted metadata is incorrect or lost due to improper maintenance, you are responsible for all losses and consequences caused by data decryption failures.
Scenarios
-
Highly sensitive data: You want to encrypt sensitive data, such as Personal Identifiable Information (PII), transaction records, and health data, before the data leaves your local environment. This ensures effective protection of your data even when the data is intercepted.
-
Regulatory compliance: Regulations, such as Health Insurance Portability and Accountability Act (HIPAA) and General Data Protection Regulation (GDPR), require encryption of data stored on third-party platforms. Client-side encryption meets these requirements because CMKs are managed by users and not passed over networks or to cloud service providers.
-
Strong permission control: Your enterprise or developer may want to have full control over the encryption process, including the selection of encryption algorithms and the management and rotation of keys. In this case, you can use client-side encryption to ensure that only authorized users can decrypt and access data.
-
Secure data migration across regions: Client-side encryption helps keep data encrypted throughout migration. This enhances data security during transmission over the Internet.
Notes
-
In this topic, the public endpoint of the China (Hangzhou) region is used. If you want to access OSS from other Alibaba Cloud services in the same region as OSS, use an internal endpoint. For more information about OSS regions and endpoints, see Regions and Endpoints.
-
In this topic, access credentials are obtained from environment variables. For more information about how to configure access credentials, see Configure access credentials.
-
This topic demonstrates creating an OSSClient instance with an OSS endpoint. For alternative configurations, such as using a custom domain or authenticating with credentials from Security Token Service (STS), see Configure a client (Go SDK V1).
Background information
In client-side encryption, a random data key is generated for each object to perform symmetric encryption on the object. The client uses a CMK to encrypt the random data key. The encrypted data key is uploaded as part of the object metadata and stored in the OSS server. When an encrypted object is downloaded, the client uses the CMK to decrypt the random data key, and then uses the decrypted data key to decrypt the object. To ensure data security, the CMK is used only on the client and is not transmitted over the network or stored on the server.
-
Client-side encryption supports multipart upload for objects larger than 5 GB. You must specify the total object size and each part size. All parts except the last must be the same size and a multiple of 16 bytes.
-
After you upload objects encrypted on the client, object metadata related to client-side encryption is protected, and cannot be modified by calling the CopyObject operation.
Encryption methods
A master key is currently used in the following two ways:
-
KMS-managed CMKs
When you use a CMK managed in Key Management Service (KMS) for client-side encryption, you must provide OSS SDK for Python with the CMK ID.
-
RSA-based CMKs managed by yourself
When you use a CMK managed by yourself for client-side encryption, you must send the public key and the private key of your CMK to OSS SDK for Python as parameters.
You can use the preceding encryption methods to prevent data leaks and protect your data on the client. Even if your data is leaked, the data cannot be decrypted by others.
Object metadata related to client-side encryption
|
Parameter |
Description |
Required |
|
x-oss-meta-client-side-encryption-key |
The encrypted data key. The encrypted data key is a string encrypted by using a CMK and encoded in Base64. |
Yes |
|
x-oss-meta-client-side-encryption-start |
The initial value that is randomly generated for data encryption. The initial value is a string encrypted by using a CMK and encoded in Base64. |
Yes |
|
x-oss-meta-client-side-encryption-cek-alg |
The algorithm that is used to encrypt data. |
Yes |
|
x-oss-meta-client-side-encryption-wrap-alg |
The algorithm that is used to encrypt the data key. |
Yes |
|
x-oss-meta-client-side-encryption-matdesc |
The description of the CMK in JSON format. Warning
We recommend that you configure a description for each CMK and store the mapping relationship between the CMK and its description. A CMK without a matching description cannot be replaced. |
No |
|
x-oss-meta-client-side-encryption-unencrypted-content-length |
The length of data before encryption. If content-length is not specified, this parameter is not generated. |
No |
|
x-oss-meta-client-side-encryption-unencrypted-content-md5 |
The MD5 hash of the data before encryption. If Content-MD5 is not specified, this parameter is not generated. |
No |
|
x-oss-meta-client-side-encryption-data-size |
The total size of the object for which you want to perform multipart upload. If you want to encrypt the object on the client side, you must specify this parameter when you initialize a multipart upload task for the object. |
Yes (for multipart upload) |
|
x-oss-meta-client-side-encryption-part-size |
The size of each part in a multipart upload task for the object. If you want to encrypt the object on the client side, you must specify this parameter when you initialize a multipart upload task for the object. Note
The size of each part must be an integer multiple of 16 bytes. |
Yes (for multipart upload) |
Sample code
References
-
For more information about the API operation that you can call to configure server-side encryption, see SetBucketEncryption.
-
For more information about the API operation that you can call to query server-side encryption configurations, see GetBucketEncryption.