Duplicate register to the same GitLab runner will not fail

Summary

Running gitlab-runner register multiple times target to the same GitLab project runner with same or different configurations will result in success, but it seems there is still only one runner configuration takes effect.

Steps to reproduce

  1. In GitLab project's CI/CD settings, create a new runner.
  2. Use this runner's token to register multiple times:
    sudo gitlab-runner register --url https://gitlab.com --token YOUR_RUNNER_TOKRN --executor=docker
    sudo gitlab-runner register --url https://gitlab.com --token YOUR_RUNNER_TOKRN --executor=docker
    sudo gitlab-runner register --url https://gitlab.com --token YOUR_RUNNER_TOKRN --executor=shell

Actual behavior

Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!

Subsequent registering will produce a warning message:

WARNING: A runner with this system ID and token has already been registered.

Furthermore, if I try to unregister all registered runners, only the first one will be unregistered in success, the others will failed due to "resource not found" (see logs below).

Expected behavior

In my understanding, there should be only one registered runner targeted to each project runner. So, if we try to repeatedly register to the same project runner identified by URL and token, the register process should not only warn "a runner has been registered", but fail the register request immediately. Nevertheless, if we try to register to different GitLab runner, the request should success. As a result, the local runner service will be share by multiple GitLab runners.

Relevant logs and/or screenshots

Error logs when unregistering all runners (3 out of 4 failed):

WARNING: Unregistering all runners
ERROR: Unregistering runner from GitLab failed      runner=DUKZmXSg_ status=DELETE https://gitlab.com/api/v4/runners/managers: 404 Not Found (404 Not found)
ERROR: Failed to unregister runner AORUS-DESKTOP
ERROR: Unregistering runner from GitLab failed      runner=DUKZmXSg_ status=DELETE https://gitlab.com/api/v4/runners/managers: 404 Not Found (404 Not found)
ERROR: Failed to unregister runner AORUS-DESKTOP
ERROR: Unregistering runner from GitLab failed      runner=DUKZmXSg_ status=DELETE https://gitlab.com/api/v4/runners/managers: 404 Not Found (404 Not found)
ERROR: Failed to unregister runner AORUS-DESKTOP

Environment description

The runner service configuration file after duplicated registration:

concurrent = 1
check_interval = 0
connection_max_age = "15m0s"
shutdown_timeout = 0

[session_server]
  session_timeout = 1800

[[runners]]
  name = "AORUS-DESKTOP"
  url = "https://gitlab.com"
  id = 34415044
  token = "MY_TOKEN"
  token_obtained_at = 2024-04-04T03:05:02Z
  token_expires_at = 0001-01-01T00:00:00Z
  executor = "docker"
  [runners.docker]
    tls_verify = false
    image = "ubuntu:jammy"
    privileged = false
    disable_entrypoint_overwrite = false
    oom_kill_disable = false
    disable_cache = false
    volumes = ["/cache"]
    shm_size = 0
    network_mtu = 0

[[runners]]
  name = "AORUS-DESKTOP"
  url = "https://gitlab.com"
  id = 34415044
  token = "MY_TOKEN"
  token_obtained_at = 2024-04-04T04:44:57Z
  token_expires_at = 0001-01-01T00:00:00Z
  executor = "docker"
  [runners.docker]
    tls_verify = false
    image = "ubuntu:jammy"
    privileged = false
    disable_entrypoint_overwrite = false
    oom_kill_disable = false
    disable_cache = false
    volumes = ["/cache"]
    shm_size = 0
    network_mtu = 0

[[runners]]
  name = "AORUS-DESKTOP"
  url = "https://gitlab.com"
  id = 34415044
  token = "MY_TOKEN"
  token_obtained_at = 2024-04-04T04:47:19Z
  token_expires_at = 0001-01-01T00:00:00Z
  executor = "shell"
  [runners.cache]
    MaxUploadedArchiveSize = 0

Used GitLab Runner version

Version:      16.10.0
Git revision: 81ab07f6
Git branch:   16-10-stable
GO version:   go1.21.7
Built:        2024-03-21T19:43:25+0000
OS/Arch:      linux/amd64

Possible fixes

The registration behavior should be modified, or the documentation about duplicated registration should be clarified.

Edited by Gary Wang