Skip to content

Add support for using HTTP TLS client cert

Stan Hu requested to merge sh-support-mutual-tls-http-client into master

What does this MR do?

Some customers need to configure mutual TLS authentication for Webhooks. This commit adds support for an instance-wide client certificate via two settings added in gitlab!140263 (merged):

gitlab_rails['http_client']['tls_client_cert_file'] = '/path/to/cert.pem'
gitlab_rails['http_client']['tls_client_cert_password'] = 'somepassword'

Related issues

How to set up and validate locally

You can test mutual TLS authentication via https://client.badssl.com/:

  1. Run gitlab-rails console.
  2. Run ::Gitlab::HTTP_V2.get('https://client.badssl.com'). This should fail:
irb(main):001:0> ::Gitlab::HTTP_V2.get('https://client.badssl.com')
=>
"<html>\r\n" +
"<head><title>400 No required SSL certificate was sent</title></head>\r\n" +
"<body bgcolor=\"white\">\r\n" +
"<center><h1>400 Bad Request</h1></center>\r\n" +
"<center>No required SSL certificate was sent</center>\r\n" +
"<hr><center>nginx/1.10.3 (Ubuntu)</center>\r\n" +
"</body>\r\n" +
"</html>\r\n"
  1. Download the client cert: curl -o /tmp/badssl.com-client.pem https://badssl.com/certs/badssl.com-client.pem
  2. In /etc/gitlab/gitlab.rb, add:
gitlab_rails['http_client']['tls_client_cert_file'] = '/tmp/badssl.com-client.pem'
gitlab_rails['http_client']['tls_client_cert_password'] = 'badssl.com'
  1. Run gitlab-ctl reconfigure.
  2. Repeat steps 1 and 2 again. This should succeed:
irb(main):001:0> ::Gitlab::HTTP_V2.get('https://client.badssl.com')
=>
"<!DOCTYPE html>\n" +
"<html>\n" +
"<head>\n" +
"  <meta charset=\"utf-8\">\n" +
"  <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n" +
"  <link rel=\"shortcut icon\" href=\"/icons/favicon-green.ico\"/>\n" +
"  <link rel=\"apple-touch-icon\" href=\"/icons/icon-green.png\"/>\n" +
"  <title>client.badssl.com</title>\n" +
"  <link rel=\"stylesheet\" href=\"/style.css\">\n" +
"  <style>body { background: green; }</style>\n" +
"</head>\n" +
"<body>\n" +
"<div id=\"content\">\n" +
"  <h1 style=\"font-size: 12vw;\">\n" +
"    client.<br>badssl.com\n" +
"  </h1>\n" +
"</div>\n" +
"\n" +
"<div id=\"footer\">\n" +
"  This site requires a <a href=\"https://en.wikipedia.org/wiki/Transport_Layer_Security#Client-authenticated_TLS_handshake\">client-authenticated</a> TLS handshake.\n" +
"</div>\n" +
"\n" +
"</body>\n" +
"</html>\n"

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 labeled "~workflow::ready for review" per the Distribution MR workflow.

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.
Edited by Stan Hu

Merge request reports