0Pricing
gRPC & High Performance APIs · Lektion

Mutual TLS (mTLS) zur Service-zu-Service-Authentifizierung

Sichern Sie gRPC-Aufrufe zwischen Services mit Mutual TLS ab, bei dem Client und Server Zertifikate vorlegen, um ihre Identität kryptografisch nachzuweisen.

Mutual TLS (mTLS) zur Service-zu-Service-Authentifizierung ist eine kostenlose gRPC & High Performance APIs-Lektion auf CoddyKit. Dies ist Lektion 4 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des gRPC & High Performance APIs-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der gRPC & High Performance APIs-Kurs umfasst insgesamt 4 Lektionen.

Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.

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

Häufig gestellte Fragen

Ist die Lektion „Mutual TLS (mTLS) zur Service-zu-Service-Authentifizierung“ kostenlos?

Ja — der vollständige Text von „Mutual TLS (mTLS) zur Service-zu-Service-Authentifizierung“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des gRPC & High Performance APIs-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der gRPC & High Performance APIs-Kurs umfasst insgesamt 4 Lektionen.

Was lerne ich in „Mutual TLS (mTLS) zur Service-zu-Service-Authentifizierung“?

Sichern Sie gRPC-Aufrufe zwischen Services mit Mutual TLS ab, bei dem Client und Server Zertifikate vorlegen, um ihre Identität kryptografisch nachzuweisen. Du übst gRPC & High Performance APIs mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.

Brauche ich Erfahrung, um gRPC & High Performance APIs zu starten?

Keine Vorkenntnisse erforderlich. gRPC & High Performance APIs auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 4 von 4.

Wie lange dauert die Lektion „Mutual TLS (mTLS) zur Service-zu-Service-Authentifizierung“?

Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.

Kann ich in dieser gRPC & High Performance APIs-Lektion Code schreiben und ausführen?

Ja. Jede gRPC & High Performance APIs-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.

Alle Lektionen in diesem Kurs

  1. TLS/SSL für gRPC
  2. Authentifizierung und Autorisierung
  3. Interceptor für die Sicherheit
  4. Mutual TLS (mTLS) zur Service-zu-Service-Authentifizierung
← Zurück zu gRPC & High Performance APIs