Delivering Secrets to Kubernetes Workloads with Workload Identity and CSI
As soon as you start declaring deployments with GitOps, the same question appears. Where do the database password and the OAuth client secret live? The fastest answer is a Kubernetes Secret manifest committed to the repository, and at that moment the lifetime of the secret value becomes the lifetime of Git history.
If Splitting Platform and Application Delivery Across Two Argo CD Instances drew the reconciliation boundary, this article covers the credentials that cross it. The short version: secret delivery is not one problem but four separable claims, and putting values in a manifest hands all four to Git and cluster administrators at once.
Secret delivery is four separate claims
Section titled āSecret delivery is four separate claimsāFor a workload to read database-password from a vault, four different things must be true.
- Ownership: who creates and rotates the value. When IaC creates it rather than a person, the value never passes through anyoneās terminal.
- Workload identity: how a running Pod proves what it is, without a static credential.
- Authorization: which vault entries that identity may read. This axis is distinct from cluster administration rights.
- Injection: what shape the value takes inside the process, and when it is refreshed.
kubectl create secret collapses all four. The owner becomes whoever ran the command, the workloadās identity is replaced by namespace access, authorization shrinks to Kubernetes RBAC alone, and injection becomes a base64 string in etcd. Separating these four axes at Runtime is the whole subject of this article.
IaC creates the vault and the secret entry together
Section titled āIaC creates the vault and the secret entry togetherāThe first axis, ownership, is settled in Terraform. The vault itself, a randomly generated password, and the database that consumes it are created in one apply.
resource "random_password" "orders_db_admin" { length = 32 special = true}
resource "azurerm_key_vault_secret" "orders_db_admin" { name = "database-password" key_vault_id = module.vault.keyvault_id value = random_password.orders_db_admin.result}
resource "azurerm_mssql_server" "orders" { name = "sql-orders-dev" administrator_login_password = azurerm_key_vault_secret.orders_db_admin.value}What matters here is not random_password but the direction of reference. Because the database resource references the vault entry, the vault becomes the single source of the value. Build it the other way (create the database first and copy the password into the vault afterwards) and you now have two truths that will diverge the first time you rotate.
The vault is created with RBAC authorization mode, soft delete, and network restrictions. Up to this point the secret value exists only inside Terraform state, and not one character of it enters the GitOps repository.
A federated credential names one service account in one namespace
Section titled āA federated credential names one service account in one namespaceāThe second axis, workload identity, is solved by a single federated credential. It trusts the clusterās OIDC issuer, but not any Pod in that cluster; only one service account in one namespace.

resource "azurerm_federated_identity_credential" "orders_app" { name = "cred-k8s-orders-app" resource_group_name = var.resource_group_name parent_id = var.workload_identity_id
issuer = module.kubernetes.aks_cluster_issuer_url subject = "system:serviceaccount:orders:kv-service-account"
audience = ["api://AzureADTokenExchange"]}The subject string is the real security boundary of this design. system:serviceaccount:orders:kv-service-account accepts only a projected token issued to kv-service-account in the orders namespace. Creating a service account with the same name in payments produces a different subject and the token exchange is refused. In other words, the ability to create a namespace does not become the ability to read secrets.
The third axis, authorization, is created by granting that identity only a Key Vault Secrets User level role on the vault. Write permission stays with the separate identity used by the IaC pipeline. If readers and writers share one identity, a single compromised workload makes the entire vault writable.
SecretProviderClass declares references, not values
Section titled āSecretProviderClass declares references, not valuesāThe fourth axis, injection, begins inside the cluster. SecretProviderClass is committed to the GitOps repository, but it contains only secret names and vault coordinates.

apiVersion: secrets-store.csi.x-k8s.io/v1kind: SecretProviderClassmetadata: name: orders-secrets namespace: ordersspec: provider: azure parameters: usePodIdentity: "false" tenantId: <tenant-id> clientID: <workload-identity-client-id> keyvaultName: platform-secrets objects: | array: - | objectName: database-password objectType: secret objectVersion: "" - | objectName: oauth-client-secret objectType: secret objectVersion: "" - | objectName: signing-key objectType: secret objectVersion: ""
# secretObjects: # - secretName: orders-db-secret # type: Opaque # data: # - key: DATABASE_PASSWORD # objectName: database-passwordusePodIdentity: "false" declares that this uses Workload Identity rather than the older Pod Identity mechanism. objectVersion: "" means always read the latest version, and that choice directly affects the rotation behaviour discussed below.
The commented-out secretObjects block deserves attention. Enabling it makes the CSI driver synchronise mounted values into a real Kubernetes Secret object. Left disabled, the values exist only as files and never appear in etcd. This is an explicit trade of convenience against exposure, not an oversight.
The Pod selects its identity through a label and serviceAccountName
Section titled āThe Pod selects its identity through a label and serviceAccountNameāThe Deployment overlay needs three things: a pod label that activates the Workload Identity webhook, a serviceAccountName matching the federated subject, and the CSI volume.
apiVersion: apps/v1kind: Deploymentmetadata: name: orders-apispec: template: metadata: labels: app: orders-api azure.workload.identity/use: "true" spec: serviceAccountName: kv-service-account containers: - name: orders-api image: registry.example.com/orders-api:<immutable-tag> volumeMounts: - name: platform-secrets mountPath: /mnt/secrets-store readOnly: true volumes: - name: platform-secrets csi: driver: secrets-store.csi.k8s.io readOnly: true volumeAttributes: secretProviderClass: orders-secretsThe label is what makes the webhook inject the projected service account token volume and the identity environment variables. The serviceAccountName is what makes that tokenās subject match the federated credential. Omit either and the mount fails with an authentication error, and because it fails at Pod start, it does not fail silently, which is a feature rather than a defect.
The full flow and its trust boundaries
Section titled āThe full flow and its trust boundariesāThe critical property is that no solid line (no actual value) ever crosses the GitOps boundary. GitOps declares only what should be read; what it is exists only at Runtime.
File mount versus a synchronised Kubernetes Secret
Section titled āFile mount versus a synchronised Kubernetes SecretāWhether to enable secretObjects is not a matter of taste but a trade-off.
| Aspect | File mount only | Synchronised into a Kubernetes Secret |
|---|---|---|
| Environment variable compatibility | None. The application must read files | Yes. secretKeyRef wires straight into existing 12-factor apps |
| Where the value is stored | Only in the Podās tmpfs volume | Additionally stored in etcd |
| Exposure scope | That Podās filesystem | Every principal with Secret read rights in the namespace |
| Rotation behaviour | File contents refresh on the driverās rotation interval | The Secret object refreshes too, but environment variables keep the old value until the process restarts |
| Application change required | Read a file, or point config at a path | None |
| Secret object lifetime | None | Persists until the last referencing Pod is gone, and is easily orphaned |
| Blast radius | Small | Grows to namespace scope |
The practical guidance is this. Make file mount the default for new services and let the config loading layer accept a file path. For legacy applications that only support environment variables, use secretObjects synchronisation, but narrow the Secret read RBAC in that namespace separately and document that rotation requires a restart.
Operational failure matrix
Section titled āOperational failure matrixāThis structure has many parts, and each fails with a different symptom. You need to be able to work backwards from symptom to cause.
| Failure cause | Observed symptom | Where to check |
|---|---|---|
| Namespace or service account name mismatch in the federated subject | Pod stuck in ContainerCreating with a token exchange rejection in mount events | Compare the credentialās subject string against the real namespace/SA character by character |
Missing pod label azure.workload.identity/use | No projected token or identity environment variables are injected, so authentication fails | Whether the injected volume and environment variables exist in the Pod spec |
Missing serviceAccountName | The default service account is used and the subject does not match | The Podās effective service account |
| No vault read role on the identity | Authentication succeeds but the mount fails with a permission error | Role assignments on the vault |
| Typo in a SecretProviderClass objectName | One bad object fails the entire mount | The actual list of secret names in the vault |
| Vault network restrictions block the cluster | Mount fails as a timeout | Vault network rules and private endpoint |
| CSI driver addon not installed | The volume plugin cannot be found | Cluster addon status |
| Application still uses the old value after rotation | Appears as an authentication error, not a mount failure | Whether the file is re-read, and the restart policy if environment variables are used |
The last row is the most commonly misread. āThe CSI driver refreshes the fileā and āthe application uses the new valueā are different statements. For an application that reads the file once at startup, rotation is not automatic. A rotation design must explicitly answer what picks up the new value, and the answer is usually either a file watch or a controlled rolling restart.
Development choices versus production hardening
Section titled āDevelopment choices versus production hardeningāThe structure described here was validated on the development cluster aks-platform-dev-01, and it is not automatically a production standard.
| Axis | Development choice | Additionally required in production |
|---|---|---|
| Vault access path | Public endpoint allowed to simplify initial setup | Restricted to a private endpoint and network rules |
| Identity separation | Several namespaces easily share a similar-purpose identity | Separate identity and role per namespace or service |
| Rotation | Manual, only when needed | Scheduled rotation plus automated post-rotation verification |
| Auditing | Default vault logs | Retain vault access logs separately and Alert on anomalous access |
| Secret synchronisation | Tempting to use secretObjects for convenience | File mount by default, exceptions only by documented approval |
Summary
Section titled āSummaryāTreat secret delivery as one problem and the answer is always āstore the value somewhere.ā Split it into ownership, workload identity, authorization, and injection, and each axis can be owned by a different tool. IaC creates the value, a federated credential names exactly one service account in one namespace, a vault role bounds the read scope, and a CSI volume places files only at Runtime.
The result is a GitOps repository that holds references and policy but no values. The next article, GitOps-Deployed Observability Pipelines: From Sampling to Grafana, applies the same declarative boundary to Traces, Metrics, and Logs.