Gitlab uses letsencrypt out of the box to automatically request and install SSL certificates. But this only works with public DNS records. Furthermore, letsencrypt will fail the validation check if your DNS record points to a private IP address.
Certbot can similarly be used to fetch SSL certificates, by confirming ownership of the domain. The good news is there isn't a similar validation problem with private IP space. In fact a public DNS record pointing to your host IP is not required at all. The only requirement for verifying domain ownership is creation of a specific TXT record. This is known as the manual method, and requires a specific command.
- You need certbot installed
- You need a public DNS zone you can create records on
Use this command syntax below, and replace the hostname with your own server hostname. This is the name you will use to connect to your Gitlab server.
- Install certbot on a server, it can be any server, not necessary your Gitlab server
- Run this command to start the process
certbot certonly --manual -d *.mydomain.com
OR
certbot certonly --manual --preferred-challenges dns -d *.mydomain.com
- Certbot will ask you questions, and eventually give you an output similar to
Please deploy a DNS TXT record under the name:
_acme-challenge.dnsif.ca.
with the following value:
vqcwGUeQVgpfu-D_TIgHobOZ44o7wUUsSpT9nJBKKs4
-
Create the TXT record on your public domain, as requested by certbot
-
Hit Enter to continue on certbot
-
Certbot will verify the DNS record and give you this output
Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/dnsif.ca/fullchain.pem
Key is saved at: /etc/letsencrypt/live/dnsif.ca/privkey.pem
This certificate expires on 2024-10-01.
These files will be updated when the certificate renews.
- Grab the 2 certificate files and copy them into your Gitlab server
/etc/letsencrypt/live/dnsif.ca/fullchain.pem
/etc/letsencrypt/live/dnsif.ca/privkey.pem
- Place the certificates in the following locations, replacing existing certificates
- sudo cp fullchain.pem /etc/gitlab/ssl/myhost.mydomain.com.crt
- sudo cp privkey.pem /etc/gitlab/ssl/myhost.mydomain.com.key
- Restart gitlab services
sudo gitlab-ctl restart
Your certificates are now installed.