Skip to content

fix(hermes): correct env arg order in run-as-hal0 guard (#843 follow-up)#847

Merged
thinmintdev merged 1 commit into
mainfrom
fix/runas-guard-env-order
Jun 15, 2026
Merged

fix(hermes): correct env arg order in run-as-hal0 guard (#843 follow-up)#847
thinmintdev merged 1 commit into
mainfrom
fix/runas-guard-env-order

Conversation

@thinmintdev

Copy link
Copy Markdown
Contributor

Follow-up to #844.

Bug

The guard re-exec wrapped the command as env HOME=<h> -u HERMES_HOME <cmd>.
GNU env stops option parsing at the first NAME=VALUE, so -u was treated as
the commandenv: '-u': No such file or directory (exit 127) when hermes
is run as root. The systemd service path is unaffected (it runs as hal0, guard
is a no-op), so this only broke interactive root invocations — i.e. the guard
errored instead of cleanly re-execing as hal0.

Caught during the live CT105 deploy, not by CI: the original test only
string-matched the argv and never executed env.

Fix

Reorder to env -u HERMES_HOME HOME=<h> <cmd> (options before assignments) in
the runuser + setpriv branches (sudo branch was already correct). Add a test
whose stub runuser execs the wrapped command, so env runs for real —
verifies HERMES_HOME stripped and HOME = the target user's home. This test
fails (exit 127) against the old lib and passes against the fix.

Verification

  • 8/8 guard tests pass; shellcheck clean.
  • Hotfixed live on CT105 and verified: hal0_ensure_runas hal0 id -unhal0;
    printenv HOME under the guard → /var/lib/hal0; hermes as root re-execs
    (exit 0) without recreating /root/.hermes.

🤖 Generated with Claude Code

The re-exec wrapped the command as `env HOME=<h> -u HERMES_HOME <cmd>`, but
GNU env stops option parsing at the first NAME=VALUE — so `-u` was treated as
the command and the guard died with `env: '-u': No such file or directory`
when run as root (the systemd path is unaffected: it runs as hal0, guard no-op).

Reorder to `env -u HERMES_HOME HOME=<h> <cmd>` (options before assignments) for
the runuser + setpriv branches. The original test only string-matched the argv
and never executed env, so it stayed green; add a test whose stub runuser EXECs
the wrapped command, exercising env for real (HERMES_HOME stripped, HOME set).

Hotfixed live on CT105.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@thinmintdev thinmintdev enabled auto-merge (squash) June 15, 2026 10:28
@thinmintdev thinmintdev merged commit 222a9d7 into main Jun 15, 2026
3 checks passed
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