feat: add lab unlock / lab lock for passwordless privileged setup - #14
Merged
Conversation
…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>
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.
4.2.0 —
lab unlock/lab lockRemoves the last thing that blocks a headless run / AI agent: the
sudopassword prompt lab shows for its privileged setup (the macOS loopback alias re-added on the firstlab upafter each boot, and the hosts-file write).What it does
lab unlock— one password prompt installs:/usr/local/lib/lab-cli/lab-elevate.sh(not user-writable) that performs only two tightly-validated actions: add anlo0alias limited to127.0.0.0/8, and copy a temp file onto/etc/hosts;visudo-validated/etc/sudoers.d/lab-clirule grantingNOPASSWDfor 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
visudo -cbefore activation so a bad rule can’t breaksudo.Network/DockerHostsuse the helper only when unlock is active and otherwise fall back to today’s prompting elevation — no change for users who never runlab unlock.Verification
npm run build✅ ·npm test✅ (27 suites / 55 tests; newUnlock/UnlockCommandtests cover the sudoers/helper content, the install/remove elevation, the routing, and the platform/again-guards). The realsudoinstall isn’t executed in CI — it modifies the machine and needs a password, so it’s run by the user vialab unlock.🤖 Generated with Claude Code