examples/agent-eyes: use the setuid sg wrapper, not whatever PATH offers

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.
This commit is contained in:
Hermenix committed 2026-10-01 04:00:01 +00:00
1 parent 09903c5676
commit 9dc9e0da9a
1 file changed
+16 -1
+16 -1
View File
@@ -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() {