关于gitlab-ci-runner:gitlabrunner-x509-certificate-signed-by-unknown-authority

gitlab的单元测试依赖于gitlab-runnergitlab-runner的作用便是根本gitlab仓库相干的配置来运行单元测试(蕴含但不限于)并把单元测试的后果反馈给gitlab

所以如果咱们跑单元测试的环境是macos,则须要在一台macos主机上安装gitlab-runner;如果咱们跑单元测试的环境是ubuntu,则须要在一台ubuntu的主机上安装gitlab-runner

gitlab-runner装置实现后,须要将其注册到gitlab中,这样gitlab才会对其发动近程的调用。注册命令如下:

sudo gitlab-runner register --url https://yourGitLab.ServerDomainName.com --registration-token yourGitLabToken

但出于某些平安方面的起因,如果咱们的gitlab服务器的证书并不在拟运行单元测试主机的无效验证范畴,则会报一个如下谬误:

This solves the x509: certificate signed by unknown authority problem when registering a runner.

此时则须要咱们在运行注册命令时,手动的为其指定一个无效的证书。

解决方案

gitlab官网专门对这个问题进行了阐明。大略就是说咱们须要手动的为每个预注册的站点来指定相干的证书。

https的拜访过程中,浏览器会主动的为咱们下载证书并应用 CA 证书进行验证,但gitlab-runner并不会如此,所以咱们须要手动的帮忙一下它。

尽管gitlab的官网给出了几种解决方案,但试验证实将下载到的证书注册到操作系统上是最简略的计划。

步骤如下:

获取证书

如果跑gitlab服务的网站的证书就是你申请的,那么你自身就领有一个crt证书,能够略过此步,持续往下看。

如果咱们并不把握以后站点的证书,则能够应用openssl来将获取服务器的crt证书,该操作能够在运行gitlab-runner的测试机上进行,也能够在本人的电脑上进行:

openssl s_client -showcerts -connect gitlab.example.com:443(批改为你本人的域名及端口) < /dev/null 2>/dev/null | openssl x509 -outform PEM > ~/gitlab.example.com.crt(批改为本人的名字)

总之呢,咱们须要的是一个在gitlab站点上装置的crt证书。

注册证书

假如咱们按上一步的操作拿到了相干站点的证书,并且上传到了运行gitlab-runner的机器上。上面,咱们以ubuntu操作系统为例,介绍如何把这个证书全局的装置到操作系统。

yunzhi@yunzhi-virtual-machine:/etc/ca-certificates$ sudo apt-get install -y ca-certificates
[sudo] password for yunzhi: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
ca-certificates is already the newest version (20210119~20.04.2).
0 upgraded, 0 newly installed, 0 to remove and 160 not upgraded.
yunzhi@yunzhi-virtual-machine:~$ sudo cp gitlab.example.com.crt /usr/local/share/ca-certificates/
yunzhi@yunzhi-virtual-machine:/usr/local/share/ca-certificates$ sudo update-ca-certificates
Updating certificates in /etc/ssl/certs...
rehash: warning: skipping DigiCert-Global-Root-CA.pem,it does not contain exactly one certificate or CRL
1🥰 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d...
done.

🥰是要害,示意胜利增加了1个证书。

注册runner

证书增加实现后,便能够主动应用该证书实现注册了:

yunzhi@yunzhi-virtual-machine:~$ sudo gitlab-runner register
Runtime platform                                    arch=amd64 os=linux pid=813430 revision=f188edd7 version=14.9.1
Running in system-mode.                            
                                                   
Enter the GitLab instance URL (for example, https://gitlab.com/):
https://gitlab.example.com:8888/
Enter the registration token:
yourGitLabTokenHere
Enter a description for the runner:
[yunzhi-virtual-machine]: ubuntu
Enter tags for the runner (comma-separated):

Enter optional maintenance note for the runner:
 
Registering runner... succeeded                     runner=GR134894
Enter an executor: docker-ssh+machine, kubernetes, custom, docker, parallels, ssh, docker-ssh, shell, virtualbox, docker+machine:

至此gitlab-runner x509:谬误便被胜利解决掉了。

HTTPS原理和通信流程
gitlab官网:Self-signed certificates or custom Certification Authorities
Ubuntu官网:Installing a root CA certificate in the trust store

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理