Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

the get_runner_reg.sh stopped working #2

Open
a-t-0 opened this issue Aug 19, 2021 · 1 comment
Open

the get_runner_reg.sh stopped working #2

a-t-0 opened this issue Aug 19, 2021 · 1 comment

Comments

@a-t-0
Copy link

a-t-0 commented Aug 19, 2021

Hi, thank you for providing an example on how to get the runner token in a .sh script. A few days ago it was working like a charm, however when running it today I noticed the second body_header variable is empty. Upon inspecting the gitlab-header.txt file, I noticed it contained:

You are being redirected.

Whereas I would expect it to be signed in at that point, with a gitlab-header.txt file that contains the respective runner registration token. I expect I am doing something wrong, however, perhaps there has been an update to the gitlab/gitlab-ce:latest package such that a change to the script is required.

For completeness, I hardcoded the email, username and password, and manually verified I was able to log into the GitLab server with those credentials:

GITURL="$GITLAB_SERVER_HTTP_URL"
   GITUSER="$gitlab_server_account"
   GITROOTPWD="$gitlab_server_password"
   echo "GITUSER=$GITUSER"
   echo "GITROOTPWD=$GITROOTPWD"

   # 1. curl for the login page to get a session cookie and the sources with the auth tokens
   body_header=$(curl -k -c gitlab-cookies.txt -i "${GITURL}/users/sign_in" -sS)
   
   # grep the auth token for the user login for
   #   not sure whether another token on the page will work, too - there are 3 of them
   csrf_token=$(echo $body_header | perl -ne 'print "$1\n" if /new_user.*?authenticity_token"[[:blank:]]value="(.+?)"/' | sed -n 1p)
   
   # 2. send login credentials with curl, using cookies and token from previous request
   curl -sS -k -b gitlab-cookies.txt -c gitlab-cookies.txt "${GITURL}/users/sign_in" \
   	--data "user[login]=${GITUSER}&user[password]=${GITROOTPWD}" \
   	--data-urlencode "authenticity_token=${csrf_token}"  -o /dev/null
   
   # 3. send curl GET request to gitlab runners page to get registration token
   body_header=$(curl -sS -k -H 'user-agent: curl' -b gitlab-cookies.txt "${GITURL}/admin/runners" -o gitlab-header.txt)
   reg_token=$(cat gitlab-header.txt | perl -ne 'print "$1\n" if /code id="registration_token">(.+?)</' | sed -n 1p)
   echo $reg_token
@MxNxPx
Copy link
Owner

MxNxPx commented Aug 22, 2021

hello @a-t-0
i recently pinned this demo to a specific k8s gitlab version since it did appear to break with a newer version of gitlab.
Here is the version I am using (via helm) - https://github.com/MxNxPx/gitlab-cicd-demo/blob/master/README.md#using-helm---install-gitlab-to-minikube
Hope this helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants