Skip to content

On v14.8.0 registering a runner fails from template config merging

Summary

After upgrading to v14.8.0, registering a runner with a specified template config fails. This appears to happen because the registration token gets merged into the template config under the 'token' field, where it probably does not belong.

Steps to reproduce

Create a template config file like the following:

[[runners]]
    name = "gitlab-runner-arm-stock-shell"
    url = "https://www.gitlab.com/"
    executor = "shell"
    limit = 1

Attempt to register the runner with a command like the following:

sudo gitlab-runner register --non-interactive --url https://gitlab.com/ --template-config /etc/gitlab-runner/shell_template.toml --registration-token <snip> --tag-list arm --executor shell

The registration fails, and the registration token will have been added to the template config file under token = "blah".

Example Project

What is the current bug behavior?

Registration is failing when given a template config and a registration token. After the command has run and failed, the registration token has been added to the template config file as the other token.

What is the expected correct behavior?

The registration should succeed. When downgrading to v14.7.0, registration succeeds as expected -- although the registration token does still end up in the template config file, where it probably doesn't belong.

Relevant logs and/or screenshots

On v14.8.0, the output from failed registration:

+ sudo gitlab-runner register --non-interactive --url https://gitlab.com/ --template-config /etc/gitlab-runner/shell_template.toml --registration-token <snip> --tag-list arm --executor shell
Runtime platform                                    arch=arm64 os=linux pid=93323 revision=565b6c0b version=14.8.0
Running in system-mode.                            
                                                   
Merging configuration from template file "/etc/gitlab-runner/shell_template.toml" 
Token specified trying to verify runner...         
WARNING: If you want to register use the '-r' instead of '-t'. 
ERROR: Verifying runner... is removed               runner=<snip>
PANIC: Failed to verify the runner. You may be having network problems. 

The key here is WARNING: If you want to register use the '-r' instead of '-t'.

On v14.7.0, the output from successful registration:

+ sudo gitlab-runner register --non-interactive --url https://gitlab.com/ --template-config /etc/gitlab-runner/shell_template.toml --registration-token <snip> --tag-list arm --executor shell
Runtime platform                                    arch=arm64 os=linux pid=86179 revision=98daeee0 version=14.7.0
Running in system-mode.                            
                                                   
Registering runner... succeeded                     runner=<snip>
Merging configuration from template file "/etc/gitlab-runner/shell_template.toml" 
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded! 

Output of checks

Results of GitLab environment info

Expand for output related to GitLab environment info

(For installations with omnibus-gitlab package run and paste the output of:
`sudo gitlab-rake gitlab:env:info`)

(For installations from source run and paste the output of:
`sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production`)

Results of GitLab application Check

Expand for output related to the GitLab application check

(For installations with omnibus-gitlab package run and paste the output of: sudo gitlab-rake gitlab:check SANITIZE=true)

(For installations from source run and paste the output of: sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production SANITIZE=true)

(we will only investigate if the tests are passing)

Possible fixes

This seems like it was introduced in !2561 (merged), but the underlying issue seems to be in the way the template merge is done.