Opscraft
Service mesh in depth · Lesson 4 of 6 · 3 min read

Security

Mutual TLS and workload identity

The control plane acts as a certificate authority: each workload gets a short-lived certificate (rotated automatically, by default every day) whose identity is a SPIFFE ID derived from its Kubernetes service account:

spiffe://cluster.local/ns/payments/sa/payments-api

With mutual TLS, both sides present certificates, so traffic is encrypted and each side knows exactly which workload is on the other end, independent of pod IPs.

Rolling it out without breaking things:

Enlarge diagramPERMISSIVEaccept mTLS and plain textcheckall traffic shows mTLSSTRICTnamespace by namespace123
Figure 1. Rolling out mTLS without breaking callers.
Swipe sideways to see all of it, or tap to open it full screen.
  1. Install the mesh with PERMISSIVE mode (the default): proxies accept both mTLS and plain text, so unmeshed clients keep working.
  2. Add workloads to the mesh; check in metrics or Kiali that traffic between them is mTLS.
  3. Switch namespaces to STRICT with a PeerAuthentication resource, then the whole mesh.
apiVersion: security.istio.io/v1
kind: PeerAuthentication
metadata: { name: default, namespace: payments }
spec:
  mtls: { mode: STRICT }

Authorisation policies

AuthorizationPolicy allows or denies requests by source identity, namespace, method, path or JWT claims:

apiVersion: security.istio.io/v1
kind: AuthorizationPolicy
metadata: { name: payments-allow-checkout, namespace: payments }
spec:
  selector: { matchLabels: { app: payments-api } }
  action: ALLOW
  rules:
    - from: [{ source: { principals: ["cluster.local/ns/checkout/sa/checkout"] } }]
      to: [{ operation: { methods: ["POST"], paths: ["/charge"] } }]

Once any ALLOW policy selects a workload, everything not explicitly allowed is denied, so roll these out with care, starting in a staging namespace. Path and method rules are Layer 7, so in ambient mode they need a waypoint proxy.

Enlarge diagramcheckoutsa: checkoutreportssa: reportspayments-apiALLOW checkout: POST /chargeallowed403
Figure 2. Authorisation by identity: only checkout’s service account may POST /charge to payments.
Swipe sideways to see all of it, or tap to open it full screen.

A mesh complements rather than replaces Kubernetes NetworkPolicy: network policies block traffic at Layer 3/4 in the CNI even for pods outside the mesh, while mesh policies understand identities and HTTP.

Egress control: set outboundTrafficPolicy to REGISTRY_ONLY so pods can only call external hosts you've declared with ServiceEntry, and route them through an egress gateway when you need a fixed exit point for auditing.