Cloud Computing
VERIFIED FIXES

Self-hosted GitHub Actions runner cannot access /var/run/docker.sock when launched as systemd service

Environment

Environment

Ubuntu 22.04 VM running GitHub Actions runner installed as systemd service (runner v2.x), Docker Engine 20.10, runner service unit sets User=ci-runner and uses Workspace under /home/ci-runner

Symptoms

Symptoms

Workflows that call docker CLI fail immediately with 'Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?' from the runner; jobs time out and are marked failed.

Observations

Observations

docker.sock exists at /var/run/docker.sock (srw-rw---- root:docker). The runner process runs as ci-runner user. journalctl for runner shows 'permission denied' when opening socket. Adding ci-runner to docker group on host and restarting user shell fixed access for interactive login but runner service still fails.

Already attempted

Already attempted

Chowning/chmodding socket to 666 (temporary) allowed jobs to run; restarted runner service after adding group membership (no effect). Reviewed systemd unit: no Groups= or SupplementaryGroups set. AppArmor not enforcing on docker.sock path.

Question

Question

How can I safely allow the systemd-managed self-hosted runner service to access Docker socket without making the socket globally writable or compromising host security?

COMMUNITY RESPONSES

Verified community troubleshooting

1 reply
0
hugohardware Answer
user
Posted 1mo ago • 0 confirmations

First check the runner's systemd unit — systemd doesn't automatically pick up new supplementary groups for a running service. Add Group=docker or SupplementaryGroups=docker to the unit file instead of chmodding /var/run/docker.sock. Example: edit /etc/systemd/system/actions.runner.<name>.service, add Group=docker under [Service], then sudo systemctl daemon-reload && sudo systemctl restart actions.runner.<name>.service. Verify by reproducing a workflow that calls docker or running sudo -u ci-runner docker ps. If you need stronger hardening, remove broad group grants and instead use a carefully-scoped bind-mount or socket proxy (or run the runner in a short-lived container). If AppArmor/SELinux is enabled, check audit logs before changing permissions. This avoids making the socket world-writable and is reversible by restoring the unit file and restarting the service.

Showing 1 of 1 community responses
AI DIAGNOSTICS

Incident analysis

Updated 1mo ago• Trouble ID

Most likely causes

Service process started by systemd doesn't have docker group in its supplementary groups because unit lacks Groups= or SupplementaryGroups=; systemd won't pick up /etc/group changes automatically 85%
Unit uses ProtectSystem/ProtectHome/PrivateDevices or other hardening that prevents access to /var/run/docker.sock even if group membership is present 45%
Docker daemon placed socket in different mount/namespace or rootless Docker created socket owned by different user/group not matching runner expectations 20%

Summary

Symptoms point to a classic systemd/user-group vs. login-session problem: adding the user to the docker group changes /etc/group but systemd does not re-evaluate supplementary groups for an existing service unless the unit config applies them. The runner process therefore lacks the docker group membership at start and cannot open the socket. A temporary chmod 666 obscures the real issue; correct fix is to configure the service unit to run with appropriate group privileges or use a socket-ownership approach. Alternate, less likely causes include filesystem namespace isolation (PrivateTmp) or ProtectSystem flags that block the path.

Suggested Fixes

Diagnostic step 1
Inspect the runner systemd unit: sudo systemctl cat actions.runner.<name>.service and look for User=, Group=, SupplementaryGroups= and PrivateTmp/ProtectSystem/PrivateDevices flags.
Diagnostic step 2
If intended: add Group=docker (or SupplementaryGroups=docker) to the unit and avoid chmodding the socket. Example: set Group=docker and restart systemd daemon: sudo systemctl daemon-reload; sudo systemctl restart actions.runner.<name>.service.
Diagnostic step 3
If unit must retain a non-privileged group, create a minimal wrapper unit that binds the socket into the runner's namespace with a safe bind-mount: use Systemd Mount unit or ProtectedBindPaths carefully; prefer Group= approach.

Continue troubleshooting

Matched from the title, description and tags