简体   繁体   English

Gitlab-CI runner:忽略自签名证书

[英]Gitlab-CI runner: ignore self-signed certificate

gitlab-ci-multi-runner register

gave me给我

couldn't execute POST against https://xxxx/ci/api/v1/runners/register.json:
Post https://xxxx/ci/api/v1/runners/register.json: 
x509: cannot validate certificate for xxxx because it doesn't contain any IP SANs

Is there a way to disable certification validation?有没有办法禁用认证验证?

I'm using Gitlab 8.13.1 and gitlab-ci-multi-runner 1.11.2.我正在使用 Gitlab 8.13.1 和 gitlab-ci-multi-runner 1.11.2。

Based on Wassim's answer, and gitlab documentation about tls-self-signed and custom CA-signed certificates , here's to save some time if you're not the admin of the gitlab server but just of the server with the runners (and if the runner is run as root):根据 Wassim 的回答以及有关 tls 自签名和自定义 CA 签名证书的 gitlab 文档,如果您不是 gitlab 服务器的管理员,而只是具有运行程序的服务器的管理员(如果运行程序以 root 身份运行):

SERVER=gitlab.example.com
PORT=443
CERTIFICATE=/etc/gitlab-runner/certs/${SERVER}.crt

# Create the certificates hierarchy expected by gitlab
sudo mkdir -p $(dirname "$CERTIFICATE")

# Get the certificate in PEM format and store it
openssl s_client -connect ${SERVER}:${PORT} -showcerts </dev/null 2>/dev/null | sed -e '/-----BEGIN/,/-----END/!d' | sudo tee "$CERTIFICATE" >/dev/null

# Register your runner
gitlab-runner register --tls-ca-file="$CERTIFICATE" [your other options]

Update 1: CERTIFICATE must be an absolute path to the certificate file.更新 1: CERTIFICATE必须是证书文件的绝对路径。

Update 2 : it might still fail with custom CA-signed because of gitlab-runner bug #2675更新 2 :由于gitlab-runner 错误 #2675 ,自定义 CA 签名可能仍然失败

In my case I got it working by adding the path to the .pem file as following:在我的情况下,我通过将路径添加到 .pem 文件来使其工作,如下所示:

sudo gitlab-runner register --tls-ca-file /my/path/gitlab/gitlab.myserver.com.pem

Often, gitlab-runners are hosted in a docker container.通常,gitlab-runners 托管在 docker 容器中。 In that case, one needs to make sure that the tls-ca-file is available in the container.在这种情况下,需要确保tls-ca-file在容器中可用。

Ok I followed step by step this post http://moonlightbox.logdown.com/posts/2016/09/12/gitlab-ci-runner-register-x509-error and then it worked like a charm.好的,我一步一步地跟随这篇文章http://moonlightbox.logdown.com/posts/2016/09/12/gitlab-ci-runner-register-x509-error然后它就像一个魅力。 To prevent dead link I copy the steps below:为了防止死链接,我复制以下步骤:

First edit ssl configuration on the GitLab server (not the runner)首先在 GitLab 服务器(不是运行程序)上编辑 ssl 配置

vim /etc/pki/tls/openssl.cnf

[ v3_ca ]
subjectAltName=IP:192.168.1.1 <---- Add this line. 192.168.1.1 is your GitLab server IP.

Re-generate self-signed certificate重新生成自签名证书

cd /etc/gitlab/ssl
sudo openssl req -x509 -nodes -days 3650 -newkey rsa:2048 -keyout /etc/gitlab/ssl/192.168.1.1.key -out /etc/gitlab/ssl/192.168.1.1.crt
sudo openssl dhparam -out /etc/gitlab/ssl/dhparam.pem 2048
sudo gitlab-ctl restart

Copy the new CA to the GitLab CI runner将新 CA 复制到 GitLab CI runner

scp /etc/gitlab/ssl/192.168.1.1.crt root@192.168.1.2:/etc/gitlab-runner/certs

Thanks @Moon Light @Wassim Dhif谢谢@Moon Light @Wassim Dhif

Currently there is no possibility to run the multi runner with an insecure ssl option.目前无法使用不安全的 ssl 选项运行多运行器。

There is currently an open issue at GitLab about that. GitLab 目前有一个关于此的未决问题。

Still you should be able to get your certificate, make it a PEM file and give it to the runner command using --tls-ca-file您仍然应该能够获得您的证书,使其成为 PEM 文件并使用--tls-ca-file将其提供给 runner 命令

To craft the PEM file use openssl.要制作 PEM 文件,请使用 openssl。
openssl x509 -in mycert.crt -out mycert.pem -outform PEM

The following steps worked in my environment.以下步骤适用于我的环境。 (Ubuntu) (Ubuntu)

Download certificate下载证书
I did not have access to the gitlab server.我无权访问 gitlab 服务器。 Therefore,所以,

  1. Open https://some-host-gitlab.com in browser (I use chrome).在浏览器中打开https://some-host-gitlab.com (我使用 chrome)。
  2. View site information, usually a green lock in URL bar.查看站点信息,通常是 URL 栏中的绿色锁。
  3. Download/Export certificate by navigating to certificate information(chrome, firefox has this option)通过导航到证书信息下载/导出证书(chrome、firefox 有这个选项)

In gitlab-runner host在 gitlab-runner 主机中

  1. Rename the downloaded certificate with .crt使用 .crt 重命名下载的证书

    $ mv some-host-gitlab.com some-host-gitlab.com.crt

  2. Register the runner now with this file现在用这个文件注册跑步者

    $ sudo gitlab-runner register --tls-ca-file /path/to/some-host-gitlab.com.crt

I was able to register runner to a project.我能够将跑步者注册到一个项目中。

In my setup the following the following worked as well.在我的设置中,以下内容也有效。 It's just important that IP/Name used for creating certificate matches IP/Name used for registering the runner.重要的是,用于创建证书的 IP/Name 与用于注册 runner 的 IP/Name 匹配。

gitlab-runner register --tls-ca-file /my/path/gitlab/gitlab.myserver.com.pem

Furthermore, it could be necessary to add a line for hostname lookup to the runners config.toml file also (section [runners.docker]): extra_hosts = ["git.domain.com:192.168.99.100"] see also https://gitlab.com/gitlab-org/gitlab-runner/issues/2209此外,可能还需要在 runners config.toml 文件中添加一行用于主机名查找的行(部分 [runners.docker]): extra_hosts = ["git.domain.com:192.168.99.100"]另见https:/ /gitlab.com/gitlab-org/gitlab-runner/issues/2209

In addition, there could be some network-trouble if for gitlab/gitlab-runner network-mode host is used, it has to be added to the config.toml as well, as it starts additional containers, which otherwise could have a problem to connect to the gitlab-host ((section [runners.docker]): network_mode="host"此外,如果使用 gitlab/gitlab-runner 网络模式主机,可能会出现一些网络问题,它也必须添加到 config.toml 中,因为它会启动额外的容器,否则可能会出现问题连接到 gitlab-host ((section [runners.docker]): network_mode="host"

Finally, there might be an issue with the self-signed SSL-Cert ( https://gitlab.com/gitlab-org/gitlab-runner/issues/2659 ).最后,自签名 SSL 证书 ( https://gitlab.com/gitlab-org/gitlab-runner/issues/2659 ) 可能存在问题。 A dirty workaround is to add environment = ["GIT_SSL_NO_VERIFY=true"] to the [[runners]] section.一个肮脏的解决方法是将environment = ["GIT_SSL_NO_VERIFY=true"]到 [[runners]] 部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM