In ACK Pro clusters, keys created in Alibaba Cloud Key Management Service (KMS) encrypt the Kubernetes Secret data at rest.
Prerequisites
Item | Description |
KMS key | Create a KMS key in the Key Management Service console and make sure that the key resides in the same region as the target ACK Pro cluster. ACK Pro clusters support default keys, software-protected keys, and hardware-protected keys. Select a key type based on your business requirements. For more information about KMS key management and related operations, see Key management quickstart. For more information about KMS billing, see Billing. Important After you enable encryption at rest, do not use the KMS console or OpenAPI to disable or delete the key selected for Secret encryption and decryption of the cluster. Otherwise, the API server of the cluster becomes unavailable and objects such as Secrets and ServiceAccounts cannot be retrieved, which affects your workloads. |
Network ACL rules of the cluster | When you enable encryption at rest, the KMS plugin on the control plane must access Alibaba Cloud KMS OpenAPI to encrypt and decrypt Secret instances. Make sure that the outbound rules of the cluster security group allow the CIDR block of Alibaba Cloud services ( |
Authorization | Based on the type of account that you use, confirm that the following authorization operations are complete:
|
How Secret encryption works
In a Kubernetes cluster, the Secret model typically stores and manages the sensitive information required by your workloads, such as application passwords, TLS certificates, and Docker image pull credentials. Kubernetes stores the data of all Secret objects in the cluster's etcd. For more information about Secrets, see Secrets.
KMS encryption is based on the KMS Encryption Provider mechanism of Kubernetes and uses envelope encryption to automatically encrypt and decrypt the Kubernetes Secrets stored in etcd. Kubernetes Secrets are encrypted and decrypted as follows:
When application data must be stored through the Kubernetes Secret API, the API server first encrypts it with a randomly generated data encryption key. The data key is then encrypted with the specified KMS key and stored in etcd as a ciphertext key.
When a Kubernetes Secret is decrypted, the system first calls the KMS decryption OpenAPI operation to decrypt the ciphertext key. The system then uses the decrypted plaintext key to decrypt the Secret data and returns the data to you.
For more information, see the KMS Encryption Provider mechanism and Use envelope encryption.
KMS v2
Starting with Kubernetes 1.31, ACK Pro clusters prioritize the community KMS v2 interface for encryption at rest. KMS v2 supports more Secret instances in a cluster and provides better encryption and decryption performance. For more information about the KMS v2 encryption and decryption process, see KMS v2.
To upgrade the KMS v1 interface used by your cluster to the KMS v2 interface, see How do I upgrade to KMS v2 for Secret encryption at rest?
The Kubernetes community marked KMS v1 as deprecated in version 1.27 and disabled the v1 interface by default starting with version 1.29. To ensure compatibility, ACK Pro clusters still enable the v1 interface by setting the KMS v1 feature gate.
Enable Secret encryption at rest for an ACK Pro cluster
Enable Secret encryption at rest for a new ACK Pro cluster
-
Log on to the ACK console. In the left navigation pane, click Clusters.
On the Clusters page, click Create Kubernetes Cluster.
At the bottom of the ACK Managed Cluster tab, expand Advanced Options (Optional), find Secret Encryption, select the Select Key check box, and then select a KMS key ID from the drop-down list. Configure the other parameters as needed and click Create Kubernetes Cluster.
To configure other parameters when you create an ACK Pro cluster, see ACK managed cluster: Parameters.
Log on to the ActionTrail console and click Cluster Events Query in the left-side navigation pane. If encryption and decryption event logs of the AliyunCSManagedSecurityRole system role appear on the Cluster Events Query page, Secret encryption at rest is enabled for the cluster.
If you no longer need Secret encryption at rest, click the name of the cluster in the cluster list. On the Cluster Information page, click the Basic Information tab. In the Security and Auditing section, turn off the Secret Encryption switch.
Enable Secret encryption at rest for an existing ACK Pro cluster
-
Log on to the ACK console. In the left navigation pane, click Clusters.
On the Clusters page, click the name of the target cluster. On the cluster details page, click the Basic Information tab. In the Security and Auditing section, turn on the Secret Encryption switch.
When you enable Secret encryption at rest for the first time, follow the prompt and click Go to RAM console to go to the Cloud Resource Access Authorization page, and then click Confirm to complete the authorization.
NoteTo enable encryption at rest, make sure that the RAM user or RAM role currently logged on has the administrator or O&M engineer RBAC permissions on the cluster. For more information, see Authorize operations on in-cluster resources with RBAC.
To authorize AliyunCSManagedSecurityRole, make sure that you are logged on with an Alibaba Cloud account or with a RAM user or RAM role that has RAM management permissions.
In the Secret Encryption dialog box that appears, select an existing KMS key and click OK.
If you have not created a KMS key, click Create Key and go to the Key Management Service console to create a key. For more information, see Create a key.
When the cluster status changes from Updating to Running, Secret encryption at rest is enabled for the cluster.
If you no longer need Secret encryption at rest, in the Security and Auditing section, turn off the Secret Encryption switch.
Enable Secret encryption at rest by using an automatically rotated key
Use the automatic key rotation feature of KMS to encrypt Secrets at rest. When a key is automatically rotated, existing Secrets are still encrypted with the key version used before the rotation. New Secrets are encrypted with the new key version generated after the rotation. For more information about how to automatically rotate a key, see Key rotation.
After the key is automatically rotated, forcibly re-encrypt all existing Secrets with the new key version.
kubectl get secrets --all-namespaces -o json | kubectl annotate --overwrite -f - encryption-key-rotation-time="$(date -u +'%Y-%m-%dT%H:%M:%S%z')"FAQ
How do I upgrade to KMS v2 for Secret encryption at rest?
To use KMS v2 for Secret encryption at rest, make sure that your ACK Pro cluster is version 1.31 or later.
If Secret encryption at rest is not enabled for your cluster, see Enable Secret encryption at rest for an ACK Pro cluster to enable encryption for the cluster. After encryption is enabled, Secret instances in the cluster are automatically encrypted and decrypted through the KMS v2 interface when they are written to and read from disks.
If Secret encryption at rest is already enabled for your cluster, rotate the encryption method of the on-disk keys during off-peak hours in either of the following ways:
Method 1: Run the
kubectl get secrets --all-namespaces -o json | kubectl replace -f -command. This command re-encrypts all Secret instances already written to disk by using the KMS v2 interface.Method 2: Log on to the ACK console. On the Cluster Information page, go to the Basic Information tab, find Secret Encryption, and turn it off. Turning off this switch triggers the rotation of all Secret instances written to disk in the cluster. After the cluster status changes from Updating to Running, wait at least 5 minutes, and then see Enable Secret encryption at rest for an ACK Pro cluster to enable encryption for the cluster again. After encryption is enabled, all Secret instances in the cluster are encrypted at rest through the KMS v2 interface.
After Secret encryption at rest is enabled, are the Secrets retrieved by the kubectl command encrypted ciphertext?
No. Secret encryption at rest encrypts the raw data stored in etcd. After Secret encryption at rest is enabled, the Secret data stored in etcd is ciphertext. However, the Secret data that a client retrieves through the Secret API provided by the API server is still the original plaintext data.
How do I prevent a RAM user or RAM role from enabling or disabling Secret encryption at rest in an existing ACK Pro cluster?
Attach the following RAM access policy, which denies the operation, to a RAM user or RAM role. This prevents the RAM user or RAM role from enabling or disabling Secret encryption at rest in an existing ACK Pro cluster. For more information, see Grant cluster and cloud resource access with RAM.
{
"Action": [
"cs:UpdateKMSEncryption"
],
"Effect": "Deny",
"Resource": [
"*"
]
}