security: optional dialed-host check for gRPC server certificates (#12663)

* security: optionally check the dialed host against gRPC server certificates

verify_server_host under [grpc] or a [grpc.<component>] section switches
the client to certificate-and-host verification.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* scaffold: document verify_server_host

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Chris LuandClaude Opus 5.5 authored and GitHub committed 2026-11-15 12:38:37 -08:00
1 parent 799fd10342
commit d80e905fc7
3 files changed
+44 -1

No files matched your search

+5 -1
View File
@@ -78,7 +78,10 @@ expires_after_seconds = 10 # seconds
# gRPC mTLS configuration
# All gRPC TLS authentications are mutual (mTLS)
# The values for ca, cert, and key are paths to the certificate/key files
# The host name is not checked, so the certificate files can be shared
# The host name is not checked, so the certificate files can be shared.
# Set verify_server_host = true under [grpc] or a [grpc.<component>] section to
# require that a server certificate is valid for the host or IP that component
# dials, as the Rust volume server always does.
# Each [grpc.<component>] section also accepts optional client_cert/client_key,
# presented when that component dials other servers. Set them when your CA
# issues separate serverAuth-only and clientAuth-only certificates; when unset,
@@ -89,6 +92,7 @@ expires_after_seconds = 10 # seconds
# fatal: the component never falls back to plaintext.
[grpc]
ca = ""
verify_server_host = false
# Set wildcard domain for enable TLS authentication by common names
allowed_wildcard_domain = "" # .mycompany.com
# Optional allowlist a client checks the dialed server's certificate against:
+3
View File
@@ -245,6 +245,9 @@ func loadClientTLS(config *util.ViperProxy, component, targetComponent string) (
},
VerificationType: advancedtls.CertVerification,
}
if config.GetBool(component+".verify_server_host") || config.GetBool("grpc.verify_server_host") {
options.VerificationType = advancedtls.CertAndHostVerification
}
targetPrefix := ""
if targetComponent != component {
targetPrefix = strings.TrimPrefix(targetComponent, "grpc.") + "_"
+36
View File
@@ -178,6 +178,42 @@ func TestLoadClientTLSFallsBackToServingCert(t *testing.T) {
// A serverAuth-only cert presented as the client identity fails the peer's
// clientAuth EKU verification — the failure mode client_cert exists to fix.
func TestLoadClientTLSVerifyServerHost(t *testing.T) {
dir := t.TempDir()
ca := newTestCA(t, dir)
serverCert, serverKey := ca.issueWithSANs(t, dir, "seaweed-master", []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth}, []string{"master.invalid"}, nil)
clientCert, clientKey := ca.issue(t, dir, "client", []x509.ExtKeyUsage{x509.ExtKeyUsageClientAuth})
v := util.NewViperProxy(viper.New())
v.Set("grpc.ca", ca.file)
v.Set("grpc.master.cert", serverCert)
v.Set("grpc.master.key", serverKey)
v.Set("grpc.client.cert", clientCert)
v.Set("grpc.client.key", clientKey)
v.Set("grpc.client.allowed_server_commonNames", "seaweed-master")
addr := startTestGrpcServer(t, v, "grpc.master")
_, port, _ := net.SplitHostPort(addr)
byName := net.JoinHostPort("localhost", port)
if err := healthCheck(t, byName, LoadClientTLS(v, "grpc.client")); err != nil {
t.Fatalf("the dialed host is not checked by default: %v", err)
}
v.Set("grpc.verify_server_host", true)
if err := healthCheck(t, byName, LoadClientTLS(v, "grpc.client")); err == nil {
t.Fatal("expected a certificate for master.invalid to be rejected on a connection to localhost")
}
if err := healthCheck(t, addr, LoadClientTLS(v, "grpc.client")); err != nil {
t.Fatalf("the certificate's IP SAN matches the dialed address: %v", err)
}
v.Set("grpc.verify_server_host", false)
v.Set("grpc.client.verify_server_host", true)
if err := healthCheck(t, byName, LoadClientTLSForTarget(v, "grpc.client", "grpc.master")); err == nil {
t.Fatal("expected the component setting to check the dialed host")
}
}
func TestLoadClientTLSServerOnlyEkuRejected(t *testing.T) {
dir := t.TempDir()
ca := newTestCA(t, dir)