Lesson 02 of 14 · Foundations of trust
From TLS to mTLS
What each message of a TLS 1.3 handshake actually proves, what changes when both sides present certificates (mTLS), and how to choose where TLS ends in a platform: at the edge, re-encrypted hop by hop, or passed through to the pod.
What TLS gives you
TLS has three jobs: agree on secret keys over an untrusted network, authenticate the server (and optionally the client), then encrypt and integrity-protect everything that follows. The Networking Deep Dive covers the basics; here we look at what each step proves, because that is what security reviews ask about.
The TLS 1.3 handshake, message by message
Client Server
│── ClientHello ─────────────────────────────────────────►│
│ versions, cipher suites, key_share (ephemeral ECDHE │
│ public key), SNI = api.example.com, ALPN = h2 │
│◄──────────────────────────────────────── ServerHello ───│
│ chosen cipher, key_share (server's ephemeral key) │
│ │
│ Both sides now compute the same shared secret │
│ (ECDHE) and derive handshake keys. All that follows │
│ is encrypted. │
│◄── EncryptedExtensions │
│◄── Certificate leaf + intermediate │
│◄── CertificateVerify signature over the transcript │
│◄── Finished MAC over the transcript │
│── Finished ────────────────────────────────────────────►│
│══ application data, AEAD-encrypted ═════════════════════│
What each piece proves:
| Step | Proves |
|---|---|
| ECDHE key shares | Both sides share a secret no observer can compute |
| Certificate | Claims an identity: this public key belongs to api.example.com, vouched for by a CA |
| CertificateVerify | The server holds the private key for that certificate (proof of possession), for this handshake |
| Finished | Nobody tampered with the handshake messages |
| Client's chain check | The CA is trusted, the name is in the SAN, the certificate is valid and not revoked |
Showing a photocopy of a passport proves nothing; anyone can photocopy it. CertificateVerify is like signing your name in front of the officer and having it match the passport. And the secret handshake you agree on (ECDHE) is forgotten as soon as the meeting ends, so even if someone steals your passport later, they can't replay what you said today (forward secrecy).
Two properties worth naming precisely:
- Forward secrecy: session keys come from ephemeral keys, so stealing the certificate's private key later cannot decrypt recorded traffic. TLS 1.3 removed the old RSA key exchange that lacked this.
- The private key never leaves the server. It only signs. Protect it like a password: in a KMS/HSM, or at least in a Secret with tight RBAC.
Mutual TLS: the client proves who it is too
Normal TLS leaves the client anonymous at the transport layer; it identifies itself later with a cookie or token. In mTLS the server asks for a certificate:
Server ── … Certificate, CertificateRequest, CertificateVerify, Finished ─► Client
Client ── Certificate (client cert), CertificateVerify (signed with client key), Finished ─► Server
Server validates the client chain against ITS list of trusted CAs,
then maps the identity in the certificate (SAN, SPIFFE ID) to a permission.
Where mTLS is the right tool:
- Service to service inside a platform (usually automated by a mesh: next lessons).
- Partner and B2B APIs, and agents or connectors installed at customer sites that call home.
- Infrastructure components: API server ↔ kubelet and etcd, Kafka clients, database clients.
The hard part is never the handshake. It is issuing, rotating and revoking client certificates at scale, and mapping certificate identities to permissions. That is why PKI automation and SPIFFE exist.
mTLS proves the workload, not the user
When service A calls service B on behalf of a user, mTLS tells B that A is calling. It says nothing about which user. Carry the user identity separately (a token), as covered in the token lesson.
Where TLS ends: three patterns
1 Edge termination: client ══TLS══► load balancer ──plain HTTP──► pods
2 Re-encryption: client ══TLS══► edge/WAF ══TLS══► gateway ══mTLS══► pods
3 Passthrough: client ══TLS, end to end (LB routes on SNI only)═══► pod
| Pattern | Good | Bad | Use when |
|---|---|---|---|
| Edge termination | Simple; WAF can inspect | Plaintext inside the network | Low-risk internal tools only |
| Re-encryption | Inspection at the edge and encryption on every hop | More certificates to manage (automate them) | The default for regulated or multi-tenant platforms |
| Passthrough | True end to end | No L7 routing, no WAF, certificates in every app | Apps that must see the client certificate themselves |
Going deeper
With re-encryption, the gateway can forward the original client's certificate details in a header (for example X-Forwarded-Client-Cert in Envoy) so a backend can still make decisions on it. Only trust that header when it comes from your gateway: strip it from incoming external requests.
Try it
Create a tiny CA and run an mTLS server locally:
$ openssl req -x509 -newkey rsa:2048 -nodes -keyout ca.key -out ca.crt -days 1 -subj "/CN=demo-ca"
$ openssl req -newkey rsa:2048 -nodes -keyout srv.key -out srv.csr -subj "/CN=localhost"
$ openssl x509 -req -in srv.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out srv.crt -days 1
$ openssl req -newkey rsa:2048 -nodes -keyout cli.key -out cli.csr -subj "/CN=orders"
$ openssl x509 -req -in cli.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out cli.crt -days 1
$ openssl s_server -accept 8443 -cert srv.crt -key srv.key -CAfile ca.crt -Verify 1 -www &
$ curl --cacert ca.crt https://localhost:8443/
$ curl --cacert ca.crt --cert cli.crt --key cli.key https://localhost:8443/
What you should see
The first curl fails during the handshake: -Verify 1 (capital V) makes the client certificate mandatory and none was sent. The second succeeds and returns the server's status page, and the s_server output shows the client chain being verified (depth=0 CN = orders, verify return:1). CN=orders is the identity a policy would use.
Recap
- TLS 1.3: ECDHE agrees keys (with forward secrecy), the certificate claims an identity, CertificateVerify proves possession of the key, Finished protects the handshake.
- mTLS adds CertificateRequest: the client proves its identity too. Use it for services, partners, agents and infrastructure; automate the certificates.
- mTLS identifies workloads, not users.
- Prefer re-encryption: inspect at the edge, encrypt and authenticate every hop after it.
This site is a public version of my personal engineering knowledge hub. It intentionally excludes confidential company information and internal operational details.