Mutual TLS Design
Both sides prove their identity with certificates -- the server authenticates to the
client and the client authenticates to the server, establishing a cryptographically
verified service-to-service channel
When to Use
- Authenticating services to each other in a microservices architecture
- Implementing zero trust networking where network location is not sufficient for trust
- Replacing API keys or shared secrets for service-to-service communication
- Deploying a service mesh (Istio, Linkerd, Cilium) with automatic mTLS
- Building internal PKI for workload identity
- Meeting compliance requirements for encrypted and authenticated internal traffic
Threat Context
Standard TLS authenticates only the server -- the client verifies the server's
certificate, but the server has no cryptographic proof of the client's identity. In
service-to-service communication, this means any service on the network can call any other
service. API keys or bearer tokens add authentication but are static, shared, and
vulnerable to theft -- a stolen API key grants access until someone notices and rotates
it, which can be weeks or months. mTLS provides mutual cryptographic authentication: each
service has its own certificate issued by a trusted CA, and both sides verify the other's
identity during the TLS handshake. The 2017 Equifax breach exploited flat internal
networking with no service authentication -- internal services trusted any connection from
the internal network, allowing the attacker to move laterally through 48 databases after
exploiting a single Apache Struts vulnerability.
Instructions
Deploy an internal CA. Use Vault PKI, step-ca (Smallstep), cfssl, or a service
mesh's built-in CA. Do not use Let's Encrypt for internal mTLS -- Let's Encrypt
certificates are publicly trusted, intended for public-facing services, and require
public domain names. Internal CAs issue certificates trusted only within your
organization's trust store. This limits the blast radius of CA compromise and allows
you to issue certificates for internal service names that are not publicly resolvable.
Issue short-lived certificates. 24-72 hour certificate lifetimes eliminate the need
for revocation infrastructure. If a certificate is compromised, it expires within hours
rather than remaining valid for months. Automate certificate rotation with cert-manager
(Kubernetes), Vault Agent, or the service mesh's automatic certificate rotation. The
operational cost of short-lived certificates is higher, but the security benefit is
decisive: revocation (CRLs, OCSP) is complex, unreliable, and can be bypassed. Short
lifetimes make revocation unnecessary.
Use SPIFFE for workload identity. SPIFFE (Secure Production Identity Framework for
Everyone) standardizes workload identity as a URI:
spiffe://cluster.local/ns/production/sa/payment-service. SPIRE (the reference
implementation) acts as a workload attestation agent that verifies workload identity
using platform-specific selectors (Kubernetes service account, AWS instance metadata,
Docker container ID) and issues SVID (SPIFFE Verifiable Identity Document) certificates.
Service meshes (Istio, Linkerd) implement SPIFFE-compatible identity natively.
Configure certificate validation correctly. Both client and server must validate
the peer's certificate: verify the certificate chain (signed by a trusted CA), verify
the certificate is not expired, verify the SAN (Subject Alternative Name) matches the
expected service identity. Do not disable certificate verification in production --
ever. InsecureSkipVerify: true (Go), rejectUnauthorized: false (Node.js),
verify=False (Python requests) all defeat the entire purpose of mTLS by accepting
any certificate, including attacker-generated ones.
Enforce mTLS at the network level. In Kubernetes, use PeerAuthentication policies
(Istio) or NetworkPolicy with identity selectors (Cilium) to ensure that only mTLS
connections are accepted. Istio's STRICT mode rejects any plaintext connection to the
service. This prevents accidental fallback to unencrypted communication and ensures
that no service can communicate without presenting a valid identity certificate.
Handle the migration from plaintext to mTLS. In brownfield environments with
existing services communicating over plaintext, deploy mTLS in PERMISSIVE mode first
(accept both plaintext and mTLS). Monitor which services are still sending plaintext
using service mesh telemetry. Migrate them one by one, verifying each migration. Once
all services use mTLS, switch to STRICT mode. Istio's PeerAuthentication supports
per-namespace and per-service PERMISSIVE/STRICT configuration for gradual rollout.
Details
mTLS Handshake
The full TLS handshake with mutual authentication proceeds as follows:
- Client sends ClientHello (supported cipher suites, TLS version)
- Server responds with ServerHello, Server Certificate, and CertificateRequest
- Client verifies the server's certificate against its trust store
- Client sends its own Client Certificate and CertificateVerify message
- The CertificateVerify contains a signature over the handshake transcript, proving the
client possesses the private key corresponding to its certificate
- Server verifies the client's certificate against its trust store
- Both sides derive session keys and the encrypted channel is established
The critical difference from standard TLS is step 2 (CertificateRequest) and steps 4-6.
Without the CertificateRequest, the client never presents a certificate and the server
has no cryptographic proof of the client's identity.
Service Mesh mTLS
In Istio, Envoy sidecar proxies handle mTLS transparently. The application sends
plaintext to localhost on a designated port. The local Envoy sidecar intercepts the
outbound connection, establishes an mTLS connection to the destination's Envoy sidecar,
and forwards the traffic. The destination sidecar decrypts and delivers plaintext to the
destination application. No application code changes are required. Linkerd uses a similar
sidecar architecture with its own proxy (linkerd2-proxy, written in Rust). Cilium uses
eBPF to implement mTLS more efficiently without sidecars, reducing the per-pod resource
overhead.
SPIFFE/SPIRE Deep Dive
SPIRE has two components: the SPIRE Server (central authority that maintains the signing
CA, registration entries, and trust bundles) and the SPIRE Agent (runs on each node,
attests workloads, caches and distributes SVIDs). Workload attestation uses
platform-specific selectors: Kubernetes service account name and namespace, Docker
container labels, AWS instance ID and IAM role, bare-metal process UID and binary path.
This ensures that only the legitimate workload receives the certificate for its identity.
An attacker who compromises the host but not the workload's attestation properties cannot
obtain a valid SVID.
Debugging mTLS Failures
Common failure modes and their diagnostics:
| Symptom |
Likely Cause |
Diagnostic Command |
| Connection refused |
STRICT mode, client has no certificate |
Check PeerAuthentication policy |
| TLS handshake error |
Certificate not signed by trusted CA |
openssl s_client -cert ... -key ... |
| Identity mismatch |
SAN does not match expected identity |
openssl x509 -text -in cert.pem |
| Intermittent failures |
Certificate expired, clock skew |
Check system time, certificate validity |
| Works from one pod, not another |
Missing sidecar injection |
istioctl authn tls-check |
Anti-Patterns
InsecureSkipVerify: true in production. This disables certificate validation,
meaning any certificate (self-signed, expired, wrong identity) is accepted. This
provides encryption but zero authentication. A man-in-the-middle with any certificate
can intercept all traffic. This single line of code negates the entire mTLS deployment.
Long-lived client certificates. Certificates with 1-year lifetimes require
revocation infrastructure (CRLs, OCSP) that is complex and unreliable in practice. CRL
checking is best-effort in most TLS implementations, and OCSP has soft-fail behavior.
Use short-lived certificates (24-72 hours) with automatic rotation instead.
Sharing client certificates across services. If all services use the same client
certificate and private key, you cannot distinguish between services at the
authorization layer and cannot implement per-service access control. Each service must
have its own unique identity certificate. Sharing certificates also means that
compromising one service compromises the identity of all services.
mTLS without authorization. mTLS proves identity but does not enforce
authorization. After verifying the client's certificate identity (e.g.,
payment-service), you still need to check whether payment-service is authorized to
access the requested endpoint. Use service mesh authorization policies (Istio
AuthorizationPolicy, Cilium NetworkPolicy) to define which services can call which
endpoints.
Manual certificate distribution. Copying certificates to servers via SSH, baking
them into Docker images, or storing them in environment variables does not scale and
leads to expiration outages. Automate certificate lifecycle with SPIRE, cert-manager,
Vault Agent, or service mesh automatic rotation. If a human is involved in certificate
distribution, it will eventually fail.
1---2name: security-mtls-design3description: Mutual TLS Design4metadata:5 source: https://skillmd.com/skills/intense-visions/security-mtls-design6---7# Mutual TLS Design89> Both sides prove their identity with certificates -- the server authenticates to the10> client and the client authenticates to the server, establishing a cryptographically11> verified service-to-service channel1213## When to Use1415- Authenticating services to each other in a microservices architecture16- Implementing zero trust networking where network location is not sufficient for trust17- Replacing API keys or shared secrets for service-to-service communication18- Deploying a service mesh (Istio, Linkerd, Cilium) with automatic mTLS19- Building internal PKI for workload identity20- Meeting compliance requirements for encrypted and authenticated internal traffic2122## Threat Context2324Standard TLS authenticates only the server -- the client verifies the server's25certificate, but the server has no cryptographic proof of the client's identity. In26service-to-service communication, this means any service on the network can call any other27service. API keys or bearer tokens add authentication but are static, shared, and28vulnerable to theft -- a stolen API key grants access until someone notices and rotates29it, which can be weeks or months. mTLS provides mutual cryptographic authentication: each30service has its own certificate issued by a trusted CA, and both sides verify the other's31identity during the TLS handshake. The 2017 Equifax breach exploited flat internal32networking with no service authentication -- internal services trusted any connection from33the internal network, allowing the attacker to move laterally through 48 databases after34exploiting a single Apache Struts vulnerability.3536## Instructions37381. **Deploy an internal CA.** Use Vault PKI, step-ca (Smallstep), cfssl, or a service39 mesh's built-in CA. Do not use Let's Encrypt for internal mTLS -- Let's Encrypt40 certificates are publicly trusted, intended for public-facing services, and require41 public domain names. Internal CAs issue certificates trusted only within your42 organization's trust store. This limits the blast radius of CA compromise and allows43 you to issue certificates for internal service names that are not publicly resolvable.44452. **Issue short-lived certificates.** 24-72 hour certificate lifetimes eliminate the need46 for revocation infrastructure. If a certificate is compromised, it expires within hours47 rather than remaining valid for months. Automate certificate rotation with cert-manager48 (Kubernetes), Vault Agent, or the service mesh's automatic certificate rotation. The49 operational cost of short-lived certificates is higher, but the security benefit is50 decisive: revocation (CRLs, OCSP) is complex, unreliable, and can be bypassed. Short51 lifetimes make revocation unnecessary.52533. **Use SPIFFE for workload identity.** SPIFFE (Secure Production Identity Framework for54 Everyone) standardizes workload identity as a URI:55 `spiffe://cluster.local/ns/production/sa/payment-service`. SPIRE (the reference56 implementation) acts as a workload attestation agent that verifies workload identity57 using platform-specific selectors (Kubernetes service account, AWS instance metadata,58 Docker container ID) and issues SVID (SPIFFE Verifiable Identity Document) certificates.59 Service meshes (Istio, Linkerd) implement SPIFFE-compatible identity natively.60614. **Configure certificate validation correctly.** Both client and server must validate62 the peer's certificate: verify the certificate chain (signed by a trusted CA), verify63 the certificate is not expired, verify the SAN (Subject Alternative Name) matches the64 expected service identity. Do not disable certificate verification in production --65 ever. `InsecureSkipVerify: true` (Go), `rejectUnauthorized: false` (Node.js),66 `verify=False` (Python requests) all defeat the entire purpose of mTLS by accepting67 any certificate, including attacker-generated ones.68695. **Enforce mTLS at the network level.** In Kubernetes, use PeerAuthentication policies70 (Istio) or NetworkPolicy with identity selectors (Cilium) to ensure that only mTLS71 connections are accepted. Istio's STRICT mode rejects any plaintext connection to the72 service. This prevents accidental fallback to unencrypted communication and ensures73 that no service can communicate without presenting a valid identity certificate.74756. **Handle the migration from plaintext to mTLS.** In brownfield environments with76 existing services communicating over plaintext, deploy mTLS in PERMISSIVE mode first77 (accept both plaintext and mTLS). Monitor which services are still sending plaintext78 using service mesh telemetry. Migrate them one by one, verifying each migration. Once79 all services use mTLS, switch to STRICT mode. Istio's PeerAuthentication supports80 per-namespace and per-service PERMISSIVE/STRICT configuration for gradual rollout.8182## Details8384### mTLS Handshake8586The full TLS handshake with mutual authentication proceeds as follows:87881. Client sends ClientHello (supported cipher suites, TLS version)892. Server responds with ServerHello, Server Certificate, and CertificateRequest903. Client verifies the server's certificate against its trust store914. Client sends its own Client Certificate and CertificateVerify message925. The CertificateVerify contains a signature over the handshake transcript, proving the93 client possesses the private key corresponding to its certificate946. Server verifies the client's certificate against its trust store957. Both sides derive session keys and the encrypted channel is established9697The critical difference from standard TLS is step 2 (CertificateRequest) and steps 4-6.98Without the CertificateRequest, the client never presents a certificate and the server99has no cryptographic proof of the client's identity.100101### Service Mesh mTLS102103In Istio, Envoy sidecar proxies handle mTLS transparently. The application sends104plaintext to localhost on a designated port. The local Envoy sidecar intercepts the105outbound connection, establishes an mTLS connection to the destination's Envoy sidecar,106and forwards the traffic. The destination sidecar decrypts and delivers plaintext to the107destination application. No application code changes are required. Linkerd uses a similar108sidecar architecture with its own proxy (linkerd2-proxy, written in Rust). Cilium uses109eBPF to implement mTLS more efficiently without sidecars, reducing the per-pod resource110overhead.111112### SPIFFE/SPIRE Deep Dive113114SPIRE has two components: the SPIRE Server (central authority that maintains the signing115CA, registration entries, and trust bundles) and the SPIRE Agent (runs on each node,116attests workloads, caches and distributes SVIDs). Workload attestation uses117platform-specific selectors: Kubernetes service account name and namespace, Docker118container labels, AWS instance ID and IAM role, bare-metal process UID and binary path.119This ensures that only the legitimate workload receives the certificate for its identity.120An attacker who compromises the host but not the workload's attestation properties cannot121obtain a valid SVID.122123### Debugging mTLS Failures124125Common failure modes and their diagnostics:126127| Symptom | Likely Cause | Diagnostic Command |128| ------------------------------- | -------------------------------------- | --------------------------------------- |129| Connection refused | STRICT mode, client has no certificate | Check PeerAuthentication policy |130| TLS handshake error | Certificate not signed by trusted CA | `openssl s_client -cert ... -key ...` |131| Identity mismatch | SAN does not match expected identity | `openssl x509 -text -in cert.pem` |132| Intermittent failures | Certificate expired, clock skew | Check system time, certificate validity |133| Works from one pod, not another | Missing sidecar injection | `istioctl authn tls-check` |134135## Anti-Patterns1361371. **`InsecureSkipVerify: true` in production.** This disables certificate validation,138 meaning any certificate (self-signed, expired, wrong identity) is accepted. This139 provides encryption but zero authentication. A man-in-the-middle with any certificate140 can intercept all traffic. This single line of code negates the entire mTLS deployment.1411422. **Long-lived client certificates.** Certificates with 1-year lifetimes require143 revocation infrastructure (CRLs, OCSP) that is complex and unreliable in practice. CRL144 checking is best-effort in most TLS implementations, and OCSP has soft-fail behavior.145 Use short-lived certificates (24-72 hours) with automatic rotation instead.1461473. **Sharing client certificates across services.** If all services use the same client148 certificate and private key, you cannot distinguish between services at the149 authorization layer and cannot implement per-service access control. Each service must150 have its own unique identity certificate. Sharing certificates also means that151 compromising one service compromises the identity of all services.1521534. **mTLS without authorization.** mTLS proves identity but does not enforce154 authorization. After verifying the client's certificate identity (e.g.,155 `payment-service`), you still need to check whether `payment-service` is authorized to156 access the requested endpoint. Use service mesh authorization policies (Istio157 AuthorizationPolicy, Cilium NetworkPolicy) to define which services can call which158 endpoints.1591605. **Manual certificate distribution.** Copying certificates to servers via SSH, baking161 them into Docker images, or storing them in environment variables does not scale and162 leads to expiration outages. Automate certificate lifecycle with SPIRE, cert-manager,163 Vault Agent, or service mesh automatic rotation. If a human is involved in certificate164 distribution, it will eventually fail.