TLS reciproco (mTLS) per l'autenticazione tra servizi
Protegga le chiamate gRPC tra servizi con il TLS reciproco, in cui client e server presentano certificati per dimostrare crittograficamente la propria identità.
TLS reciproco (mTLS) per l'autenticazione tra servizi è una lezione gRPC & High Performance APIs gratuita su CoddyKit. Questa è la lezione 4 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento gRPC & High Performance APIs, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso gRPC & High Performance APIs include 4 lezioni in totale.
Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.
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
Domande Frequenti
La lezione «TLS reciproco (mTLS) per l'autenticazione tra servizi» è gratuita?
Sì — il testo completo di «TLS reciproco (mTLS) per l'autenticazione tra servizi» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso gRPC & High Performance APIs, passa a CoddyKit PRO. Il corso gRPC & High Performance APIs include 4 lezioni in totale.
Cosa imparerò in «TLS reciproco (mTLS) per l'autenticazione tra servizi»?
Protegga le chiamate gRPC tra servizi con il TLS reciproco, in cui client e server presentano certificati per dimostrare crittograficamente la propria identità. Eserciti gRPC & High Performance APIs con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.
Ho bisogno di esperienza per iniziare gRPC & High Performance APIs?
Non è richiesta alcuna esperienza precedente. gRPC & High Performance APIs su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 4 di 4.
Quanto tempo richiede la lezione «TLS reciproco (mTLS) per l'autenticazione tra servizi»?
La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.
Posso scrivere ed eseguire codice in questa lezione gRPC & High Performance APIs?
Sì. Ogni lezione gRPC & High Performance APIs include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.
Tutte le lezioni di questo corso
- TLS/SSL per gRPC
- Autenticazione e autorizzazione
- Interceptor per la sicurezza
- TLS reciproco (mTLS) per l'autenticazione tra servizi