Skip to content

Commit 6a39eb6

Browse files
committed
feat(runner): enhance group management for GitHub Actions
- Adds error handling for adding the runner to groups to prevent failures. - Implements a check to warn if the Docker socket has GID 0, guiding users to set a safer GID. - Uses sudo to start the GitHub Actions runner with the correct permissions for group access.
1 parent 8c25821 commit 6a39eb6

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

src/entrypoint.sh

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,10 @@ setup_groups() {
129129
if [ -n "${GITHUB_RUNNER_GID}" ]; then
130130
echo "Creating github-actions-runner group with GID ${GITHUB_RUNNER_GID}..."
131131
sudo groupadd -f -g ${GITHUB_RUNNER_GID} github-actions-runner || true
132-
sudo usermod -aG github-actions-runner runner
132+
sudo usermod -aG github-actions-runner runner || true
133133
echo "Added runner user to github-actions-runner group"
134134
fi
135-
135+
136136
# Handle Docker socket access if requested
137137
if [ "${GITHUB_RUNNER_DOCKER_SOCK}" = "true" ]; then
138138
if [ -S /var/run/docker.sock ]; then
@@ -147,11 +147,18 @@ setup_groups() {
147147
echo "Docker socket detected with GID ${DOCKER_GID}"
148148
fi
149149

150-
# Create group with the determined GID
151-
echo "Creating github-actions-runner-dockersock group with GID ${DOCKER_GID}..."
152-
sudo groupadd -f -g ${DOCKER_GID} github-actions-runner-dockersock || true
153-
sudo usermod -aG github-actions-runner-dockersock runner
154-
echo "Added runner user to github-actions-runner-dockersock group"
150+
# Check if GID is 0 (root)
151+
if [ "${DOCKER_GID}" = "0" ]; then
152+
echo "WARNING: Docker socket has GID 0 (root group)."
153+
echo "Cannot safely add runner to root group."
154+
echo "Please set GITHUB_RUNNER_DOCKER_SOCK_GID to a non-root GID or handle permissions differently."
155+
else
156+
# Create group with the determined GID
157+
echo "Creating github-actions-runner-dockersock group with GID ${DOCKER_GID}..."
158+
sudo groupadd -f -g ${DOCKER_GID} github-actions-runner-dockersock || true
159+
sudo usermod -aG github-actions-runner-dockersock runner || true
160+
echo "Added runner user to github-actions-runner-dockersock group"
161+
fi
155162
else
156163
echo "WARNING: GITHUB_RUNNER_DOCKER_SOCK=true but /var/run/docker.sock not found"
157164
fi
@@ -178,11 +185,13 @@ main() {
178185

179186
# Start the runner in background to capture PID
180187
echo "Starting GitHub Actions runner..."
181-
./run.sh &
188+
189+
# Use sudo to start with fresh session that has all groups
190+
sudo -u runner -i ./run.sh &
182191
RUNNER_PID=$!
183-
192+
184193
echo "Runner started with PID: $RUNNER_PID"
185-
194+
186195
# Wait for the runner process
187196
wait $RUNNER_PID
188197
}

0 commit comments

Comments
 (0)