Raise error if empty token obtained when register
What does this MR do?
Add code to raise an error if the token obtained from gitlab instance is an empty string when it is registered.
In a case user input too long runner tag (>255 chars), I found gitlab instance returns an empty token though it is registered successfully. So, the runner sets empty string token to config.toml, resulting in causing 400 Bad Request
. In this situation, we cannot unregister nor delete runner by verify --delete
.
Why was this MR needed?
To fix a bug
If the gitlab instance's behavior is unexpected, I will fix that.
What's the best way to test this MR?
To reproduce the bug, register with tag-list which has a tag longer than 255 chars.
gitlab-runner register --non-interactive --name my-runner --registration-token ${REGISTRATION_TOKEN} --url ${GITLAB_URL} --executor docker --docker-image alpine --tag-list abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv
The config.toml file will look like this:
...
[[runners]]
name = "my-runner"
url = "${GITLAB_URL}"
id = 34
token = ""
token_obtained_at = 2022-09-28T10:39:43Z
token_expires_at = 0001-01-01T00:00:00Z
executor = "docker"
[runners.custom_build_dir]
[runners.cache]
[runners.cache.s3]
[runners.cache.gcs]
[runners.cache.azure]
[runners.docker]
tls_verify = false
image = "alpine"
privileged = false
disable_entrypoint_overwrite = false
oom_kill_disable = false
disable_cache = false
volumes = ["/cache"]
shm_size = 0
After this MR's build, the register command will fail:
$ ./out/binaries/gitlab-runner --debug register --non-interactive --name my-runner --registration-token ${REGISTRATION_TOKEN} --url ${GITLAB_URL} --executor docker --docker-image alpine --tag-list abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv
Runtime platform arch=amd64 os=linux pid=2519687 revision=b92833e1 version=15.5.0~beta.83.gb92833e1
Checking runtime mode GOOS=linux uid=1000
WARNING: Running in user-mode.
WARNING: The user-mode requires you to manually start builds processing:
WARNING: $ gitlab-runner run
WARNING: Use sudo for system-mode:
WARNING: $ sudo gitlab-runner...
Dialing: tcp ${GITLAB_URL}:443 ...
Registering runner... succeeded runner=xXvAfse1
PANIC: Failed to obtain a valid token.