Mutual TLS between services: short-lived certificates and SPIFFE-style identity

A steel padlock hanging from a chain on a rusty green metal door

Written by

in

Most mTLS rollouts I’ve seen go the same way. Someone turns on client certificate verification, the handshake works in staging, and a year later nobody knows who holds the CA key, the certificates last ten years, and the “authorization” amounts to the caller having a cert from the right CA. That’s a bouncer checking that your ticket is a real ticket, without checking whether it’s for this show.

This post covers the version that holds up. The certificates live for an hour, the identities mean something, and there’s an authorization check after the handshake.

What mutual TLS adds

Sequence diagram: workloads obtain one-hour certificates from an issuer, web and billing perform a TLS 1.3 mutual handshake, then billing checks the SPIFFE ID against an allow list before serving the request

The diagram shows the full flow: issuance, the mutual handshake, and the authorization check that comes after it.

In a normal TLS 1.3 handshake (RFC 8446) only the server proves who it is. With mTLS the server sends a CertificateRequest, and the client answers with its own Certificate and a CertificateVerify signature over the handshake transcript. If the client has no certificate or the chain doesn’t validate, the server aborts with an alert. You can see the failure directly if you point a client without a cert at a server that demands one:

tlsv13 alert certificate required ... SSL alert number 116

You get two things from this. The channel is encrypted, and the server learns a cryptographically proven identity for the caller. Most people underuse the second part. A source IP is a weak identity once you have autoscaling, NAT and shared nodes. A certificate chain you control is much better, as long as the identity inside it is something a policy can reason about.

Put a workload identity in the certificate, not a hostname

Service certificates have traditionally carried a DNS name, because browsers care about DNS names. Services calling each other care which workload is calling, and that isn’t the same thing as the host it runs on. SPIFFE defines a URI for this, in the form spiffe://trust-domain/path, and the X.509-SVID format carries it in a URI subject alternative name. The SPIFFE spec asks for exactly one URI SAN on a leaf, CA:FALSE, and no keyCertSign or cRLSign usage, so a workload certificate can’t be used to mint more certificates.

I built a small throwaway CA in a container to show what a leaf should look like. The identity is spiffe://demo.test/ns/prod/sa/billing, and the validity window is one hour.

Terminal output of openssl x509 for a demo workload certificate: subject CN billing, validity of exactly one hour, key usage Digital Signature, and the URI subject alternative name spiffe://demo.test/ns/prod/sa/billing

This is a synthetic demo PKI I generated for the post with OpenSSL 3.0.13. It isn’t anyone’s production setup. Two things to notice: the identity lives in the URI SAN, so the subject CN doesn’t matter, and notAfter is sixty minutes after notBefore.

Why short lifetimes beat revocation

In practice, revocation for internal services mostly doesn’t work. CRLs and OCSP need infrastructure that every client has to reach, and when clients can’t reach it, most of them fail open, because failing closed would take production down. SPIRE sidesteps the problem. Its default X.509-SVID lifetime is one hour (default_x509_svid_ttl), agents rotate well before expiry, and “revoking” a workload means stopping issuance. Istio’s default workload certificate lifetime is 24 hours. That’s a looser setting, same idea.

The math is simple. If a key is stolen from a compromised pod, the attacker’s useful window is at most the remaining lifetime of that one certificate, and they have to keep re-compromising the workload to renew it. With a three-year certificate, you end up planning a CA rotation in the middle of an incident.

Short lifetimes move the risk somewhere else, though. The issuer is now on the critical path for rotation, even though it isn’t on the path of each request. If your CA or SPIRE server stays down longer than the remaining lifetime, services start failing handshakes. So alert on the remaining validity of the certs in use, not just on the CA’s health, and make rotation a hot reload. Restarting a process to pick up a new certificate turns a one-hour TTL into an outage generator.

Verification is not authorization

The handshake only tells you the peer holds a certificate your CA signed. Every workload in the mesh has one, so any of them can call the billing service unless you say otherwise. Teams skip this step all the time, and it’s why I get wary when someone says “we have mTLS” as if that settled the security question.

In Go, requiring and verifying the client certificate is one config flag. The authorization decision is still yours to write:

cfg := &tls.Config{
	MinVersion: tls.VersionTLS13,
	ClientAuth: tls.RequireAndVerifyClientCert,
	ClientCAs:  caPool,
	GetCertificate: func(*tls.ClientHelloInfo) (*tls.Certificate, error) {
		return certs.Current() // reloaded from disk on rotation
	},
}

func allowed(r *http.Request) bool {
	if r.TLS == nil || len(r.TLS.PeerCertificates) == 0 {
		return false
	}
	for _, u := range r.TLS.PeerCertificates[0].URIs {
		if u.String() == "spiffe://demo.test/ns/prod/sa/web" {
			return true
		}
	}
	return false
}

Here certs.Current() stands in for whatever holds your reloaded certificate. The GetCertificate callback is what makes rotation painless, because it runs on each new handshake. A hard-coded allow list is fine for a demo and falls apart at scale. Real deployments push the policy into the mesh (Istio AuthorizationPolicy, Envoy RBAC) or into an authorization service, keyed on the same SPIFFE ID. The thing that matters is that the policy names identities and the default is deny.

Trust domains and the CA you forgot about

Four failure modes come up again and again.

Over-broad CAs. If dev, staging and prod share one CA, a dev workload can present a valid chain to prod. Use a separate trust domain per environment, and have the verifier check the trust domain in the SPIFFE ID, not just the chain.

Everything is trusted. Plenty of clients fall back to the system trust store when no pool is set, so any public CA can vouch for an internal caller. Set the pool explicitly to your own CA bundle.

Wrong key usage. A leaf that carries keyCertSign turns one compromised service into a CA. Check this in your issuance pipeline and fail the build if it shows up.

Proxies that terminate TLS. If an ingress or sidecar terminates the mTLS and forwards plain HTTP with an X-Client-Cert header, the application must only accept that header from the proxy, and the hop between them needs to be locally trusted. I’ve watched a header spoofing bug wipe out the benefit of an otherwise excellent certificate scheme.

What I’d do on day one

Pick one internal call path that matters, usually the one that reaches a database or a payment system. Issue short-lived certs with a SPIFFE-style URI SAN, require client certs on the server, and write an explicit allow list of caller identities. Then test the negative case on purpose. That’s the test that shows whether it works.

Terminal output of two openssl s_client runs against an mTLS server: with a client certificate verification is OK on TLSv1.3, without one the server sends tlsv13 alert certificate required, alert number 116

Same throwaway CA, this time against a server that requires a client certificate. With a valid one the handshake completes on TLS 1.3 and verification is OK. Without one, the server sends alert 116 and closes the connection. I filtered the output with grep and trimmed the error prefix to fit the width.

Comments

Leave a Reply