When you enable client-side encryption, objects are encrypted locally before they are uploaded to Object Storage Service (OSS). Only users who have the key can decrypt the objects. This enhances data security 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 may want to encrypt sensitive data, such as personally identifiable information (PII), financial transaction records, and medical or health data, before it leaves your local environment. This ensures that your raw data is protected even if it is intercepted during transmission.
Compliance requirements: Some industries and regulations, such as the Health Insurance Portability and Accountability Act (HIPAA) and the General Data Protection Regulation (GDPR), require strict control over the encryption of data stored on third-party platforms. Client-side encryption helps you meet these compliance requirements because you manage the keys. The keys are not transmitted over the network or directly controlled by cloud service providers.
Enhanced autonomous control: You may want full control over the encryption process, including selecting encryption algorithms and managing and rotating keys. Client-side encryption helps you achieve this goal and ensures that only authorized users can decrypt and access data.
Cross-region data migration security: When you migrate data from one region to another, client-side encryption ensures that the data remains encrypted throughout the migration process. This enhances data security during transmission over the Internet.
Usage 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.
In this topic, an OSSClient instance is created by using an OSS endpoint. If you want to create an OSSClient instance by using custom domain names or Security Token Service (STS), see Configure OSSClient instances.
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 in size. When you use multipart upload to upload an object, you must specify the total size of the object and the size of each part. The size of each part except for the last part must be the same and be a multiple of 16.
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
You can use two types of CMKs for client-side encryption:
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.
Encryption metadata
Parameter | Description | Required |
x-oss-meta-client-side-encryption-key | The encrypted data key. This is a Base64-encoded string of the data key that is encrypted using a master key. | Yes |
x-oss-meta-client-side-encryption-start | The random initial value used for data encryption. This is a Base64-encoded string of the initial value that is encrypted using a master key. | Yes |
x-oss-meta-client-side-encryption-cek-alg | The data encryption algorithm. | Yes |
x-oss-meta-client-side-encryption-wrap-alg | The data key encryption algorithm. | Yes |
x-oss-meta-client-side-encryption-matdesc | The description of the master key in JSON format. Warning We strongly recommend that you configure a description for each master key and save the mapping between the master key and its description. Otherwise, you cannot change the master key for encryption. | No |
x-oss-meta-client-side-encryption-unencrypted-content-length | The length of the data before encryption. This parameter is not generated if `content-length` is not specified. | No |
x-oss-meta-client-side-encryption-unencrypted-content-md5 | The MD5 hash of the data before encryption. This parameter is not generated if an MD5 hash is not specified. | No |
x-oss-meta-client-side-encryption-data-size | If you encrypt a file using multipart upload, you must pass the total size of the file when you initialize the multipart upload. | Yes (for multipart upload) |
x-oss-meta-client-side-encryption-part-size | If you encrypt a file using multipart upload, you must pass the part size when you initialize the multipart upload. Note The part size must be a multiple of 16. | Yes (for multipart upload) |
Sample code
References
For more information about the API operation to configure server-side encryption, see SetBucketEncryption.
For more information about the API operation to query server-side encryption configurations, see GetBucketEncryption.