0Pricing
gRPC & High Performance APIs · Lección

TLS mutuo (mTLS) para la autenticación entre servicios

Proteja las llamadas entre servicios gRPC con TLS mutuo, en el que tanto el cliente como el servidor presentan certificados para demostrar criptográficamente su identidad.

TLS mutuo (mTLS) para la autenticación entre servicios es una lección gratuita de gRPC & High Performance APIs en CoddyKit. Esta es la lección 4 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de gRPC & High Performance APIs, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de gRPC & High Performance APIs incluye 4 lecciones en total.

Partes de esta lección aún no han sido traducidas y se muestran en 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 -nodes

Server 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.CommonName

Certificate 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 RequireAndVerifyClientCert on the server, present a client cert on the dial
  • Read peer identity from the verified certificate
  • Rotate certs often; meshes automate the whole flow

Preguntas frecuentes

¿La lección «TLS mutuo (mTLS) para la autenticación entre servicios» es gratis?

Sí — el texto completo de «TLS mutuo (mTLS) para la autenticación entre servicios» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de gRPC & High Performance APIs, actualiza a CoddyKit PRO. El curso de gRPC & High Performance APIs incluye 4 lecciones en total.

¿Qué aprenderé en «TLS mutuo (mTLS) para la autenticación entre servicios»?

Proteja las llamadas entre servicios gRPC con TLS mutuo, en el que tanto el cliente como el servidor presentan certificados para demostrar criptográficamente su identidad. Practicas gRPC & High Performance APIs con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.

¿Necesito experiencia previa para empezar gRPC & High Performance APIs?

No se requiere experiencia previa. gRPC & High Performance APIs en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 4 de 4.

¿Cuánto tiempo toma la lección «TLS mutuo (mTLS) para la autenticación entre servicios»?

La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.

¿Puedo escribir y ejecutar código en esta lección de gRPC & High Performance APIs?

Sí. Cada lección de gRPC & High Performance APIs incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.

Todas las lecciones de este curso

  1. TLS/SSL para gRPC
  2. Autenticación y autorización
  3. Interceptores para la seguridad
  4. TLS mutuo (mTLS) para la autenticación entre servicios
← Volver a gRPC & High Performance APIs