Skip to content

Commit 23fcc0e

Browse files
committed
Switch to the authentication token-based runner creation workflow
Starting in GitLab v15.10 (and enabled by default in v16.0), the runner creation uses a workflow based on authentication tokens instead of registration tokens. This introduces a new runner property named system_id that needs to be passed to the /jobs/request API. Extend the runner with a new system_id parameter (passed through the environment variable 'RUNNER_SYSTEM_ID'. Additionall update the documentation in README.md to explain the new workflow. Signed-off-by: Laurent Pinchart <[email protected]>
1 parent b94ca50 commit 23fcc0e

File tree

2 files changed

+52
-28
lines changed

2 files changed

+52
-28
lines changed

README.md

+49-27
Original file line numberDiff line numberDiff line change
@@ -9,42 +9,64 @@ A gitlab runner implementation intended to bridge gitlab to
99
The lava gitlab runner only requires network (https) access to both the gitlab
1010
server and the lava server(s), so can pretty much run anywhere.
1111

12-
The runner requires a runner token to connect to the gitlab server and pick up
13-
jobs. The lava url and token are provided by the gitlab-ci jobs so don't have
14-
to be configured on the runner.
12+
The runner requires a runner authentication token to connect to the gitlab
13+
server and pick up jobs. The lava url and token are provided by the gitlab-ci
14+
jobs so don't have to be configured on the runner.
15+
16+
## Creating a new runner
17+
18+
A new runner must be created on the GitLab server. This can be done using the
19+
[runner creation API](https://docs.gitlab.com/ee/api/users.html#create-a-runner-linked-to-a-user),
20+
or manually in the GitLab
21+
[runner management web interface](https://docs.gitlab.com/ee/ci/runners/runners_scope.html).
22+
Make sure to follow the runner creation with an authentication token workflow,
23+
as the registration token workflow is deprecated.
24+
25+
One key parameter provided when creating the runner is `run_untagged=false` (or
26+
leaving the `Run untagged jobs` box unchecked in the web interface), which will
27+
make the runner *only* pickup jobs which matches its tags. This is important to
28+
prevent the runner from picking up "normal" jobs which it will not be able to
29+
process.
1530

16-
## Registering a new runner
31+
When the runner is created GitLab provides an authentication token starting
32+
with `glrt-`. This token should be provided to the runner for its GitLab
33+
connection, along with a system ID that identifies the machine on which the
34+
runner is executed.
1735

18-
The runner cannot register itself with the gitlab server, so this has to be
19-
done by hand using the gitlab
20-
[runner registration API](https://docs.gitlab.com/ee/api/runners.html#register-a-new-runner).
36+
The system ID should be a unique string. GitLab doesn't currently require any
37+
particular formatting, but it is recommended to follow the way the official
38+
`gitlab-runner` creates system IDs:
2139

22-
The registration token can be retrieved from the runners section in the Gitlab
23-
administration area. With that token the runner can be register using a curl
24-
command like:
25-
```
26-
curl --request POST "https://GITLAB_URL/api/v4/runners" \
27-
--form "description=Lava runner" \
28-
--form "run_untagged=false" \
29-
--form "tag_list=lava-runner" \
30-
--form "token=REGISTRATION_TOKEN"
31-
```
40+
- Deriving it from the machine ID, found in `/var/lib/dbus/machine-id` or
41+
`/etc/machine-id`, but concatenating the machine ID with the string
42+
"gitlab-runner", taking the first 12 characters of its SHA256 hash in hex
43+
form, and prepending it with `s_`.
3244

33-
As a response to this command a new token for the registered runner will be
34-
provided, this token should be provided to the runner for it's gitlab
35-
connection.
45+
- Generating a random 12-character string using letters and digits
46+
(`[a-z][A-Z][0-9]`), and prepending it with `r_`.
3647

37-
One thing to key parameter provided here is `run_untagged=false`, which will
38-
make the runner *only* pickup jobs which matches its tag. This is important to
39-
prevent the runner from picking up "normal" jobs which it will not be able to
40-
process.
48+
In either case the system ID should be recorded in a persistent storage, along
49+
with the authentication token, and be passed to the `Runner::new()` function.
50+
51+
The token can be verified using a curl command like:
52+
53+
```shell
54+
curl --request POST "https://GITLAB_URL/api/v4/runners/verify" \
55+
--form "token=AUTHENTICATION_TOKEN" \
56+
--form "system_id=SYSTEM_ID"
57+
```
58+
59+
This step is optional. If performed, it will pre-register the system ID with
60+
the GitLab server. Otherwise the system ID will be registered the first time
61+
the runner pings for jobs.
4162

4263
## Running the runner from the source tree
4364

4465
The runner can be build using Cargo like any Rust program. To run it the url to
45-
the gitlab server and the token have to be either provided on the command line
46-
or in the `GITLAB_URL` and `GITLAB_TOKEN` environment variables. For example to
47-
run directly from source `cargo run https://gitlab.myserver.org RUNNER_TOKEN`.
66+
the gitlab server, the token and the system ID have to be either provided on
67+
the command line or in the `GITLAB_URL`, `GITLAB_TOKEN` and `RUNNER_SYSTEM_ID`
68+
environment variables. For example to run directly from source `cargo run
69+
https://gitlab.myserver.org RUNNER_TOKEN SYSTEM_ID`.
4870

4971
## Running from a docker image
5072

src/main.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ struct Opts {
8888
server: Url,
8989
#[structopt(env = "GITLAB_TOKEN")]
9090
token: String,
91+
#[structopt(env = "RUNNER_SYSTEM_ID")]
92+
system_id: String,
9193
#[structopt(short, long, env = "RUNNER_LOG")]
9294
log: Option<String>,
9395
#[structopt(
@@ -927,7 +929,7 @@ async fn main() {
927929
let dir = tempfile::tempdir().unwrap();
928930

929931
let (mut runner, layer) =
930-
Runner::new_with_layer(opts.server, opts.token, dir.path().to_path_buf());
932+
Runner::new_with_layer(opts.server, opts.token, opts.system_id, dir.path().to_path_buf());
931933

932934
let log_targets: filter::Targets = if let Some(log) = opts.log {
933935
log.parse().unwrap()

0 commit comments

Comments
 (0)