Skip to content

Invalidate the sudo timestamp when the quattro upgrader exits - #15295

Open
nekomario28 wants to merge 2 commits into
omacom:quattrofrom
nekomario28:quattro-sudo-k-on-exit
Open

nekomario28 wants to merge 2 commits into
omacom:quattrofrom
nekomario28:quattro-sudo-k-on-exit

Conversation

@nekomario28

Copy link
Copy Markdown
Contributor

omarchy-upgrade-to-quattro authenticates sudo once and keeps the timestamp fresh with a background keepalive for the whole run. cleanup_on_exit stops that keepalive, but the refreshed timestamp stays valid for the sudo timeout, so the upgrade's authorization outlives the script and whatever runs right afterwards inherits it. omarchy update invalidates the timestamp on every exit (end_update_authorization); the upgrader should do the same.

This invalidates the timestamp in cleanup_on_exit, guarded to the non-root path that starts the keepalive, and asserts it in test/shell.d/upgrade-to-quattro-test.sh.

Test: bash test/shell.d/upgrade-to-quattro-test.sh passes (31 checks); with the sudo -k line reverted, the new assertion fails.

@greptile-apps

greptile-apps Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge, with no new actionable issues found.

Summary

The Quattro upgrader now clears cached sudo authorization during cleanup.

  • The Quattro upgrader clears cached sudo access when it exits.

Reviews (3) · Last reviewed commit: "Let the keepalive finish its refresh bef..." · Reviewed by Greptile

Comment thread test/shell.d/upgrade-to-quattro-test.sh Resolved
@nekomario28
nekomario28 force-pushed the quattro-sudo-k-on-exit branch from c341892 to e11371d Compare October 13, 2026 15:32
Comment thread test/shell.d/upgrade-to-quattro-test.sh Resolved
The upgrade authenticates sudo once and keeps the timestamp fresh with a
background keepalive. cleanup_on_exit stops the keepalive, but the refreshed
timestamp stays valid for the sudo timeout, so the upgrade's authorization
outlives the script and whatever runs right afterwards inherits it.

Invalidate the timestamp in cleanup_on_exit, as omarchy update does on every
exit, and assert it in the upgrade shell test.
@nekomario28
nekomario28 force-pushed the quattro-sudo-k-on-exit branch from e11371d to 075effc Compare October 13, 2026 22:42
@nekomario28

Copy link
Copy Markdown
Contributor Author

Addressed in 075effc: the behavioural case now skips the logged sudo -k when the suite runs as root (root has no cached credential to clear, and cleanup_on_exit correctly skips the call). Verified by running this test file under sudo: with the guard it reports # SKIP and exits 0; with the guard removed it fails on cleanup invalidates the cached credential on exit because the stub never runs. The exit-status and "exits rather than returning" checks still run either way.

Cleanup killed the keepalive loop and then ran sudo -k, but killing the loop's shell leaves a `sudo -n true` already in flight running as an orphan, and that refresh can land after the revoke and re-validate the timestamp. On a worker with real sudo and the 60s sleep shortened, authorization survived the upgrader's exit in 26 of 200 runs.

The keepalive now traps TERM the way omarchy update's does: bash holds the trap until the foreground refresh finishes, and the sleep runs under wait so it is interrupted at once. Cleanup waits for the loop before revoking, so sudo -k is the last word. The same race harness then leaked in 0 of 200 runs.

The test now runs the script's own keepalive against a sudo stub whose refresh marks its start and then holds until sudo -k is logged, or for a second if cleanup is waiting on it. The fixture exits only once a refresh is in flight, the check waits for that refresh to log, and sudo -k must be the last call. Without the wait, or with the old loop, the refresh logs after the revoke and the test fails.

Co-Authored-By: Codex Medium <noreply@openai.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@omarchybot omarchybot added bug Something isn't working verified Omarchy Triage has verified that this issue is ready for final review ready Good to merge labels Oct 17, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Thanks @nekomario28. The problem is real, and the fix holds once one more race is closed. I pushed that fix as 6906a3a.

Reproduced. On a worker built from the Omarchy ISO, I ran the upgrader's own trap, keepalive and cleanup_on_exit as a user whose sudo needs a password. On quattro (cce8b1c), sudo still ran without a password after the script ended, whether it exited 0, exited 1 or was killed with SIGTERM. With your change it was revoked in all three cases. With only the sudo -k block removed, the leak came back.

What I changed. Cleanup killed the keepalive loop and then ran sudo -k, but killing the loop's shell does not stop a sudo -n true it has already started. That refresh finishes as an orphan, and if it lands after the revoke it makes the timestamp valid again. With real sudo and the 60-second sleep shortened to widen the window, sudo stayed authorized after exit in 26 of 200 runs. The keepalive now traps TERM the way omarchy update's does: bash holds the trap until the refresh in flight finishes, and the sleep runs under wait so it can be interrupted. Cleanup also waits for the loop before revoking. The same harness then leaked in 0 of 200 runs. Your test now runs the script's real keepalive against a stub whose refresh holds until sudo -k is logged, and it requires sudo -k to be the last call. It fails every time without the wait or with the old loop, including under full CPU load, and still skips cleanly as root.

Tests. test/shell.d/upgrade-to-quattro-test.sh (32/32) and ./test/cli pass on the worker, both at this head and with it applied to current quattro.

Second opinion. Codex Medium reviewed it in four rounds. It agreed the problem was real and proportionately fixed. It raised the keepalive race, which I had asked it to check, so treat that as agreement rather than an independent find; I then confirmed the race with real sudo. In later rounds it pointed out twice that the test's timing could let a regression slip through, and both are fixed. Its last round, on this head, found nothing. Its independence from this review is not guaranteed.

Both of Greptile's earlier comments are addressed at this head. It is waiting on the maintainer.

@omarchybot omarchybot removed ready Good to merge verified Omarchy Triage has verified that this issue is ready for final review labels Oct 27, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Thanks @nekomario28. I took another look because this no longer merges with quattro. The conflict itself is small, but quattro has since changed the policy this pull request is built on, so I have not ported it.

What changed on quattro. #17000 (56a910b) returned Omarchy to ordinary sudo. etc/sudoers.d/omarchy-sudo-timeout now sets timestamp_timeout=10, so one password lasts ten minutes. No Omarchy command clears the timestamp when it starts or exits any more. end_update_authorization in bin/omarchy-update now only stops the keepalive, and omarchy_security_revoke_sudo_timestamp is gone. This pull request's reason for revoking in the upgrader was that omarchy update does the same, and that is no longer true. On current quattro, a timestamp that is still valid after the upgrader exits is intended behaviour, not a leak. The comment the pull request adds at bin/omarchy-upgrade-to-quattro:375 would also be wrong once it landed.

The test. The conflict is in test/shell.d/upgrade-to-quattro-test.sh. #16334 removed the cleanup_body source greps that this pull request's assertions extend, and the grep -F '/usr/bin/sudo -k' check is the kind of test that change removed. The behavioural block runs the real cleanup and keepalive, but it is about 60 lines of test for a requirement the project has since dropped.

What still holds. The mechanism is sound. With the keepalive's TERM trap and the wait in cleanup, no refresh lands after the revoke, as reproduced on a worker on 2026-10-17. Nothing in the head has changed since then, so I did not run it again: the open question is policy, not whether the code works.

Second opinion. Codex Medium and muse-wonder (via pi, thinking high) both reviewed it against current quattro. They found no defect in the keepalive shutdown, and both recommend closing it as superseded by #17000. Each added a point I had not raised. Codex noted that keeping the authorization after a failed run helps the user repair and rerun, which is what the script tells them to do. muse-wonder noted that sudo -k in the exit trap would also clear a timestamp the user already had in that terminal before starting the upgrade. Their agreement with the rest is agreement, and their independence from this review is not guaranteed.

This is waiting on the maintainer. My recommendation is to close it as superseded by #17000, unless they want revocation back for the upgrader as a deliberate exception.

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

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants