From 9dc9e0da9a7052c689b805d76fce9bbeb3ab4e27 Mon Sep 17 00:00:00 2001 From: Hermenix Date: Thu, 1 Oct 2026 04:00:01 +0000 Subject: [PATCH] examples/agent-eyes: use the setuid sg wrapper, not whatever PATH offers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There are two `sg` on this box: the setuid wrapper in /run/wrappers/bin and a plain symlink to shadow's sg in the system profile. A login shell has the wrapper first and works; a cron job's PATH reaches the plain one, which cannot switch groups and dies with "setgroups: Operation not permitted" — which reads as "chromium exited immediately" once a consumer discards its stderr. The helper now looks for a setuid `sg` explicitly and says so if there is none. --- examples/agent-eyes | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/examples/agent-eyes b/examples/agent-eyes index ba995b6..1b6c964 100755 --- a/examples/agent-eyes +++ b/examples/agent-eyes @@ -25,9 +25,24 @@ SHOT_DIR=${AGENT_EYES_SHOT_DIR:-/var/lib/hermes/public/agent-eyes} die() { printf 'agent-eyes: %s\n' "$*" >&2; exit 1; } have_group() { [ -x "$RUNDIR" ] && [ -r "$SOCKET" ]; } +# Only the setuid wrapper can switch groups, and PATH order decides which `sg` +# you get. A login shell has /run/wrappers/bin first and works; a cron job's +# PATH reaches the non-setuid copy in the system profile instead, which dies +# with "setgroups: Operation not permitted" — and, with stderr going to +# /dev/null, that looks like "chromium exited immediately". So pick the wrapper +# deliberately rather than trusting PATH. +sg_bin() { + local c + for c in /run/wrappers/bin/sg "$(command -v sg 2>/dev/null || true)"; do + [ -n "$c" ] && [ -x "$c" ] && [ -u "$c" ] && { printf '%s\n' "$c"; return 0; } + done + return 1 +} + # One self re-exec, so every branch below may assume group access. if ! have_group; then - exec sg "$GROUP" -c "$(printf '%q ' "$0" "$@")" + SG=$(sg_bin) || die "cannot join group $GROUP: no setuid 'sg' found (looked in /run/wrappers/bin)" + exec "$SG" "$GROUP" -c "$(printf '%q ' "$0" "$@")" fi wayland_socket() {