Установка gitlab-runner v14.0.0 с tls на CentOS7
#!/bin/bash
set -eu
echo "скачиваем пакет"
wget 'https://packages.gitlab.com/runner/gitlab-runner/packages/el/7/gitlab-runner-14.0.0-1.x86_64.rpm/download.rpm'
mv download.rpm gitlab-runner-14.0.0-1.x86_64.rpm
rpm --checksig gitlab-runner-14.0.0-1.x86_64.rpm
echo "устанавливаем раннер"
yum install -y gitlab-runner-14.0.0-1.x86_64.rpm
echo "добавляем пользователя gitlab-runner в группу докер"
usermod -aG docker gitlab-runner
eсho "добавляем необходимые каталоги"
mkdir -p ~/.docker
mkdir -p /etc/docker
echo "добавляем конфигурацию openssl для клиента"
touch ~/.docker/openssl.cnf
cat <<EOF > /root/.docker/openssl.cnf
[req]
req_extensions = v3_req
distinguished_name = req_distinguished_name
[req_distinguished_name]
[ v3_req ]
basicConstraints = CA:FALSE
keyUsage = nonRepudiation, digitalSignature, keyEncipherment
extendedKeyUsage = serverAuth, clientAuth
EOF
echo "записываем IP в переменную"
IP_address=$(hostname -I | head -c 11)
echo $IP_address
echo"добавляем конфигурацию openssl для сервера"
touch /etc/docker/openssl.cnf
cat <<EOF > /etc/docker/openssl.cnf
[req]
req_extensions = v3_req
distinguished_name = req_distinguished_name
[req_distinguished_name]
[ v3_req ]
basicConstraints = CA:FALSE
keyUsage = nonRepudiation, digitalSignature, keyEncipherment
extendedKeyUsage = serverAuth, clientAuth
subjectAltName = @alt_names
[alt_names]
# signed IP for certificate
IP.1=127.0.0.1
IP.2=$IP_address
EOF
echo "генерируем корневой сертификат и добавляем в неодбходимые каталоги"
openssl genrsa -out ~/.docker/ca-key.pem 2048
openssl req -x509 -new -nodes -key ~/.docker/ca-key.pem -days 10000 -sha256 -out ~/.docker/ca.pem -subj "/CN=docker-CA"
cp ~/.docker/ca.pem /etc/docker/ca.pem
echo "генерируем сертификаты и ключи для клиента"
openssl genrsa -out ~/.docker/key.pem 2048
openssl req -new -key ~/.docker/key.pem -out ~/.docker/cert.csr -subj "/CN=docker-client" -config ~/.docker/openssl.cnf
openssl x509 -req -sha256 -in ~/.docker/cert.csr -CA ~/.docker/ca.pem -CAkey ~/.docker/ca-key.pem -CAcreateserial -out ~/.docker/cert.pem -days 365 -extensions v3_req -extfile ~/.docker/openssl.cnf
echo "генерируем сертификаты и ключи для сервера"
openssl genrsa -out /etc/docker/key.pem 2048
openssl req -new -key /etc/docker/key.pem -out /etc/docker/cert.csr -subj "/CN=docker-server" -config /etc/docker/openssl.cnf
openssl x509 -req -sha256 -in /etc/docker/cert.csr -CA /etc/docker/ca.pem -CAkey ~/.docker/ca-key.pem -CAcreateserial -out /etc/docker/cert.pem -days 365 -extensions v3_req -extfile /etc/docker/openssl.cnf
echo "редактируем сервис для использования сертификатов"
mkdir -p /etc/systemd/system/docker.service.d/
cat <<EOF > /etc/systemd/system/docker.service.d/override.conf
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd --host tcp://0.0.0.0:2376 --host fd:// --tlsverify --tlscacert /etc/docker/ca.pem --tlscert /etc/docker/cert.pem --tlskey /etc/docker/key.pem
EOF
echo "перезапускаем демон и сервис докера"
systemctl daemon-reload
systemctl restart docker