fix(hermes): correct env arg order in run-as-hal0 guard (#843 follow-up)#847
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #844.
Bug
The guard re-exec wrapped the command as
env HOME=<h> -u HERMES_HOME <cmd>.GNU
envstops option parsing at the firstNAME=VALUE, so-uwas treated asthe command →
env: '-u': No such file or directory(exit 127) whenhermesis run as root. The systemd service path is unaffected (it runs as
hal0, guardis 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) inthe runuser + setpriv branches (sudo branch was already correct). Add a test
whose stub
runuserexecs the wrapped command, soenvruns for real —verifies
HERMES_HOMEstripped andHOME= the target user's home. This testfails (exit 127) against the old lib and passes against the fix.
Verification
hal0_ensure_runas hal0 id -un→hal0;printenv HOMEunder the guard →/var/lib/hal0;hermesas root re-execs(exit 0) without recreating
/root/.hermes.🤖 Generated with Claude Code