diff --git a/runner_scripts/root/cleanup.sh b/runner_scripts/root/cleanup.sh index 6ae593906b5c9a019c8a6c6adad0821c0d4e7fa2..d7df286c641ab22bfc0fa9d595ed160ad6109559 100755 --- a/runner_scripts/root/cleanup.sh +++ b/runner_scripts/root/cleanup.sh @@ -36,7 +36,11 @@ id -u "$AUTH_USER" >/dev/null 2>&1 || error "User $AUTH_USER does not exist" ## Use a key pair to authenticate the user (private key has to be set as a GitLab CI/CD variable) AUTH_KEY=$CUSTOM_ENV_AUTH_KEY -AUTH_PUB=/etc/gitlab-runner/authorized_keys +AUTH_PUB="/etc/gitlab-runner/auth/${CI_SERVER_HOST}/${CI_PROJECT_NAMESPACE}/${CI_PROJECT_NAME}/authorized_keys" + +if [[ ! -f "$AUTH_PUB" ]]; then + error "Authentication for user $AUTH_USER not configured for this project." +fi ( while read -r PUB diff --git a/runner_scripts/root/config.sh b/runner_scripts/root/config.sh index 0145bdec47d83d8df3e6f40826159ecf2f29b430..c733da231004dfc5dd558e37c937fc129bbbecb9 100755 --- a/runner_scripts/root/config.sh +++ b/runner_scripts/root/config.sh @@ -17,6 +17,11 @@ function error { [ -z "${CUSTOM_ENV_AUTH_USER:+x}" ] && error "AUTH_USER CI/CD variable has not been set." [ -z "${CUSTOM_ENV_AUTH_KEY:+x}" ] && error "AUTH_KEY secret CI/CD variable has not been set." +AUTH_PUB="/etc/gitlab-runner/auth/${CI_SERVER_HOST}/${CI_PROJECT_NAMESPACE}/${CI_PROJECT_NAME}/authorized_keys" +if [[ ! -f "$AUTH_PUB" ]]; then + error "Authentication for user $AUTH_USER not configured for this project." +fi + AUTH_USER=$CUSTOM_ENV_AUTH_USER AUTH_USER_WORK=$(runuser "$AUTH_USER" --login --command "echo \$WORK") diff --git a/runner_scripts/root/run.sh b/runner_scripts/root/run.sh index f527675a67ef97982f8b608a8868645a84f2b183..b720e277814d6d1b60979a840a9d9ef5df101d23 100755 --- a/runner_scripts/root/run.sh +++ b/runner_scripts/root/run.sh @@ -41,7 +41,11 @@ id -u "$AUTH_USER" >/dev/null 2>&1 || error "User $AUTH_USER does not exist" ## Use a key pair to authenticate the user (private key has to be set as a GitLab CI/CD variable) AUTH_KEY=$CUSTOM_ENV_AUTH_KEY -AUTH_PUB=/etc/gitlab-runner/authorized_keys +AUTH_PUB="/etc/gitlab-runner/auth/${CI_SERVER_HOST}/${CI_PROJECT_NAMESPACE}/${CI_PROJECT_NAME}/authorized_keys" + +if [[ ! -f "$AUTH_PUB" ]]; then + error "Authentication for user $AUTH_USER not configured for this project." +fi ( while read -r PUB