networking kubernetes/networking

TLS
Mutual TLS - Hussein Nasser
What Is Mutual TLS (mTLS), Why Do We Need It, And How Do We Get It.
mTLS in Kubernetes - A Hands-On Project

mTLS (Mutual TLS)

Tldr

mTLS is an extension of TLS where both client and server authenticate each other via X.509 certificates. It is the foundation of Zero Trust service-to-service security and is widely used in Kubernetes service meshes.

What is mTLS?

Mutual TLS (mTLS) extends the standard TLS (Transport Layer Security) protocol so that both sides of a connection prove their identity. Unlike standard TLS — where only the server presents a certificate — mTLS requires the client to do the same, making it the cornerstone of zero-trust architectures.

How TLS vs mTLS Works

Standard TLS

sequenceDiagram
    participant C as Client
    participant S as Server

    C->>S: ClientHello
    S->>C: ServerHello
    S->>C: Server Certificate
    C->>S: ClientKeyExchange
    C->>S: Finished
    S->>C: Finished
    Note over C,S: Encrypted channel (server only verified)

mTLS (Mutual TLS)

sequenceDiagram
    participant C as Client
    participant S as Server

    C->>S: ClientHello
    S->>C: ServerHello
    S->>C: Server Certificate
    S->>C: CertificateRequest 🔐
    C->>S: Client Certificate 🔐
    C->>S: ClientKeyExchange
    C->>S: Finished
    S->>C: Finished
    Note over C,S: Encrypted channel (both sides verified)

mTLS Additions

The two highlighted steps — CertificateRequest and Client Certificate — are what distinguish mTLS from standard TLS.

Key Concepts

TermDescription
X.509 CertificateDigital certificate used to prove identity
CA (Certificate Authority)Trusted entity that signs and issues certificates
Private KeySecret key used to sign/decrypt; never shared
Public KeyShared key embedded in the certificate
SPIFFE/SVIDStandard for workload identity in cloud-native environments

Why Use mTLS?

  • Zero Trust Security — No implicit trust; every connection is verified.
  • Service-to-Service Auth — Ensures only authorized services communicate.
  • Encryption in Transit — All traffic is encrypted automatically.
  • Prevents Impersonation — Certificates are cryptographically verified.
  • Compliance — Meets requirements for PCI-DSS, HIPAA, SOC 2, etc.

Network Concepts: How TLS/mTLS Fits Together

Mental Model

TCP, TLS, HTTPS, and mTLS are not alternatives — they are a layered stack. Each protocol builds on the one below it.

OSI Layer Map

block-beta
  columns 1
  block:osi["OSI Model & Protocol Mapping"]:1
    L7["Layer 7 – Application\nHTTP · gRPC · WebSocket"]
    L65["Layer 6/5 – Presentation / Session\nTLS / mTLS  ← encryption + identity"]
    L4["Layer 4 – Transport\nTCP · UDP"]
    L3["Layer 3 – Network\nIP"]
    L2["Layer 2 – Data Link\nEthernet · Wi-Fi"]
    L1["Layer 1 – Physical\nCables · Signals"]
  end

Where does TLS sit?

TLS/mTLS operates between Layer 4 and Layer 7 — it wraps the TCP byte stream before the application ever sees the data. It is often informally called “Layer 4.5” or “Layer 5/6”.

Protocol Stack

flowchart TD
    A["🌐 Application Data (HTTP · gRPC · etc.)"]
    B["🔐 mTLS mutual cert auth — both sides verified"]
    C["🔒 TLS encryption + server cert auth"]
    D["📡 TCP reliable ordered byte stream"]
    E["📦 IP packet routing between hosts"]

    A --> B --> C --> D --> E

Protocol Relationships

ProtocolOSI LayerDepends OnWhat It Adds
TCPL4IPReliable, ordered delivery
TLSL4.5–L5TCPEncryption + server auth
Mutual TLS (mTLS)L4.5–L5TCPEncryption + mutual auth
HTTPSL7TLSHTTP semantics over TLS
gRPCL7HTTP/2 + TLSRPC framing (common with mTLS)

Full Connection Lifecycle

sequenceDiagram
    participant C as Client
    participant S as Server

    rect rgb(40, 60, 80)
        Note over C,S: Layer 4 — TCP Handshake
        C->>S: SYN
        S->>C: SYN-ACK
        C->>S: ACK
    end

    rect rgb(50, 80, 50)
        Note over C,S: Layer 5 — TLS / mTLS Handshake
        C->>S: ClientHello
        S->>C: ServerHello + Server Certificate
        S->>C: CertificateRequest (mTLS only)
        C->>S: Client Certificate (mTLS only)
        C->>S: ClientKeyExchange + Finished
        S->>C: Finished
    end

    rect rgb(70, 50, 80)
        Note over C,S: Layer 7 — Application Data
        C->>S: GET /api/data HTTP/1.1
        S->>C: 200 OK + body
    end

    rect rgb(40, 60, 80)
        Note over C,S: Layer 4 — TCP Teardown
        C->>S: FIN
        S->>C: FIN-ACK
        C->>S: ACK
    end

Info

Steps 1 and 2 (TCP + TLS handshakes) are invisible to application code. The app just opens a socket and sees a secure, verified stream.

Common Misconceptions

Does mTLS replace HTTPS?
No. HTTPS = HTTP over TLS (server auth only). mTLS adds client auth on top. You can — and often should — have HTTPS with mTLS, which is standard in API gateways and service meshes.

Important

When you use mTLS, TLS is still running in full — you haven’t replaced or removed anything. You’ve simply told the server to also ask “who are you?” during the same handshake it was already doing.

Is mTLS only for HTTP?
No. Because TLS runs at L4.5, mTLS works with _any_ TCP-based protocol: gRPC, PostgreSQL, AMQP, raw TCP sockets, etc.

Does TCP encrypt data?
No. TCP only ensures reliable, ordered delivery. Encryption is TLS’s job entirely. Without TLS, TCP traffic is plaintext and visible to anyone on the network path.

What is a TLS termination proxy?
A proxy (e.g., Nginx, Envoy) that unwraps TLS, inspects or routes the plaintext traffic, then optionally re-encrypts before forwarding. In a [[Service Mesh|Service Mesh]], the sidecar proxy terminates mTLS so the app container itself never handles certificates.


Mutual TLS (mTLS) in Kubernetes