Workload identity
SPIRE
1.Why SPIRE ?
Pods talk to each other, but how does Pod A prove it is Pod A ? IPs change, so an IP is a bad identity.
- Static secrets (API keys, long-lived certs) get leaked, copied and never rotated
- Service Account tokens prove identity only to the k8s API, not across clusters or clouds
- SPIRE checks facts (node, namespace, SA, image) then issues a short-lived SVID
- Result : zero-trust mTLS with no secret to store
SPIFFE = the standard. SPIRE = the software. CNCF Graduated (TOC vote 2022-08-23, announced 2022-09-20).
2.Components
The hardened chart's recommended layout puts the server in spire-server and the agents in spire-system. One server, one agent per node.
- Node attestor proves the node (options in 3.)
- Workload attestor inspects the caller (k8s via kubelet, unix via uid/gid)
- SVID = X.509 cert (mTLS) or JWT (bearer calls)
- Trust domain = the security boundary, its trust bundle holds the CA certs
- SPIRE ServerSigning authority. Holds entries, issues SVIDs. Usually a StatefulSet.
- SPIRE AgentDaemonSet. Attests to the server, then attests local workloads.
- Workload APIUnix socket where a workload asks "who am I ?".
- controller-managerTurns CRDs into registration entries.
- SPIFFE CSI driverMounts the agent socket into Pods.
3.Attestation and SVID Flow
Two steps : the agent proves the node, then identifies the process.
| Node attestor | Proves with | Catch |
|---|---|---|
| k8s_psat | Projected SA token | Default on k8s |
| aws_iid | EC2 identity doc | AWS only |
| gcp_iit | GCE identity token | GCP only |
| azure_msi | Managed identity | Azure only |
| join_token | One-time token | Manual, tests |
| x509pop | Existing node cert | Needs your PKI |
one per agent, the server must run the same plugin
1.Registration Entries
Entry = SPIFFE ID + parent ID + selectors. The parent ID points at the agent allowed to hand it out.
ID looks like spiffe://
| Kind (cluster scope) | Use |
|---|---|
| ClusterSPIFFEID | Which pods get which ID |
| ClusterFederatedTrustDomain | Federate with another trust domain |
| ClusterStaticEntry | Hand-written entry for non-pod things |
all spire.
2.k8s Automation
spire-controller-manager is a reconcile loop, like a Deployment controller, but the output is SPIRE entries.
kind: ClusterSPIFFEID
metadata: {name: web}
spec:
className: spire-mgmt-spire
spiffeIDTemplate: "spiffe://{{ .TrustDomain }}\
/ns/{{ .PodMeta.Namespace }}\
/sa/{{ .PodSpec.ServiceAccountName }}"
podSelector:
matchLabels: {app: web}
namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: defaultapiVersion: spire.spiffe.io/v1alpha1 . Pods labelled app: web in default get an ID built from their Namespace and ServiceAccount. className names the chart's controller manager (release namespace, then release): without it, the CR is ignored. A workload fetches it over the Workload API socket, no credentials needed.
web in default getsspiffe://<trust-domain>/ns/default/sa/web 1.Install and Inspect
Two Helm charts from the hardened repo, CRDs first, then server + agent + controller manager, both released into spire-mgmt.
| Command | Description |
|---|---|
helm upgrade --install --create-namespace -n spire-mgmt spire-crds spire-crds --repo https:// | Install the CRDs first (release namespace: spire-mgmt) |
helm upgrade --install -n spire-mgmt spire spire --repo https:// | Server, agent, controller manager. The values set the trust domain, the cluster name and global. |
kubectl get pods -n spire-server | Server and controller manager (agents and CSI driver: -n spire-system) |
kubectl exec -n spire-server spire-server-0 -c spire-server -- spire-server entry show | List registration entries |
spire-server entry create -spiffeID <id> -parentID <id> -selector <sel> | Create an entry by hand, e.g. -selector k8s:ns:default |
spire-server entry delete -entryID <id> | Delete an entry |
kubectl get clusterspiffeid | List ClusterSPIFFEID objects |
kubectl logs -n spire-system -l | Agent logs when attestation fails |
2.No SVID ? Debug Order
= the bug
3.Gotchas
- Install the CRDs before the main chart (separate spire-crds chart)
- Server needs persistent storage (SQLite by default) or entries and CA state are lost, prod usually wants external SQL
- Charts are beta and the controller API is v1alpha1, use released versions not git main
- Recheck versions before quoting (latest seen : v1.15.5, chart spire 0.30.4)
- A typo in a selector like
k8s:nsmeans silently no SVID - Parent ID must match the agent that really runs the workload
- SVIDs are short-lived, apps must reload certs via the Workload API or a library
- Not a secret store, that is Vault or External Secrets
entry show, and when no SVID shows up, look at selectors, parent IDs and the agent logs.