Here is a video tutorial
Introduction
To use a domain name instead of an IP address in the .gitlab-ci.yml
pipeline in GitLab for cloning repositories, follow the steps below to configure your system accordingly.
Step-by-Step Guide
Adding SSH Key to User’s SSH Keys Section in GitLab
To ensure secure and proper access to your GitLab repository, follow these steps to remove the public ed25519 key from the project’s deploy keys section and add it to a user’s SSH keys section.
-
Remove the SSH Key from Deploy Keys:
-
Navigate to Your Project:
- Log in to your GitLab instance.
- Go to your project (e.g.,
https://gitlab.sysadmin.homes/developers/taiko
).
-
Access Deploy Keys:
- On the left sidebar, navigate to Settings > Repository.
- Scroll down to the Deploy Keys section.
-
Remove the Public Key:
- Find the SSH key (ed25519.pub) you want to remove.
- Click the Delete button next to the key to remove it from the deploy keys.
-
-
Add the SSH Key to a User’s SSH Keys:
-
Access User Settings:
- Click on your avatar in the top right corner of the GitLab interface.
- Select Settings from the dropdown menu.
-
Navigate to SSH Keys:
- In the user settings menu, click on SSH Keys in the left sidebar.
-
Add the Public Key:
- Copy the content of your
ed25519.pub
key. You can find this key on your local machine, typically located in the~/.ssh/
directory.
1
cat ~/.ssh/id_ed25519.pub
- Paste the copied key into the Key field.
- Add a descriptive Title for the key to help identify it later.
- Click the Add key button to save it.
- Copy the content of your
-
-
Verify the SSH Key:
After adding the SSH key, verify that it has been added correctly:
- List SSH Keys:
- In the SSH Keys section of your user settings, ensure that the new key appears in the list.
- List SSH Keys:
By removing the public ed25519 key from the project’s deploy keys and adding it to your GitLab user’s SSH keys section, you enhance security and ensure that the key is associated with a specific user rather than being accessible as a deploy key. This method is more secure and provides better control over access to your repositories.
-
Install OpenSSL (if not already installed):
Ensure
openssl
is installed on your machine. If not, install it using the package manager of your distribution.1 2
sudo apt-get update sudo apt-get install openssl
-
Download the Certificate:
Use the
openssl
command to connect to your GitLab server and retrieve the certificate. Replacegitlab.sysadmin.homes
with your GitLab server’s domain.1
echo -n | openssl s_client -connect gitlab.sysadmin.homes:443 -servername gitlab.sysadmin.homes | openssl x509 > gitlab.crt
This command will create a file named
gitlab.crt
in your current directory containing the server’s certificate. -
Verify the Certificate:
Verify the downloaded certificate using the following command:
1
openssl x509 -in gitlab.crt -text -noout
This will print out the details of the certificate, allowing you to ensure it is the correct one.
-
Copy the Certificate to the Trusted Store:
Move the downloaded certificate to the system’s trusted certificate directory and update the CA certificates:
1 2
sudo cp gitlab.crt /usr/local/share/ca-certificates/gitlab.crt sudo update-ca-certificates
-
Test Connection to GitLab Server from GitLab Runner:
From gitlab-runner command line, test the SSH access to ensure it works correctly:
1 2
ssh -i ~/.ssh/id_ed25519 -T git@gitlab.sysadmin.homes ssh -T git@gitlab.sysadmin.homes
-
Unregister the Runner:
Unregister the GitLab runner:
1
sudo gitlab-runner unregister --all-runners
-
Navigate to Your Project:
- Log in to your GitLab instance.
- Go to your project (e.g.,
https://gitlab.sysadmin.homes/developers/taiko
).
- Access Continuous Integration/Continuous Development Settings:
- On the left sidebar, navigate to Settings > Continuous Integration/Continuous Development.
- Scroll down to the Runners section.
- Remove the GitLab Runner:
- In the Runners section, find the runner you want to remove.
- Click on the Edit button next to the runner to view its details.
- At the bottom of the runner’s details page, click the Delete button to remove the runner from the project.
- Add a New Runner:
- Under the Available specific runners section, you will see an Add Runner button. Click on it.
- Fill in Runner Details:
- A form will appear where you need to provide details for the new runner.
- Description: Enter a description for the runner (e.g.,
docker-runner
). - Tags: Add tags to identify the runner (e.g.,
docker
,linux
). - Run untagged jobs: Enable or disable this option based on your preference.
- Locked: Choose whether to lock the runner to the current project or not.
- Generate and Copy Registration Token:
- After filling in the details, click on the Register Runner button.
- A registration token will be generated. Copy this token as you will need it for the runner registration.
- Register the Runner Again:
With the certificate now trusted, attempt to register the GitLab runner again:
|
|
- Modify
config.toml
Again:
Edit the file /etc/gitlab-runner/config.toml
with the below command:
|
|
Ensure the entry contains: tags = ["docker"]
, privileged = true
, and services_limit = 1
.
The configuration should look similar to this:
|
|
Summary
By downloading the certificate from your GitLab server and adding it to your system’s trusted certificates, you can resolve the certificate verification issue and successfully register your GitLab runner.
Modified .gitlab-ci.yml file
The modified .gitlab-ci.yml
file includes the necessary steps to add the entry to /etc/hosts
and to download and install the SSL certificate on Alpine Linux inside the before_script
section.
|
|
In this updated .gitlab-ci.yml
, the before_script
section includes the necessary steps to add the entry to /etc/hosts
and to download and install the SSL certificate for the GitLab server on an Alpine-based Docker container. This ensures that the GitLab Runner can properly connect to your GitLab server during the job execution. Adding [[ -f /.dockerenv ]] && echo -e “Host *StrictHostKeyChecking no” > ~/.ssh/config should disable host key checking for SSH connections, which may help solve the access problem.