UbuntuへリポジトリからインストールしたGitLabRunnerをrootで動作させる
以前に以下のメモを書きました。
GitLab Runnerをリポジトリからインストールするとgitlab-runnerユーザで動作するようです。これをrootユーザへ変更する手順をメモします。
検証環境¶
対象 | バージョン |
---|---|
Ubuntu | 24.04.3 LTS |
GitLab Runner | 18.2.1-1 |
リポジトリからGitLab Runnerをインストールする¶
以下を実行してリポジトリからGitLab Runnerをインストールします。
curl -L "https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh" | sudo bash &&
sudo apt-get install -y gitlab-runner
インストール直後の実行ユーザ¶
インストール直後にsystemctl status gitlab-runner
を実行すると「GitLab Runnerがgitlab-runnerユーザで動作している」ことが分かります。
# systemctl status gitlab-runner
● gitlab-runner.service - GitLab Runner
Loaded: loaded (/etc/systemd/system/gitlab-runner.service; enabled; preset: enabled)
Active: active (running) since Fri 2025-08-15 22:41:14 JST; 17min ago
Main PID: 823 (gitlab-runner)
Tasks: 9 (limit: 4604)
Memory: 87.9M (peak: 94.8M)
CPU: 528ms
CGroup: /system.slice/gitlab-runner.service
└─823 /usr/bin/gitlab-runner run --config /etc/gitlab-runner/config.toml --working-directory /home/gitlab-runner --service gitlab-runner --user gitlab-runner
GitLab Runnerの実行ユーザをrootへ変更する¶
GitLab Runnerの動作ユーザは/etc/systemd/system/gitlab-runner.service
で定義されているようです。直接、このファイルを編集しても問題無いと思いますが、以下のコマンドを実行することで設定変更することができました。
gitlab-runner install --user=root --working-directory=/root && \
systemctl restart gitlab-runner
再度、systemctl status gitlab-runner
を実行すると実行ユーザがrootへ変更されていることが分かります。
# systemctl status gitlab-runner
● gitlab-runner.service - GitLab Runner
Loaded: loaded (/etc/systemd/system/gitlab-runner.service; enabled; preset: enabled)
Active: active (running) since Fri 2025-08-15 22:59:35 JST; 1s ago
Main PID: 1588 (gitlab-runner)
Tasks: 9 (limit: 4604)
Memory: 32.1M (peak: 32.5M)
CPU: 146ms
CGroup: /system.slice/gitlab-runner.service
└─1588 /usr/bin/gitlab-runner run --config /etc/gitlab-runner/config.toml --working-directory /root --service gitlab-runner --user root