run0: install via scripts/as-root, chandra-root for GUI apps as root, session refuses root
CI / test (push) Failing after 16s

- scripts/as-root runs a command as root with run0 (systemd PID 1 + run0 present), else sudo,
  doas or pkexec; resolves the program to an absolute path since run0 doesn't inherit PATH.
  The install-session recipes use it and pass install.py by absolute path.
- session/chandra-root (installed to /usr/local/bin): run a graphical app as root inside
  Chandra, passing WAYLAND_DISPLAY (absolute) and the Wayland toolkit variables through
  run0 --setenv (or sudo/doas/pkexec env).
- chandra-session: refuses to run as root (CHANDRA_ALLOW_ROOT=1 overrides), fills in HOME and
  XDG_RUNTIME_DIR when started without a login environment, logs when the logind session has
  no seat (run0 --user / su / ssh), and starts an installed polkit agent once the socket is up
  so run0/pkexec from the launcher can prompt (CHANDRA_POLKIT_AGENT picks one or 'none').
- install.py: checks for root before --remove too; installs chandra-root.
- docs/run0.md: invocations for installing, starting from a TTY, apps as root, polkit agents.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hkq6Hq7AXG85g5HyJU
This commit is contained in:
Claude committed 2026-11-25 20:13:55 +00:00
1 parent f844ac66ff
commit 9c0a794c2d
7 files changed
+254 -8

No files matched your search

+50
View File
@@ -0,0 +1,50 @@
#!/bin/sh
# Run a graphical app as root inside Chandra, e.g. `chandra-root gparted`.
#
# `run0 gparted` alone opens no window: run0 runs the app as a systemd service with a clean
# environment, so the app has no WAYLAND_DISPLAY and can't find the compositor. This passes the
# compositor's socket (as an absolute path, since root's XDG_RUNTIME_DIR is not ours) and the
# "use Wayland" toolkit variables through run0 --setenv. Root can open the socket in our runtime
# directory; nothing else of ours (session bus, runtime dir, HOME) is handed to the root app.
#
# Started from a terminal, run0 asks for the password there. Started from the launcher or a
# shortcut, it needs a polkit authentication agent, which chandra-session starts when one is
# installed (polkit-gnome, mate-polkit, polkit-kde, lxpolkit, ...). Without run0 (systemd < 256,
# or not systemd) it uses sudo, doas or pkexec instead; CHANDRA_AS_ROOT picks one.
[ $# -gt 0 ] || { echo "usage: chandra-root APP [ARG...]" >&2; exit 2; }
prog=$(command -v "$1") || { echo "chandra-root: $1: not found" >&2; exit 127; }
shift
rt=${XDG_RUNTIME_DIR:-/run/user/$(id -u)}
disp=${WAYLAND_DISPLAY:-wayland-moon-0}
case "$disp" in /*) ;; *) disp="$rt/$disp" ;; esac
[ -S "$disp" ] || { echo "chandra-root: no Wayland socket at $disp (is Chandra running?)" >&2; exit 1; }
set -- WAYLAND_DISPLAY="$disp" XDG_SESSION_TYPE=wayland XDG_CURRENT_DESKTOP="${XDG_CURRENT_DESKTOP:-chandra}" \
GDK_BACKEND=wayland QT_QPA_PLATFORM=wayland SDL_VIDEODRIVER=wayland MOZ_ENABLE_WAYLAND=1 \
ELECTRON_OZONE_PLATFORM_HINT=wayland CLUTTER_BACKEND=wayland "$prog" "$@"
[ -n "$LANG" ] && set -- LANG="$LANG" "$@"
if [ "$(id -u)" = 0 ]; then exec env "$@"; fi
for tool in ${CHANDRA_AS_ROOT:-run0 sudo doas pkexec}; do
command -v "$tool" >/dev/null 2>&1 || continue
case "$tool" in
run0)
[ -d /run/systemd/system ] || continue
# run0 --setenv=NAME=VALUE for each variable, then the program and its arguments.
n=$#
while [ "$n" -gt 0 ]; do
a=$1; shift; n=$((n - 1))
case "$a" in
*=*) [ -z "$done_env" ] && { set -- "$@" "--setenv=$a"; continue; } ;;
esac
done_env=1
set -- "$@" "$a"
done
exec run0 "$@"
;;
*) exec "$tool" env "$@" ;;
esac
done
echo "chandra-root: none of run0, sudo, doas or pkexec is available" >&2
exit 1
+65
View File
@@ -5,6 +5,27 @@
# WebAssembly component, run by chandra-host; if only the native binary was installed
# (session/install.py --native), it runs that instead.
share=/usr/local/share/chandra
# The desktop runs as the user who logged in, never as root: as root (say `run0 chandra-session`
# or `sudo chandra-session`) every app would run as root, its socket would live in root's runtime
# dir where your apps can't see it, and settings would land in /root. For one app that needs
# root, use `chandra-root APP` inside the session. CHANDRA_ALLOW_ROOT=1 overrides this.
if [ "$(id -u)" = 0 ] && [ -z "$CHANDRA_ALLOW_ROOT" ]; then
echo "chandra-session: refusing to run the desktop as root; start it as yourself" \
"(use chandra-root APP for single apps that need root)" >&2
exit 1
fi
# Started from a login without the usual session environment (run0 --user=..., su, a bare
# `env -i`): fill in HOME and the runtime directory from the system instead of falling back to
# /tmp, so the socket lands where apps and chandra-root look for it.
if [ -z "$HOME" ]; then
HOME=$(getent passwd "$(id -u)" | cut -d: -f6)
export HOME
fi
if [ -z "$XDG_RUNTIME_DIR" ] && [ -d "/run/user/$(id -u)" ] && [ -O "/run/user/$(id -u)" ]; then
export XDG_RUNTIME_DIR="/run/user/$(id -u)"
fi
case "$0" in /*) self="$0" ;; *) self="$PWD/$0" ;; esac # for the dbus-run-session re-exec
export XDG_SESSION_TYPE=wayland
@@ -65,5 +86,49 @@ if command -v gnome-keyring-daemon >/dev/null 2>&1; then
[ -n "$SSH_AUTH_SOCK" ] && export SSH_AUTH_SOCK
fi
# A logind session without a seat (made by run0 --user=..., su - or ssh rather than by logging in
# on the VT) can't open the screen and input devices through logind; say so in the log, since
# the compositor's own error ("could not take control of the session") doesn't explain why.
if [ -n "$XDG_SESSION_ID" ] && command -v loginctl >/dev/null 2>&1; then
seat=$(loginctl show-session "$XDG_SESSION_ID" -p Seat --value 2>/dev/null)
if [ -z "$seat" ]; then
echo "chandra-session: login session $XDG_SESSION_ID has no seat (started by run0, su or" \
"ssh?); log in on the VT itself, or DRM/input access through logind will fail" >>"$log"
fi
fi
# A polkit authentication agent, so `chandra-root APP`, run0 and pkexec started from the launcher
# or a shortcut (no terminal to ask in) can show a password prompt. Uses the first one installed,
# once the compositor's socket is up (the agents are GTK/Qt apps that need it at startup).
# CHANDRA_POLKIT_AGENT names one explicitly, or "none" to start none (say, when a systemd user
# unit already starts one).
agent=${CHANDRA_POLKIT_AGENT:-}
if [ -z "$agent" ]; then
for a in \
/usr/lib/polkit-gnome/polkit-gnome-authentication-agent-1 \
/usr/libexec/polkit-gnome-authentication-agent-1 \
/usr/lib/mate-polkit/polkit-mate-authentication-agent-1 \
/usr/libexec/polkit-mate-authentication-agent-1 \
/usr/lib/x86_64-linux-gnu/polkit-mate/polkit-mate-authentication-agent-1 \
/usr/lib/polkit-kde-authentication-agent-1 \
/usr/libexec/polkit-kde-authentication-agent-1 \
/usr/libexec/kf6/polkit-kde-authentication-agent-1 \
/usr/lib/x86_64-linux-gnu/libexec/polkit-kde-authentication-agent-1 \
/usr/lib/hyprpolkitagent/hyprpolkitagent \
/usr/libexec/hyprpolkitagent \
/usr/libexec/xfce-polkit \
/usr/lib/xfce-polkit/xfce-polkit \
"$(command -v lxpolkit 2>/dev/null)"; do
if [ -n "$a" ] && [ -x "$a" ]; then agent=$a; break; fi
done
fi
if [ -n "$agent" ] && [ "$agent" != none ]; then
(
i=0
while [ ! -S "$sock" ] && [ $i -lt 200 ]; do sleep 0.1; i=$((i + 1)); done
WAYLAND_DISPLAY="$sock" GDK_BACKEND=wayland exec "$agent"
) >>"$log" 2>&1 &
fi
exec "$@" --drm --socket "$sock" \
--theme "$share/config/themes/moon-night.json" >>"$log" 2>&1
+11 -3
View File
@@ -1,5 +1,6 @@
#!/usr/bin/env python3
"""Install (or remove) the Chandra login session. Run as root, once:
"""Install (or remove) the Chandra login session. Run as root, once (`just install-session` etc. do
this through scripts/as-root, which uses run0 and falls back to sudo, doas or pkexec):
run0 python3 session/install.py # install: the compositor as a wasm component
run0 python3 session/install.py --link # dev: symlink into this checkout (see below)
@@ -7,6 +8,9 @@
run0 python3 session/install.py --rust-host # the wasm compositor on the Rust host (host-wasm)
run0 python3 session/install.py --remove # uninstall
(`sudo python3 session/install.py` works the same. run0 keeps the working directory when the
target is root, so the relative path is fine from the checkout's root.)
With --link nothing is copied: the installed files are symlinks to the build outputs in this
checkout, so after one root install, `just compositor-wasm wasmhost modules` is all it takes for the
next login to run your latest build (no root, no reinstall). The checkout must stay where it is.
@@ -16,6 +20,7 @@ Installs:
/usr/local/share/chandra/compositor.wasm the compositor, as a WebAssembly component
/usr/local/bin/chandra (--native) release native compositor binary
/usr/local/bin/chandra-session session launcher (starts the host if installed)
/usr/local/bin/chandra-root run one graphical app as root in the session (run0)
/usr/local/share/chandra/{config,wit,assets}/ files the compositor reads at runtime
/usr/local/share/chandra/modules/*.wasm the panel's wasm modules (build them first: just modules)
/usr/share/wayland-sessions/chandra.desktop display-manager entry
@@ -37,9 +42,13 @@ targets = [
"/usr/local/bin/chandra",
"/usr/local/bin/chandra-host",
"/usr/local/bin/chandra-session",
"/usr/local/bin/chandra-root",
"/usr/share/wayland-sessions/chandra.desktop",
]
if os.geteuid() != 0:
sys.exit("run as root: run0 python3 session/install.py (or sudo), or `just install-session`")
if "--remove" in sys.argv:
for t in targets:
if os.path.lexists(t):
@@ -50,8 +59,6 @@ if "--remove" in sys.argv:
print("removed", share)
sys.exit(0)
if os.geteuid() != 0:
sys.exit("run as root: run0 python3 session/install.py")
if native:
if not os.path.exists(exe):
sys.exit("missing %s - run `just build-release` first" % exe)
@@ -94,6 +101,7 @@ os.makedirs(share, exist_ok=True)
if not native:
install(component, os.path.join(share, "compositor.wasm"))
install(os.path.join(root, "session/chandra-session"), "/usr/local/bin/chandra-session")
install(os.path.join(root, "session/chandra-root"), "/usr/local/bin/chandra-root")
# The display-manager entry stays a real file: some managers don't follow symlinks there.
put(os.path.join(root, "session/chandra.desktop"), "/usr/share/wayland-sessions/chandra.desktop", 0o644)
# Read at runtime relative to the working directory (the launcher cd's here): the Interface Explorer