Admin

Azure

Featured

Azure AKS: Secure Secrets with Workload Identity & Key Vault CSI Driver

Implement Azure AKS Workload Identity with Key Vault CSI driver. Securely access secrets in Kubernetes pods without manual credential management.

By Sujay SinghPublished: September 9, 202612 min read71 views✓ Fact Checked
Azure AKS: Secure Secrets with Workload Identity & Key Vault CSI Driver [dwze]
Azure AKS: Secure Secrets with Workload Identity & Key Vault CSI Driver [dwze]

Overview: Securing AKS Workloads with Azure Workload Identity and Key Vault CSI Driver

In the modern cloud-native landscape, securing sensitive information within containerized applications running on Kubernetes is paramount. Azure Kubernetes Service (AKS) provides a robust platform, but developers and operations teams constantly seek more secure, efficient, and identity-driven ways to manage secrets, certificates, and keys. Traditional methods often involved storing secrets directly in Kubernetes Secrets, which, while encrypted at rest, still presented challenges regarding lifecycle management, rotation, and distribution. This is where Azure Workload Identity and the Key Vault CSI (Container Storage Interface) driver revolutionize secret management for AKS workloads. Azure Workload Identity is a modern approach that allows Kubernetes pods to authenticate with Azure AD using a Kubernetes Service Account. This eliminates the need for client secrets, certificates, or even the legacy AAD Pod Identity, significantly enhancing security posture and simplifying credential management. By leveraging OIDC (OpenID Connect), Workload Identity maps a Kubernetes Service Account to an Azure AD user-assigned managed identity, granting the pod fine-grained access to Azure resources without ever exposing credentials. The Azure Key Vault CSI driver seamlessly integrates Azure Key Vault with AKS. It enables you to mount secrets, keys, and certificates stored in Key Vault directly into your pods as a volume. When combined with Azure Workload Identity, this pattern offers an incredibly secure and streamlined way for applications to consume sensitive data. The pod authenticates to Azure Key Vault using its associated Workload Identity, retrieves the specified secrets, and the CSI driver then presents them as files within the pod's filesystem. This means your application simply reads from a file path, completely decoupled from the underlying secret storage mechanism or the complexities of authentication to Key Vault. This article will guide you through the process of setting up AKS with Workload Identity and integrating the Key Vault CSI driver to securely retrieve secrets. We'll cover everything from cluster creation and identity configuration to deploying a sample application that consumes secrets from Azure Key Vault, ensuring your applications operate with the highest level of security and operational efficiency.

Prerequisites

Before diving into the implementation, ensure you have the following tools and Azure resources configured:
  • An active Azure subscription.
  • Azure CLI installed and configured. Ensure you're logged in with `az login`.
  • `kubectl` installed and configured to connect to your AKS cluster.
  • Helm installed (version 3+).
  • Sufficient permissions within your Azure subscription to create resource groups, AKS clusters, Key Vaults, and Managed Identities, and assign roles.

Step-by-step Implementation

Let's walk through the detailed steps to set up AKS with Workload Identity and integrate the Key Vault CSI driver.

1. Create an Azure Resource Group

First, we'll create a dedicated resource group for our AKS cluster and related resources.


RESOURCE_GROUP="tech-news-aks-rg"
LOCATION="eastus"

az group create --name $RESOURCE_GROUP --location $LOCATION

2. Create an Azure Kubernetes Service (AKS) Cluster with Workload Identity Enabled

When creating the AKS cluster, we need to explicitly enable the OIDC Issuer and Workload Identity features. This will configure the cluster with the necessary OIDC endpoint for federated identity.


AKS_CLUSTER_NAME="tech-news-aks-cluster"
NODE_COUNT=3 # Adjust as needed

az aks create \
    --resource-group $RESOURCE_GROUP \
    --name $AKS_CLUSTER_NAME \
    --node-count $NODE_COUNT \
    --enable-oidc-issuer \
    --enable-workload-identity \
    --generate-ssh-keys \
    --kubernetes-version 1.27.7 # Specify your desired Kubernetes version

This command creates an AKS cluster with Workload Identity enabled. The `enable-oidc-issuer` flag provisions an OIDC endpoint for your cluster, which is essential for Workload Identity. The `enable-workload-identity` flag ensures the necessary components are installed and configured.

3. Get AKS Cluster Credentials

Once the cluster is created, configure `kubectl` to connect to it.


az aks get-credentials --resource-group $RESOURCE_GROUP --name $AKS_CLUSTER_NAME

4. Retrieve the OIDC Issuer URL for Your AKS Cluster

The OIDC issuer URL is crucial for configuring the federated credential later. This URL uniquely identifies your AKS cluster's OIDC endpoint.


AKS_OIDC_ISSUER="$(az aks show --name $AKS_CLUSTER_NAME --resource-group $RESOURCE_GROUP --query "oidcIssuerProfile.issuerUrl" -o tsv)"
echo "AKS OIDC Issuer URL: $AKS_OIDC_ISSUER"

You should see an output similar to `https://eastus.oidc.prod.azure.com/REDACTED-GUID/`. This URL will be used to establish trust between Azure AD and your Kubernetes Service Account.

5. Create an Azure Key Vault

Now, let's create an Azure Key Vault to store our secrets.


KEY_VAULT_NAME="tech-news-aks-kv-$(head /dev/urandom | tr -dc a-z0-9 | head -c 8)" # Unique name
az keyvault create \
    --name $KEY_VAULT_NAME \
    --resource-group $RESOURCE_GROUP \
    --location $LOCATION \
    --enable-rbac-authorization false # Using access policies for simplicity in this demo, but RBAC is recommended for production

We've disabled RBAC authorization for the Key Vault for simpler demonstration purposes using access policies. For production environments, Azure Key Vault RBAC is generally preferred for its fine-grained control.

6. Create Secrets in Key Vault

Add some sample secrets to your Key Vault that your application will consume.


az keyvault secret set --vault-name $KEY_VAULT_NAME --name "demosecret1" --value "SuperSecretValue123!"
az keyvault secret set --vault-name $KEY_VAULT_NAME --name "dbPassword" --value "MyStrongDBPassword#2024"

7. Create an Azure AD User-Assigned Managed Identity

This managed identity will be used by your AKS pod (via Workload Identity) to authenticate to Azure Key Vault.


MANAGED_IDENTITY_NAME="tech-news-aks-mi"
az identity create --resource-group $RESOURCE_GROUP --name $MANAGED_IDENTITY_NAME --location $LOCATION

MANAGED_IDENTITY_CLIENT_ID=$(az identity show --resource-group $RESOURCE_GROUP --name $MANAGED_IDENTITY_NAME --query clientId -o tsv)
MANAGED_IDENTITY_RESOURCE_ID=$(az identity show --resource-group $RESOURCE_GROUP --name $MANAGED_IDENTITY_NAME --query id -o tsv)

echo "Managed Identity Client ID: $MANAGED_IDENTITY_CLIENT_ID"
echo "Managed Identity Resource ID: $MANAGED_IDENTITY_RESOURCE_ID"

8. Grant Permissions to the Managed Identity on Key Vault

The managed identity needs permissions to retrieve secrets from the Key Vault. We'll use Key Vault access policies here, but for RBAC-enabled Key Vaults, you'd assign roles like "Key Vault Secrets User".


az keyvault set-policy \
    --name $KEY_VAULT_NAME \
    --secret-permissions get list \
    --object-id $MANAGED_IDENTITY_CLIENT_ID # Use the Client ID for access policies

This command grants the managed identity `get` and `list` permissions for secrets within the specified Key Vault.

9. Create a Kubernetes Service Account

In your AKS cluster, create a Kubernetes Service Account that will be associated with the Azure Managed Identity.


cat <

The crucial part here is the `azure.workload.identity/client-id` annotation, which links this Kubernetes Service Account to our Azure Managed Identity's Client ID.

10. Create a Federated Identity Credential

This step establishes the trust relationship between your Azure Managed Identity and the Kubernetes Service Account. It tells Azure AD that the specified Kubernetes Service Account, when presenting tokens from your AKS cluster's OIDC issuer, is allowed to impersonate this Managed Identity.


FEDERATED_CREDENTIAL_NAME="tech-news-federated-cred"
SERVICE_ACCOUNT_NAMESPACE="default"
SERVICE_ACCOUNT_NAME="tech-news-sa"

az identity federated-credential create \
    --name $FEDERATED_CREDENTIAL_NAME \
    --identity-name $MANAGED_IDENTITY_NAME \
    --resource-group $RESOURCE_GROUP \
    --issuer "$AKS_OIDC_ISSUER" \
    --subject "system:serviceaccount:$SERVICE_ACCOUNT_NAMESPACE:$SERVICE_ACCOUNT_NAME"

The `--subject` parameter specifies the exact identity that will be allowed to authenticate. It's a combination of the namespace and name of your Kubernetes Service Account.

11. Install/Verify Azure Key Vault CSI Driver

The Key Vault CSI driver is often enabled by default in newer AKS clusters. You can verify its status or enable it if necessary.

Check if it's installed:


az aks show -g $RESOURCE_GROUP -n $AKS_CLUSTER_NAME --query "addonProfiles.azureKeyvaultSecretsProvider.enabled"

If the output is `false`, enable it:


az aks enable-addons --addons azure-keyvault-secrets-provider --name $AKS_CLUSTER_NAME --resource-group $RESOURCE_GROUP

After enabling, verify the CSI driver pods are running:


kubectl get pods -n kube-system -l app=csi-secrets-store-provider-azure
kubectl get pods -n kube-system -l app=csi-secrets-store

12. Create a SecretProviderClass

The `SecretProviderClass` Kubernetes custom resource defines which secrets from Key Vault should be retrieved and how they should be mounted. This is where you specify the Key Vault details and the secrets you want.


TENANT_ID=$(az account show --query tenantId -o tsv) # Your Azure Tenant ID

cat <

Notice `usePodIdentity: "false"` and `useVMManagedIdentity: "false"`. These are crucial to ensure the CSI driver uses Workload Identity for authentication. The `clientID` parameter specifies which managed identity the CSI driver should use for authenticating to Key Vault. The `objects` array lists the specific secrets to retrieve.

13. Deploy a Sample Application

Finally, deploy a sample Nginx application that mounts the secrets defined in the `SecretProviderClass`.


cat <

Key elements in this deployment manifest:

  • `serviceAccountName: tech-news-sa`: Links the pod to the Kubernetes Service Account configured with Workload Identity.
  • `azure.workload.identity/use: "true"`: This annotation instructs the Workload Identity webhook to inject the necessary environment variables and projected service account token into the pod for Workload Identity to function.
  • `volumeMounts` and `volumes`: These define how the secrets-store CSI driver mounts the secrets into the `/mnt/secrets-store` path within the Nginx container, referencing the `azure-keyvault-tech-news` SecretProviderClass.

14. Verify Secret Mounting

After the pod is running, executive into it and verify the secrets are mounted as files.


kubectl get pods -l app=nginx-secrets

# Wait for the pod to be running, then exec into it
POD_NAME=$(kubectl get pods -l app=nginx-secrets -o jsonpath='{.items[0].metadata.name}')
kubectl exec -it $POD_NAME -- ls /mnt/secrets-store/

You should see `demosecret1` and `dbPassword` listed as files. You can then view their content:


kubectl exec -it $POD_NAME -- cat /mnt/secrets-store/demosecret1
kubectl exec -it $POD_NAME -- cat /mnt/secrets-store/dbPassword

The output should be the secret values you set in Azure Key Vault. This confirms that your application successfully retrieved secrets from Key Vault via the CSI driver, authenticated using Azure Workload Identity.

Security Considerations

Implementing this pattern significantly improves security, but certain considerations remain vital:
  • Least Privilege: Always adhere to the principle of least privilege. Grant the Managed Identity only the necessary permissions (e.g., `get`, `list` on secrets) to the specific Key Vault. Avoid granting broader permissions like `all`.
  • Key Vault RBAC vs. Access Policies: While access policies were used in this demo for simplicity, Azure Key Vault RBAC offers more granular control and is generally recommended for production environments. It allows assigning specific data plane roles to Azure AD identities.
  • Network Security: Implement network restrictions on your Key Vault using private endpoints or virtual network service endpoints. This ensures that only authorized networks (like your AKS VNet) can access the Key Vault, adding another layer of security.
  • Kubernetes RBAC: Ensure that only authorized users or CI/CD pipelines can create or modify `ServiceAccount` and `SecretProviderClass` resources, as these control access to your secrets.
  • Auditing and Logging: Enable comprehensive auditing and logging for Azure Key Vault and AKS. Monitor access attempts, secret retrievals, and any configuration changes to detect suspicious activity.
  • Secret Rotation: While the CSI driver fetches secrets on pod startup and periodically refreshes them, implementing automated secret rotation within Key Vault itself is crucial for long-term security. The CSI driver will automatically pick up rotated secrets during its refresh interval.
  • Workload Identity Webhook: Be aware that the Workload Identity webhook modifies your pod's manifest. Ensure its integrity and monitor its behavior.

Best Practices

To maximize the benefits and security of this setup, consider the following best practices:
  • One Managed Identity per Workload/Service Account: Create a unique user-assigned managed identity for each application or microservice. This ensures strict isolation and allows for granular permission management. If one workload is compromised, it doesn't automatically grant access to secrets meant for others.
  • Environment-Specific Key Vaults: Use separate Key Vaults for different environments (e.g., Dev, Staging, Production). This prevents accidental exposure of production secrets and allows for different access policies per environment.
  • CI/CD Integration: Integrate the creation and configuration of Managed Identities, Federated Credentials, and Key Vault permissions into your CI/CD pipelines. Automate the deployment of `SecretProviderClass` and application manifests.
  • Monitor Refresh Intervals: Understand the refresh interval of the Key Vault CSI driver (default is 2 minutes). If a secret is rotated in Key Vault, it might take a few minutes for the updated value to appear in the mounted volume within the pod. For highly sensitive, rapidly changing secrets, consider direct API calls via Azure SDKs (also using Workload Identity) if real-time updates are critical, though this adds complexity.
  • Avoid Hardcoding IDs: Use environment variables or Azure CLI queries to dynamically retrieve resource IDs (e.g., Key Vault name, Managed Identity Client ID, Tenant ID) in your deployment scripts, rather than hardcoding them into YAML files. This improves portability and reduces errors.
  • Regular Security Audits: Periodically review your Key Vault access policies/RBAC assignments and Workload Identity configurations to ensure they align with your security posture and compliance requirements.

FAQ

1. What is the difference between Workload Identity and AAD Pod Identity (legacy)?

AAD Pod Identity (legacy) used Node Managed Identity and a component called MIC (Managed Identity Controller) to intercept token requests and assign identities to pods. While it worked, it had several limitations, including performance overhead, scalability issues (especially with MIC), and a security concern where a compromised node could potentially impersonate other identities.

Azure Workload Identity is a more secure and performant solution. It leverages OIDC and projected service account tokens to allow pods to authenticate directly with Azure AD. There's no intermediary MIC component, making it more robust and scalable. It aligns with the upstream Kubernetes standard for federated identity, offering a more native and future-proof approach.

2. Can I use Workload Identity with multiple Key Vaults?

Yes, absolutely. You can create multiple `SecretProviderClass` resources, each configured to retrieve secrets from a different Azure Key Vault. Each `SecretProviderClass` would specify the `keyvaultName` and the `clientID` of the managed identity that has access to that specific Key Vault. Your application pods can then mount multiple volumes, each corresponding to a different `SecretProviderClass`, effectively accessing secrets from various Key Vaults simultaneously.

3. How does secret rotation work with Key Vault CSI driver?

When a secret in Azure Key Vault is rotated (i.e., a new version is created), the Key Vault CSI driver will automatically detect and update the mounted secret files within the pod. The driver periodically polls Key Vault for updates to the secrets specified in the `SecretProviderClass`. By default, this refresh interval is 2 minutes. Once a new version is detected, the CSI driver updates the corresponding file in the mounted volume. Your application, if designed to re-read the secret file periodically or on change, will then pick up the new value.

Conclusion

Securing sensitive application data is a non-negotiable requirement for modern cloud-native applications. By adopting Azure Workload Identity in conjunction with the Key Vault CSI driver, you empower your AKS workloads with a highly secure, identity-driven, and operationally efficient mechanism for managing secrets. This pattern eliminates the need to handle credentials within your application code or Kubernetes manifests, reduces the attack surface, and simplifies compliance. The transition from legacy methods to this robust solution marks a significant step forward in cloud security best practices. By following the detailed steps outlined in this article, you can confidently deploy applications on AKS that securely access Azure Key Vault, ensuring your sensitive data remains protected while maintaining developer agility and operational excellence. Embrace this powerful combination to elevate the security posture of your Azure Kubernetes Service deployments.
📧

Enjoyed this article?

Get articles like this delivered to your inbox daily. Join 10,000+ tech professionals.

Written By

Sujay Singh

Technology Expert / Cloud Architect at Virtual Venture covering AI, cloud computing, cybersecurity, and emerging tech trends.

Sources & References

• Official company announcements and press releases

• Industry reports from Gartner, IDC, and Statista

• Peer-reviewed research and technical documentation

• On-record statements from industry experts

Last verified: September 9, 2026

Fact-checked by TechNews Venture editorial team

Leave a Comment

Comments are moderated and will appear after review.