Skip to content

Refactor XFCE container startup for POSIX compliance, secure env forw…#4

Open
frangarb wants to merge 2 commits into
Droidspaces:mainfrom
frangarb:main
Open

Refactor XFCE container startup for POSIX compliance, secure env forw…#4
frangarb wants to merge 2 commits into
Droidspaces:mainfrom
frangarb:main

Conversation

@frangarb

Copy link
Copy Markdown
Contributor

What

Hardens the XFCE session launcher used in DroidSpaces containers, replacing
the previous best-effort script with a POSIX-portable, fail-fast version that
works on both util-linux and BusyBox/Alpine userspaces.

Why

The original script:

  • Ran DISPLAY/PulseAudio/virgl setup only when the env file was absent,
    so those defaults were skipped whenever /run/droidspaces.env existed.
  • Used chown "$XFCE_USER" and the non-POSIX chown user: idiom.
  • chowned /tmp sockets without guarding against symlinks.
  • Forwarded environment variables without validating names.
  • Assumed util-linux su -w was always available.

Changes

  • Fail-fast: set -eu; env file sourced under set -a/set +a.
  • Correct setup ordering: DISPLAY, PULSE_SERVER, and GALLIUM_DRIVER
    defaults applied unconditionally via : "${VAR:=default}".
  • Symlink-safe ownership: safe_chown skips non-existent paths and symlinks.
  • POSIX ownership: explicit user:GID via id -g; validates XFCE_USER
    existence and GID resolution with clear errors.
  • Env whitelist: restricted to strict POSIX identifier names, excluding
    session-poisoning vars (HOME, USER, XDG_RUNTIME_DIR, etc.).
  • su portability: anchored su --help detection for -w /
    --whitelist-environment; quote-escaped EXPORTS fallback for BusyBox su.
  • Root fallback: explicit warnings when XFCE_USER is root, unset, or empty.

Notes / limitations

  • Only local :N displays are supported (TCP host:N is not parsed).
  • Env values containing newlines are unsupported (line-based enumeration; no
    GNU env -0), acceptable for the controlled DroidSpaces environment.

frangarb added 2 commits June 15, 2026 19:11
…arding, and fail-safe execution

Harden XFCE session launcher for DroidSpaces

- Add set -eu and set -a/+a for safe, fail-fast env-file sourcing
- Always apply DISPLAY/PulseAudio/virgl setup (no longer skipped when
  the env file exists)
- Add safe_chown to skip symlinks when chowning sockets in shared /tmp
- Assign explicit user:GID ownership via id -g (POSIX/BusyBox-safe,
  replaces non-POSIX "chown user:")
- Validate that XFCE_USER exists and that its GID resolves
- Whitelist forwarded env vars to strict POSIX identifier names
- Detect util-linux su -w via anchored --help match; add quote-escaped
  EXPORTS fallback for BusyBox/Alpine su
- Guard XFCE_USER with ${XFCE_USER:-} so set -u does not abort when unset
- Warn explicitly when falling back to root
Remove su -l in the whitelist path; -l reset the environment and silently defeated -w.
Single-quote XDG_RUNTIME_DIR inside every su -c string to prevent breakage on special characters.
Replace eval in the BusyBox fallback with printenv to remove a code-injection vector.
Gate PulseAudio/VirGL socket chown behind their config flags so stale sockets aren't re-owned.
Split the whitelist launch into explicit branches instead of a fragile ${VAR:+...} expansion that mangled -w args.
Guard su --help with || true so a non-zero exit doesn't abort under set -e.
safe_chown now handles dangling symlinks and uses chown -h (no link following).
Use numeric UID:GID for ownership consistently.
Fix DISPLAY parsing so TCP displays (host:5) resolve the socket path correctly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant