Reference architecture: Zero‑trust microservices mesh (SPIFFE + mTLS + policy + discovery + observability + IR)
1) Core principles (what “zero trust” means here)
- Every request is authenticated and authorized (not “trusted because it’s inside the cluster/VPC”).
- Identity is workload-based, not IP-based: services prove who they are via SPIFFE IDs.
- mTLS everywhere, with short‑lived certs and automated rotation.
- Default deny at network + service authorization layers; explicit allow by policy.
- Strong telemetry + auditability tied to identity (SPIFFE), enabling fast containment.
2) High-level building blocks (planes)
Identity plane (SPIFFE/SPIRE)
- SPIFFE Trust Domain (e.g.,
spiffe://prod.company.internal)
- SPIRE Server (CA + identity issuance + registration API)
- SPIRE Agents (node-level attestors; provide Workload API to local workloads/sidecars)
- Workload Attestation (K8s: service account/UID/namespace/labels; VM: TPM, AWS IID, etc.)
- SVIDs (X.509 SVID for mTLS; optional JWT-SVID for app-layer auth)
Data plane (service connectivity)
- L7 proxies (commonly Envoy) deployed as:
- Sidecar per pod, or
- Ambient / node proxy model (reduces sidecars; still enforces mTLS/policy)
- Proxy obtains SVID from SPIRE Agent (via SDS/Workload API), then performs mTLS to peers.
- Control plane distributes routing + policy config to proxies (xDS or mesh-native APIs).
Policy plane (authorization + governance)
- Service-to-service authZ (L4/L7) based on SPIFFE principal, method/path, headers, etc.
- Typical engines:
- Mesh-native (e.g., Istio AuthorizationPolicy / Consul intentions / Linkerd policy)
- OPA / Envoy ext_authz for fine-grained ABAC/Rego
- Egress policy: restrict outbound destinations; enforce TLS origination; use egress gateways.
Discovery plane (service discovery + endpoint selection)
- Registry: Kubernetes Services/Endpoints, or Consul, or a dedicated service catalog.
- Mesh maps “service name” → endpoints, then authn/authz is still identity-based (SPIFFE), not DNS-based.
Observability plane
- Metrics: RED/USE + mTLS handshake stats + policy denies
- Tracing: W3C tracecontext propagation; proxy spans + app spans
- Logs: structured access logs at proxies, correlated by SPIFFE ID, trace ID
- Audit: policy/config changes, identity issuance events, admin access
Incident response plane
- Detection (alerts), containment (policy changes / quarantine), eradication (fix + rotate), recovery, forensics.
3) Identity: SPIFFE/SPIRE design
Trust domain & naming
Define SPIFFE IDs that encode environment + service identity, not instance identity, e.g.:
spiffe://prod.company.internal/ns/payments/sa/api
spiffe://prod.company.internal/ns/payments/sa/worker
Keep IDs stable across deploys; let certs be ephemeral.
Attestation (how a workload earns an identity)
- Kubernetes: SPIRE Agent uses K8s workload attestor (service account token + pod metadata).
- Enforce registration entries that bind:
- Namespace + service account + optional labels → SPIFFE ID
- Optional hardening:
- Require specific node pools, PSA/OPA admission constraints, image signatures (cosign), etc.
Issuance & rotation
- SVID TTL: typically 5–30 minutes (short-lived reduces need for revocation).
- Automate rotation via Workload API; proxies reload certs without restarts.
- Protect trust root:
- SPIRE Server signing keys in KMS/HSM (where possible)
- Strict admin RBAC + audit logging on registration API
Federation (multi-cluster / partners)
- Use SPIFFE federation bundles to trust another domain selectively.
- Prefer separate trust domains per environment (prod/stage) and per major boundary (internal/partner).
4) Mutual TLS: how traffic is secured
Inbound/Outbound mTLS enforcement
- Proxies enforce mTLS required for service-to-service.
- Peer authentication checks:
- Validate certificate chain to trust bundle
- Verify SPIFFE ID principal matches expected policy
- Cipher/TLS policy:
- TLS 1.2+ (ideally TLS 1.3), modern ciphers
- Disable plaintext ports internally unless explicitly needed
Traffic flow (typical)
- Workload starts → proxy starts.
- Proxy fetches SVID from SPIRE Agent (local).
- Client proxy connects to server proxy with mTLS.
- Server proxy verifies client SPIFFE ID.
- Authorization policy evaluated (allow/deny).
- Request routed to workload.
5) Policy enforcement: “default deny” with identity-based allow
Layered controls (recommended)
- Kubernetes NetworkPolicies / CNI policies (coarse L3/L4 segmentation)
- Mesh authorization policies (identity-aware L4/L7 allowlist)
- App-layer authorization (business permissions; defense-in-depth)
What policies should reference
- Source principal: SPIFFE ID (or SPIFFE ID pattern)
- Destination service: service identity / namespace
- Request attributes (optional): method/path/host, JWT claims, headers
- Context: time, risk signals, mTLS properties
Example policy intent (conceptual)
- Only
spiffe://.../ns/payments/sa/api may call spiffe://.../ns/ledger/sa/ledger-api on POST /v1/entries
- Deny everything else by default.
Egress governance
- Force all outbound through:
- Egress gateway (central policy, logging, DLP controls), or
- Per-namespace egress policies
- Require:
- DNS allowlist / service entries
- TLS origination and SNI verification
- Optional upstream mTLS with external partners
Rate limiting and abuse controls
- Envoy local/global rate limits keyed by SPIFFE ID + route
- Circuit breaking / outlier detection to reduce blast radius
6) Service discovery & routing (without trusting DNS)
Discovery sources
- Kubernetes service registry (Endpoints/EndpointSlices) or Consul catalog.
- Proxies receive endpoints via control plane (xDS).
Key point
- Discovery tells you “where”, SPIFFE/mTLS tells you “who”.
- Even if DNS/registry is poisoned, unauthorized endpoints fail mTLS/policy.
Advanced routing
- Progressive delivery (canary, blue/green) with identity preserved
- Multi-cluster:
- East-west gateways
- Cluster-local identities + federated trust where needed
7) Observability: tie everything to identity
Metrics
- Per service + per principal:
- Request rate, error rate, latency (p50/p95/p99)
- mTLS handshake failures (by reason)
- Authorization denies (by policy, source SPIFFE ID)
- SLOs: availability/latency per service and per dependency edge
Logs
- Proxy access logs with fields:
source_spiffe_id, dest_spiffe_id
mtls=true/false, tls_version, san, policy_decision
trace_id, route, status_code
- Centralize in SIEM; protect log integrity (WORM / immutability where needed)
Tracing
- Distributed tracing with consistent sampling
- Add proxy spans around retries, timeouts, policy checks
- Correlate traces with identity and policy decisions
Auditability
- SPIRE:
- Registration entry changes
- SVID issuance anomalies (volume spikes, unexpected selectors)
- Mesh control plane:
- Policy/config changes (who/when/what)
- Admin endpoint access
8) Incident response design (built-in playbooks)
Detection signals
- Spike in:
- mTLS failures (unknown SPIFFE ID, expired cert, bundle mismatch)
- Authorization denies from a previously quiet principal
- New outbound destinations / DNS anomalies
- Unusual SVID issuance volume for a selector
- Lateral movement indicators:
- One workload principal attempting many destinations/paths
Containment actions (fast, reversible)
- Quarantine identity: deny that SPIFFE ID everywhere via mesh auth policy.
- Quarantine namespace: default deny all inbound/outbound at mesh + NetworkPolicy.
- Egress lockdown: restrict to known dependencies; block internet.
- Traffic shadowing: duplicate suspicious traffic to analysis sink (where supported).
Eradication & recovery
- Fix compromised workload (image rebuild, secrets rotation, patch).
- Rotate identity credentials by:
- Reducing SVID TTL temporarily
- Removing/adjusting SPIRE registration entries (prevents re-issuance)
- Rotating trust bundle only in extreme CA compromise scenarios (planned runbook required)
Forensics readiness
- Keep:
- Proxy access logs (identity + route)
- SPIRE audit logs
- Policy change history (GitOps commits + control plane audit)
- Packet capture capability at gateway (optional, tightly controlled)
“Break glass” (controlled)
- Emergency policy overrides via signed, time-bound change (GitOps + approval)
- Separate admin identities; mandatory MFA; full audit trail
9) Recommended operational model (so it stays zero-trust)
GitOps for policy and config
- All mesh policies, SPIRE registrations (or templates), gateway configs versioned.
- CI policy tests:
- Connectivity tests (allowed edges)
- Negative tests (default deny)
- OPA tests for ABAC rules
Progressive rollout & safety
- Start with:
- mTLS in permissive → strict (phased)
- Observe denies; then enforce
- Use canaries for policy changes that might break traffic.
Hardening checklist (minimum)
- Short-lived SVIDs + automatic rotation
- Default-deny authorization policies
- Egress controls
- Control plane protected (RBAC, network isolation, audit)
- Node/workload attestation enforced (no “wildcard” registrations)
- Observability integrated with SIEM and on-call alerts
10) Concrete reference stack options (common combinations)
-
SPIRE + Envoy-based mesh (Istio or similar)
Strong L7 policy, mature telemetry, integrates well with SPIFFE via SDS/Workload API.
-
SPIRE + Consul service mesh
Tight coupling of discovery/intentions; good multi-datacenter patterns.
-
SPIRE + Linkerd (where SPIFFE integration fits your needs)
Simpler operational model; verify current SPIFFE/SVID integration path for your exact requirements.
(Exact product choice matters less than enforcing: SPIFFE identity, strict mTLS, default-deny authZ, controlled egress, and identity-centric telemetry.)
If you share your target platform (Kubernetes vs mixed VM/K8s), multi-cluster needs, and preferred mesh (Istio/Consul/Linkerd/other), I can adapt this into a concrete deployment topology (components per cluster, trust domain/federation layout, and sample identity + authorization policy patterns).