After you enable the disk encryption feature, the system automatically encrypts data transmitted to a disk and decrypts the data when it is read. Disk encryption is suitable for scenarios that require high security or have compliance requirements. You can protect the privacy and autonomy of your data without the need to create and maintain a key management infrastructure. This topic describes how to use the keys that are hosted in Key Management Service (KMS) to encrypt data stored in disk volumes.
Feature description
How disk volume encryption works
Data types that can be encrypted
Prerequisites
The Container Storage Interface (CSI) plug-in is installed in the cluster.
NoteIn the left-side navigation pane of the cluster management page, choose Update csi-plugin and csi-provisioner.
. On the Storage tab, you can check whether csi-plugin and csi-provisioner are installed. For more information about how to update CSI plug-ins to use specific capabilities, seeIf your cluster uses FlexVolume, you must migrate the cluster to the CSI plug-in because FlexVolume is no longer available. For more information, see Upgrade from FlexVolume to CSI.
Usage notes
You can encrypt Enterprise SSDs (ESSDs), ESSD AutoPL disks, ESSD Entry disks, standard SSDs, ultra disks, and basic disks.
You cannot encrypt local disks.
You cannot directly convert unencrypted disks into encrypted disks or directly convert encrypted disks into unencrypted disks.
Authorize ECS to access KMS
When you use KMS to encrypt disks, you must first authorize ECS to access KMS.
Create a Resource Access Management (RAM) user that is used to access KMS. For more information, see Create a RAM role for a trusted Alibaba Cloud service.
NoteIf the AliyunECSDiskEncryptDefaultRole role already exists, you can skip this step.
Take note of the following parameters:
Set Principal Type to Cloud Service.
Set Principal Name to Elastic Compute Service.
Set Role Name to AliyunECSDiskEncryptDefaultRole.
Grant permissions to the AliyunECSDiskEncryptDefaultRole role. For more information, see Grant permissions to a RAM role.
Take note of the following parameters:
Set to Resource Scope to Account.
Select the AliyunKMSFullAccess system policy or the AliyunECSDiskEncryptCustomizedPolicy custom policy in the Policy section.
ImportantThe AliyunKMSFullAccess system policy provides full permissions. If you require finer-grained access control, refer to Create custom policies.
Encrypt disk volumes
You can enable disk encryption only when you create a disk. When you mount or unmount a disk, no encryption-related operations are involved.
Create a StorageClass that enables disk encryption.
Modify the following YAML template based on your business requirements and copy the modified template to a file named sc-kms.yaml:
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: Delete
Take note of the following parameters in the
parameters
section:encrypted
: specifies whether to enable disk encryption for disks created by using the StorageClass. If you want to use the StorageClass to create encrypted disks, set the value totrue
.kmsKeyId
: specifies the KMS key that is used to encrypt the disks created by using the StorageClass. If you do not set this parameter, the default CMK is used. If you setencrypted
tofalse
, this parameter does not take effect.
Create a StorageClass.
kubectl create -f sc-kms.yaml
Create a persistent volume claim (PVC).
Create a file named sc-pvc.yaml and copy the following content to the file:
apiVersion: v1 kind: PersistentVolumeClaim metadata: name: disk-pvc spec: accessModes: - ReadWriteOnce resources: requests: storage: 20Gi storageClassName: csi-disk-encrypted
Create a PVC.
kubectl create -f sc-pvc.yaml
Check the PVC.
kubectl get pvc
The following output shows that the PVC is created and bound to a persistent volume (PV) that is automatically created by the system. You can view the disk ID in the
VOLUME
column.NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS VOLUMEATTRIBUTESCLASS AGE disk-pvc Bound d-2ze0nmbv2var0d9h**** 20Gi RWO csi-disk-encrypted <unset> 6m20s
Check whether the disk is encrypted.
Log on to the ECS console.
In the left-side navigation pane, choose .
On the Cloud Disk tab, find the disk that is created and click its ID.
On the Basic Information tab of the disk details page, check whether Encrypted is displayed in the Encrypted/Unencrypted field.
References
For more information about disk encryption, see Encrypt cloud disks.