Skip to main content
Zero-Trust Service-to-Service Auth with SPIFFE and SPIRE

Zero-Trust Service-to-Service Auth with SPIFFE and SPIRE

KU
· Founder & Chief Editor
• 7 min read•Updated •55 views

Static service tokens leaked into logs and never rotated. SPIFFE identities plus SPIRE-issued SVIDs gave us short-lived certs and killed the shared-secret sprawl.

Key takeaways

  • SPIFFE gives every workload a URI identity, and SPIRE proves it with short-lived X.509 certificates called SVIDs, issued only after node and workload attestation.
  • Services authenticate each other with mTLS instead of shared tokens.
  • SPIRE's default SVID lifetime is one hour, and the agent rotates certificates at half-life without restarts.

Replace shared service tokens with SPIFFE identities: SPIRE attests each node and pod, then issues it a short-lived X.509 certificate (an SVID, one hour by default) that services use for mutual TLS. No workload holds a long-lived secret, the agent rotates certs automatically, and the peer's SPIFFE ID becomes the authorization check.

Verified against

SPIRE 1.15.5 (released 2026-10-20), go-spiffe v2.9.0, SPIRE Controller Manager, against the spiffe.io SPIRE concepts, server and agent configuration docs. Checked October 2026.

The pattern that pushes teams here is depressingly common. A debug log line prints request headers, a bearer token for the payments service lands in plaintext in a log index, and it turns out the token has never been rotated, because rotating it means coordinating a redeploy across every service that has it baked into a Kubernetes Secret. Shared secrets fail like this because they are long-lived by design.

The idea behind SPIFFE is simple even if the implementation has sharp edges: every workload gets a cryptographic identity, that identity is proven with a short-lived certificate, and no service ever holds a shared secret again. Certs live for an hour, not a year.

What SPIFFE actually gives you

A SPIFFE ID is just a URI, for example spiffe://prod.internal/ns/payments/sa/payments-api. That string names a workload by namespace and service account. SPIFFE is the spec; SPIRE is the runtime that decides which process on which node is allowed to receive the SVID for that ID.

The trust model rests on attestation, in two stages. First the SPIRE agent proves its node's identity to the server, on Kubernetes with the k8s_psat attestor (a projected service account token). Then, when a pod asks the agent for its identity, the agent doesn't take its word for it: it asks the kubelet about the calling process, reads the pod's namespace and service account, and only hands over a cert if a registration entry matches. That chain of checks is the whole point. A compromised pod can't request an identity it wasn't registered for.

Registering workloads without going insane

The part that bites people is registration entries. Each one maps a set of selectors to a SPIFFE ID, and doing it by hand drifts within a week. Here's a manual entry so the mechanics are clear:

Terminal
spire-server entry create \
    -spiffeID spiffe://prod.internal/ns/payments/sa/payments-api \
    -parentID spiffe://prod.internal/spire/agent/k8s_psat/prod-cluster/node-7 \
    -selector k8s:ns:payments \
    -selector k8s:sa:payments-api \
    -x509SVIDTTL 3600

-x509SVIDTTL 3600 asks for one-hour certs, which is also the server's default_x509_svid_ttl. The SPIRE agent docs describe the default rotation strategy as "1/2 of lifetime", so certs renew around the 30-minute mark with no restart and no human. The parentID ties the entry to a node that proved itself via k8s_psat. If you use the join_token attestor in production instead, you've reintroduced a pre-shared key at the root of the trust chain, which is the problem you were trying to kill.

In a real cluster, don't write entries at all. The old Kubernetes Workload Registrar was deprecated in SPIRE 1.5.0 "in favor of SPIRE Controller Manager", which watches pods and reconciles entries from a cluster-scoped ClusterSPIFFEID resource:

spire/clusterspiffeid-payments.yaml
apiVersion: spire.spiffe.io/v1alpha1
kind: ClusterSPIFFEID
metadata:
  name: payments-workloads
spec:
  spiffeIDTemplate: "spiffe://prod.internal/ns/{{ .PodMeta.Namespace }}/sa/{{ .PodSpec.ServiceAccountName }}"
  namespaceSelector:
    matchLabels:
      team: payments

One template covers every service account in every matching namespace, and the controller deletes entries when pods go away. If a guide still tells you to deploy k8s-workload-registrar, it predates SPIRE 1.5 (November 2022).

Consuming the SVID in code

Applications fetch their SVID over the Workload API, a Unix domain socket the agent exposes on each node. You don't parse certs yourself. The go-spiffe v2 library keeps an in-memory copy that updates on rotation:

Go
source, err := workloadapi.NewX509Source(ctx,
    workloadapi.WithClientOptions(
        workloadapi.WithAddr("unix:///run/spire/sockets/agent.sock")))
if err != nil {
    log.Fatalf("spiffe source: %v", err)
}
tlsConfig := tlsconfig.MTLSClientConfig(source, source,
    tlsconfig.AuthorizeID(spiffeid.RequireFromString(
        "spiffe://prod.internal/ns/ledger/sa/ledger-api")))

That AuthorizeID line is the authorization decision. The ledger client will only complete a handshake with a peer presenting the ledger-api identity. No allowlist of IPs, no API keys checked in the app. The mTLS handshake is the auth. For the broader case against bearer tokens between services, see mTLS for service-to-service auth, beyond API keys.

For services you can't recompile, such as a legacy Java app, run Envoy as a sidecar with the SPIRE agent as its SDS provider; the agent docs confirm it serves the Envoy Secret Discovery Service on the same socket as the Workload API. Envoy terminates and originates mTLS, the app speaks plain HTTP to localhost, and it never knows SPIFFE exists.

What breaks in practice

Two things cost the most time. First, clock skew. SVIDs are short-lived, so a node whose clock drifts far enough starts rejecting valid certs as not yet valid, or accepting them past expiry. Run chrony on every node and alert on offset well before it reaches seconds; we'd page at a few hundred milliseconds.

Second, the SPIRE server datastore. SQLite 3 is the default, and the spiffe.io concepts page lists MySQL and PostgreSQL as the alternatives. SQLite is fine for a demo and wrong for an HA control plane: under pod churn, entry syncs lag, freshly scheduled pods sit without identities, and anything that fails hard without one crash-loops. Use Postgres or MySQL with at least two server replicas:

HCL
# spire/server.conf (excerpt)
DataStore "sql" {
  plugin_data {
    database_type = "postgres"
    connection_string = "dbname=spire host=spire-db.prod sslmode=require"
  }
}

Questions people ask

What is the difference between SPIFFE and SPIRE?

SPIFFE is a set of open specifications: the SPIFFE ID URI format, the SVID document formats (X.509 and JWT), and the Workload API that hands identities to processes. SPIRE is the reference implementation of those specs, a server and per-node agent that attest nodes and workloads and issue SVIDs. Service meshes such as Istio also emit SPIFFE-format IDs without running SPIRE itself.

How long do SPIRE certificates last, and how are they rotated?

SPIRE's server sets default_x509_svid_ttl to one hour unless you change it, and registration entries can override it with -x509SVIDTTL. The agent rotates each X.509-SVID at half its lifetime by default, and libraries like go-spiffe pick up the new cert from the Workload API in memory. No pod restart is involved, which is what makes hour-long certificates operationally cheap.

Do I need SPIRE if I already run a service mesh?

Usually not at first. Istio and Linkerd both issue workload certificates and do mTLS between pods with no extra control plane. SPIRE earns its place when identity must span clusters, VMs and non-mesh workloads, or when you need stronger node attestation than a mesh's CA provides. For comparing the mesh options themselves, see Istio vs Linkerd.

The call we'd make

If you're running more than a handful of services on Kubernetes and passing secrets between them, SPIFFE/SPIRE is worth the setup tax. The operational load is real: you're now running a PKI control plane, and you need to babysit its datastore and the nodes' clocks. For a three-service startup that's overkill, and a service mesh with built-in mTLS (Linkerd issues its own identities) gets you most of the value with far less to run. But once a leaked long-lived token means an all-hands incident, short-lived attested identities stop being a nice-to-have.

Sources

React
Share this post
Cite this article
Plain text

Kiril Urbonas (2026). Zero-Trust Service-to-Service Auth with SPIFFE and SPIRE. DevOpsNess. Updated 2026-10-31. https://www.devopsness.com/blog/zero-trust-service-auth-spiffe-spire

Markdown

[Zero-Trust Service-to-Service Auth with SPIFFE and SPIRE](https://www.devopsness.com/blog/zero-trust-service-auth-spiffe-spire) (Kiril Urbonas, DevOpsNess, updated 2026-10-31)

KU

Kiril Urbonas

Founder & Chief Editor

605 articles
View all articles by Kiril Urbonas

You might have missed

Evergreen posts worth revisiting.