Admin

Azure

Azure AKS Workload Identity & Key Vault CSI Driver for Secure Secrets

Master Azure AKS secret management. Use Workload Identity & Key Vault CSI driver for secure, seamless access to Key Vault secrets in Kubernetes.

By Sujay SinghPublished: July 9, 202612 min read21 views✓ Fact Checked
Azure AKS Workload Identity & Key Vault CSI Driver for Secure Secrets
Azure AKS Workload Identity & Key Vault CSI Driver for Secure Secrets

Navigating the Cloud Security Labyrinth: Azure AKS with Workload Identity and Key Vault CSI Driver

In the dynamic landscape of cloud-native development, managing sensitive information like database connection strings, API keys, and certificates within Kubernetes clusters has always presented a significant security challenge. Traditional methods often involved storing secrets directly in Kubernetes Secrets objects, which, while encrypted at rest within etcd, still required careful handling of access control and lifecycle management. The risk of exposing these secrets through misconfigurations or unauthorized access loomed large, prompting the need for more robust, secure, and auditable solutions.

Enter Azure Kubernetes Service (AKS) combined with Azure AD Workload Identity and the Azure Key Vault Container Storage Interface (CSI) driver. This powerful triumvirate offers a modern, secure, and idiomatic way for Kubernetes workloads to access secrets, keys, and certificates stored in Azure Key Vault without ever exposing them directly to the pod's environment variables or file system in an unencrypted state. It eliminates the need for manual secret rotation, reduces the attack surface, and integrates seamlessly with Azure's identity and access management capabilities.

Azure AD Workload Identity extends the capabilities of Azure AD Pod Identity (which is now deprecated for new deployments) by leveraging Kubernetes service accounts as identities within Azure AD. This allows your pods to authenticate directly with Azure AD and obtain tokens for accessing Azure resources, adhering to the principle of least privilege. When combined with the Key Vault CSI driver, this means a Kubernetes pod, through its associated service account, can authenticate with Azure AD using Workload Identity, obtain a token, and then use that token to access specific secrets in Azure Key Vault. The CSI driver then mounts these secrets as files into the pod's filesystem, making them accessible to the application as if they were local files, without the application needing to know anything about Azure AD authentication or Key Vault APIs.

This article will guide you through the process of setting up AKS with Workload Identity and integrating it with the Key Vault CSI driver to securely access secrets. We will cover the prerequisites, a detailed step-by-step implementation, crucial security considerations, and best practices to ensure your cloud-native applications handle sensitive data with the highest level of integrity and confidentiality.

Prerequisites

Before we embark on our journey, ensure you have the following tools and Azure resources configured:

  • Azure Subscription: An active Azure subscription.
  • Azure CLI: Version 2.40.0 or later installed and configured. You can verify your version with az --version.
  • kubectl: Kubernetes command-line tool installed and configured to interact with your AKS cluster.
  • Helm: Version 3 or later installed. Helm is used to deploy the Key Vault CSI driver and its provider.
  • Permissions: An Azure account with permissions to create resource groups, AKS clusters, managed identities, and Key Vaults, as well as assign roles.

Let's begin by logging into Azure CLI:

az login

Step-by-Step Implementation

1. Create an Azure Resource Group

First, we'll create a dedicated resource group to house all our resources.

RESOURCE_GROUP="aks-wi-kv-rg"
LOCATION="eastus"

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

2. Create an AKS Cluster with Workload Identity Enabled

Next, we provision an AKS cluster and explicitly enable Workload Identity. It's crucial to specify --enable-workload-identity during cluster creation.

AKS_CLUSTER_NAME="techventure-aks-cluster"
NODE_COUNT=3

az aks create \
    --resource-group $RESOURCE_GROUP \
    --name $AKS_CLUSTER_NAME \
    --node-count $NODE_COUNT \
    --enable-managed-identity \
    --enable-workload-identity \
    --generate-ssh-keys \
    --node-vm-size Standard_DS2_v2

# Get AKS credentials
az aks get-credentials --resource-group $RESOURCE_GROUP --name $AKS_CLUSTER_NAME

Verify the cluster is running and kubectl is configured:

kubectl get nodes

3. Create an Azure AD User-Assigned Managed Identity

This managed identity will be used by your Kubernetes workloads to authenticate with Azure Key Vault. It acts as the identity for your application.

MANAGED_IDENTITY_NAME="techventure-app-mi"

az identity create \
    --resource-group $RESOURCE_GROUP \
    --name $MANAGED_IDENTITY_NAME

# Store the principal ID and client ID of the managed identity
MANAGED_IDENTITY_PRINCIPAL_ID=$(az identity show --resource-group $RESOURCE_GROUP --name $MANAGED_IDENTITY_NAME --query principalId -o tsv)
MANAGED_IDENTITY_CLIENT_ID=$(az identity show --resource-group $RESOURCE_GROUP --name $MANAGED_IDENTITY_NAME --query clientId -o tsv)

echo "Managed Identity Principal ID: $MANAGED_IDENTITY_PRINCIPAL_ID"
echo "Managed Identity Client ID: $MANAGED_IDENTITY_CLIENT_ID"

4. Create an Azure Key Vault and Store a Secret

We'll create a Key Vault and populate it with a sample secret that our application will later consume.

KEY_VAULT_NAME="techventuresujaykv$(openssl rand -hex 4)" # Ensure unique name

az keyvault create \
    --name $KEY_VAULT_NAME \
    --resource-group $RESOURCE_GROUP \
    --location $LOCATION \
    --sku Standard \
    --enable-rbac-authorization false # Disable RBAC for simplicity in this example, use AAD Auth for policy.

# Add a sample secret
SECRET_NAME="my-db-password"
SECRET_VALUE="SuperSecureDBPassword123!"

az keyvault secret set \
    --vault-name $KEY_VAULT_NAME \
    --name $SECRET_NAME \
    --value $SECRET_VALUE

5. Grant Managed Identity Access to Key Vault

Now, we grant the user-assigned managed identity permissions to retrieve secrets from the Key Vault. We'll use an access policy here, which is simpler for demonstration. For production, consider using Azure RBAC for Key Vault.

az keyvault set-policy \
    --name $KEY_VAULT_NAME \
    --object-id $MANAGED_IDENTITY_PRINCIPAL_ID \
    --secret-permissions get list

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

6. Install the Key Vault CSI Driver and Azure Key Vault Provider

The CSI driver allows Kubernetes to mount volumes that represent secrets from external secret stores. The Azure Key Vault provider is specifically for Azure Key Vault.

# Add Helm repositories
helm repo add secrets-store-csi-driver https://kubernetes-sigs.github.io/secrets-store-csi-driver/charts
helm repo add csi-secrets-store-provider-azure https://azure.github.io/secrets-store-csi-driver-provider-azure/charts

# Update Helm repositories
helm repo update

# Install the Secrets Store CSI driver
helm install csi-secrets-store-driver secrets-store-csi-driver/secrets-store-csi-driver --namespace kube-system --set syncSecret.enabled=true

# Install the Azure Key Vault Provider for the CSI driver
helm install csi-secrets-store-provider-azure csi-secrets-store-provider-azure/csi-secrets-store-provider-azure --namespace kube-system

Verify the pods are running in the kube-system namespace:

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

7. Associate Managed Identity with Kubernetes Service Account (Workload Identity)

This is the core of Workload Identity. We will create a Kubernetes service account and link it to our Azure AD user-assigned managed identity using a federated credential. This allows the service account to assume the identity of the managed identity in Azure AD.

Get the OIDC Issuer URL for your AKS cluster:

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

Create a Kubernetes Service Account:

We'll define a service account in a new namespace.

NAMESPACE="techventure-app"
SERVICE_ACCOUNT_NAME="techventure-sa"

kubectl create namespace $NAMESPACE

cat <

The annotation azure.workload.identity/client-id links this Kubernetes service account to our Azure AD managed identity.

Create a Federated Credential:

This step establishes the trust relationship between your AKS cluster's OIDC issuer and the Azure AD managed identity.

FEDERATED_CREDENTIAL_NAME="techventure-fed-cred"

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:$NAMESPACE:$SERVICE_ACCOUNT_NAME"

This command tells Azure AD that tokens issued by your AKS cluster's OIDC issuer, specifically for the subject system:serviceaccount:techventure-app:techventure-sa, should be trusted when authenticating as the techventure-app-mi managed identity.

8. Create a SecretProviderClass

The SecretProviderClass custom resource defines which secrets from Key Vault should be made available and how. It acts as a bridge between the CSI driver and your Key Vault.

cat <

Notice usePodIdentity: "false" and userAssignedIdentityID: "$MANAGED_IDENTITY_CLIENT_ID". These parameters instruct the CSI driver to use the specified user-assigned managed identity via Workload Identity for authentication. The secretObjects section is optional but extremely useful if you also want to create a native Kubernetes secret from the mounted content, allowing applications to consume it via environment variables or existing Kubernetes secret mechanisms.

9. Deploy a Sample Application to Consume Secrets

Finally, we deploy a simple Nginx application that mounts the secrets from Key Vault via the CSI volume. The application will use the service account we created, which is linked to our managed identity.

cat <

This deployment creates an Nginx pod. The crucial part is the serviceAccountName which points to our Workload Identity-enabled service account, and the volumes section which uses the CSI driver and references our SecretProviderClass.

10. Verify Secret Access

Let's confirm that the secret has been successfully mounted into the Nginx pod.

# Wait for the pod to be running
kubectl get pods -n $NAMESPACE -w

# Get the pod name
POD_NAME=$(kubectl get pods -n $NAMESPACE -l app=nginx -o jsonpath='{.items[0].metadata.name}')

echo "Pod name: $POD_NAME"

# List files in the mounted directory
kubectl exec -it $POD_NAME -n $NAMESPACE -- ls /mnt/secrets-store/

# Display the content of the secret file
kubectl exec -it $POD_NAME -n $NAMESPACE -- cat /mnt/secrets-store/$SECRET_NAME

You should see the output SuperSecureDBPassword123!, confirming that your application successfully accessed the secret from Azure Key Vault via Workload Identity and the CSI driver. If you also configured secretObjects, you can verify the Kubernetes secret:

kubectl get secret my-app-secret-k8s -n $NAMESPACE -o yaml

You'll see the base64 encoded secret, which applications can consume as traditional Kubernetes secrets.

Security Considerations

While Workload Identity and Key Vault CSI driver significantly enhance security, it's vital to be aware of potential pitfalls and implement best practices:

  • Least Privilege: Always adhere to the principle of least privilege. Grant your managed identities only the necessary permissions (e.g., secrets get, keys decrypt) on the specific Key Vaults and secrets they need to access. Avoid granting broad permissions.
  • Key Vault Access Policies vs. RBAC: For production environments, prefer Azure RBAC for Key Vault over access policies. Azure RBAC offers finer-grained control and is consistent with other Azure resource access models.
  • SecretProviderClass Scope: Control who can create and modify SecretProviderClass objects in your cluster. Misconfigured SecretProviderClass could potentially expose secrets.
  • Pod Security Standards: Implement Pod Security Standards (PSS) or OPA/Gatekeeper policies to restrict what pods can do. For instance, restrict capabilities, ensure read-only root filesystems, and prevent privileged containers.
  • Network Security: Ensure your AKS cluster's network is properly secured. Use Azure Network Security Groups (NSGs) and Azure Firewall to restrict inbound and outbound traffic to and from your cluster and Key Vault. Consider Private Endpoints for Key Vault to ensure traffic remains within the Azure backbone network.
  • Auditing and Logging: Enable comprehensive auditing and logging for both AKS and Azure Key Vault. Monitor access attempts to secrets and identify any unusual patterns. Azure Monitor and Azure Sentinel can be invaluable here.
  • Secret Rotation: While the CSI driver fetches the latest secret version, ensure your application is designed to gracefully handle secret rotation (e.g., by re-reading the mounted file periodically or restarting).

Best Practices

  • Dedicated Managed Identities: Create separate user-assigned managed identities for different applications or components within an application. This isolates permissions and reduces the blast radius in case of compromise.
  • Namespace Isolation: Deploy applications into dedicated Kubernetes namespaces. This improves organization and allows for better isolation of resources and policies, including SecretProviderClass objects and service accounts.
  • Automate Deployment: Use Infrastructure-as-Code (IaC) tools like Bicep, ARM templates, or Terraform to define and deploy your AKS cluster, Key Vault, managed identities, and Kubernetes configurations. This ensures consistency, repeatability, and version control.
  • Regular Updates: Keep your AKS cluster, Kubernetes components, and Helm charts (especially for the CSI driver and provider) up to date. This ensures you benefit from the latest security patches and features.
  • Environment Variables vs. Mounted Files: While secretObjects can create Kubernetes secrets for environment variables, directly consuming secrets as mounted files (as demonstrated) is generally more secure. Environment variables are susceptible to being leaked through logs or process introspection.
  • GitOps Workflows: Implement GitOps principles where your desired state (including Kubernetes manifests for deployments, service accounts, and SecretProviderClasses) is stored in Git and automatically reconciled by tools like Flux CD or Argo CD.

FAQ

Q1: What is the main advantage of Workload Identity over Azure AD Pod Identity?

Workload Identity is the recommended successor to Azure AD Pod Identity for new deployments. Its primary advantage lies in its native integration with Kubernetes service accounts and the OpenID Connect (OIDC) standard. This eliminates the need for an NMI (Node Managed Identity) component that intercepted traffic, simplifying the architecture, improving performance, and enhancing security by directly leveraging Kubernetes-native concepts for identity federation. It also addresses some of the scaling and security challenges faced by Pod Identity.

Q2: Can I use Workload Identity to access other Azure services beyond Key Vault?

Absolutely. Workload Identity is a general mechanism for Kubernetes pods to authenticate with Azure AD using their service accounts. Once authenticated, the pod can obtain an access token and use it to interact with any Azure service that supports Azure AD authentication, provided the associated managed identity has the necessary permissions. This includes Azure Storage, Azure SQL Database, Azure Cosmos DB, and many more.

Q3: How does the Key Vault CSI driver handle secret rotation?

The Key Vault CSI driver, by default, will periodically re-synchronize the secrets from Azure Key Vault. When a new version of a secret is available in Key Vault, the CSI driver will update the mounted file in the pod's filesystem. The frequency of this synchronization can be configured in the SecretProviderClass. Applications should be designed to detect changes in the mounted files (e.g., by monitoring file system events or periodically re-reading the file) and react accordingly to use the new secret version without requiring a pod restart.

Conclusion

The combination of Azure AKS, Workload Identity, and the Key Vault CSI driver represents a significant leap forward in secure secret management for cloud-native applications. By abstracting away the complexities of identity management and secure secret retrieval, developers can focus on building robust applications, confident that their sensitive data is handled with best-in-class security practices. This architecture not only enhances security posture but also streamlines operations, reduces manual overhead, and provides a clear, auditable trail of secret access.

Adopting this pattern moves organizations closer to a "zero-trust" security model, where every workload's identity is verified, and access to resources is granted on a least-privilege basis. As cloud-native adoption continues to accelerate, solutions like these become indispensable for maintaining security, compliance, and operational efficiency in complex Kubernetes environments. Embrace these powerful Azure capabilities to fortify your applications against an ever-evolving threat landscape.

📧

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: July 9, 2026

Fact-checked by TechNews Venture editorial team

Leave a Comment

Comments are moderated and will appear after review.