gitaly: Present a client certificate on Gitaly outbound connections
This relates to gitlab#634060, which it does not close, and is part of gitlab#634072.
Gitaly now presents a client certificate on its outbound connections. The pair is client_certificate_path and client_key_path in [tls], separate from the listener's certificate_path and key_path, with no fallback to them. A half-set pair, an unreadable file, or a certificate whose extended key usage leaves out clientAuth stops startup and names the problem.
Merge order: third of four. It depends on !9555 (merged), which depends on !9554 (merged). It targets B's branch, zt/mtls-b-client, so its diff shows only its own 9 commits. It is safe alone, since an unset pair presents nothing. require on a Gitaly node behind Praefect works only once the Praefect outbound MR has merged. require 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 it directly, and a fork or storage move also needs this MR. The Praefect keys in [tls] validate here but take effect in D.
flowchart LR
G["Gitaly process"] -->|"connection pool, pair read at startup"| N["Other Gitaly nodes and Praefect"]
L["gitaly subcommands (hooks, pool, bundle-uri)"] -->|"pair from config.toml"| M["this node's own address, over TLS when tls_listen_addr is its only one"]
G -->|"paths in GITALY_TLS_CLIENT_CERT_FILE and _KEY_FILE"| S["gitaly-ssh, per run"]
S --> N
B["gitaly-backup, same variables per run"] --> NClaims, not in this MR, and operator notes
Code citations are at f718370e. Each test runs with and without the certificate against a server set to require.
- The keys and the loader:
internal/gitaly/config/config.go:276-281,541-562. A half-set or mismatched pair fails throughValidateClientSettings(:376), and so does a certificate whose extended key usage leaves out clientAuth (:440-446). The subcommands dial this node's own address,cfg.GetAddressWithScheme()(config.go:1638). Tests:TestTLS_Validate_clientCertificate,TestTLS_ClientCertificate. - The pool presents the pair, and an unreadable file stops startup:
internal/cli/gitaly/serve.go:791-817. Local subcommands do the same:internal/cli/gitaly/subcmd_pool.go:70-80. Tests:TestNewConnsPool,TestPoolSubcommand_ClientCertificate,TestHooksSubcommands_ClientCertificate,TestDial_clientCertificate. - gitaly-ssh receives paths, never key material:
internal/git/gitcmd/command_options.go:267-273,cmd/gitaly-ssh/main.go:144-154. Tests:TestWithInternalFetchWithSidechannel_clientCertificate,TestClientCertificate. gitaly-backup reads the same two variables, which the operator sets where it runs, and fails closed naming the variable:internal/cli/gitalybackup/pool.go:10-28,doc/gitaly-backup.md. Tests:TestCreateSubcommand_clientCertificate,TestRestoreSubcommand_clientCertificate. - All 9 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 the Praefect, race, PgBouncer and SHA-256 jobs. The manual jobs were not run. client_certificate_pathmust hold the leaf and any intermediates up to a CA in the server'sclient_ca_path. A leaf-only file issued by an intermediate sends no certificate when that path holds only the root, and the server fails the handshake as "certificate required". The pool's pair is read at startup and onhup, while gitaly-ssh and gitaly-backup read it on each run. Swapping in a pair the peer rejects fails CreateFork and the fetch step of ReplicateRepository at once, while the pool keeps the old pair untilhup. Replace both files together, thenhup.- Not here: Praefect's own dials (the last MR), restart-free rotation, and a client-side CA variable. The environment variable names differ from 634060's.
An AI coding assistant wrote this change and ran the checks above on test VMs.