TLS mútuo (mTLS) para autenticação entre serviços
Proteja chamadas gRPC entre serviços com TLS mútuo, no qual cliente e servidor apresentam certificados para comprovar criptograficamente suas identidades.
TLS mútuo (mTLS) para autenticação entre serviços é uma aula grátis de gRPC & High Performance APIs no CoddyKit. Esta é a aula 4 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de gRPC & High Performance APIs, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de gRPC & High Performance APIs inclui 4 aulas no total.
Partes desta aula ainda não foram traduzidas e aparecem em inglês.
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
Perguntas Frequentes
A aula “TLS mútuo (mTLS) para autenticação entre serviços” é grátis?
Sim — o texto completo de “TLS mútuo (mTLS) para autenticação entre serviços” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de gRPC & High Performance APIs, atualize para CoddyKit PRO. O curso de gRPC & High Performance APIs inclui 4 aulas no total.
O que vou aprender em “TLS mútuo (mTLS) para autenticação entre serviços”?
Proteja chamadas gRPC entre serviços com TLS mútuo, no qual cliente e servidor apresentam certificados para comprovar criptograficamente suas identidades. Você pratica gRPC & High Performance APIs com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.
Preciso ter experiência prévia para começar gRPC & High Performance APIs?
Nenhuma experiência prévia é necessária. gRPC & High Performance APIs no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 4 de 4.
Quanto tempo leva a aula “TLS mútuo (mTLS) para autenticação entre serviços”?
A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.
Posso escrever e executar código nesta aula de gRPC & High Performance APIs?
Sim. Cada aula de gRPC & High Performance APIs inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.
Todas as aulas deste curso
- TLS/SSL para gRPC
- Autenticação e autorização
- Interceptadores para segurança
- TLS mútuo (mTLS) para autenticação entre serviços