Skip to content

Agent injector stuck in Init:0/1: “invalid audience (aud) claim”

Securitytested on OpenBao 2.7 mit Agent Injector auf kind

The injector worked (0/2: the sidecar is there), but the init container never finishes. It logs in with the pod's default token, whose audience is the Kubernetes API server – the OpenBao role expects the audience openbao.

Symptom

kubectl apply -f 10-shop-api-naiv.yaml
sleep 20
kubectl -n shop get pod -l app=shop-api
deployment.apps/shop-api created
NAME                        READY   STATUS     RESTARTS   AGE
shop-api-8557c9d4cc-lsz2w   0/2     Init:0/1   0          25s

With only the three mandatory annotations the pod gets stuck in init.

Diagnosis

The init container's logs give the reason.

kubectl -n shop logs deploy/shop-api -c vault-agent-init | grep -A7 ERROR | head -8
2026-10-12T07:26:57.052Z [ERROR] agent.auth.handler: error authenticating:
  error=
  | Error making API request.
  |
  | URL: PUT http://openbao.openbao.svc:8200/v1/auth/kubernetes/login
  | Code: 403. Errors:
  |
  | * invalid audience (aud) claim: audience claim does not match any expected audience

Causes

audThe token's audience does not match the role

The token from kube-api-access-… is issued for the API server, the role shop-api expects openbao.

kubectl -n shop create token shop-api \
  | jq -R 'split(".")[1] | @base64d | fromjson | .aud'
bao read -field=audience auth/kubernetes/role/shop-api
[
  "https://kubernetes.default.svc.cluster.local"
]
openbao

Fix

Provide a dedicated projected token with audience openbao and a short lifetime just for the agent; the annotation points at that volume. The change compared with the first attempt:
>         vault.hashicorp.com/agent-service-account-token-volume-name: "bao-token"
>       volumes:
>         - name: bao-token
>           projected:
>             sources:
>               - serviceAccountToken:
>                   path: token
>                   audience: openbao
>                   expirationSeconds: 600
kubectl apply -f 20-shop-api-token.yaml
kubectl -n shop rollout status deploy/shop-api --timeout=90s
kubectl -n shop exec deploy/shop-api -c app -- cat /vault/secrets/api
deployment "shop-api" successfully rolled out
data: map[api_key:lab-api-key-456 db_password:lab-db-pw-123 db_user:shop]

Don't: Do not remove the audience from the role – then OpenBao accepts any token of the service account, even one issued for a completely different recipient.

▶
Break it yourself and find it – free
OpenBao secrets in Kubernetes and CI/CD, Day 5: agent injector – annotations, audience, templates and env file.
Go to day 5 →

FAQ

What do I check first when a pod hangs in Init:0/1?

The vault-agent-init logs, then role and audience with bao read auth/kubernetes/role/<role>, then the policy.

Does the app container have to mount the token?

No, the injector mounts the volume only into the agent containers; kubelet renews the token itself.

Related error patterns

More