config: Verify client certificates on Gitaly and Praefect listeners

This relates to gitlab#634055, which it does not close, and is part of gitlab#634072. It replaces !9547 (closed), which @echui-gitlab asked to split. Patrick Steinhardt proposed client-side certificates to assert a client's identity.

The Gitaly and Praefect tls_listen_addr listeners can now verify client certificates. client_auth_mode takes none, verify_if_given or require, checked against client_ca_path, and defaults to none, so existing configurations behave as before.

Merge order: first of four, targeting master, and safe alone. Nothing presents a client certificate until the later MRs merge, so leave client_auth_mode at none or verify_if_given until then. require on a Gitaly node behind Praefect works once the Praefect outbound MR has merged. require on Praefect or on a standalone Gitaly node waits on every client that dials it presenting a certificate: Rails, Workhorse, gitlab-shell, the GitLab agent server for Kubernetes (KAS) and the Elasticsearch and Zoekt indexers, because those clients dial Praefect and standalone Gitaly directly, and a fork or storage move also needs !9556.

flowchart LR
  C["Client"] -->|"TLS handshake"| L["tls_listen_addr"]
  L -->|"none: no certificate asked for"| T["Token check"]
  L -->|"verify_if_given: a certificate, if sent, must chain to client_ca_path"| T
  L -->|"require: a certificate that chains to client_ca_path"| T
  T --> R["RPC"]
  X["listen_addr and the unix socket"] -.->|"not covered"| R
Claims, not in this MR, and operator notes

Code citations are at bf953ffb. Each test runs a client with and without a certificate, and none is the control.

  • Each mode maps to a Go verification mode, and ClientCAs holds only the file named by client_ca_path, never the system pool: internal/gitaly/config/config.go:404-423. Tests: TestTLS_configureClientAuth, TestTLS_configureClientAuth_unreadableCA, TestGitalyServerFactory_clientAuth (no certificate, wrong CA, trusted CA, all three modes), TestGitalyServerFactory_clientAuthCertificates (expired, not-yet-valid and server-only certificates are refused).
  • Gitaly applies it to its external listener at internal/gitaly/server/server.go:90, Praefect to its secure listener at internal/praefect/server_factory.go:75. The token check still runs afterward and sidechannels are checked too: TestGitalyServerFactory_clientAuthWithToken, TestGitalyServerFactory_clientAuthSidechannel.
  • Startup refuses require with a plaintext listen_addr, a verifying mode without tls_listen_addr, and a missing or unreadable CA: config.go:367, config.go:1454, internal/praefect/config/config.go:386. Tests: TestTLS_ValidateListeners, TestGitalyServerFactory_clientAuthPlaintextListener, TestGitalyServerFactory_clientAuthCAMissing, TestConfigValidation.
  • These run from Cfg.Validate (config.go:1231) as well as ValidateV2 (config.go:1281), because V2 failures only warn at startup (internal/cli/gitaly/serve.go:177). The settings are opt-in, so failing closed breaks no existing configuration. Tests: TestCfg_Validate_clientAuthListeners, TestCfg_ValidateV2_clientAuthListeners.
  • Measured before the split, on the combined branch 8f83d601 that carries this listener code unchanged: on a FIPS-mode host TestFIPSTLSHandshake (internal/gitaly/server/tls_fips_acceptance_test.go:46) passes 6 of 6, and on a Gitaly Cluster of one Praefect and two nodes a client certificate under require added about 201 µs to the handshake at p50, about 12%, against 4 to 11 µs between identical runs.
  • All 16 commits build and pass go vet, and none is flagged by the commit linter. On a private copy of this branch every job that runs by default passed, including verify and verify:docs. The manual jobs were not run.
  • Not here: presenting a certificate (the next three MRs), revocation, authorizing an identity beyond chaining to client_ca_path, the plaintext listener and unix socket, logging rejections, reloading the CA without a hup, and the TLS documentation page. A misspelled [tls] key is ignored like any unknown key. The mode is verify_if_given, where 634055 writes verify-if-given, to match the other [tls] keys. Rails (lib/gitlab/gitaly_client.rb:259 in gitlab-org/gitlab passes root CAs only), Workhorse and gitlab-shell present no certificate yet. With require on Praefect, startup refuses a plaintext listen_addr such as Omnibus GitLab's default localhost:2305.

An AI coding assistant wrote this change and ran the checks above on test VMs.

Edited by Andrew Dunn

Merge request reports

Loading
Loading