From 3102b8d18845a024bd95b4df27dd3bbf4ef1a488 Mon Sep 17 00:00:00 2001
From: Lukas Werner <lks.werner@fau.de>
Date: Tue, 24 Aug 2021 16:20:38 +0200
Subject: [PATCH] Fix namespaced auth

---
 runner_scripts/root/cleanup.sh | 2 +-
 runner_scripts/root/config.sh  | 2 +-
 runner_scripts/root/run.sh     | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/runner_scripts/root/cleanup.sh b/runner_scripts/root/cleanup.sh
index d7df286..b8a840b 100755
--- a/runner_scripts/root/cleanup.sh
+++ b/runner_scripts/root/cleanup.sh
@@ -36,7 +36,7 @@ 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/auth/${CI_SERVER_HOST}/${CI_PROJECT_NAMESPACE}/${CI_PROJECT_NAME}/authorized_keys"
+AUTH_PUB="/etc/gitlab-runner/auth/${CUSTOM_ENV_CI_SERVER_HOST}/${CUSTOM_ENV_CI_PROJECT_NAMESPACE}/${CUSTOM_ENV_CI_PROJECT_NAME}/authorized_keys"
 
 if [[ ! -f "$AUTH_PUB" ]]; then
     error "Authentication for user $AUTH_USER not configured for this project."
diff --git a/runner_scripts/root/config.sh b/runner_scripts/root/config.sh
index c733da2..3857bc3 100755
--- a/runner_scripts/root/config.sh
+++ b/runner_scripts/root/config.sh
@@ -17,7 +17,7 @@ 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"
+AUTH_PUB="/etc/gitlab-runner/auth/${CUSTOM_ENV_CI_SERVER_HOST}/${CUSTOM_ENV_CI_PROJECT_NAMESPACE}/${CUSTOM_ENV_CI_PROJECT_NAME}/authorized_keys"
 if [[ ! -f "$AUTH_PUB" ]]; then
     error "Authentication for user $AUTH_USER not configured for this project."
 fi
diff --git a/runner_scripts/root/run.sh b/runner_scripts/root/run.sh
index b720e27..d7a14fa 100755
--- a/runner_scripts/root/run.sh
+++ b/runner_scripts/root/run.sh
@@ -41,7 +41,7 @@ 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/auth/${CI_SERVER_HOST}/${CI_PROJECT_NAMESPACE}/${CI_PROJECT_NAME}/authorized_keys"
+AUTH_PUB="/etc/gitlab-runner/auth/${CUSTOM_ENV_CI_SERVER_HOST}/${CUSTOM_ENV_CI_PROJECT_NAMESPACE}/${CUSTOM_ENV_CI_PROJECT_NAME}/authorized_keys"
 
 if [[ ! -f "$AUTH_PUB" ]]; then
     error "Authentication for user $AUTH_USER not configured for this project."
-- 
GitLab