Skip to content

Let sudo -v validate against the passwordless sudo grant - #16223

Open
omarchybot wants to merge 9 commits into
quattrofrom
omabot/pr-16111
Open

omarchybot wants to merge 9 commits into
quattrofrom
omabot/pr-16111

Conversation

@omarchybot

Copy link
Copy Markdown
Collaborator

Lets sudo -v validate against the passwordless sudo grant.

Under sudo's default verifypw=all, sudo -v asks for a password unless every sudoers entry the user has carries NOPASSWD. The installer's own admin rule (/etc/sudoers.d/04_<user>) requires a password, so a user who enabled passwordless sudo is still prompted by every sudo -v: omarchy-sudo-keepalive, omarchy-upgrade-to-quattro, and anything an agent runs. On a stock install with the grant enabled, sudo -n true succeeds and sudo -n -v answers "a password is required".

omarchy-sudo-passwordless now publishes a sudoers default above the rule it already wrote:

Defaults:<user> verifypw = any
<user> ALL=(ALL) NOPASSWD: ALL

The default is scoped to the account that asked for the grant, so it changes nothing for any other account on the host, and it is removed with the grant file when the grant is revoked or expires. A successful sudo -v under the grant writes no timestamp, so validation never leaves cached credentials behind after a timed grant ends.

The readers accept both the new two-line form and a grant published before the default existed. A file whose default names a different account than its rule is not this command's grant: status and expiry refuse it, and cleanup quarantines it as foreign policy under the generated prefix, as it does any other.

Grants published before the default existed are rewritten in place by a migration, keeping their rule and deadline. Migrations run once per account, so the migration only asks sudo to rewrite grants when the account running it holds an active grant, whose sudo needs no password; an account without a grant, or without sudo at all, finishes it without being asked to authorize anything, and each account's grant is rewritten when that account's migrations run.

This complements #15729, which fixes the sudo -v in the quiet-boot migration for every passwordless setup, including hand-written NOPASSWD rules this change does not reach. That migration runs before this one, so it still needs #15729.

Reviewed by Claude Opus 5.5 and Codex Medium.

Supersedes #16111 by @statick88, whose commits this carries unchanged, with the fixes above on top.

statick88 and others added 5 commits October 20, 2026 15:18
Under sudo's default verifypw=all, one password-requiring entry anywhere in
the policy is enough to make `sudo -v` prompt, so a user who enabled
passwordless sudo could not validate credentials without a password. The
installer's own admin grant is password-requiring, and package drop-ins add
more, so the grant cannot be the only entry that carries NOPASSWD.

The published grant now carries the sudoers default that makes validation
read the grant instead of every other entry, and a grant published before
that default existed is rewritten in place.
The default was unqualified, so publishing a grant for one account changed
the credential validation of every account on the host, and displaced a
verifypw setting an administrator had configured. The default now names the
account the grant belongs to, and a file whose default names another account
is not read as this command's grant.
The action was only reachable from inside the script, so the migration's call
fell through to the user-facing arguments, valid_duration rejected it and the
helper exited 1. That would have stopped omarchy-migrate on every machine
that reached the migration and left every later migration pending. The
action is dispatched now, and the test drives it through the executable and
through the migration itself.
classify_generated_rule read a sudoers default naming someone other than the rule's account as an unreadable file (2) rather than foreign policy (1), so cleanup_all_locked stopped quarantining it and left the rule live. The file was read fine; it is simply not this command's grant.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Codex Medium <noreply@openai.com>
Migrations run once per account, and this one ran sudo for every account to rewrite grants most of them do not have. An administrator with no grant was asked for a password to authorize nothing, and an account without sudo rights could never finish it, which leaves every later migration pending for that account. An account with an active grant runs sudo without a password, so checking --active first means the migration never prompts; each account's own grant is rewritten when that account's migrations run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Codex Medium <noreply@openai.com>
@greptile-apps

greptile-apps Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; the remaining test coverage concern is non-blocking.

Findings

  1. P2 Credential validation remains untested ▶

Summary

Lets generated passwordless grants support sudo -v without prompting.

  • Passwordless sudo grants let sudo -v validate against the grant.

No new actionable issues were found.

Reviews (3) · Last reviewed commit: "Keep the grant-format migration pending ..." · Reviewed by Greptile

Comment on lines +15 to +21
(
source "$library"
enable_locked 1000 15
head -1 "$(rule_file 1000)" | grep -qx 'Defaults:audituser verifypw = any'
tail -1 "$(rule_file 1000)" | grep -qxE 'audituser ALL=\(ALL\) NOTAFTER=[0-9]{14}Z NOPASSWD: ALL'
)
pass "the published grant carries the sudoers default above its rule"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Credential validation remains untested

The new tests check the generated text but never run sudo -v. The shared fixture replaces sudo, and the existing native-policy check only tests command execution. A change that writes the expected text but still prompts could pass these checks.

Add a disposable integration test with both password-requiring policy and the generated grant. Check that sudo -n -v succeeds during the grant, leaves no usable credentials after revocation or expiry, and does not change another account's behavior.

@omarchybot omarchybot added the bug Something isn't working label Oct 22, 2026
Status, enable and disable always run the installed /usr/bin copy, but under a dev link the migration runs the checkout's helper, which can be newer than the package. Rewriting a grant there left it in a form the installed copy rejects as unreadable, so the user could not revoke a permanent grant until the package caught up. The upgrade now leaves grants alone unless the installed copy knows the upgrade action, and therefore reads both forms. The fixture points INSTALLED_SELF at a private copy so a test can stand in an older one. docs/passwordless-sudo.md now describes the default the grant carries.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Codex Medium <noreply@openai.com>
Comment thread bin/omarchy-sudo-passwordless Resolved
@omarchybot omarchybot added verified Omarchy Triage has verified that this issue is ready for final review ready Good to merge labels Oct 22, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator Author

Reviewed at 89816c1 against quattro (be54892), with one fix pushed. It is verified and waiting on the maintainer.

What was checked, on a disposable Omarchy worker running sudo 1.9.17p2, with a test account that has a password-requiring rule beside the grant:

  • With a timed grant published by quattro's helper, sudo -n true succeeds and sudo -n -v answers "a password is required". The same grant published by this branch passes sudo -n -v. With the default reverted to verifypw = all, it fails again.
  • The migration rewrites an old-format permanent grant (root:root 0440), after which sudo -n -v passes. Rerunning it changes nothing. After sudo -v under the grant and revoking it, sudo -n true is refused, so no cached credential outlives the grant. Accounts with no sudo rights, and administrators with no grant, finish the migration without being prompted.
  • ./test/cli passes. On this branch merged with current quattro, the full ./test/shell has seven failing files (ascii, background reload and clone, About animation, cursor cold start, runtime smoke, screenshot sanity), and all seven fail on quattro too. In 22 runs of nopasswd-sudo-expiry-test.sh, one exited 126 at a --active assertion this change does not reach; it passed the other 21, and passed all 18 runs on quattro.

Fixed on top, in 89816c1: status, enable and disable always run the installed /usr/bin copy of omarchy-sudo-passwordless, but under a dev link the migration runs the checkout's copy. With an older package installed, the migration rewrote a permanent grant into the two-line form, the installed --disable then refused it ("Could not safely inspect passwordless sudo"), and passwordless sudo stayed on. The upgrade now leaves grants alone unless the installed copy knows the upgrade action. On the worker, the same setup now leaves the grant in the old form and --disable revokes it. A test with a stand-in for an older installed copy fails when the guard is removed. docs/passwordless-sudo.md now describes the default the grant carries.

The second opinion came from Codex Medium and muse-spark-1.3 (thinking high). Codex found the dev-link problem, and both found the missing docs sentence. Both also raised these, which were weighed and left unchanged:

  • A timed grant expiring between --active and the sudo call can still prompt. Using sudo -n there could leave the migration pending forever for an account whose only passwordless rule covers the installed helper.
  • A broken helper (--active exiting 126) completes the migration without rewriting. That costs only the original prompt.
  • migrations/1791898365.sh runs before this migration, so its sudo -v still needs Authorize the quiet boot migration without sudo -v #15729.

Their second round on 89816c1 found nothing further. Independence is not guaranteed, since they can read this session.

@chessing234 chessing234 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all good

@omarchybot omarchybot removed the ready Good to merge label Oct 31, 2026
omarchybot and others added 3 commits October 31, 2026 22:35
Brings the branch up to quattro after #17000 (ordinary sudo) and #16302 (no migration tests).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
quattro no longer tests migrations (#16302): they run once and are frozen once they ship. The fixture branch these two tests drove the migration through went with that change, so they now fail on the merged tree.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…read it

When the installed omarchy-sudo-passwordless predates the two-line grant, the upgrade skipped and returned success, so the migration was marked done and a permanent grant on a dev-linked machine kept the old form for good. It now fails, leaving the migration pending until the package catches up, as the migrations guide asks of one that cannot finish.

The tests move into the existing lifecycle suite and keep only what fails without this change: the published default, the upgrade through the dispatch the migration uses, and the refusal under an older installed copy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Codex Medium <noreply@openai.com>

Co-Authored-By: muse-wonder High <noreply@meta.com>
@omarchybot

Copy link
Copy Markdown
Collaborator Author

The maintainer asked at the desk whether this is still needed now that quattro uses ordinary sudo (#17000). It is, so it stays open. Reviewed again at f030b57 against quattro (846e030), with the branch brought up to date and two fixes pushed. It is verified and waiting on the maintainer.

Why it is still needed: #17000 adds Defaults timestamp_timeout=10 and leaves sudo's default verifypw=all alone, and the installer's password-requiring rule is still there. So with a grant active and no cached password, sudo -v still prompts. omarchy-update sidesteps this itself (its comment at bin/omarchy-update:16 says so) by authorizing with sudo true. But omarchy-sudo-keepalive:6 still calls sudo -v, and so do omarchy-upgrade-to-quattro:386 and migrations/1791898365.sh:24. omarchy pkg install and omarchy pkg aur install both source the keepalive.

What was checked, on a disposable Omarchy worker at the head merged with quattro, with quattro's ten-minute timeout installed:

  • With a timed grant from quattro's helper, sudo -n true succeeds and sudo -n -v answers "a password is required". The same grant from this branch passes sudo -n -v, and reverting the default to verifypw = all makes it fail again.
  • The migration rewrites an old-format permanent grant, after which sudo -n -v passes. Running it again changes nothing. After revoking, sudo -n true is refused. Accounts with no grant, or with no sudo rights, finish the migration without a prompt.
  • Under a dev link, with an older installed helper, the migration now exits 1 and leaves the grant as it was, so it stays pending. Once the newer helper is installed, the retry rewrites the grant and --disable still revokes it.
  • ./test/cli passes. Every passwordless-sudo suite passes. Each new test fails with the change it guards reverted. In the full ./test/shell, the five files that fail on quattro (agent-account-exec, ascii, About animation, first-run, runtime smoke) fail here too. A sixth, remote-session-service-test.sh, then failed three runs out of three on quattro as well, on the same worker.

Pushed:

  • 2818e97 merges quattro. The merge had no conflicts with Use ordinary sudo: one password for ten minutes, plain update scripts #17000's edits to bin/omarchy-sudo-passwordless.
  • 70aa65a and f030b57 bring the tests in line with quattro's rules. quattro stopped testing migrations in Remove migration tests #16302 and dropped the fixture branch this branch's migration tests used, so those tests failed after the merge. They are gone. The rest of the new passwordless-sudo-verifypw-test.sh is folded into passwordless-grant-lifecycle-test.sh, keeping three tests that each fail without the change they guard.
  • f030b57 also fixes a bug. When the installed helper could not read the new grant format, the upgrade skipped the rewrite but still reported success. The one-shot migration was then marked done, so a permanent grant on a dev-linked machine kept the old format for good. The upgrade now fails instead, as agents/skills/migrations.md asks of a migration that cannot finish. On a packaged install, $OMARCHY_PATH/bin links to the /usr/bin copy, so only a dev-linked checkout that is ahead of its package can hit this.

The second opinion came from Codex Medium and muse-wonder (thinking high). Both concluded on their own reading that the fix is still needed after #17000, and both found the deferral bug and the test-rule problems fixed above. Their second round, on f030b57, found nothing further. Independence is not guaranteed, since they can read this session.

Still open for the maintainer: migrations/1791898365.sh runs before this migration, so its sudo -v still needs #15729. A dev-linked machine whose installed package is older than this branch will stop at this migration until the package catches up. The description above does not yet mention that last point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working verified Omarchy Triage has verified that this issue is ready for final review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants