Workloads with security or compliance requirements need data protected at rest without the overhead of managing key infrastructure. Disk encryption lets you automatically encrypt data before it is written to a disk and decrypt it when read, using keys managed by Key Management Service (KMS). This topic explains how to configure encrypted cloud disk volumes for workloads in an ACK cluster using a StorageClass.
This topic covers encrypting data volumes for workloads via a StorageClass. It does not cover encrypting node root volumes.
How encryption works
Alibaba Cloud disks use AES-256 encryption managed by KMS. KMS implements a two-tier key hierarchy — customer master keys (CMKs) and data keys (DKs) — using envelope encryption:
-
Encrypt a data key. KMS uses the CMK to encrypt a DK. The encrypted DK is stored alongside the encrypted data. Without the CMK, the DK cannot be decrypted.
-
Store and read encrypted data. When encrypted data is read, a KMS request is sent to decrypt the DK. After KMS verifies the request, it returns the plaintext DK in memory. The plaintext DK is used during disk I/O and is never written to storage.
The plaintext CMK never leaves the hardware security module managed by KMS. The plaintext DK exists only in hypervisor memory and is never stored on disk.
For more information, see Encryption process.
Data types that can be encrypted
Supported disk types
The following disk types support encryption:
| Disk type | Encryption supported |
|---|---|
| Enterprise SSDs (ESSDs) | Yes |
| ESSD AutoPL disks | Yes |
| ESSD Entry disks | Yes |
| Standard SSDs | Yes |
| Ultra disks | Yes |
| Basic disks | Yes |
| Local disks | No |
Limitations
-
Encryption can only be enabled when creating a disk. You cannot change the encryption state after a disk is created. When you mount or unmount a disk, no encryption-related operations are involved.
-
Converting an unencrypted disk to encrypted, or an encrypted disk to unencrypted, is not supported.
Authorize ECS to access KMS
Before encrypting disks, grant Elastic Compute Service (ECS) access to KMS by creating and configuring the AliyunECSDiskEncryptDefaultRole RAM role.
-
Create the RAM role. For more information, see Create a RAM role for a trusted Alibaba Cloud service. Use the following values:
If the
AliyunECSDiskEncryptDefaultRolerole already exists, skip this step.Field Value Principal Type Cloud Service Principal Name Elastic Compute Service Role Name AliyunECSDiskEncryptDefaultRole -
Grant permissions to the
AliyunECSDiskEncryptDefaultRolerole. For more information, see Grant permissions to a RAM role. Use the following values:ImportantAliyunKMSFullAccessgrants full KMS permissions. For least-privilege access, use a custom policy with the following permissions:Field Value Resource Scope Account Policy AliyunKMSFullAccess(full KMS access) orAliyunECSDiskEncryptCustomizedPolicy(minimum required permissions){ "Version": "1", "Statement": [ { "Effect": "Allow", "Action": [ "kms:DescribeKey", "kms:GenerateDataKey", "kms:Decrypt", "kms:TagResource" ], "Resource": "*" } ] } -
Click Grant permissions.
Encrypt disk volumes
Disk encryption is configured at the StorageClass level. Any persistent volume claim (PVC) that uses an encryption-enabled StorageClass is backed by an encrypted disk.
Prerequisites
Before you begin, make sure that you have:
-
The Container Storage Interface (CSI) plug-in installed in the cluster. In the left-side navigation pane of the cluster management page, choose Operations > Add-ons. On the Storage tab, check that csi-plugin and csi-provisioner are installed. For more information, see Update csi-plugin and csi-provisioner.
If your cluster uses FlexVolume, migrate to the CSI plug-in before proceeding. FlexVolume is no longer supported. See Upgrade from FlexVolume to CSI.
-
The
AliyunECSDiskEncryptDefaultRoleRAM role configured with KMS permissions (see Authorize ECS to access KMS)
Step 1: Create an encrypted StorageClass
-
Create a file named
sc-kms.yamlwith the following content, adjusting parameters as needed:Parameter Description encryptedSet to "true"to encrypt disks created by this StorageClass.kmsKeyIdThe KMS key used to encrypt the disk. If not set, the default CMK is used. Has no effect when encryptedis"false".typeThe disk type. fsTypeThe file system type. apiVersion: storage.k8s.io/v1 kind: StorageClass metadata: name: csi-disk-encrypted provisioner: diskplugin.csi.alibabacloud.com parameters: fsType: ext4 type: cloud_essd encrypted: "true" kmsKeyId: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx reclaimPolicy: DeleteThe following table describes the encryption-related parameters in the
parameterssection: -
Create the StorageClass:
kubectl create -f sc-kms.yaml
Step 2: Create a PVC
-
Create a file named
sc-pvc.yamlwith the following content:apiVersion: v1 kind: PersistentVolumeClaim metadata: name: disk-pvc spec: accessModes: - ReadWriteOnce resources: requests: storage: 20Gi storageClassName: csi-disk-encrypted -
Create the PVC:
kubectl create -f sc-pvc.yaml -
Verify that the PVC is bound:
kubectl get pvcThe output should show the PVC in
Boundstatus. TheVOLUMEcolumn shows the ID of the automatically provisioned disk:NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS VOLUMEATTRIBUTESCLASS AGE disk-pvc Bound d-2ze0nmbv2var0d9h**** 20Gi RWO csi-disk-encrypted <unset> 6m20s
Step 3: Verify disk encryption
-
Log on to the ECS console.
-
In the left-side navigation pane, choose Storage & Snapshots > Block Storage.
Log on to the ECS console.
-
On the Cloud Disk tab, find the disk and click its ID.
-
On the Basic Information tab, confirm that Encrypted appears in the Encrypted/Unencrypted field.
What's next
For more information about disk encryption on Alibaba Cloud, see Encrypt cloud disks.