Self-Hosted eBPF TLS Certificate Rotation and mTLS Observability with SPIFFE/SPIRE
Quick Summary (TL;DR)
- SPIRE issues short-lived X.509-SVIDs to workloads based on attested identity—no static secrets, no long-lived certs.
- Automated rotation (default 1h) keeps SVIDs fresh; the Workload API streams new certs to apps without restarts.
- eBPF uprobes on
libssl/BoringSSL trace mTLS handshakes at the syscall/library level—zero code changes.- Use eBPF to catch expired certs, SAN/SPIFFE ID mismatches, and rotation lag in real time.
- This guide covers a production Kubernetes deployment, rotation config, and a comparison of eBPF vs. traditional monitoring.
Introduction: Why mTLS Observability Matters
Mutual TLS (mTLS) is now the default for service-to-service traffic in zero-trust architectures. But mTLS introduces a subtle operational hazard: certificates expire, rotate, and occasionally mismatch—and when they do, the failure mode is a cryptic handshake error buried in logs. With short-lived certificates (SPIFFE SVIDs rotate hourly by default), the blast radius of a misconfiguration grows.
Traditional monitoring can’t see inside encrypted handshakes. You get “connection refused” or tls: bad certificate with no context on which identity failed, when it rotated, or why the cert was rejected. eBPF changes this: by attaching uprobes to the TLS library functions (SSL_do_handshake, SSL_get_peer_certificate), you can observe handshake outcomes, certificate serials, and SANs—without instrumenting a single application.
This guide walks you through deploying SPIRE for workload identity, automating X.509-SVID rotation, and building eBPF-based mTLS observability on Kubernetes.
Understanding SPIFFE and SPIRE
SPIFFE ID and SVID
SPIFFE (Secure Production Identity Framework for Everyone) defines a standard identity string—the SPIFFE ID—formatted as a URI:
spiffe://example.org/ns/payments/sa/checkout
An SVID (SPIFFE Verifiable Identity Document) is the cryptographic proof of that identity. The most common form is the X.509-SVID: a standard X.509 certificate whose URI SAN contains the SPIFFE ID. Because it’s a normal cert, it works with any TLS stack—no proprietary crypto.
SPIRE Architecture
SPIRE is the reference implementation of SPIFFE. It has two components:
- SPIRE Server: the certificate authority. It holds the trust bundle, attests agents and workloads, and signs SVIDs.
- SPIRE Agent: runs on every node (as a DaemonSet). It attests workloads via the Workload API—a Unix domain socket that streams SVIDs and trust bundles to applications.
flowchart TD
subgraph Node["Kubernetes Node"]
AG[SPIRE Agent<br/>DaemonSet]
WL1[Workload A<br/>checkout]
WL2[Workload B<br/>inventory]
WL1 -- "Workload API<br/>unix:///spiffe-workload-api" --> AG
WL2 -- "Workload API" --> AG
end
AG -- "Node Attestation (PSAT)" --> SRV[SPIRE Server<br/>CA + registration entries]
SRV -- "SVID rotation stream" --> AG
WL1 -. "mTLS handshake" .-> WL2
The agent attests each workload using a selector (e.g., k8s:ns:payments, k8s:sa:checkout) and delivers an SVID only if a matching registration entry exists.
Deploying SPIRE on Kubernetes
Prerequisites
- Kubernetes v1.19+ with
kubectlaccess - Permissions to create ClusterRoles, ServiceAccounts, DaemonSets
- A node attestation method (
k8s_psatis the standard choice) helmv3 (optional but recommended)
Step 1: Install SPIRE Server and Agents
The fastest path is the official Helm chart:
helm repo add spiffe https://spiffe.github.io/helm-charts-hardened/
helm repo update
helm install spire spiffe/spire \
--namespace spire-system \
--create-namespace \
--set spire-server.replicaCount=1 \
--set spire-agent.agent.nodeAttestor.k8sPSAT.enabled=true
Verify both components are healthy:
kubectl get pods -n spire-system
kubectl exec -n spire-system spire-server-0 -- \
/opt/spire/bin/spire-server healthcheck
Step 2: Configure Node Attestation
With k8s_psat, the agent proves its node identity using a projected service account token. The server validates it against the Kubernetes API. Confirm the node attestor is registered:
kubectl exec -n spire-system spire-server-0 -- \
/opt/spire/bin/spire-server agent list
Each node should appear with a k8s_psat attestation type. If agents don’t register, check that the server’s ClusterRole allows TokenReview and that the spire-system namespace is trusted.
Step 3: Register Workloads
Registration entries bind selectors to a SPIFFE ID. Create one per workload:
kubectl exec -n spire-system spire-server-0 -- \
/opt/spire/bin/spire-server entry create \
-spiffeID spiffe://example.org/ns/payments/sa/checkout \
-parentID spiffe://example.org/ns/spire-system/sa/spire-agent \
-selector k8s:ns:payments \
-selector k8s:sa:checkout \
-ttl 3600
The -ttl 3600 sets the SVID lifetime to one hour. Only pods matching both selectors receive this identity.
Automating X.509-SVID Rotation
Rotation Configuration
SPIRE rotates SVIDs automatically. Two knobs control it:
| Setting | Location | Default | Effect |
|---|---|---|---|
default_x509_svid_ttl | Server config | 3600s | Lifetime of issued X.509-SVIDs |
| Rotation timing | Agent | ~50% of TTL | Agent fetches the new SVID before expiry |
To tighten security, shorten the TTL in the server config:
server {
default_x509_svid_ttl = "900s" # 15 minutes
}
The agent proactively rotates at roughly half the TTL (≈7.5 min here), so workloads always hold a valid cert with ample headroom.
Workload API Integration
Applications don’t poll—they subscribe. The Workload API streams updates over a Unix socket. Most TLS libraries support SPIFFE natively, but the pattern is universal: watch the stream, reload on change.
// Go: spiffe-go Workload API client
source, _ := workloadapi.NewX509Source(ctx)
tlsConfig := tlsconfig.MTLSServerConfig(source, source,
tlsconfig.AuthorizeAny())
// `source` auto-updates on rotation; tlsConfig picks up new certs
The key property: rotation is transparent. No restart, no config reload, no dropped connections—the source swaps certificates in memory and new handshakes use the fresh SVID.
sequenceDiagram
participant App
participant WAPI as Workload API
participant Agent
participant Server
App->>WAPI: Subscribe (X509Source)
WAPI->>Agent: fetch SVID
Agent->>Server: sign request
Server-->>Agent: X.509-SVID (TTL 900s)
Agent-->>WAPI: SVID + bundle
WAPI-->>App: stream cert
Note over Agent,Server: ~50% TTL elapsed
Agent->>Server: re-sign
Server-->>Agent: new SVID
Agent-->>WAPI: push update
WAPI-->>App: swap cert in memory
eBPF Observability for mTLS
How eBPF Uprobes Work
A uprobe is an eBPF hook attached to a function in a userspace binary or shared library. When the kernel loads libssl.so, eBPF can instrument SSL_do_handshake and read its arguments—including the SSL* struct, from which certificate data is reachable. Because the hook lives in the kernel, it works across all processes using that library, with no recompilation.
Tracing OpenSSL/BoringSSL Handshakes
The typical probe targets:
SSL_do_handshake— entry/return to measure handshake success and durationSSL_get_peer_certificate— capture the peer’s cert for SAN extractionSSL_get_verify_result— read the verification result code
A minimal bpftrace snippet to trace handshake outcomes:
bpftrace -e '
uprobe:/usr/lib/x86_64-linux-gnu/libssl.so:SSL_do_handshake {
@start[tid] = nsecs;
}
uretprobe:/usr/lib/x86_64-linux-gnu/libssl.so:SSL_do_handshake
/ @start[tid] /
{
$dur = (nsecs - @start[tid]) / 1000000;
printf("handshake tid=%d ret=%d dur=%dms\n", tid, retval, $dur);
delete(@start[tid]);
}'
For production, tools like Pixie or Cilium wrap this into dashboards, but the primitives are identical.
Detecting Expired or Mismatched Certificates
By reading the peer certificate struct, you can extract:
notAfter— compare against current time to flag expiring/expired certs- URI SAN — compare against the expected SPIFFE ID to catch identity mismatches
A mismatch usually means a registration entry is wrong or a workload is presenting the wrong SVID. Emit a counter/metric when the observed SAN ≠ expected SAN:
mtls_handshake_total{result="ok"} 10432
mtls_handshake_total{result="expired"} 3
mtls_handshake_total{result="san_mismatch"} 1
Monitoring Rotation Latency
Rotation latency = time between a new SVID being issued and its first use in a handshake. eBPF can measure it by tracking certificate serial numbers: when a new serial appears in handshakes, compare its timestamp to the issue time from the Workload API. High latency signals an app that isn’t consuming the stream promptly—or a stalled agent.
flowchart LR
A[SVID issued<br/>t=0] --> B{Handshake uses<br/>new serial?}
B -- No --> C[Rotation lag<br/>alert if > 2x TTL/2]
B -- Yes --> D[Latency = t_use - t_issue]
D --> E[Record histogram]
Comparison: eBPF vs. Traditional mTLS Monitoring
| Capability | eBPF Uprobes | Service Mesh (sidecar) | App Instrumentation |
|---|---|---|---|
| Code changes required | None | None (sidecar inject) | Yes |
| Visibility into handshake | Full (cert, SAN, result) | Full (proxy-level) | Partial |
| Performance overhead | Very low | Moderate (extra hop) | Low |
| Works with non-mesh apps | Yes | No | Only if instrumented |
| Detects SAN mismatch | Yes | Yes | Depends on impl |
| Kernel/OS dependency | Linux 4.18+ | Any | Any |
| Setup complexity | Medium (probes) | Medium (mesh) | High (per-app) |
| Encrypted payload visibility | Metadata only | Metadata only | Full (in-process) |
eBPF wins on zero-instrumentation breadth across heterogeneous workloads. A service mesh gives richer L7 policies but adds a proxy hop. Use eBPF when you need universal, low-overhead handshake observability—especially in mixed or legacy environments.
Best Practices and Troubleshooting
- Keep TTLs short but sane. 15–60 min balances security against server load. Going below 5 min stresses the CA.
- Alert on rotation lag. If a workload’s new serial appears >1.5× the rotation interval late, investigate the Workload API subscription.
- Pin library paths. Uprobes attach to specific
.sopaths; containerized apps may bundle BoringSSL statically, requiring per-binary probes. - Watch for static linking. If an app statically links OpenSSL, uprobes on
libssl.sowon’t fire—probe the binary directly or use a mesh. - Validate selectors carefully. A typo in
k8s:sa:silently yields no SVID; always verify withspire-server entry show. - Test eBPF in staging. Kernel verifier rejections and probe overhead should be measured before production rollout.
Common failure: SSL_do_handshake returns -1 with SSL_get_verify_result = X509_V_ERR_CERT_HAS_EXPIRED. eBPF surfaces the exact serial and SAN, turning a blind error into a diagnosable event.
Conclusion
Combining SPIRE for short-lived, automatically rotated workload identities with eBPF uprobes for handshake-level observability gives you a zero-trust mTLS posture you can actually see. SPIRE eliminates static secrets and streamlines rotation via the Workload API; eBPF turns opaque encrypted handshakes into rich, queryable telemetry—expired certs, SAN mismatches, and rotation lag—all without touching application code. Deploy the pieces incrementally, alert on the three failure modes above, and you’ll catch mTLS incidents before they cascade.
FAQ
What is the difference between SPIFFE and SPIRE? SPIFFE is the open standard for defining workload identities (the SPIFFE ID and SVID formats). SPIRE is the production-ready implementation that issues and manages SVIDs across a cluster or fleet.
Can I use eBPF to monitor mTLS without modifying my applications?
Yes—uprobes attach to libssl/BoringSSL functions used by your apps, tracing handshakes with no code changes, provided the app uses those shared libraries.
How often should X.509-SVIDs be rotated? The default is 1 hour. Shorter intervals (15–30 min) increase security but add CA load. Choose based on your threat model and server capacity.
What causes rotation latency and how can I monitor it? Latency stems from delayed Workload API consumption, app polling gaps, or network issues. eBPF tracks certificate serials at handshake time and compares them to issue timestamps to measure lag.
Is eBPF-based monitoring safe for production? Yes—programs are kernel-verified and sandboxed. Test in staging, watch overhead, and prefer hardened tooling like Pixie or Cilium for production dashboards.