Gitaly Go client package: present a client certificate on tls:// dials (Workhorse, GitLab Shell, Praefect, gitaly-backup, Gitaly-to-Gitaly)

Finding

No Go client of Gitaly presents a client certificate. Workhorse, GitLab Shell, Praefect, gitaly-backup, and Gitaly itself (cross-storage fetches, health checks, replication) dial through Gitaly's shared Go client package, which builds credentials.NewTLS with root CAs only. Once I-1 lands, these clients must present an identity or they will be rejected under client_auth = "require".

Standards

  • NIST SP 800-53 Rev. 5 IA-3(1) Cryptographic Bidirectional Authentication, IA-9 Service Identification and Authentication.
  • NIST SP 800-172 3.5.1e (CMMC Level 3, IA.L3-3.5.1e): the requirement applies explicitly to server-server authentication.
  • NSA CSI Application and Workload Pillar (May 2024): applications and workloads may need their own credentials, such as certificates, to authenticate to resources and other applications, scoped by least privilege.
  • DoD Zero Trust Capability Execution Roadmap v1.1: 2.1 Device Inventory (NPE/PKI, device under management), 2.3 Enterprise PKI.

Proposal

In the shared dial path for tls:// addresses, add a GetClientCertificate callback so the client presents a certificate when the server requests one. Two configuration routes, both supported:

  1. An explicit dial option (client.WithClientCertificate(certPath, keyPath) or a tls.Config option) for callers with their own configuration files (Praefect, Workhorse, GitLab Shell, gitaly-backup).
  2. Environment variables GITALY_CLIENT_CERT_PATH, GITALY_CLIENT_KEY_PATH, and GITALY_CLIENT_CA_PATH, read by the dial path when no explicit option is given. This enables every Go client across the stack in one change and lets enclave operators adopt mutual TLS before Omnibus (I-7) and chart (I-8) plumbing is complete.

Gitaly's own outbound dials (Gitaly-to-Gitaly over tls://, health checks) should default to presenting the process's own [tls] server key pair when no client pair is configured, so that I-1 require mode does not break cross-storage operations. Local hook invocations over the internal Unix socket are unaffected because they do not traverse tls_listen_addr.

Implementation sketch (file paths to be confirmed by maintainers)

// shared client dial path, tls:// branch
tlsCfg := &tls.Config{RootCAs: pool, MinVersion: tls.VersionTLS12}

certPath, keyPath := opts.clientCertPath, opts.clientKeyPath
if certPath == "" {
    certPath, keyPath = os.Getenv("GITALY_CLIENT_CERT_PATH"), os.Getenv("GITALY_CLIENT_KEY_PATH")
}
if certPath != "" && keyPath != "" {
    tlsCfg.GetClientCertificate = func(*tls.CertificateRequestInfo) (*tls.Certificate, error) {
        cert, err := tls.LoadX509KeyPair(certPath, keyPath) // re-read per handshake: rotation without restart
        if err != nil {
            return nil, fmt.Errorf("loading gitaly client key pair: %w", err)
        }
        return &cert, nil
    }
}
creds := credentials.NewTLS(tlsCfg)

GetClientCertificate re-reads the key pair on each new handshake and only sends a certificate when the server issues a CertificateRequest, so the change is inert against servers running I-1 in none mode.

Acceptance criteria

  • With I-1 in require mode, Workhorse clone/push, GitLab Shell SSH operations, Praefect replication and transactions, gitaly-backup, and Gitaly cross-storage fetches succeed when a client pair is configured, and fail closed with a clear error when it is not.
  • Both configuration routes are covered by tests.
  • Gitaly-to-Gitaly dials default to the process's own server key pair when no client pair is configured.
  • Rotation of the client key pair on disk takes effect on the next handshake without restart.
  • Sidechannel transfers (DialSidechannel) function under mutual TLS.
  • Depends on:
  • Blocks:
  • Tracked by:

Context

Impacts programs operating self-hosted GitLab at DoD Impact Levels 5 and 6 and under CMMC Level 3. Google Public Sector is co-affected.

Edited by 🤖 GitLab Bot 🤖