gpt4 book ai didi

docker - 如何让 Docker 中的 GitLab Runner 看到自定义 CA 根证书

转载 作者:IT老高 更新时间:2023-10-28 21:20:03 32 4
gpt4 key购买 nike

我已经安装并配置好了:

  1. ServerA 上运行在 HTTPS 上的本地 GitLab Omnibus
  2. ServerB
  3. 中作为 Docker 服务安装的本地 GitLab-Runner

ServerA 证书由自定义 CA Root 生成

配置

我已将 CA 根证书放在 ServerB 上:

/srv/gitlab-runner/config/certs/ca.crt

ServerB 上安装了 Runner,如 Run GitLab Runner in a container - Docker image installation and configuration 中所述:

docker run -d --name gitlab-runner --restart always \
-v /srv/gitlab-runner/config:/etc/gitlab-runner \
-v /var/run/docker.sock:/var/run/docker.sock \
gitlab/gitlab-runner:latest

按照 Registering Runners - One-line registration command 中的说明注册 Runner :

docker run --rm -t -i 
-v /srv/gitlab-runner/config:/etc/gitlab-runner
--name gitlab-docker-runner gitlab/gitlab-runner register \
--non-interactive \
--executor "docker" \
--docker-image alpine:latest \
--url "https://MY_PRIVATE_REPO_URL_HERE/" \
--registration-token "MY_PRIVATE_TOKEN_HERE" \
--description "MyDockerServer-Runner" \
--tag-list "TAG_1,TAG_2,TAG_3" \
--run-untagged \
--locked="false"

此命令给出以下输出:

Updating CA certificates...
Runtime platform arch=amd64 os=linux pid=5 revision=cf91d5e1 version=11.4.2
Running in system-mode.

Registering runner... succeeded runner=8UtcUXCY
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!

我检查过

$ docker exec -it gitlab-runner bash 

并在容器中使用一次

$ awk -v cmd='openssl x509 -noout -subject' '
/BEGIN/{close(cmd)};{print | cmd}' < /etc/ssl/certs/ca-certificates.crt

并且自定义 CA 根目录正确存在

问题

从 GitLab-CI 运行 Gitlab-Runner 时,管道失败,惨痛地告诉我:

$ git clone https://gitlab-ci-token:${CI_BUILD_TOKEN}@ServerA/foo/bar/My-Project.wiki.git


Cloning into 'My-Project.wiki'...


fatal: unable to access 'https://gitlab-ci-token:xxxxxxxxxxxxxxxxxxxx@ServerA/foo/bar/My-Project.wiki.git/': server certificate verification failed. CAfile: /etc/ssl/certs/ca-certificates.crt CRLfile: none


ERROR: Job failed: exit code 1

它无法识别颁发者(我的自定义 CA Root),但根据 The self-signed certificates or custom Certification Authorities ,第 n.1 点,它应该是开箱即用的:

Default: GitLab Runner reads system certificate store and verifies the GitLab server against the CA’s stored in system.

然后我尝试了第 n.3 点的解决方案,正在编辑

/srv/gitlab-runner/config/config.toml:

并添加:

[[runners]]
tls-ca-file = "/srv/gitlab-runner/config/certs/ca.crt"

但还是不行。

如何让 Gitlab Runner 读取 CA Root 证书?

最佳答案

你有两个选择:

忽略 SSL 验证

把它放在你的 .gitlab-ci.yml 的顶部:

variables:
GIT_SSL_NO_VERIFY: "1"

将 GitLab-Runner 指向正确的证书

official documentation 中所述,您可以使用 tls-*-file 选项来设置您的证书,例如:

[[runners]]
...
tls-ca-file = "/etc/gitlab-runner/ssl/ca-bundle.crt"
[runners.docker]
...

作为 documentation声明,“每次运行者尝试访问 GitLab 服务器时都会读取此文件。”

其他选项包括 tls-cert-file 以定义在需要时使用的证书。

关于docker - 如何让 Docker 中的 GitLab Runner 看到自定义 CA 根证书,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53159258/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com