Skip to content

Ensure that runner always uses the customized User-Agent

Tomasz Maczukin requested to merge ensure-user-agent-is-always-used into main

What does this MR do?

Ensures that the customized User-Agent is used for all API requests made by GitLab Runner.

Why was this MR needed?

While working on one data egress investigation we've found that GitLab Runner doesn't use the customized User-Agent when requesting artifact downloads. This MR fixes that situation.

What's the best way to test this MR?

Before fix

$ ./out/binaries/gitlab-runner artifacts-downloader --url http://localhost:55555 --token abc --id 123

$ nc -l 55555
GET /api/v4/jobs/123/artifacts? HTTP/1.1
Host: localhost:55555
User-Agent: Go-http-client/1.1
Job-Token: abc
Accept-Encoding: gzip

$ ./out/binaries/gitlab-runner-helper/gitlab-runner-helper.x86_64 artifacts-downloader --url http://localhost:55555 --token abc --id 123

$ nc -l 55555
GET /api/v4/jobs/123/artifacts? HTTP/1.1
Host: localhost:55555
User-Agent: Go-http-client/1.1
Job-Token: abc
Accept-Encoding: gzip

$ ./out/binaries/gitlab-runner run-single --url http://localhost:55555/ --token abc --executor shell
Runtime platform                                    arch=amd64 os=linux pid=305860 revision=0c1266fc version=15.3.0~beta.40.g0c1266fc
Starting runner for http://localhost:55555/ with token abc ...

$ nc -l 55555
POST /api/v4/jobs/request HTTP/1.1
Host: localhost:55555
User-Agent: gitlab-runner 15.3.0~beta.40.g0c1266fc (main; go1.17.5; linux/amd64)
Content-Length: 664
Accept: application/json
Content-Type: application/json
Accept-Encoding: gzip

After fix

$ ./out/binaries/gitlab-runner artifacts-downloader --url http://localhost:5555/ --token abc --id 123

$ nc -l 5555
GET /api/v4/jobs/123/artifacts? HTTP/1.1
Host: localhost:5555
User-Agent: gitlab-runner 15.3.0~beta.41.g25c158ec (ensure-user-agent-is-always-used; go1.17.5; linux/amd64)
Job-Token: abc
Accept-Encoding: gzip

$ ./out/binaries/gitlab-runner-helper/gitlab-runner-helper.x86_64 artifacts-downloader --url http://localhost:5555/ --token abc --id 123

$ nc -l 5555
GET /api/v4/jobs/123/artifacts? HTTP/1.1
Host: localhost:5555
User-Agent: gitlab-runner-helper 15.3.0~beta.41.g25c158ec (ensure-user-agent-is-always-used; go1.17.5; linux/amd64)
Job-Token: abc
Accept-Encoding: gzip

$ ./out/binaries/gitlab-runner run-single --url http://localhost:5555/ --token abc --executor shell
Runtime platform                                    arch=amd64 os=linux pid=334958 revision=25c158ec version=15.3.0~beta.41.g25c158ec
Starting runner for http://localhost:5555/ with token abc ...

$ nc -l 5555
POST /api/v4/jobs/request HTTP/1.1
Host: localhost:5555
User-Agent: gitlab-runner 15.3.0~beta.41.g25c158ec (ensure-user-agent-is-always-used; go1.17.5; linux/amd64)
Content-Length: 664
Accept: application/json
Content-Type: application/json
Accept-Encoding: gzip

What are the relevant issue numbers?

Related to https://gitlab.com/gitlab-org/gitlab/-/issues/360462, https://gitlab.com/gitlab-org/gitlab/-/issues/362897

Edited by Tomasz Maczukin

Merge request reports

Loading