Mutual TLS (mTLS) for Service-to-Service Auth
Secure gRPC service-to-service calls with mutual TLS, where both client and server present certificates to cryptographically prove their identity.
Mutual TLS (mTLS) for Service-to-Service Auth is a free gRPC & High Performance APIs lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the gRPC & High Performance APIs learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Beyond One-Way TLS
Standard TLS authenticates only the server to the client. In a zero-trust network, the server also needs to verify who is calling.
Mutual TLS (mTLS) makes both sides present certificates.
How mTLS Works
During the handshake:
- The server sends its certificate (as in normal TLS)
- The server then requests the client's certificate
- The client presents its cert and proves it holds the private key
- Each side validates the other against a trusted CA
The Role of the CA
A Certificate Authority (CA) signs both client and server certs. Each peer trusts the CA, so any cert signed by it is accepted. In service meshes an internal CA issues short-lived certs automatically.
Generating Certificates
For a test setup you create a CA, then sign a server cert and a client cert with it. Tools like openssl or cfssl produce the key/cert pairs.
openssl req -x509 -newkey rsa:4096 -keyout ca.key -out ca.crt -days 365 -nodesServer Side in Go
Configure the server's tls.Config to load its cert and require client certs verified against the CA pool.
cfg := &tls.Config{
Certificates: []tls.Certificate{serverCert},
ClientCAs: caPool,
ClientAuth: tls.RequireAndVerifyClientCert,
}
creds := credentials.NewTLS(cfg)Wiring the Server
Pass the TLS credentials when constructing the gRPC server so every connection is mutually authenticated.
s := grpc.NewServer(grpc.Creds(creds))Client Side in Go
The client presents its own certificate and trusts the CA to validate the server.
cfg := &tls.Config{
Certificates: []tls.Certificate{clientCert},
RootCAs: caPool,
}
conn, _ := grpc.Dial(addr, grpc.WithTransportCredentials(credentials.NewTLS(cfg)))Reading the Peer Identity
Once connected, the server can read the client's certificate from the connection's peer info and use the subject or SAN as an authenticated identity.
p, _ := peer.FromContext(ctx)
tlsInfo := p.AuthInfo.(credentials.TLSInfo)
name := tlsInfo.State.PeerCertificates[0].Subject.CommonNameCertificate Rotation
Certs expire. Production systems rotate them frequently using short lifetimes (hours/days). A sidecar or mesh control plane reloads new certs without restarting the service.
mTLS in Service Meshes
Meshes like Istio or Linkerd automate mTLS entirely: sidecar proxies handle the handshake, issue certs, and rotate them, so application code stays unchanged.
Common Pitfalls
Watch out for:
- Clock skew breaking cert validity checks
- Wrong CA pool causing handshake failures
- Mismatched SAN/hostname errors
- Forgetting
RequireAndVerifyClientCert(downgrades to one-way TLS)
Quick Check
Test your mTLS understanding.
Recap
You learned mutual TLS for gRPC:
- mTLS authenticates both client and server
- A shared CA signs and validates certificates
- Set
RequireAndVerifyClientCerton the server, present a client cert on the dial - Read peer identity from the verified certificate
- Rotate certs often; meshes automate the whole flow
Frequently asked questions
Is the “Mutual TLS (mTLS) for Service-to-Service Auth” lesson free?
Yes — the full text of “Mutual TLS (mTLS) for Service-to-Service Auth” is free to read here on the web, and the gRPC & High Performance APIs course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the gRPC & High Performance APIs course, upgrade to CoddyKit PRO.
What will I learn in “Mutual TLS (mTLS) for Service-to-Service Auth”?
Secure gRPC service-to-service calls with mutual TLS, where both client and server present certificates to cryptographically prove their identity. You practise gRPC & High Performance APIs with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start gRPC & High Performance APIs?
No prior experience is required. gRPC & High Performance APIs on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Mutual TLS (mTLS) for Service-to-Service Auth” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this gRPC & High Performance APIs lesson?
Yes. Every gRPC & High Performance APIs lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- TLS/SSL for gRPC
- Authentication and Authorization
- Interceptors for Security
- Mutual TLS (mTLS) for Service-to-Service Auth