Skip to content

feat: add lab unlock / lab lock for passwordless privileged setup - #14

Merged
graphicfox merged 2 commits into
masterfrom
feat/unlock-command
Jul 17, 2026
Merged

feat: add lab unlock / lab lock for passwordless privileged setup#14
graphicfox merged 2 commits into
masterfrom
feat/unlock-command

Conversation

@graphicfox

Copy link
Copy Markdown
Contributor

4.2.0 — lab unlock / lab lock

Removes the last thing that blocks a headless run / AI agent: the sudo password prompt lab shows for its privileged setup (the macOS loopback alias re-added on the first lab up after each boot, and the hosts-file write).

What it does

  • lab unlock — one password prompt installs:

    • a root-owned helper /usr/local/lib/lab-cli/lab-elevate.sh (not user-writable) that performs only two tightly-validated actions: add an lo0 alias limited to 127.0.0.0/8, and copy a temp file onto /etc/hosts;
    • a visudo-validated /etc/sudoers.d/lab-cli rule granting NOPASSWD for only that helper — not blanket root.

    Afterwards lab's privileged steps never prompt again, in any terminal.

  • lab lock — reverts it (removes the sudoers rule + helper).

  • Windows — prints the “run as Administrator” fallback (UAC can’t be pre-authorized this way).

Safety

  • Opt-in, scoped, reversible; sudoers validated with visudo -c before activation so a bad rule can’t break sudo.
  • Network/DockerHosts use the helper only when unlock is active and otherwise fall back to today’s prompting elevation — no change for users who never run lab unlock.

Verification

npm run build ✅ · npm test ✅ (27 suites / 55 tests; new Unlock/UnlockCommand tests cover the sudoers/helper content, the install/remove elevation, the routing, and the platform/again-guards). The real sudo install isn’t executed in CI — it modifies the machine and needs a password, so it’s run by the user via lab unlock.

🤖 Generated with Claude Code

Kim Martini and others added 2 commits July 17, 2026 14:18
…setup

lab shells out to sudo for its privileged setup - the macOS loopback alias
(re-added on the first `lab up` after every boot) and the hosts-file write. In a
fresh terminal that means a password prompt, which blocks CI and AI agents that
cannot answer it (and that the user may not even have shell access to).

`lab unlock` fixes this with a single password prompt: it installs a root-owned
helper (/usr/local/lib/lab-cli/lab-elevate.sh, not user-writable) that performs
ONLY those two tightly-validated actions (loopback alias limited to 127.0.0.0/8,
and a copy onto /etc/hosts), plus a visudo-validated /etc/sudoers.d/lab-cli rule
granting NOPASSWD for ONLY that helper - not blanket root. Afterwards the
privileged steps run without prompting, in any terminal. `lab lock` reverts it.

Network and DockerHosts route through the helper when unlock is active and fall
back to the previous prompting elevation otherwise, so nothing changes for users
who never run `lab unlock`. macOS + Linux only; on Windows the command explains
the "run as Administrator" fallback.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@graphicfox
graphicfox merged commit f347913 into master Jul 17, 2026
1 check 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