# Azure Workload Identity

Configure Azure Workload Identity for Spice.ai on AKS.

Azure Workload Identity allows Spice.ai pods on Azure Kubernetes Service (AKS) to authenticate with Azure services (Blob Storage, Key Vault, etc.) using federated credentials.

## Configuration

Annotate the Spice `ServiceAccount` with the Azure managed identity client ID, and label the Spice pods with `azure.workload.identity/use: "true"`. The AKS workload identity webhook injects the `AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, and `AZURE_FEDERATED_TOKEN_FILE` environment variables only into pods that carry this label.

### Helm Chart

`additionalLabels` applies to the Spice pods as well as the other chart resources:

```yaml
serviceAccount:
  create: true
  annotations:
    azure.workload.identity/client-id: <AZURE_CLIENT_ID>
additionalLabels:
  azure.workload.identity/use: "true"
```

### SpicepodSet (Kubernetes Operator)

`spec.labels` applies to every resource the operator creates for the `SpicepodSet`, the pods included:

```yaml
apiVersion: spice.ai/v2
kind: SpicepodSet
metadata:
  name: my-spicepod
spec:
  replicas: 1
  labels:
    azure.workload.identity/use: "true"
  serviceAccount:
    enabled: true
    create: true
    annotations:
      azure.workload.identity/client-id: <AZURE_CLIENT_ID>
  spicepod:
    name: my-spicepod
    kind: Spicepod
    version: v1
```

## Azure Key Vault

The [Azure Key Vault secret store](https://spiceai.org/docs/components/secret-stores/azure-keyvault) does not select workload identity by default. Set `auth_method: workload_identity`:

```yaml
secrets:
  - from: azure_keyvault:my-vault
    name: azure
    params:
      auth_method: workload_identity
```

When `client_id` and `tenant_id` are not set, the secret store reads them from the `AZURE_CLIENT_ID` and `AZURE_TENANT_ID` variables that the webhook injects.

## Prerequisites

1. Enable the Azure Workload Identity add-on on your AKS cluster.
2. Create a managed identity and federated credential.
3. Assign the necessary roles to the managed identity for the Azure resources your Spicepod accesses.

See [Azure Workload Identity documentation](https://learn.microsoft.com/en-us/azure/aks/workload-identity-overview) for full setup instructions.
