Mutual TLS (mTLS)
[!IMPORTANT] Mutual TLS (mTLS) ensures that both the client and the server authenticate each other using certificates. It encrypts traffic in transit between your Pods.
In a traditional network, we trust the “internal” network. In Kubernetes, we adopt Zero Trust: “Never trust, always verify.” Even if an attacker gets into your cluster, they shouldn’t be able to sniff traffic or impersonate a service.
1. Interactive: The mTLS Handshake
How does Service A prove its identity to Service B?
Service A
Service B
Idle
2. Service Mesh Automation
Implementing mTLS manually (managing certificates for 100 microservices) is a nightmare. Service Meshes (like Istio, Linkerd, Consul) automate this using the Sidecar Pattern.
- Proxy Injection: A tiny proxy (Envoy/Linkerd-proxy) is injected into every Pod.
- Traffic Interception: The application talks to
localhost. The proxy intercepts the traffic. - Automatic mTLS: The proxy talks to the destination proxy over mTLS.
- Certificate Rotation: The control plane rotates certificates automatically (often every hour).
Conceptual Diagram
[ Service A Container ] -> (localhost:80) -> [ Proxy A ]
||
(mTLS Tunnel)
||
[ Service B Container ] <- (localhost:80) <- [ Proxy B ]
[!TIP] This decouples security from application logic. Developers just write HTTP code; the mesh handles the encryption.
3. Why is this “Zero Trust”?
- Identity is Cryptographic: IP addresses can be spoofed. Certificates signed by a trusted CA cannot.
- Encryption Everywhere: Even if a bad actor is on the node sniffing packets, they only see encrypted garbage.
- Policy Enforcement: You can write rules like “Only Service A can talk to Service B”. If Service C tries (even with valid mTLS), the proxy denies it (Authorization).