mTLS
Mutual TLS
Two-way TLS authentication. Both server and client verify certificates.
Mutual TLS
Two-way TLS authentication. Both server and client verify certificates.
mTLS (Mutual TLS) is an extension of standard TLS in which not only the server but also the client presents a certificate, performing two-way authentication. As a core component of zero trust architecture, it is widely used for communication between microservices.
In standard TLS, the client verifies only the server's certificate (HTTPS). In mTLS, the server also verifies the client's certificate, so only authorized clients can connect. Strong authentication is possible even without API keys or tokens.
In a Service Mesh (Istio, Linkerd), the sidecar proxy handles mTLS automatically. All traffic between services can be encrypted and authenticated without modifying application code.
Because certificate management becomes complex, it is common to automate it using cert-manager or Vault PKI. SPIFFE/SPIRE is a workload identity standard that automates certificate issuance and rotation in dynamic environments.
# Istio: PeerAuthentication์ผ๋ก mTLS ๊ฐ์
apiVersion: security.istio.io/v1beta1
kind: PeerAuthentication
metadata:
name: default
namespace: production
spec:
mtls:
mode: STRICT # mTLS ํ์
---
# Istio: DestinationRule๋ก mTLS ์ค์
apiVersion: networking.istio.io/v1beta1
kind: DestinationRule
metadata:
name: my-service
spec:
host: my-service.production.svc.cluster.local
trafficPolicy:
tls:
mode: ISTIO_MUTUAL # Istio๊ฐ ๋ฐ๊ธํ ์ธ์ฆ์ ์ฌ์ฉ
---
# Nginx: mTLS ์ค์
server {
listen 443 ssl;
# ์๋ฒ ์ธ์ฆ์
ssl_certificate /etc/nginx/certs/server.crt;
ssl_certificate_key /etc/nginx/certs/server.key;
# ํด๋ผ์ด์ธํธ ์ธ์ฆ์ ๊ฒ์ฆ (mTLS)
ssl_client_certificate /etc/nginx/certs/ca.crt;
ssl_verify_client on; # ํ์
ssl_verify_depth 2;
location / {
# ํด๋ผ์ด์ธํธ ์ธ์ฆ์ ์ ๋ณด๋ฅผ ๋ฐฑ์๋์ ์ ๋ฌ
proxy_set_header X-Client-Cert-DN $ssl_client_s_dn;
proxy_pass http://backend;
}
}
---
# Node.js: mTLS ํด๋ผ์ด์ธํธ
import https from 'https';
import fs from 'fs';
const options = {
hostname: 'api.example.com',
port: 443,
path: '/data',
method: 'GET',
// ํด๋ผ์ด์ธํธ ์ธ์ฆ์ (mTLS)
cert: fs.readFileSync('client.crt'),
key: fs.readFileSync('client.key'),
// ์๋ฒ CA ๊ฒ์ฆ
ca: fs.readFileSync('ca.crt'),
};
const req = https.request(options, (res) => {
console.log(`Status: ${res.statusCode}`);
});
---
# cert-manager: ์ธ์ฆ์ ์๋ ๋ฐ๊ธ
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
name: my-service-cert
namespace: production
spec:
secretName: my-service-tls
duration: 2160h # 90์ผ
renewBefore: 360h # ๋ง๋ฃ 15์ผ ์ ๊ฐฑ์
privateKey:
algorithm: ECDSA
size: 256
usages:
- server auth
- client auth # mTLS์ฉ
dnsNames:
- my-service.production.svc.cluster.local
issuerRef:
name: cluster-ca
kind: ClusterIssuer
Security: "If we apply mTLS to service-to-service communication, authentication happens at the network level, so the burden of managing API keys is reduced."
Development: "Managing certificate expiration seems like it will be difficult..."
Security: "You can just use cert-manager for automatic renewal. Or if you use Istio, the sidecar handles it for you."
Interviewer: "Please explain the difference between mTLS and standard TLS."
Candidate: "In standard TLS, the client verifies only the server certificate, which is one-way authentication. mTLS is two-way authentication in which the server also verifies the client's certificate, so only authorized clients can communicate. It is mainly used for service-to-service authentication in microservice environments and is central to zero trust architecture."
Take a mock interview on this topic โ WIA SOOM AI Interview ยท Start for free
Reviewer: "There's no logic in the mTLS setup to check the certificate expiration date. What happens if a request is made with an expired certificate?"
Author: "It gets rejected during the TLS handshake. But it would be good to add an alert for approaching expiration."