Skip to content

Commit 57e1ee8

Browse files
committed
tasks: Bind the host's podman API socket
This paves the way for spawning per-job tasks containers from the container (via `job-runner`). Getting the permissions right is unfortunately annoyingly complicated, as the host's socket has 660 permissions, but the tasks container runs as uid 1111. Ideally we could use something like -v "${XDG_RUNTIME_DIR:-/run}/podman/podman.sock:/podman.sock:idmap=gids=$(id -g)-1111-1" but that fails with "invalid mappings", and is generally not well documented. `--mount=type=bind,[...],idmap --uidmap [...]` does not work either. So resort to adding an ACL for user 1111 to the host. This is fine for production hosts (where the secrets etc. are all already chmod'ed to the container user), and does not hurt too much for a human developer: The socket itself may be accessible to uid 1111 (which *might* be an untrusted local user), but its directory (/run/user/uid) is not.
1 parent c118069 commit 57e1ee8

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

tasks/run-local.sh

+21-1
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,13 @@ EOF
104104
ln -s ..data/s3-keys--localhost.localdomain tasks/s3-keys--localhost.localdomain
105105
)
106106

107-
# need to make files world-readable, as containers run as different user
107+
# start podman API
108+
systemctl $([ $(id -u) -eq 0 ] || echo "--user") start podman.socket
109+
110+
# need to make files world-readable, as containers run as different user 1111
108111
chmod -R go+rX "$SECRETS"
112+
# for the same reason, make podman socket accessible to that container user
113+
setfacl -m user:1111:rw ${XDG_RUNTIME_DIR:-/run}/podman/podman.sock
109114
fi
110115
}
111116

@@ -170,6 +175,8 @@ EOF
170175
podman run -d -it --name cockpituous-tasks --pod=cockpituous \
171176
-v "$SECRETS"/tasks:/secrets:ro,z \
172177
-v "$SECRETS"/webhook:/run/secrets/webhook:ro,z \
178+
-v "${XDG_RUNTIME_DIR:-/run}/podman/podman.sock:/podman.sock" \
179+
-e CONTAINER_HOST=unix:///podman.sock \
173180
-e COCKPIT_CA_PEM=/run/secrets/webhook/ca.pem \
174181
-e COCKPIT_BOTS_REPO=${COCKPIT_BOTS_REPO:-} \
175182
-e COCKPIT_BOTS_BRANCH=${COCKPIT_BOTS_BRANCH:-} \
@@ -186,6 +193,9 @@ cleanup_containers() {
186193
# clean up dummy token, so that image-prune does not try to use it
187194
rm "$SECRETS"/webhook/.config--github-token
188195

196+
# remove podman socket ACL
197+
setfacl -b ${XDG_RUNTIME_DIR:-run}/podman/podman.sock
198+
189199
if [ -n "$INTERACTIVE" ]; then
190200
podman stop cockpituous-tasks
191201
else
@@ -289,6 +299,15 @@ test_queue() {
289299
echo "$OUT" | grep -q 'queue public is empty'
290300
}
291301

302+
test_podman() {
303+
# tasks can connect to host's podman service
304+
# this will be covered implicitly by job-runner, but as a more basal plumbing test this is easier to debug
305+
out="$(podman exec -i cockpituous-tasks podman-remote ps)"
306+
assert_in 'cockpituous-tasks' "$out"
307+
out="$(podman exec -i cockpituous-tasks podman-remote run -it --rm quay.io/cockpit/tasks:latest whoami)"
308+
assert_in '^user' "$out"
309+
}
310+
292311
#
293312
# main
294313
#
@@ -311,6 +330,7 @@ else
311330
# tests which don't need GitHub interaction
312331
test_image
313332
test_queue
333+
test_podman
314334
# if we have a PR number, run a unit test inside local deployment, and update PR status
315335
[ -z "$PR" ] || test_pr
316336
fi

0 commit comments

Comments
 (0)