How to Add KMS to an Azure Kubernetes Service cluster

Makendran G
5 min readMay 25, 2022

--

Azure Kubernetes Service now helps Key Management System (KMS) plugin integration which permits encryption at the rest of our Kubernetes data in etcd using Azure Key Vault. We can now store secrets in carry your own key (BYOK) encrypted etcd using KMS.

KMS Plugin for Key Vault is the advocated preference for the usage of a third-party tool for key management. KMS plugin simplifies key rotation, with a new data encryption key (DEK) generated for each encryption, and key encryption key (KEK) rotation controlled by way of the user.

Features

  • Use a key in Key Vault.
  • Bring your own keys.
  • Provide encryption at rest for secrets stored in etcd.

Prerequisites

Install the aks-preview Azure CLI

We also want the aks-preview Azure CLI extension version 0.5.58 or later. Install the aks-preview Azure CLI extension by using the az extension add command or install any available updates by using the az extension update command.

Register the AzureKeyVaultKmsPreview preview feature

To use the feature, we must also enable the AzureKeyVaultKmsPreview feature flag on our subscription.

Register the AzureKeyVaultKmsPreview feature flag by using the az feature register command, as shown in the following example:

It takes a few minutes for the status to show Registered. Verify the registration status by using the az feature list command:

When ready, refresh the registration of the Microsoft.ContainerService resource provider by using the az provider register command:

Limitations

The following obstacles observe when we integrate KMS etcd encryption with AKS:

  • The KMS etcd encryption feature is disabled.
  • Changing of key ID, inclusive of key name and key version.
  • The Key Vault or the associated identity can be deleted.
  • System-Assigned Managed Identity doesn’t work with KMS etcd encryption. Before the feature is enabled, the keyvault access-policy needs to be set. System-Assigned Managed Identity isn’t available until cluster creation.
  • PrivateLink is enabled when using the azure key vault.
  • There are more than 2000 secrets in the cluster.
  • There is managed support for hsm.
  • You can bring your own key vault from another tenant.

Create a KeyVault and key

Use az keyvault create to create a KeyVault.

Use az keyvault key create to create a key.

Use az keyvault key show to export the Key ID.

The above example stores the Key ID in KEY_ID.

Create a user-assigned managed identity

Use az identity create to create a User-assigned managed identity.

Use az identity showto get Identity Object ID.

The above example stores the value of the Identity Object ID in IDENTITY_OBJECT_ID.

Use az identity show to get Identity Resource ID.

The above example stores the value of the Identity Resource ID in IDENTITY_RESOURCE_ID.

Assign permissions (decrypt and encrypt) to access key vault

Use az keyvault set-policy to create an Azure KeyVault policy.

Create an AKS cluster with KMS etcd encryption enabled

Create an AKS cluster using the az aks create command with the --enable-azure-keyvault-kms and --azure-keyvault-kms-key-id parameters to enable KMS etcd encryption.

Update an exiting AKS cluster to enable KMS etcd encryption

Use az aks update with the --enable-azure-keyvault-kms and --azure-keyvault-kms-key-id parameters to enable KMS etcd encryption on an existing cluster.

Use beneath command to update all secrets. Otherwise, the old secrets aren’t encrypted.

For greater records on the use of the KMS plugin, see Encrypting Secret Data at Rest.

Note

This feature is in a preview. On a self-service basis, preview features are available in AKS. Previews are not included in the service-level agreements and limited warranty. On a best-effort basis, AKS previews are partially covered by customer support. These features are not meant for production use.

Thanks for reading my article till the end. I hope you learned something extraordinary today. If you loved this article, please share it with your friends and if you have pointers or thoughts to share with me, please write in the comment box.

Originally published at https://dev.to on May 25, 2022.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Makendran G
Makendran G

No responses yet

Write a response