I am experiencing an issue with a docker+machine runner which is running a gitlab-ci.yml that uses a docker image to run CI tools on docker containers such as terraform. It gets to the docker login and fails with “x509: certificate signed by unknown authority”.
I’m perplexed as the CA certificate has been installed on the docker image using two ways:
In my (sanitised) config.toml file I have:
pre_build_script = """
export HTTP_PROXY=http://192.168.0.1:3128/
export HTTPS_PROXY=http://192.168.0.1:3128/
export NO_PROXY=<internal domain>,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,docker
apk update >/dev/null
apk add ca-certificates > /dev/null
rm -rf /var/cache/apk/*
wget http://<CA Webserver>certs/ca-cert.pem -O /usr/local/share/ca-certificates/ca-cert.pem
update-ca-certificates --fresh > /dev/null
"""
and in my gitlab-ci.yml:
before_script:
- |
set -xv
http_proxy=$http_proxy
https_proxy=$https_proxy
no_proxy=${no_proxy},docker
apk add --no-cache ca-certificates
wget http://<ca webserver>/certs/ca-cert.pem -O /usr/local/share/ca-certificates/ca-cert.pem && update-ca-certificates
Now I believe these are superflous as, looking at the CI output, it appears they run on the same docker container.
Can anyone suggest why the addition of the CA is not working?
Here is my config.toml in full:
concurrent = 1
check_interval = 0
[session_server]
session_timeout = 1800
[[runners]]
name = "docker-machine-runner"
url = "https://gitlab.<internal domain>"
token = "syzrstC3iD36x97iTXgX"
executor = "docker+machine"
environment = [
"GIT_SSL_NO_VERIFY=1"
]
pre_build_script = """
export HTTP_PROXY=http://192.168.0.1:3128/
export HTTPS_PROXY=http://192.168.0.1:3128/
export NO_PROXY=<internal domain>,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,docker
apk update >/dev/null
apk add ca-certificates > /dev/null
rm -rf /var/cache/apk/*
wget http://<CA webserver>/certs/ca-cert.pem -O /usr/local/share/ca-certificates/ca-cert.pem
update-ca-certificates --fresh > /dev/null
"""
[runners.custom_build_dir]
[runners.cache]
[runners.cache.s3]
[runners.cache.gcs]
[runners.cache.azure]
[runners.docker]
tls_verify = false
image = "docker:latest"
privileged = false
disable_entrypoint_overwrite = false
oom_kill_disable = false
disable_cache = false
volumes = ["/cache", "/certs/client", "/var/run/docker.sock:/var/run/docker.sock"]
network_mode = "host"
shm_size = 0
[runners.machine]
IdleCount = 0
IdleTime = 60
IdleScaleFactor = 0.0
IdleCountMin = 0
MachineDriver = "vmwarevsphere"
MachineName = "gitlab-docker-machine-runner-%s"
MachineOptions = ["vmwarevsphere-username=administrator@vsphere.local", "vmwarevsphere-password=<password>", "vmwarevsphere-vcenter=vc", "vmwarevsphere-vcenter-port=443", "vmwarevsphere-datacenter=<DC>", "vmwarevsphere-folder=DevOps/Tools/Gitlab", "vmwarevsphere-datastore=fastnas_DS1_2TB", "vmwarevsphere-cpu-count=2", "vmwarevsphere-memory-size=2048", "vmwarevsphere-disk-size=2048", "vmwarevsphere-disk-size=10000", "vmwarevsphere-network=DSwitch0_VLAN-100-Mgmt", "vmwarevsphere-boot2docker-url=http://192.168.0.1/yum/boot2docker/boot2docker.iso", "engine-env=HTTP_PROXY=http://192.168.0.1:3128/", "engine-env=HTTPS_PROXY=http://192.168.0.1:3128/", "engine-env=NO_PROXY=.<internal domain>,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16"]
and my gitlab-ci.yml:
stages:
- terraform_plan
merge review:
stage: terraform_plan
image: docker:20.10.16
variables:
DOCKER_TLS_CERTDIR: ""
before_script:
- |
set -xv
http_proxy=$http_proxy
https_proxy=$https_proxy
no_proxy=${no_proxy},docker
apk add --no-cache ca-certificates
wget http://<CA webserver>/certs/ca-cert.pem -O /usr/local/share/ca-certificates/ca-cert.pem && update-ca-certificates
docker info
docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
script:
- |
set -xv
echo -en "http_proxy=${http_proxy}\n\
https_proxy=${https_proxy}\n\
no_proxy=${no_proxy},docker\n\
CI_REGISTRY=${CI_REGISTRY}\n\
TF_IMAGE=${TF_IMAGE}\n\
TF_IMAGE_TAG=${TF_IMAGE_TAG}\n\
TF_VAR_vsphere_user=${TF_VAR_vsphere_user}\n\
TF_VAR_vsphere_password='${TF_VAR_vsphere_password}'\n\
TF_VAR_dns_key_secret=${TF_VAR_dns_key_secret}\n\
TERRAFORM_TFSTATE_NFS_HOST=${TERRAFORM_TFSTATE_NFS_HOST}\n\
TERRAFORM_TFSTATE_NFS_OPTS=${TERRAFORM_TFSTATE_NFS_OPTS}\n\
TERRAFORM_TFSTATE_NFS_PATH=${TERRAFORM_TFSTATE_NFS_PATH}\n\
TERRAFORM_TFSTATE_MOUNTPOINT=${TERRAFORM_TFSTATE_MOUNTPOINT}\n" > .env
echo -en "terraform {\n backend \"local\" {\n path = \"${TERRAFORM_TFSTATE_MOUNTPOINT}/terraform.tfstate\"\n }\n}\n" > tfstate.tf
docker compose run --rm terraform init
docker compose run --rm terraform plan --out=${TERRAFORM_TFSTATE_MOUNTPOINT}/$PLAN | tee -a $PLAN.txt
echo \`\`\` >> ${PLAN}.txt
sed -i -e 's/ +/+/g' ${PLAN}.txt
sed -i -e 's/ ~/~/g' ${PLAN}.txt
sed -i -e 's/ -/-/g' ${PLAN}.txt
MESSAGE=$(cat ${PLAN}.txt)
curl -X POST -g -H "PRIVATE-TOKEN: ${GITLAB_TOKEN}" --data-urlencode "body=${MESSAGE}" "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/merge_requests/${CI_MERGE_REQUEST_IID}/discussions"
artifacts:
name: plan
paths:
- ${TERRAFORM_TFSTATE_MOUNTPOINT}/$PLAN
Any suggestions?