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.tomlThat 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"
FAILEDgitlab-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, otherwisegitlab_shell['http_settings']. As before, the Gitaly table replaces the gitlab-shell one. - A
ca_pathset in either table still takes precedence, and their other keys are kept. - The gitlab-shell configuration doesn't change.
- Gitaly adds
ca_pathto the system certificate pool, so the service trusts the same CAs as before.gitaly checknow trusts the trusted-certs CAs in addition to the OS store.
Test plan
On a GitLab 19.5.4 Linux package instance:
- 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 setgitlab_rails['internal_api_url'] = 'https://gitlab-internal.test:8443'. - Stock 19.5.4: the documented
gitaly checkcommand failed withx509: certificate signed by unknown authority. The same command with the service'sSSL_CERT_DIRpassed. - Applied this change to
/opt/gitlab/embedded/cookbooksand rangitlab-ctl reconfigure:config.tomlhasca_path = "/opt/gitlab/embedded/ssl/certs/"and the documentedgitaly checkpasses with no extra environment. - A
git pushthrough 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 checkcommand 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:fipsno longer exists (removed inb7cb856e1). The FIPS build is the manualUbuntu-22.04-fips-branchjob in theTrigger:ee-packagechild pipeline.
Related issues
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-packagejobs have a green pipeline running against latest commit.- To debug QA failures, refer to the Investigate QA failures section.
- If
config/softwareorconfig/patchesdirectories are changed, make sure thebuild-package-on-all-osjob within theTrigger:ee-packagedownstream pipeline succeeded. - If you are changing anything SSL related, then the
Trigger:package:fipsmanual job within theTrigger:ee-packagedownstream pipeline must succeed. - If CI configuration is changed, the branch must be pushed to
dev.gitlab.orgto 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, duration10s, URIscheme://user:passwd@host:portmay 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.