This repository demonstrates how to set up and use Azure AD Workload Identity with Azure Kubernetes Service (AKS). The demo showcases a secure way for Kubernetes applications to access Azure resources (like Key Vault) without managing credentials directly in the application code or Kubernetes manifests.
- Azure CLI (latest version)
- kubectl command-line tool
- bash shell environment
- Azure subscription with required permissions
- Docker (if building images locally)
- gettext-base package (for envsubst)
- Clone the repository:
git clone git@github.com:ttruongatl/aks-secops-workload-identity-example.git
cd aks-secops-workload-identity-example
- Run the deployment script:
./scripts/create.sh
The script accepts the following optional parameters:
Usage: ./scripts/create.sh [-n <acr-name>] [-g <resource-group>] [-l <location>] [-s <subscription-id>]
-n : Name of Azure Container Registry (default: aksworkloadidentityexample)
-g : Resource group name (default: aks-secops-workload-identity-example)
-l : Location (default: eastus2)
-s : Subscription ID (default: your-subscription-id)
-h : Show this help message
The script creates:
- A resource group
- An AKS cluster with:
- OIDC issuer enabled
- Workload Identity enabled
- Azure CNI networking
- Azure KeyVault Secrets Provider
- An Azure Container Registry
- A Key Vault with:
- RBAC authorization
- A sample secret
- A Managed Identity with:
- Federated credentials for Kubernetes service account
- Key Vault Secrets User role assignment
- Kubernetes resources:
- Namespace
- Service Account with workload identity
- ConfigMap with Key Vault configuration
- Sample application deployment
The infrastructure is defined using Bicep templates:
azure-templates/main.bicep
: Main template orchestrating the deploymentazure-templates/modules/
:aks.bicep
: AKS cluster configurationkeyvault.bicep
: Key Vault setupnetworking.bicep
: Virtual network configuration
The Kubernetes resources are defined in the deployment/
directory:
namespace.yaml
: Creates the application namespaceserviceaccount.yaml
: Sets up the service account with workload identityconfigmap.yaml
: Configures the applicationdeployment.yaml
: Deploys the sample application
Environment variables are substituted at deployment time using envsubst
.