Skip to content

[codex] Revoke passwordless grants when settings is removed - #257

Open
AFOliveira wants to merge 9 commits into
omacom:masterfrom
AFOliveira:codex/om-sec-01-passwordless-package-cleanup
Open

AFOliveira wants to merge 9 commits into
omacom:masterfrom
AFOliveira:codex/om-sec-01-passwordless-package-cleanup

Conversation

@AFOliveira

@AFOliveira AFOliveira commented Sep 1, 2026 •

Copy link
Copy Markdown
Member

Settings owns the complete temporary sudo-grant lifecycle: publication helper, shared security library, boot cleanup and an aborting pre-transaction revocation hook. Removing only the desktop runtime preserves expiry support; upgrading or removing settings revokes the grant before those files disappear.

The hook and grant publication share one lock and a package-transition marker. Revocation failure aborts the ALPM transaction and blocks new grants until a successful retry. Scriptlets retain the legacy fallback for the first upgrade from packages without the hook; scriptlet errors are not claimed to abort that transaction.

Companion: Omarchy #9457. Rebased onto current master (v4.0.4, c668141e) as three commits with no release bump of their own: the runtime packages now require the exact pkgver-pkgrel of their matching settings package in both channels, settings gains the sudo dependency, the hook and the two helpers. #239 is separate overlapping ownership work, not a required parent.

Not mergeable before #9457: the declared upstream source c668141e predates it and cannot build these settings recipes. After #9457 lands, advance both release pins and checksums together to the real upstream commit containing it, bump pkgrel on the pair, build the declared sources, and publish each matching pair together. No fork revision or duplicate backport has been substituted for that upstream prerequisite.

Validation at the rebased head: all four PKGBUILDs parse (makepkg --printsrcinfo); the cross-repository suites in #9457 at ea617b91 (passwordless-grant-lifecycle-test.sh, nopasswd-sudo-expiry-test.sh) pass with OMARCHY_PKGS_PATH pointing at this checkout, including both settings scriptlets' revoke, block and recover paths and the native lock serialization against grant publication. Earlier heads were reviewed independently by Daybreak and exercised in a disposable VM (reinstall, stable/dev transfers, runtime and settings removal, aborting removal on a benign revocation error, recovery); native ARM runtime and fresh-ISO validation remain untested.

@ErikMelton

Copy link
Copy Markdown
Member

LGTM - pending 9457

@AFOliveira
AFOliveira marked this pull request as ready for review September 17, 2026 08:43
@AFOliveira
AFOliveira force-pushed the codex/om-sec-01-passwordless-package-cleanup branch from b787991 to 32c1415 Compare September 17, 2026 08:45
@ErikMelton

ErikMelton commented Sep 17, 2026 •

Copy link
Copy Markdown
Member

After changes:

  • [P1] Exact dev dependency breaks normal builds — PKGBUILD:21
    "omarchy-settings-dev=${pkgver}-${pkgrel}"
    makepkg checks dependencies before running pkgver(), so it requests the stale omarchy-settings-dev=4.0.0.r847.g4de185b-1 even after the builder produces newer settings. The normal build path skips its preliminary version refresh for integer pkgrels. I reproduced this dependency failure. Refresh the dev version before dependency resolution while retaining the exact dependency in the resulting package.

AFOliveira and others added 2 commits September 17, 2026 17:10
makepkg resolves dependencies against the static pkgver before it runs
pkgver(), so the omarchy-dev package's exact same-version dependency on
omarchy-settings-dev requested the stale placeholder release even after
the builder had produced newer settings. The builder already refreshed
VCS versions before the real build, but only for packages with a dotted
local pkgrel.

Run the refresh for every VCS package. Dotted pkgrels are still restored
afterwards; integer pkgrels keep makepkg's normal reset. The real build
then runs with --holdver so it packages the revision the refresh fetched
and the dependency check validated, rather than fetching the branch a
second time. The resulting package retains the exact dependency, now on
the refreshed version.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
pacman does not stop a transaction when a scriptlet fails, so a failed
or interrupted pre_upgrade fallback could be followed directly by
post_upgrade, which cleared the removal blocker on a bare file check
while a passwordless rule was still live. The same happened when an
interrupted removal left the blocker and a rule behind and a later
fresh install completed, and a fresh install has no earlier step at all.

On completion, hold the blocker, sweep the reserved sudoers prefix, and
remove the blocker only once nothing remains and the boot cleanup is
present; a sweep that fails leaves publication refused. Run that
recovery before the optional /etc overrides so an override failure
cannot strand the blocker, bound the shared lock wait so a stalled grant
operation cannot hang pacman indefinitely, and clear inherited glob
state so the sweep cannot be blinded by pacman's environment.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@AFOliveira

Copy link
Copy Markdown
Member Author

Fixed in 21b3b32, now at 9b9a9c8. The builder's VCS refresh runs for every VCS package, so dependency resolution sees the refreshed pkgver and the package keeps the exact settings dependency; the real build uses --holdver so it packages the revision it validated. The other integer-pkgrel VCS packages are all commit-pinned, so only the redundant fetch goes away.

The same head hardens the scriptlets: completion writes the blocker before waiting for the lock, sweeps the reserved prefix, and clears the blocker only when nothing remains and the boot cleanup is present, so a failed pre_upgrade followed by post_upgrade, an interrupted removal, or a fresh install with a leftover rule all leave publication refused. Recovery runs before the /etc overrides, lock waits are bounded to 60s, and inherited glob state is cleared. The cross-repo contract test in #9457 covers each case. Still not mergeable before #9457 lands and the pin advances.

@AFOliveira

Copy link
Copy Markdown
Member Author

@ryanrhughes this is not a feature, but a security fix.

@AFOliveira

Copy link
Copy Markdown
Member Author

@ErikMelton @ryanrhughes #9457 has been merged, can we get this in as well? Thanks!

@spencerbull

Copy link
Copy Markdown
Contributor

Reviewed at 9b9a9c8e, merged onto the current master (e2bc7586, merges cleanly), with packages built from omarchy quattro (82979b9a). The grant lifecycle works in every transaction I ran. Two things stop it merging as it stands, and neither has a fix that is only the author's call.

Why it is needed. Since omarchy a6385e60, omarchy-sudo-passwordless refuses to publish a grant unless 05-omarchy-passwordless-revoke.hook is installed, and master installs it nowhere. On a disposable Omarchy worker with packages built from current quattro and master's recipes, __enable returns 1 and no rule is written. With the hook installed where this pull request puts it, the same call publishes a grant with its expiry timer. That is the second half of omacom/omarchy#13421.

Transaction flows, each on its own fresh worker cloned from a 4.0.4 install. The stable pair was built as 4.0.98 and 4.0.99, plus the dev pair, all from the merged recipes with pkgrel aligned to 1 (see the first blocker):

Flow Result
4.0.4 → this pair, with a legacy 99-omarchy-nopasswd-omarchy grant live and no hook installed yet upgrade succeeds; the scriptlet fallback sweeps the legacy grant; the blocker clears; all four files are owned by omarchy-settings and none by omarchy; pacman -Qkk is clean; migration 1788163635 completes; enable, status and disable work
Grant lifecycle the rule carries NOTAFTER and passes visudo; the timer is armed; renewal leaves one rule; the timer removes the rule at the deadline; status returns to 3
Settings 4.0.98 → 4.0.99 with a grant live the PreTransaction hook runs and revokes the grant; the blocker clears; enable works afterwards
pacman -Rdd omarchy with a grant live helper, library, boot rule and hook all survive; expiry still removes the rule; enable still works
pacman -Rdd omarchy-settings with a grant live the hook revokes the grant before the files go; the blocker stays set; reinstalling settings clears it
stable → dev and dev → stable, each in one transaction with a grant live no conflicting files; the grant is revoked; ownership moves to omarchy-settings-dev and back
Reboot with a 60-minute grant live boot cleanup removes it; status is 3; enable works
Revocation made to fail (chattr +i on the rule) during a settings upgrade pacman reports failed to run transaction hooks and the transaction aborts; packages stay at 4.0.98; the blocker is set and publication refused; once revocation can succeed, the retry upgrades, revokes and clears the blocker

83 checks, none failing. omarchy's passwordless-grant-lifecycle-test.sh also passes all of its packaging cases against these recipes, where on master it fails at pre_remove.

Blocking, as merged onto master today:

  1. The exact pkgver-pkgrel dependency makes the stable pair uninstallable. Master bumped omarchy-settings alone to pkgrel=2 for the platform guard (7ed92ad0, Sep 25). omarchy stays at pkgrel=1, so merged as-is, omarchy 4.0.4-1 requires omarchy-settings=4.0.4-1, which the repository no longer builds; my first build produced exactly that unsatisfiable pair. The dev pair matches today, but omarchy-dev/PKGBUILD:21 breaks the same way on its next settings-only bump. That conflicts with master's own convention of bumping pkgrel alone to repackage. Coupling on pkgver alone, as master does now, or bumping both release counters together every time, are both workable; which one is a release-policy decision.
  2. Stable settings cannot build from its current pin. v4.0.4 (c668141e) contains neither the hook nor omarchy-security-functions, and the settings recipe installs both unconditionally. The body already says the pins must advance to an upstream commit that contains [codex] Complete passwordless sudo expiry across suspend omarchy#9457. So this lands together with a stable pin bump, not on its own.

Lower:

  • Both .install scriptlets clear GLOBIGNORE and noglob but not failglob. If a scriptlet ever inherits BASHOPTS=failglob, the sweep's glob errors and _passwordless_package_transition returns before it removes the blocker. I confirmed the Bash behaviour; sudo's environment reset normally keeps BASHOPTS out, so it is hardening rather than a live bug. shopt -u failglob beside set +f closes it.
  • Upgrading settings on its own over an old runtime that still owns the helpers fails on file conflicts. It fails safely, and a normal pacman -Syu moves both together.
  • Master now pins the dev pair to a commit and has dropped its pkgver(), so the build/build.sh VCS refresh and --holdver change no longer affect this pair. Worth deciding whether to keep them.

Second opinion: Codex XHigh reviewed the diff against master. It found both blockers and the failglob issue independently; I verified all three against the source before listing them here. It found no ownership-transfer defect, consistent with the flows above. Primary review and the worker runs by Opus 5.5 in Claude Code.

Open: a maintainer's choice on the pkgrel coupling and the release to carry the pin bump. I have pushed nothing to this branch, since both are choices rather than defects.

Signed-off-by: Afonso Oliveira <afonso.oliveira707@gmail.com>
Signed-off-by: Afonso Oliveira <afonso.oliveira707@gmail.com>
Signed-off-by: Afonso Oliveira <afonso.oliveira707@gmail.com>
Signed-off-by: Afonso Oliveira <afonso.oliveira707@gmail.com>
@AFOliveira

Copy link
Copy Markdown
Member Author

@spencerbull please take another look at d2837e7. Both channels now match settings by pkgver, allowing independent pkgrel bumps; both scriptlets clear failglob; and the obsolete builder changes are gone. Regression tests catch the previous failures and pass under CI’s root/read-only conditions.

The dev packages were rebuilt from the current declared pin and tested in an x86_64 VM, including grant revocation/recovery, runtime/settings removal and a settings-only revision bump.

The stable source pin remains a merge prerequisite: 4.0.4 lacks the hook/library, and its declared build still fails. This needs the release containing the fix selected and built before merging.

spencerbull added a commit to ekollof/omarchy-pkgs that referenced this pull request Sep 28, 2026
The hardened omarchy-sudo-passwordless publishes a grant only when its revocation hook is installed and no package transaction has left /run/omarchy-sudo-passwordless-package-removing behind. The hook sets that marker before every settings upgrade, and the settings scriptlets are what clear it, so shipping the hook alone let the first grant work and then refused every grant after the next update until a reboot.

omarchy-settings-dev now ships the command, omarchy-security-functions, the boot cleanup rule and the hook together, with the scriptlets from omacom#257 that revoke before the package changes and clear the marker once no grant remains. omarchy-dev stops shipping the two helpers and requires the settings release that does: without it omarchy-update has no library to source.

Co-authored-by: Afonso Oliveira <afonso.oliveira707@gmail.com>
spencerbull added a commit to ekollof/omarchy-pkgs that referenced this pull request Sep 29, 2026
The hardened omarchy-sudo-passwordless publishes a grant only when its revocation hook is installed and no package transaction has left /run/omarchy-sudo-passwordless-package-removing behind. The hook sets that marker before every settings upgrade, and the settings scriptlets are what clear it, so shipping the hook alone let the first grant work and then refused every grant after the next update until a reboot.

omarchy-settings-dev now ships the command, omarchy-security-functions, the boot cleanup rule and the hook together, with the scriptlets from omacom#257 that revoke before the package changes and clear the marker once no grant remains. omarchy-dev stops shipping the two helpers and requires the settings release that does: without it omarchy-update has no library to source.

Co-authored-by: Afonso Oliveira <afonso.oliveira707@gmail.com>
ekollof pushed a commit to ekollof/omarchy-pkgs that referenced this pull request Sep 29, 2026
The hardened omarchy-sudo-passwordless publishes a grant only when its revocation hook is installed and no package transaction has left /run/omarchy-sudo-passwordless-package-removing behind. The hook sets that marker before every settings upgrade, and the settings scriptlets are what clear it, so shipping the hook alone let the first grant work and then refused every grant after the next update until a reboot.

omarchy-settings-dev now ships the command, omarchy-security-functions, the boot cleanup rule and the hook together, with the scriptlets from omacom#257 that revoke before the package changes and clear the marker once no grant remains. omarchy-dev stops shipping the two helpers and requires the settings release that does: without it omarchy-update has no library to source.

Co-authored-by: Afonso Oliveira <afonso.oliveira707@gmail.com>
@ekollof

ekollof commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

Rebase / scope note after #645 (c35e69a, rebased onto b7a7ad1 and reporting MERGEABLE):

This branch sits on 7228983 and merging master conflicts in 3 files: pkgbuilds/omarchy-dev/PKGBUILD (pin r6663 vs r6689), pkgbuilds/omarchy-settings-dev/PKGBUILD (same pin plus the #701 runtime-profile rework in the same hunks), and pkgbuilds/omarchy-settings/PKGBUILD (pkgrel 3 vs 4, hook placement vs the same rework).

The dev half is now redundant: #645 ships the same helper/hook move, scriptlets, and lifecycle tests for the dev pair. One difference to be aware of when trimming — this branch pins "omarchy-settings-dev=${pkgver}" (exact), which #645 found breaks the per-package PR/publish builds with "target not found"; #645 uses an unversioned dep plus a conflicts floor instead.

Suggested sequence:

  1. Land Ship the complete passwordless-sudo lifecycle in settings-dev #645.
  2. Rebase this branch and drop the dev-half files (pkgbuilds/omarchy-dev/, pkgbuilds/omarchy-settings-dev/ + dev-side tests) — they should delete cleanly at that point, leaving the stable omarchy / omarchy-settings half, which is the unique value here.
  3. The stable half still needs the pin bump to a release containing upstream [codex] Complete passwordless sudo expiry across suspend omarchy#9457 (v4.0.4 lacks the hook/library, so the recipe fails to build as-is).

I have pushed nothing here since the trim + pin bump are maintainer/author choices.

ekollof pushed a commit to ekollof/omarchy-pkgs that referenced this pull request Sep 29, 2026
The hardened omarchy-sudo-passwordless publishes a grant only when its revocation hook is installed and no package transaction has left /run/omarchy-sudo-passwordless-package-removing behind. The hook sets that marker before every settings upgrade, and the settings scriptlets are what clear it, so shipping the hook alone let the first grant work and then refused every grant after the next update until a reboot.

omarchy-settings-dev now ships the command, omarchy-security-functions, the boot cleanup rule and the hook together, with the scriptlets from omacom#257 that revoke before the package changes and clear the marker once no grant remains. omarchy-dev stops shipping the two helpers and requires the settings release that does: without it omarchy-update has no library to source.

Co-authored-by: Afonso Oliveira <afonso.oliveira707@gmail.com>
spencerbull added a commit to ekollof/omarchy-pkgs that referenced this pull request Oct 3, 2026
The hardened omarchy-sudo-passwordless publishes a grant only when its revocation hook is installed and no package transaction has left /run/omarchy-sudo-passwordless-package-removing behind. The hook sets that marker before every settings upgrade, and the settings scriptlets are what clear it, so shipping the hook alone let the first grant work and then refused every grant after the next update until a reboot.

omarchy-settings-dev now ships the command, omarchy-security-functions, the boot cleanup rule and the hook together, with the scriptlets from omacom#257 that revoke before the package changes and clear the marker once no grant remains. omarchy-dev stops shipping the two helpers and requires the settings release that does: without it omarchy-update has no library to source.

Co-authored-by: Afonso Oliveira <afonso.oliveira707@gmail.com>
spencerbull added a commit to ekollof/omarchy-pkgs that referenced this pull request Oct 3, 2026
The hardened omarchy-sudo-passwordless publishes a grant only when its revocation hook is installed and no package transaction has left /run/omarchy-sudo-passwordless-package-removing behind. The hook sets that marker before every settings upgrade, and the settings scriptlets are what clear it, so shipping the hook alone let the first grant work and then refused every grant after the next update until a reboot.

omarchy-settings-dev now ships the command, omarchy-security-functions, the boot cleanup rule and the hook together, with the scriptlets from omacom#257 that revoke before the package changes and clear the marker once no grant remains. omarchy-dev stops shipping the two helpers and requires the settings release that does: without it omarchy-update has no library to source.

Co-authored-by: Afonso Oliveira <afonso.oliveira707@gmail.com>
spencerbull added a commit to ekollof/omarchy-pkgs that referenced this pull request Oct 4, 2026
The hardened omarchy-sudo-passwordless publishes a grant only when its revocation hook is installed and no package transaction has left /run/omarchy-sudo-passwordless-package-removing behind. The hook sets that marker before every settings upgrade, and the settings scriptlets are what clear it, so shipping the hook alone let the first grant work and then refused every grant after the next update until a reboot.

omarchy-settings-dev now ships the command, omarchy-security-functions, the boot cleanup rule and the hook together, with the scriptlets from omacom#257 that revoke before the package changes and clear the marker once no grant remains. omarchy-dev stops shipping the two helpers and requires the settings release that does: without it omarchy-update has no library to source.

Co-authored-by: Afonso Oliveira <afonso.oliveira707@gmail.com>
ekollof pushed a commit to ekollof/omarchy-pkgs that referenced this pull request Oct 11, 2026
The hardened omarchy-sudo-passwordless publishes a grant only when its revocation hook is installed and no package transaction has left /run/omarchy-sudo-passwordless-package-removing behind. The hook sets that marker before every settings upgrade, and the settings scriptlets are what clear it, so shipping the hook alone let the first grant work and then refused every grant after the next update until a reboot.

omarchy-settings-dev now ships the command, omarchy-security-functions, the boot cleanup rule and the hook together, with the scriptlets from omacom#257 that revoke before the package changes and clear the marker once no grant remains. omarchy-dev stops shipping the two helpers and requires the settings release that does: without it omarchy-update has no library to source.

Co-authored-by: Afonso Oliveira <afonso.oliveira707@gmail.com>
spencerbull added a commit that referenced this pull request Oct 11, 2026
* Move the dev sudo grant lifecycle into omarchy-settings-dev

The hardened omarchy-sudo-passwordless publishes a grant only when its revocation hook is installed and no package transaction has left /run/omarchy-sudo-passwordless-package-removing behind. The hook sets that marker before every settings upgrade, and the settings scriptlets are what clear it, so shipping the hook alone let the first grant work and then refused every grant after the next update until a reboot.

omarchy-settings-dev now ships the command, omarchy-security-functions, the boot cleanup rule and the hook together, with the scriptlets from #257 that revoke before the package changes and clear the marker once no grant remains. omarchy-dev stops shipping the two helpers and requires the settings release that does: without it omarchy-update has no library to source.

Co-authored-by: Afonso Oliveira <afonso.oliveira707@gmail.com>

* Check that settings-dev registers the scriptlet the lifecycle test exercises

The lifecycle test reads the .install file directly, so it kept passing with the recipe's install= line gone, which is the one change that would strand the hook's marker again.

Co-Authored-By: Codex XHigh <noreply@openai.com>

* Keep omarchy-dev's settings dependency unversioned

The dev pair builds each package on its own against the published edge repository, in the PR build and in publish alike, so omarchy-dev cannot require a settings-dev release that only this change produces: the floor failed both omarchy-dev builds on this PR, and an exact pkgver match would fail the same way on every upstream pin bump. Nothing needs it. The upstream watch moves both pins together, publish stops the run before anything is published when one package fails, and a new settings-dev over an old runtime is refused on the files they would both own.

* Refuse settings-dev releases that predate the grant helper move

With the dependency unversioned, a new omarchy-dev could still install over a settings-dev that is held back or not yet published, removing omarchy-security-functions from both, and omarchy-update cannot start without it. A versioned conflict refuses that pairing at install time without constraining the per-package builds, which resolve only depends.

Co-Authored-By: Codex XHigh <noreply@openai.com>

* Require the security library as a capability instead of a version floor

The conflict named the last settings-dev release without the helpers, a version that moves with every upstream pin bump and settings-only pkgrel while this change waits to merge, and a rebase that kept a stale floor still passed the tests while the published release slipped past it. omarchy-settings-dev now provides omarchy-security-functions and omarchy-dev's package() requires it. makepkg checks only the top-level depends before building, so the per-package builds still resolve against the published repository, while pacman refuses a runtime without a settings release that ships the library, and pulls that release in when only the runtime is asked for.

Co-Authored-By: Codex XHigh <noreply@openai.com>

---------

Co-authored-by: Spencer Bull <spencer@omarchy.org>
Co-authored-by: Afonso Oliveira <afonso.oliveira707@gmail.com>
Co-authored-by: Codex XHigh <noreply@openai.com>

This branch has not been deployed

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

Labels

bug Something isn't working new-omarchy-feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants