Bemærk
Adgang til denne side kræver godkendelse. Du kan prøve at logge på eller ændre mapper.
Adgang til denne side kræver godkendelse. Du kan prøve at ændre mapper.
This article shows you how to enable Key Management Service (KMS) data encryption for Kubernetes secrets in Azure Kubernetes Service (AKS). KMS encryption encrypts Kubernetes secrets stored in etcd by using Azure Key Vault keys.
AKS supports two key management options:
- Platform-managed keys (PMK): AKS automatically creates and manages the encryption keys. This option provides the simplest setup with automatic key rotation.
- Customer-managed keys (CMK): You create and manage your own Azure Key Vault and encryption keys. This option provides full control over the key lifecycle and meets compliance requirements that mandate customer-managed keys.
For more information about encryption concepts and key options, see Data encryption at rest concepts for AKS.
Prerequisites
Use the Bash environment in Azure Cloud Shell. For more information, see Get started with Azure Cloud Shell.
If you prefer to run CLI reference commands locally, install the Azure CLI. If you're running on Windows or macOS, consider running Azure CLI in a Docker container. For more information, see How to run the Azure CLI in a Docker container.
If you're using a local installation, sign in to the Azure CLI by using the az login command. To finish the authentication process, follow the steps displayed in your terminal. For other sign-in options, see Authenticate to Azure using Azure CLI.
When you're prompted, install the Azure CLI extension on first use. For more information about extensions, see Use and manage extensions with the Azure CLI.
Run az version to find the version and dependent libraries that are installed. To upgrade to the latest version, run az upgrade.
- This article requires version 2.92.0 or later of the Azure CLI. Earlier versions reject versionless key IDs. If you're using Azure Cloud Shell, the latest version is already installed there.
kubectlCLI tool installed.
Supported versions and deployment methods
KMS data encryption is available for clusters that run Kubernetes 1.33 or later through the AKS REST API version 2026-07-01 or later. New clusters that run Kubernetes 1.37 or later always use KMS data encryption. After you enable KMS data encryption on a cluster, you can't switch back to the legacy KMS experience. No feature flag registration is required.
Note
KMS data encryption isn't yet available in sovereign clouds, such as Azure Government and Microsoft Azure operated by 21Vianet.
| Deployment method | Support |
|---|---|
| Azure CLI | Supported in version 2.92.0 or later. Use the commands in this article. |
| ARM templates, Bicep, or the Terraform AzAPI provider | Supported with API version 2026-07-01 or later. |
| Terraform AzureRM provider | Not yet supported. Use the AzAPI provider with API version 2026-07-01 or later. |
The following Bicep example shows the security profile settings for KMS data encryption with customer-managed keys in a private key vault. For platform-managed keys, omit the azureKeyVaultKms block. For a public key vault, set keyVaultNetworkAccess to Public. The keyVaultResourceId property is required for both public and private key vaults.
resource aksCluster 'Microsoft.ContainerService/managedClusters@2026-07-01' = {
name: clusterName
location: location
identity: {
type: 'UserAssigned'
userAssignedIdentities: {
'${identityResourceId}': {}
}
}
properties: {
// Include the other required cluster properties, such as dnsPrefix and agentPoolProfiles.
securityProfile: {
kubernetesResourceObjectEncryptionProfile: {
infrastructureEncryption: 'Enabled'
}
azureKeyVaultKms: {
enabled: true
keyId: 'https://<key-vault-name>.vault.azure.net/keys/<key-name>'
keyVaultNetworkAccess: 'Private'
keyVaultResourceId: keyVaultResourceId
}
}
}
}
Note
Some Azure Policy definitions and compliance tools might not yet recognize KMS data encryption that you enable through this implementation. Until these tools are updated, a correctly configured cluster might appear as noncompliant. To confirm the configuration, use the steps in the Verify KMS configuration section for your key type.
Key ID requirements for customer-managed keys
KMS data encryption with customer-managed keys requires a versionless Azure Key Vault key ID:
- Use a versionless key ID: Use
https://<key-vault-name>.vault.azure.net/keys/<key-name>instead ofhttps://<key-vault-name>.vault.azure.net/keys/<key-name>/<key-version>. Customer-managed keys always require a versionless key ID. - AKS uses the latest key version: Because the key ID doesn't include a version, AKS uses the latest version of the key in Azure Key Vault. When you rotate the key, AKS detects and starts using the new version automatically. For more information, see Key rotation.
- Don't delete the key version: Remove only the version segment from the key ID in your configuration. Don't delete the key version from Key Vault.
Platform-managed keys don't require you to supply a key ID.
Set up environment variables
Set up environment variables for your deployment. Replace the placeholder values with your own.
# Set environment variables
export SUBSCRIPTION_ID="<your-subscription-id>"
export RESOURCE_GROUP="<your-resource-group>"
export LOCATION="<your-location>"
export CLUSTER_NAME="<your-cluster-name>"
# Set subscription
az account set --subscription $SUBSCRIPTION_ID
# Create resource group if it doesn't exist
az group create --name $RESOURCE_GROUP --location $LOCATION
Enable platform-managed key encryption
When you use platform-managed keys, AKS automatically creates and manages the Azure Key Vault and encryption keys. The platform automatically handles key rotation.
Create a new AKS cluster with platform-managed keys
Create a new AKS cluster with KMS encryption by using platform-managed keys.
az aks create \
--name $CLUSTER_NAME \
--resource-group $RESOURCE_GROUP \
--kubernetes-version 1.33.0 \
--kms-infrastructure-encryption Enabled \
--generate-ssh-keys
Enable platform-managed keys on an existing cluster
Enable KMS encryption with platform-managed keys on an existing AKS cluster.
Note
The cluster must be running Kubernetes version 1.33 or later.
If the az aks update command returns a ReconcileAzureKeyVaultKmsError error, run the following command to check if you can read and write existing secrets:
kubectl get secrets --all-namespaces -o json | kubectl replace -f -
If this command fails (for example, webhook rejection or resource not found), fix the issue and re-run the update command. A "The object has been modified" message requires no action — treat it as success.
az aks update \
--name $CLUSTER_NAME \
--resource-group $RESOURCE_GROUP \
--kms-infrastructure-encryption Enabled
Verify KMS configuration
After you enable KMS encryption, verify the configuration.
az aks show --name $CLUSTER_NAME --resource-group $RESOURCE_GROUP --query 'securityProfile'
The output includes the KMS configuration:
{
"kubernetesResourceObjectEncryptionProfile": {
"infrastructureEncryption": "Enabled"
}
}
Enable customer-managed key encryption with a private key vault
For enhanced security, use a private key vault that has public network access disabled. AKS accesses the private key vault through the trusted services firewall exception. This section shows how to configure customer-managed keys with a private key vault.
Create a key vault and key with trusted services access
Note
This section shows how to create a key vault with public network access initially, and then how to enable the firewall with trusted services bypass. This approach is for illustrative purposes only. In production environments, create and manage your key vault as private from the start. For guidance on managing private key vaults, see Azure Key Vault network security.
Create a key vault with Azure RBAC enabled.
export KEY_VAULT_NAME="<your-key-vault-name>" az keyvault create \ --name $KEY_VAULT_NAME \ --resource-group $RESOURCE_GROUP \ --enable-rbac-authorization true \ --public-network-access Enabled # Get the key vault resource ID export KEY_VAULT_RESOURCE_ID=$(az keyvault show --name $KEY_VAULT_NAME --resource-group $RESOURCE_GROUP --query id -o tsv)Assign yourself the Key Vault Crypto Officer role to create a key.
az role assignment create \ --role "Key Vault Crypto Officer" \ --assignee-object-id $(az ad signed-in-user show --query id -o tsv) \ --assignee-principal-type "User" \ --scope $KEY_VAULT_RESOURCE_IDCreate a key in the key vault. Ensure
encryptanddecryptkey operations are enabled.export KEY_NAME="<your-key-name>" az keyvault key create --name $KEY_NAME --vault-name $KEY_VAULT_NAME # Get the key ID (without version for automatic rotation) export KEY_ID=$(az keyvault key show --name $KEY_NAME --vault-name $KEY_VAULT_NAME --query 'key.kid' -o tsv) export KEY_ID_NO_VERSION=$(echo $KEY_ID | sed 's|/[^/]*$||')Enable the key vault firewall with trusted services bypass.
az keyvault update \ --name $KEY_VAULT_NAME \ --resource-group $RESOURCE_GROUP \ --default-action Deny \ --bypass AzureServicesThe
--default-action Denyparameter blocks public network access, and the--bypass AzureServicesparameter allows trusted Azure services (including AKS) to access the key vault.
Create a user-assigned managed identity
Create a user-assigned managed identity for the cluster.
export IDENTITY_NAME="<your-identity-name>" az identity create --name $IDENTITY_NAME --resource-group $RESOURCE_GROUP # Get the identity details export IDENTITY_OBJECT_ID=$(az identity show --name $IDENTITY_NAME --resource-group $RESOURCE_GROUP --query 'principalId' -o tsv) export IDENTITY_RESOURCE_ID=$(az identity show --name $IDENTITY_NAME --resource-group $RESOURCE_GROUP --query 'id' -o tsv)Assign the required roles to the managed identity.
# Assign Key Vault Crypto User role for encrypt/decrypt operations az role assignment create \ --role "Key Vault Crypto User" \ --assignee-object-id $IDENTITY_OBJECT_ID \ --assignee-principal-type "ServicePrincipal" \ --scope $KEY_VAULT_RESOURCE_ID # Assign Key Vault Contributor role for key management az role assignment create \ --role "Key Vault Contributor" \ --assignee-object-id $IDENTITY_OBJECT_ID \ --assignee-principal-type "ServicePrincipal" \ --scope $KEY_VAULT_RESOURCE_ID
Create a new AKS cluster with customer-managed keys (private)
Create a new AKS cluster with KMS encryption using customer-managed keys with a private key vault.
az aks create \
--name $CLUSTER_NAME \
--resource-group $RESOURCE_GROUP \
--kubernetes-version 1.33.0 \
--kms-infrastructure-encryption Enabled \
--enable-azure-keyvault-kms \
--azure-keyvault-kms-key-id $KEY_ID_NO_VERSION \
--azure-keyvault-kms-key-vault-resource-id $KEY_VAULT_RESOURCE_ID \
--azure-keyvault-kms-key-vault-network-access Private \
--assign-identity $IDENTITY_RESOURCE_ID \
--generate-ssh-keys
Enable customer-managed keys on an existing cluster (private)
Enable KMS encryption with customer-managed keys using a private key vault on an existing AKS cluster.
Note
The cluster must be running Kubernetes version 1.33 or later.
If the az aks update command returns a ReconcileAzureKeyVaultKmsError error, run the following command to check if you can read and write existing secrets:
kubectl get secrets --all-namespaces -o json | kubectl replace -f -
If this command fails (for example, webhook rejection or resource not found), fix the issue and re-run the update command. A "The object has been modified" message requires no action — treat it as success.
az aks update \
--name $CLUSTER_NAME \
--resource-group $RESOURCE_GROUP \
--kms-infrastructure-encryption Enabled \
--enable-azure-keyvault-kms \
--azure-keyvault-kms-key-id $KEY_ID_NO_VERSION \
--azure-keyvault-kms-key-vault-resource-id $KEY_VAULT_RESOURCE_ID \
--azure-keyvault-kms-key-vault-network-access Private \
--assign-identity $IDENTITY_RESOURCE_ID
Verify KMS configuration
After you enable KMS encryption, verify the configuration.
az aks show --name $CLUSTER_NAME --resource-group $RESOURCE_GROUP --query 'securityProfile'
The output includes the KMS configuration:
{
"azureKeyVaultKms": {
"enabled": true,
"keyId": "https://<key-vault-name>.vault.azure.net/keys/<key-name>",
"keyVaultNetworkAccess": "Private",
"keyVaultResourceId": "<key-vault-resource-id>"
},
"kubernetesResourceObjectEncryptionProfile": {
"infrastructureEncryption": "Enabled"
}
}
Enable customer-managed key encryption with a public key vault
By using customer-managed keys, you create and manage your own Azure Key Vault and encryption keys. This section shows how to configure customer-managed keys with a public key vault.
Create a key vault and key
Create a key vault with Azure RBAC enabled.
export KEY_VAULT_NAME="<your-key-vault-name>" az keyvault create \ --name $KEY_VAULT_NAME \ --resource-group $RESOURCE_GROUP \ --enable-rbac-authorization true \ --public-network-access Enabled # Get the key vault resource ID export KEY_VAULT_RESOURCE_ID=$(az keyvault show --name $KEY_VAULT_NAME --resource-group $RESOURCE_GROUP --query id -o tsv)Assign yourself the Key Vault Crypto Officer role to create a key.
az role assignment create \ --role "Key Vault Crypto Officer" \ --assignee-object-id $(az ad signed-in-user show --query id -o tsv) \ --assignee-principal-type "User" \ --scope $KEY_VAULT_RESOURCE_IDCreate a key in the key vault. Ensure
encryptanddecryptkey operations are enabled.export KEY_NAME="<your-key-name>" az keyvault key create --name $KEY_NAME --vault-name $KEY_VAULT_NAME # Get the key ID (without version for automatic rotation) export KEY_ID=$(az keyvault key show --name $KEY_NAME --vault-name $KEY_VAULT_NAME --query 'key.kid' -o tsv) export KEY_ID_NO_VERSION=$(echo $KEY_ID | sed 's|/[^/]*$||')
Create a user-assigned managed identity
Create a user-assigned managed identity for the cluster.
export IDENTITY_NAME="<your-identity-name>" az identity create --name $IDENTITY_NAME --resource-group $RESOURCE_GROUP # Get the identity details export IDENTITY_OBJECT_ID=$(az identity show --name $IDENTITY_NAME --resource-group $RESOURCE_GROUP --query 'principalId' -o tsv) export IDENTITY_RESOURCE_ID=$(az identity show --name $IDENTITY_NAME --resource-group $RESOURCE_GROUP --query 'id' -o tsv)Assign the required roles to the managed identity.
# Assign Key Vault Crypto User role for encrypt/decrypt operations az role assignment create \ --role "Key Vault Crypto User" \ --assignee-object-id $IDENTITY_OBJECT_ID \ --assignee-principal-type "ServicePrincipal" \ --scope $KEY_VAULT_RESOURCE_ID # Assign Key Vault Contributor role for key management az role assignment create \ --role "Key Vault Contributor" \ --assignee-object-id $IDENTITY_OBJECT_ID \ --assignee-principal-type "ServicePrincipal" \ --scope $KEY_VAULT_RESOURCE_ID
Create a new AKS cluster with customer-managed keys
Create a new AKS cluster with KMS encryption using customer-managed keys.
az aks create \
--name $CLUSTER_NAME \
--resource-group $RESOURCE_GROUP \
--kubernetes-version 1.33.0 \
--kms-infrastructure-encryption Enabled \
--enable-azure-keyvault-kms \
--azure-keyvault-kms-key-id $KEY_ID_NO_VERSION \
--azure-keyvault-kms-key-vault-resource-id $KEY_VAULT_RESOURCE_ID \
--azure-keyvault-kms-key-vault-network-access Public \
--assign-identity $IDENTITY_RESOURCE_ID \
--generate-ssh-keys
Enable customer-managed keys on an existing cluster
Enable KMS encryption with customer-managed keys on an existing AKS cluster.
Note
The cluster must be running Kubernetes version 1.33 or later.
If the az aks update command returns a ReconcileAzureKeyVaultKmsError error, run the following command to check whether existing secrets can be read and written:
kubectl get secrets --all-namespaces -o json | kubectl replace -f -
If this command fails (for example, webhook rejection or resource not found), fix the issue and re-run the update command. A "The object has been modified" message requires no action — treat it as success.
az aks update \
--name $CLUSTER_NAME \
--resource-group $RESOURCE_GROUP \
--kms-infrastructure-encryption Enabled \
--enable-azure-keyvault-kms \
--azure-keyvault-kms-key-id $KEY_ID_NO_VERSION \
--azure-keyvault-kms-key-vault-resource-id $KEY_VAULT_RESOURCE_ID \
--azure-keyvault-kms-key-vault-network-access Public \
--assign-identity $IDENTITY_RESOURCE_ID
Verify KMS configuration
After you enable KMS encryption, verify the configuration.
az aks show --name $CLUSTER_NAME --resource-group $RESOURCE_GROUP --query 'securityProfile'
The output includes the KMS configuration:
{
"azureKeyVaultKms": {
"enabled": true,
"keyId": "https://<key-vault-name>.vault.azure.net/keys/<key-name>",
"keyVaultNetworkAccess": "Public",
"keyVaultResourceId": "<key-vault-resource-id>"
},
"kubernetesResourceObjectEncryptionProfile": {
"infrastructureEncryption": "Enabled"
}
}
Migrate between key management options
You can migrate between platform-managed keys and customer-managed keys.
Migrate from platform-managed keys to customer-managed keys
To migrate from platform-managed keys to customer-managed keys, first set up the key vault, key, and managed identity as described in the customer-managed keys section, and then run the update command:
az aks update \
--name $CLUSTER_NAME \
--resource-group $RESOURCE_GROUP \
--kms-infrastructure-encryption Enabled \
--enable-azure-keyvault-kms \
--azure-keyvault-kms-key-id $KEY_ID_NO_VERSION \
--azure-keyvault-kms-key-vault-resource-id $KEY_VAULT_RESOURCE_ID \
--azure-keyvault-kms-key-vault-network-access Public \
--assign-identity $IDENTITY_RESOURCE_ID
Migrate from customer-managed keys to platform-managed keys
To migrate from customer-managed keys to platform-managed keys:
az aks update \
--name $CLUSTER_NAME \
--resource-group $RESOURCE_GROUP \
--kms-infrastructure-encryption Enabled \
--disable-azure-keyvault-kms
Key rotation
With KMS data encryption, key rotation works differently depending on your key management option:
- Platform-managed keys: Key rotation happens automatically. You don't need to take any action.
- Customer-managed keys: You set up a versionless key ID, so AKS always uses the latest version of the key. After you rotate the key in Azure Key Vault, KMS periodically detects the new key version. Wait at least seven days between creating the new key version and deleting the old one.
Note
Unlike the legacy KMS experience, with this new implementation you don't need to manually re-encrypt secrets after key rotation. The platform handles this automatically.
Don't delete or expire the old key version right after you create the new one.