Setup HTTPS for Gitlab
From Bonus Bits
Contents
- 1 Purpose
- 2 Prerequisites
- 3 Change URL in Config File
- 4 Create Certificate Folder
- 5 Create Self-Signed Certificate (Option 1)
- 6 Create Trusted Certificate (Option 2)
- 7 Deploy Trusted SSL Cert to GitLab
- 8 Run Reconfiguration
- 9 Configure Firewall
- 10 Add CA Certificates
- 11 Troubleshooting
- 12 Related Articles
- 13 Sources
Purpose
This article gives the steps to setup a Self-Signed SSL/TLS HTTPS access to Gitlab and Gitlab CI omnibus setup. Example wrote for version 7.7.1.
Prerequisites
Change URL in Config File
sudo vim /etc/gitlab/gitlab.rb
external_url 'https://gitlab.domain.com'
Enable HTTP Redirect to HTTPS (Optional)
- For Gitlab site
-
nginx['redirect_http_to_https'] = true
-
- For Gitlab CI Site (Optional)
-
ci_nginx['redirect_http_to_https'] = true
-
Leave TCP Port 80 open on firewall/s to take advantage of this option.
Create Certificate Folder
sudo mkdir -p /etc/gitlab/ssl
sudo chmod 700 /etc/gitlab/ssl
Create Self-Signed Certificate (Option 1)
Create one set for Gitlab and optionally another set for Gitlab CI.
Generate Self-Signed SSL Certificate with OpenSSL
Create Trusted Certificate (Option 2)
HowTo: Generate Trusted SSL Certificate with OpenSSL
Deploy Trusted SSL Cert to GitLab
- Place the certificate here /etc/gitlab/ssl/gitlab.domain.com.crt
- Remove Certificate Request File
-
sudo rm -v /etc/gitlab/ssl/gitlab.domain.com.csr
-
- Set file permissions
-
sudo chmod 600 /etc/gitlab/ssl/gitlab.domain.com.*
-
Run Reconfiguration
- Run configuration wizard (Chef Solo Setup)
-
sudo gitlab-ctl reconfigure
-
- Restart Services
-
sudo gitlab-ctl restart
-
Configure Firewall
HTTPS TCP Port 443 Default Iptables Usage Here
Add CA Certificates
It may pop up a 500 error when you attempt to authorize Gitlab-CI to use your account. It is most likely because of an SSL verification error. To fix this for self-signed certificates, add the public cert to the system.
- Install the ca-certificates package
-
yum install ca-certificates
-
- Enable the dynamic CA configuration feature:
-
update-ca-trust enable
-
- Add it as a new file to /etc/pki/ca-trust/source/anchors/
-
cp /etc/gitlab/ssl/gitlab.domain.com.crt /etc/pki/ca-trust/source/anchors/
-
- Update Trust
-
update-ca-trust extract
-
Hack
sudo vim /opt/gitlab/embedded/service/gitlab-ci/app/controllers/user_sessions_controller.rb
def client
@client ||= ::OAuth2::Client.new(
GitlabCi.config.gitlab_server.app_id,
GitlabCi.config.gitlab_server.app_secret,
{
site: GitlabCi.config.gitlab_server.url,
authorize_url: '/oauth/authorize',
token_url: '/oauth/token',
ssl: {
verify: false
}
}
)
end
sudo gitlab-ctl restart
Troubleshooting
- Read through the Chef steps from the reconfigure starting at Recipe: gitlab::nginx
- Check that it's listening on 443
-
sudo netstat -tan | grep 443
-
- Look at nginx configuration results /var/opt/gitlab/nginx/conf/gitlab-http.conf
- Review Logs
-
sudo less /var/log/gitlab/nginx/gitlab_access.log
-
sudo less /var/log/gitlab/nginx/gitlab_error.log
-
Related Articles
- Install Gitlab on CentOS
- Install Gitlab CI on CentOS
- Setup LDAP on Gitlab
- Setup Access to First Project on Gitlab