Set Gitaly's internal API ca_path to its SSL_CERT_DIR

What does this MR do?

Gitaly's internal API client now trusts the certificates in /etc/gitlab/trusted-certs even when it runs without the service environment, as gitaly check does.

Problem

The Gitaly service runs with SSL_CERT_DIR=/opt/gitlab/embedded/ssl/certs/, where reconfigure links the certificates from /etc/gitlab/trusted-certs. The docs tell admins to run:

sudo -u git -- /opt/gitlab/embedded/bin/gitaly check /var/opt/gitlab/gitaly/config.toml

That command doesn't get the service environment, and Omnibus never sets [gitlab.http-settings] ca_path. So when the internal API uses a certificate from a CA in trusted-certs, the check fails while the service works:

Checking GitLab API access: ... error="Get \"https://gitlab-internal.test:8443/api/v4/internal/check\": tls: failed to verify certificate: x509: certificate signed by unknown authority"
FAILED

gitlab-shell has the same problem when sshd starts it, and solves it with gitlab_shell['ssl_cert_dir'].

Fix

Render Gitaly's [gitlab.http-settings] ca_path from Gitaly's own SSL_CERT_DIR env value, so the service and the check trust the same certificates. Because it's derived from gitaly['env'], an overridden SSL_CERT_DIR is followed too. ca_path takes a single directory, so it isn't set when SSL_CERT_DIR is a colon-separated list.

  • The default goes under whichever table is used: gitaly['configuration']['gitlab']['http-settings'] if set, otherwise gitlab_shell['http_settings']. As before, the Gitaly table replaces the gitlab-shell one.
  • A ca_path set in either table still takes precedence, and their other keys are kept.
  • The gitlab-shell configuration doesn't change.
  • Gitaly adds ca_path to the system certificate pool, so the service trusts the same CAs as before. gitaly check now trusts the trusted-certs CAs in addition to the OS store.

Test plan

On a GitLab 19.5.4 Linux package instance:

  1. Created a private CA, put it in /etc/gitlab/trusted-certs, served the internal API from bundled NGINX with a certificate from that CA, and set gitlab_rails['internal_api_url'] = 'https://gitlab-internal.test:8443'.
  2. Stock 19.5.4: the documented gitaly check command failed with x509: certificate signed by unknown authority. The same command with the service's SSL_CERT_DIR passed.
  3. Applied this change to /opt/gitlab/embedded/cookbooks and ran gitlab-ctl reconfigure: config.toml has ca_path = "/opt/gitlab/embedded/ssl/certs/" and the documented gitaly check passes with no extra environment.
  4. A git push through the private-CA internal API endpoint succeeded, with no x509 errors in the Gitaly log.

Specs: spec/chef/cookbooks/gitaly, spec/chef/cookbooks/praefect and spec/chef/cookbooks/gitlab/recipes/gitlab-shell_spec.rb pass (162 examples). Without the recipe change, the new and updated examples fail.

Checklist notes

  • Documentation: none needed. The documented gitaly check command now works as written.
  • GitLab QA: not added. The specs cover the rendered configuration, and the scenario needs a private-CA internal API endpoint.
  • GitLab Chart: not affected, this changes the Linux package cookbook only.
  • FIPS: Trigger:package:fips no longer exists (removed in b7cb856e1). The FIPS build is the manual Ubuntu-22.04-fips-branch job in the Trigger:ee-package child pipeline.

Closes gitaly#6487 (closed)

Checklist

See Definition of done.

For anything in this list which will not be completed, please provide a reason in the MR discussion.

Required

  • MR title and description are up to date, accurate, and descriptive.
  • MR targeting the appropriate branch.
  • Latest Merge Result pipeline is green.
  • When ready for review, MR is marked as ready (not a draft) and a reviewer is requested. Pick the reviewer suggested by the reviewer roulette, or one of the project maintainers.

For GitLab team members

If you don't have access to this, the reviewer should trigger these jobs for you during the review process.

  • The manual Trigger:ee-package jobs have a green pipeline running against latest commit.
  • If config/software or config/patches directories are changed, make sure the build-package-on-all-os job within the Trigger:ee-package downstream pipeline succeeded.
  • If you are changing anything SSL related, then the Trigger:package:fips manual job within the Trigger:ee-package downstream pipeline must succeed.
  • If CI configuration is changed, the branch must be pushed to dev.gitlab.org to confirm regular branch builds aren't broken.

Expected (please provide an explanation if not completing)

  • Test plan indicating conditions for success has been posted and passes.
  • Documentation created/updated.
  • Tests added.
  • Integration tests added to GitLab QA.
  • Equivalent MR/issue for the GitLab Chart opened.
  • Validate potential values for new configuration settings. Formats such as integer 10, duration 10s, URI scheme://user:passwd@host:port may require quotation or other special handling when rendered in a template and written to a configuration file.

Reviewer checklist

  • As soon as you begin reviewing, select Start a review on your first comment so the MR shows Reviewer started review.
Edited by Hossein Pursultani

Merge request reports

Loading
Loading