gitlab-runner|gitlab-runner x509: certificate signed by unknown authority
gitlab
的单元测试依赖于gitlab-runner
,gitlab-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-runner|gitlab-runner x509: certificate signed by unknown authority】虽然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 platformarch=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... succeededrunner=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
推荐阅读
- 【Azure|【Azure Developer - 密钥保管库 】使用 Python Azure SDK 实现从 Azure Key Vault Certificate 中下载证书(PEM文件)
- window|the vmware client integration plugin has updated its ssl certificate in fire
- vue-cli · Failed to download repo vuejs-templates/webpack: unable to verifythe first certificate
- SSL: CERTIFICATE_VERIFY_FAILED
- Python使用requests模块访问HTTPS网站报错`certificate verify failed`
- certificate|解决windows7下 pycharm启动出现Server's certificate is not trusted提示框的问题
- hostname|HttpClient 访问Https报错hostname in certificate didn't match:
- HttpClient访问报错 javax.net.ssl.SSLException: hostname in certificate didn't match
- laravel|curl: (60) SSL certificate problem: unable to get local issuer certificate 错误
- java.security.cert.CertificateException: No name matching IP found