jquery

highlight.js

2019年8月26日 星期一

[Linux] GitLab Runner 證書錯誤註冊失敗 (x509: certificate signed by unknown authority)

最近把部門自行維護的專案換到IT管的gitlab時, 要註冊runner時發生證書錯誤而無法註冊, 顯示如下面的錯誤
ERROR: Registering runner... failed
runner=CtzAuyzs status=couldn't execute POST against https://gitlab.test.com.tw/api/v4/runners: 
Post https://gitlab.test.com.tw/api/v4/runners: x509: certificate signed by unknown authority
PANIC: Failed to register this runner. Perhaps you are having network problems 



查了一下, 官方有給這題的解法, 在0.7.0以上的 GitLab Runner 可以使用自定證書
取得 host 的證書並註冊 GitLab runner:
SERVER=gitlab.example.com
PORT=443
CERTIFICATE=/etc/gitlab-runner/certs/${SERVER}.crt

#Create the certificates hierarchy expected by gitlab
#建立gitlab的證書路徑
sudo mkdir -p $(dirname "$CERTIFICATE")

#Get the certificate in PEM format and store it
#從server取得證書並用PEM格式儲存
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
#使用自訂簽證註冊 
runner gitlab-runner register --tls-ca-file="$CERTIFICATE" [your other options] 
Ref: https://docs.gitlab.com/runner/configuration/tls-self-signed.html
Ref: https://stackoverflow.com/questions/44458410/gitlab-ci-runner-ignore-self-signed-certificate


加了自定簽證後GitLab runner就過了
Please enter the gitlab-ci tags for this runner (comma separated):
shell_runner
Registering runner... succeeded 
runner=CtzAuyzs
Please enter the executor: parallels, ssh, custom, docker-ssh, shell, virtualbox, docker+machine, docker-ssh+machine, kubernetes, docker:
shell
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded! 

留言 (0)

張貼留言