Azure authentication methods for chaos faults
This guide describes the supported methods for authenticating Azure chaos faults to the Azure Resource Manager API. Choose the method that best fits your security requirements and infrastructure setup.
Overview
Azure chaos faults support the following authentication methods, listed in order of priority:
When no service principal authentication is configured, the fault uses Azure's DefaultAzureCredential, which automatically tries workload identity and managed identity in order.
Service principal
This method uses an Azure service principal with client secret authentication stored as a JSON file in Harness Secret Manager.
Prerequisites
Create a service principal:
az ad sp create-for-rbac --name "harness-chaos-sp"Note the appId, password, and tenant from the output.
Assign the required role to the service principal:
az role assignment create \
--assignee <APP_ID> \
--role "<ROLE_NAME>" \
--scope /subscriptions/<SUBSCRIPTION_ID>Refer to fault permissions for the minimum permissions required per fault.
Steps
Create a JSON file with the service principal credentials. You can either:
Option A: Generate the file automatically (legacy SDK format):
Option B: Manually create the JSON file with the following structure:
Upload the JSON file as a secret file in Harness Secret Manager:
Navigate to your Harness project's secrets section
Create a new File Secret
Upload the JSON file (e.g.,
azure.auth)Note the secret identifier for reference in your chaos experiment
How it works
The fault reads the JSON file at the path specified by AZURE_AUTH_LOCATION, extracts clientId, clientSecret, and tenantId, and authenticates using ClientSecretCredential. The subscriptionId is also read from the same file.
Workload identity (recommended)
Workload identity is the recommended method for AKS-hosted chaos experiments. It uses federated tokens instead of secrets, providing pod-level identity isolation without storing credentials.
Prerequisites
An AKS cluster with OIDC issuer and workload identity add-on enabled.
An Azure AD app registration with a federated identity credential.
A Kubernetes ServiceAccount annotated for workload identity.
Step 1: Enable OIDC issuer on the AKS cluster
For a new cluster:
For an existing cluster:
Retrieve the OIDC issuer URL (needed in Step 3):
Step 2: Create an Azure AD app registration
Create the app registration and service principal:
Assign the required role:
Step 3: Create the federated identity credential
This links the Kubernetes ServiceAccount to the Azure AD app registration:
Replace:
<OIDC_ISSUER_URL>with the URL from Step 1.<NAMESPACE>with the Kubernetes namespace where chaos experiments run (for example,hce).<SERVICE_ACCOUNT_NAME>with the ServiceAccount name the chaos pod uses (for example,litmus).
Step 4: Configure the Kubernetes ServiceAccount
Add the required annotations and labels to the chaos infrastructure configuration:
Add the annotation
azure.workload.identity/client-id: "<APP_ID>"Add the label
azure.workload.identity/use: "true"
These will be applied to the chaos experiment pods by the chaos infrastructure.
Step 5: Set the subscription ID
Set the AZURE_SUBSCRIPTION_ID environment variable to the target subscription ID in your chaos experiment configuration.
Once the pod is created with the configured annotations and labels, the AKS workload identity webhook automatically injects the following into the pod:
AZURE_CLIENT_IDAZURE_TENANT_IDAZURE_FEDERATED_TOKEN_FILEA projected service account token volume.
How it works
When AZURE_AUTH_LOCATION is not set, the fault uses DefaultAzureCredential. The credential chain detects the injected AZURE_CLIENT_ID, AZURE_TENANT_ID, and AZURE_FEDERATED_TOKEN_FILE environment variables and authenticates using WorkloadIdentityCredential. The projected service account token is exchanged for an Azure AD access token through federated identity, with no secrets involved.
Validation
Deploy a test pod with the configured ServiceAccount and verify the injected environment variables:
Expected output:
Managed identity
Managed identity uses Azure-platform-managed credentials attached to the underlying infrastructure (VM, VMSS, or AKS node pool). No secrets or federated credentials are needed, but the identity is scoped to the node rather than the individual pod.
System-assigned managed identity
Uses the identity automatically assigned to the AKS node pool VMSS.
Steps
Get the kubelet identity object ID:
Assign the required role:
Configure the chaos experiment:
Set
AZURE_SUBSCRIPTION_IDto the target subscription ID in your experiment configuration.Do not set
AZURE_AUTH_LOCATION.Do not set
AZURE_CLIENT_ID,AZURE_CLIENT_SECRET, orAZURE_TENANT_ID.
User-assigned managed identity
Uses a specific managed identity that you create and attach to the node pool VMSS.
Steps
Create the managed identity:
Note the clientId and principalId from the output.
Assign the required role:
Attach the identity to the AKS node pool VMSS:
Configure the chaos experiment:
Set
AZURE_SUBSCRIPTION_IDto the target subscription ID in your experiment configuration.(Optional) Set
AZURE_CLIENT_IDto the managed identity's client ID - only required if you have multiple user-assigned identities attached to the node and need to specify which one to use.Do not set
AZURE_AUTH_LOCATION,AZURE_CLIENT_SECRET, orAZURE_FEDERATED_TOKEN_FILE.
How it works
When AZURE_AUTH_LOCATION is not set and no workload identity environment variables are present, DefaultAzureCredential falls through to ManagedIdentityCredential. It contacts the Azure Instance Metadata Service (IMDS) on the node to obtain an access token.
System-assigned identity: Automatically uses the system-assigned identity without any additional configuration.
User-assigned identity: If
AZURE_CLIENT_IDis provided, it selects that specific identity. If not provided and only one user-assigned identity exists on the node, it automatically uses that identity.
Managed identity operates at the node level. Any pod running on the same node can potentially use the same identity. For production environments requiring pod-level isolation, use workload identity instead.
Credential resolution order
The following diagram shows the order in which the fault resolves credentials:
Last updated
Was this helpful?