Skip to content

fix(install): refuse an unsafe --prefix on uninstall - #342

Merged
CameronBrooks11 merged 2 commits into
mainfrom
fix/uninstall-prefix-guard
Oct 13, 2026
Merged

CameronBrooks11 merged 2 commits into
mainfrom
fix/uninstall-prefix-guard

Conversation

@CameronBrooks11

Copy link
Copy Markdown
Member

install.sh --uninstall --prefix "" skipped the prefix guard and reported "uninstall complete". So did a relative prefix that does not exist from the current directory. main left uninstall to _removable_prefix, but do_uninstall only calls that when the path exists, and it stops and deletes every anolis-*.service unit and the secrets in /etc/anolis whatever the prefix.

main now runs check_prefix for uninstall as well as for install and rollback. An empty, relative, top-level, $HOME or symlink prefix is refused before the root check and before anything is stopped. An existing prefix still goes through _removable_prefix as before. An absolute prefix that no longer exists still uninstalls the units and secrets.

tests/shell/prefix_guard_test.bats now runs every refusal input against uninstall as well, adds a relative prefix that does not exist, and checks that uninstall still runs for an absolute prefix that is gone. do_uninstall runs for real, and rm, rmdir, systemctl and the other commands that change the host are recording stubs.

Before the fix, 7 of 12 tests fail. The empty and missing-relative inputs exit 0 and record systemctl daemon-reload and rmdir /etc/anolis:

not ok 1 335: an empty prefix is refused before anything runs
# not refused: uninstall --prefix '' (status 0)
#   recorded: systemctl daemon-reload
#   recorded: rmdir /etc/anolis
not ok 3 335: a relative prefix that does not exist is refused
# not refused: uninstall --prefix 'opt/anolis' (status 0)
# not refused: uninstall --prefix './gone' (status 0)

The other five fail because uninstall refused those inputs only after the root check, and its message did not name --prefix. After the fix, 12 of 12 pass. With the old condition (&& ${UNINSTALL} -eq 0) put back, tests 1-7 fail again.

shellcheck tools/install.sh is clean, and bats tests/shell/ passes 175 of 175.

Closes #339

--uninstall with an empty prefix, or a relative one that does not
exist, skipped the prefix guard: main left uninstall to
_removable_prefix, which do_uninstall only calls for a path that
exists. The uninstall then stopped and deleted every anolis unit and
the secrets in /etc/anolis, and reported success.

main now runs check_prefix for uninstall too, before the root check.
An existing prefix still goes through _removable_prefix, and an
absolute prefix that is already gone still uninstalls the units.

Closes #TBD
@CameronBrooks11
CameronBrooks11 merged commit 8aced20 into main Oct 13, 2026
26 checks passed
@CameronBrooks11
CameronBrooks11 deleted the fix/uninstall-prefix-guard branch October 13, 2026 05:29
CameronBrooks11 added a commit that referenced this pull request Oct 16, 2026
Bumps `project(VERSION)` and `vcpkg.json` to 0.1.45 and rolls the
CHANGELOG. Ships, among others:
- `safety.on_startup`, default `safe_state`: the declared safe state
  runs once at every runtime start (#392, closes #362);
- Grafana and InfluxDB bound to loopback under `--with-observability`,
  with `--with-grafana-network` to open Grafana to the LAN (#359,
  closes #351);
- `install.sh` refuses a downgrade unless `--allow-downgrade` (#382,
  closes #366);
- the zero rung no longer sends a guessed boolean (#367), e-stop
  `safe_state_achieved` (#368), dispatchable coverage counts (#369),
  and startup warnings for fault-hook gaps (#370) and disarmed
  watchdogs (#371);
- `health.excluded_signals` (#377), signal unit and description in
  capabilities (#365);
- a half-open probe of an open provider circuit every 60 s, a restart
  that stops the old process first, and a restart clock that starts
  after it stops (#376, #391);
- automation status: `idle` outside AUTO, and `failed` cleared by a
  load or a new AUTO run (#373, #386);
- `install.sh`: provider liveness in the health phase (#355, #383),
  `manifest.json` restored on `--rollback` (#354), Grafana restarted
  on every observability run (#343), the datasource debug lines
  filtered from the journal (#360), and the uninstall prefix guard
  (#342);
- no ERROR lines for reads that fail during shutdown (#381).

The CHANGELOG opens 0.1.45 with upgrade notes: Grafana is on loopback
by default, `safety.on_startup` drives outputs at boot by default, and
downgrades need `--allow-downgrade`. The 0.1.44 note about restarting
grafana-server by hand is not repeated, since #343 restarts it on
every run.

The OpenAPI changes are additive: `SignalSpec.unit` and
`.description`, `EstopResponse.safe_state_achieved`,
`ParameterDefinition.source` and the runtime status
`startup_safe_state`. No provider-protocol change. anolis-workbench
vendors the OpenAPI file and needs a repin to this release.

Every commit in `git log v0.1.44..main` is in the CHANGELOG except
CI, test-only and docs-lint commits (#380, #384, #389).

After merge, tag `v0.1.45`.
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.

install.sh: --uninstall with an empty or relative prefix skips the prefix guard

1 participant