Skip to content

Fix disabled detection, add provenance and per-action privileges - #3

Merged
sderosiaux merged 3 commits into
mainfrom
hardening-and-provenance
Sep 1, 2026
Merged

sderosiaux merged 3 commits into
mainfrom
hardening-and-provenance

Conversation

@sderosiaux

Copy link
Copy Markdown
Owner

Closes #1
Closes #2

disabled never worked

launchctl print-disabled prints => disabled since macOS 13, not => true. The disabled set was therefore always empty, with a chain of consequences: no service ever showed as disabled, and since apply_disabled fell through to enabled = Some(true) for everything, the toggle could only ever plan disable — a disabled service could not be re-enabled from the UI at all.

Verified on macOS 26.4.1: 0 lines match => true, 16 match => disabled across gui/user/system. Both wordings are now accepted; 10 disabled services surface on the test machine where there were structurally zero.

Privileges are per action, not per service (#1)

The issue reported that admin services are blocked. The diagnosis was only half right: safety_for_scope tagged both GlobalAgent and SystemDaemon as AdminRequired, but launchd scope and file ownership are independent axes. An agent in /Library/LaunchAgents is root-owned on disk yet runs in the caller's gui/<uid> domain — launchctl kickstart gui/501/<label> needs no privileges whatsoever. Launchdeck was blocking itself for nothing.

ElevationNeeds { runtime, plist_write, plist_remove } is now computed at discovery from the real uid/mode of the plist and its directory, and resolved per action at plan time. Concretely, on /Library/LaunchAgents/us.zoom.updater.plist: start/stop need nothing, delete needs root.

What genuinely needs root is prefixed with sudo --, shown in full at the confirmation prompt, then run with the TUI suspended so sudo prompts on the real terminal. The command stays an argument list — never a shell string — and the password never passes through the process. osascript and SMJobBless were rejected: the first breaks over SSH and reintroduces a shell-quoting surface, the second needs a signed bundle.

Verified end to end against system/org.wireshark.ChmodBPF: prompt, execution, terminal restored.

Provenance (#2)

Origin { kind, confidence, evidence } classified from signals already in memory — no extra subprocess. Ordering is the design: a nix-darwin daemon sits in /Library/LaunchDaemons like any vendor helper, so the /nix/store command path has to win over the directory it lives in.

Kinds: homebrew, user-plist, mise, nix, vendor-app, system, runtime-only, unknown. Rendered as an origin row in the detail modal with its evidence, an ORIGIN column in launchdeck list, and indexed by search. Selecting the row puts the change hint in the status line.

On the test machine: 8 homebrew (matching exactly the 8 brew formulas), 21 user-plist, 9 vendor-app, 5 runtime-only, 1045 system, 0 unknown.

This also fixes a real gap: every plist-less job used to be lumped into ProtectedVendor regardless of what it actually was.

Other defects found along the way

  • No panic hook. Any panic inside terminal.draw left the shell in raw mode on the alternate screen.
  • tail_file seeked to an arbitrary byte offset then read_to_string. Any log whose 32 KiB boundary cut a codepoint — or any non-UTF-8 log — made the log view fail outright. Now reads bytes, decodes lossily, and drops the half-line the seek created.
  • Actions ran on the UI thread. A slow brew services froze the whole TUI. Unprivileged actions moved to a worker; elevated ones stay inline because sudo needs the terminal.
  • A panicking refresh worker killed background refresh for the session. refresh_in_progress was never reset. Now bounded by a timeout.
  • brew services list --json polled every 3 s — 0.9 s of a 1.1 s inventory pass, permanently, for state that only changes when someone runs brew. Own TTL, bypassed after an action.
  • Width specifiers were ignored on Display impls that write straight to the formatter, misaligning two columns of launchdeck list.
  • A plist rejected by plutil -lint stayed on disk. It reappeared as a broken service on the next refresh, and the "already exists" guard then blocked recreating it with the same label — a stuck state around a file the user never knew was written.

Packaging

--version (it did not exist), and a cargo publish job guarded by CARGO_REGISTRY_TOKEN that verifies the tag matches Cargo.toml. crates.io had drifted to 0.1.2 while the repo was at 0.1.3, because publishing was manual.

Tests

47 passing, up from 31. Covers both print-disabled wordings, the four elevation rules, the four provenance ordering rules, brew cache hit/expiry, and a headless render of all three views at 1×1, 8×3, 20×5 and 40×10 — which is how the detail modal growing from 17 to 19 rows was checked for panics.

Known limits

  • is_writable does not resolve supplementary groups (no libc). The bias is deliberate and one-directional: it may ask for elevation that was not strictly needed, never skip elevation that was.
  • SafetyLevel::AdminRequired no longer governs anything and survives as a location label only.
  • The pre-existing /bin/sh -lc calls in actions.rs are untouched.

launchctl print-disabled prints `=> disabled` since macOS 13, not `=> true`,
so the disabled set was always empty: no service ever showed as disabled and
the enable/disable toggle could only ever plan `disable`. Parse both wordings.

Privileges were decided per service, conflating launchd scope with file
ownership. An agent in /Library/LaunchAgents is root-owned but runs in the
caller's gui domain, so every action on it was blocked for nothing. Elevation
is now computed per axis at discovery time and per action at plan time; what
genuinely needs root is prefixed with `sudo`, shown in full at the prompt, and
run with the TUI suspended so the password reaches the real terminal.

Also adds provenance classification (homebrew, user-plist, mise, nix,
vendor-app, system, runtime-only) from signals already in memory, closing the
gap where every plist-less job was lumped into one bucket.

Other fixes found along the way:
- no panic hook, so any panic left the shell in raw mode on the alt screen
- tail_file seeked to an arbitrary byte offset then read_to_string, failing on
  any log whose 32KiB boundary cut a codepoint
- actions ran on the UI thread, freezing the TUI for the length of a slow
  `brew services`
- a panicking refresh worker disabled background refresh for the whole session
- `brew services list --json` (0.9s of a 1.1s pass) polled every 3s; it now
  has its own TTL, bypassed after an action
- width specifiers were ignored in `list` output, misaligning two columns
A plist that fails lint stayed in ~/Library/LaunchAgents: it surfaced as a
broken service on the next refresh, and the "already exists" guard then
blocked the user from retrying with the same label.

Also locks the invariant between CreateField::editable and current_value_mut,
whose unreachable!() arm depends on the two lists agreeing.
The row carried label, confidence, change hint and evidence at once: 129
characters worst case, truncated below 120 columns. The change hint is generic
per provenance kind, so it moves to the status line when the origin row is
selected, which is the mechanism the other detail rows already use. Evidence,
which is what actually varies per service, stays in the row.

Worst case is now 63 characters.
@sderosiaux
sderosiaux merged commit 06b067f into main Sep 1, 2026
2 checks passed
@sderosiaux
sderosiaux deleted the hardening-and-provenance branch September 1, 2026 22:12
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.

Show provenance for discovered services this service needs admin privileges; sudo execution is not implemented yet

1 participant