In Container Service for Kubernetes (ACK) Pro clusters, you can use keys that are created in Key Management Service (KMS) to encrypt Kubernetes Secrets. This topic describes how to use a key that is managed by KMS to encrypt Secrets for an ACK Pro cluster.
Prerequisites
- A customer master key (CMK) is created in the KMS console. For more information, see
Create a CMK.
Note ACK Pro clusters support only CMKs of the Aliyun_AES_256 type.
- After you enable Secret encryption, do not use the KMS API or the KMS console to disable or delete the CMK that is used to encrypt and decrypt Secrets, or create a schedule to delete the CMK. Otherwise, the API server becomes unavailable and cannot retrieve Secrets and service accounts. As a result, service interruptions occur.
- Your Alibaba Cloud account is authorized to assume the AliyunCSManagedSecurityRole role. Otherwise, the system prompts you to perform the authorization when you enable Secret encryption.
- If you log on to the console as a Resource Access Management (RAM) user or RAM role, you must make sure that the RAM user or RAM role has the AliyunKMSCryptoAdminAccess permission. For more information, see Grant permissions to a RAM user or RAM role.
- You are charged by KMS for key management and API calls (on a per 10,000 calls basis). After Secret encryption is enabled for the ACK Pro cluster, kube-apiserver must call the encryption and decryption API operations of KMS to read and write Secrets. By default, a large number of API calls are made to read and write Secrets when you manage the lifecycle of service accounts in the cluster. If the cluster contains a large number of service accounts and Secrets, the cost of KMS API calls is high. Make sure that your account balance is sufficient. If you are not familiar with the pricing rules or your account balance is insufficient, you can disable Secret encryption for the cluster. For more information, see Disable Secret encryption for an existing ACK Pro cluster. If your account has been overdue for more than seven days, you cannot manage the cluster. For more information about KMS billing, see Billing.
Background information
Kubernetes Secrets are used to store and manage sensitive data, such as passwords of applications, Transport Layer Security (TLS) certificates, and credentials to download Docker images. Kubernetes stores Secrets in the etcd of a cluster. For more information, see Secrets.
- When you use a Kubernetes Secret to encrypt and store a password, the API server generates a random data encryption key (DEK) to encrypt the Secret. Then, the API server sends the DEK to KMS. KMS uses the specified key to encrypt the DEK and returns the encrypted DEK to the API server. The API server then stores the encrypted Secret and DEK in etcd.
- When you decrypt the Kubernetes Secret, the system calls the Decrypt operation of KMS to decrypt the data key first. Then, the system uses the plaintext of the data key to decrypt the Kubernetes Secret and returns the decrypted Secret.
For more information, see KMS Encryption Provider mechanism and What is envelope encryption?.
Enable Secret encryption when you create an ACK Pro cluster
Enable Secret encryption for an existing ACK Pro cluster
Disable Secret encryption for an existing ACK Pro cluster
Use automatic key rotation to encrypt Secrets
You can use the automatic key rotation feature provided by KMS to encrypt Secrets. When a key is being automatically rotated, the old key version is used to encrypt the existing Secrets in your cluster. For more information, see Automatic key rotation.
To force the system to use the new key version to encrypt existing Secrets, run the following command after the key is rotated:
kubectl get secrets --all-namespaces -o json kubectl annotate --overwrite -f - encryption-key-rotation-time="TIME"
TIME
with the string that indicates when the key rotation was performed, for example,
20220101-010101.