Skip to content

Take privileged usernames from id -un, not USER - #8534

Open
marty-schneider wants to merge 12 commits into
omacom:quattrofrom
marty-schneider:passwordless-sudo-id-un
Open

marty-schneider wants to merge 12 commits into
omacom:quattrofrom
marty-schneider:passwordless-sudo-id-un

Conversation

@marty-schneider

Copy link
Copy Markdown

What was wrong

Several privileged commands interpolate $USER into sudoers, usermod, gpasswd, fprintd-enroll, and tailscale set --operator. $USER is the environment, not the euid. Anything in the session can export it.

The one that writes policy is omarchy-sudo-passwordless:

NOPASSWD_FILE="/etc/sudoers.d/99-omarchy-nopasswd-${USER}"
echo "${USER} ALL=(ALL) NOPASSWD: ALL" | sudo tee "$NOPASSWD_FILE"

USER=ALL produces a valid drop-in named 99-omarchy-nopasswd-ALL whose body is ALL ALL=(ALL) NOPASSWD: ALL. After the gum confirm and one sudo prompt (or a cached timestamp), every local account is passwordless root for the grant window.

The same environment is inherited by Setup > Security > Passwordless Sudo from the session. A plugin, hook, or export in ~/.bashrc is enough; the user sees the usual warning and thinks they are granting only themselves.

Sibling commands have a smaller version of the same bug: usermod -aG docker "$USER" with USER=nobody adds nobody to the docker group (root-equivalent) instead of the person who typed the password.

Does not overlap #7990, which clears the grant at boot. This change is who the grant names.

The change

  • omarchy-sudo-passwordless takes id -un, refuses anything outside first-boot's username pattern and the sudoers alias ALL, then writes that subject.
  • omarchy-sudo-docker --configured uses id -nG with no name, so it answers about this euid.
  • sudoless Docker setup/remove, ydotool usermod, fingerprint enroll, and Tailscale --operator take id -un.

test/shell.d/privileged-user-identity-test.sh greps those call sites. test/shell.d/sudo-docker-test.sh still passes (its id stub ignores arguments).

Copilot AI balanced review requested due to automatic review settings August 27, 2026 05:19

Copilot AI 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.

Pull request overview

Hardens privileged commands by deriving usernames from the effective UID rather than the mutable $USER environment variable.

Changes:

  • Secures passwordless sudo identity and validates usernames.
  • Updates Docker, fingerprint, Tailscale, and ydotool account handling.
  • Adds regression coverage for privileged identity usage.

Tip

If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.

Reviewed changes

Copilot reviewed 1 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
bin/omarchy-sudo-passwordless Secures sudoers subject selection.
bin/omarchy-sudo-docker Changes Docker group lookup identity.
bin/omarchy-setup-security-sudoless-docker Secures Docker group addition.
bin/omarchy-remove-security-sudoless-docker Secures Docker group removal.
bin/omarchy-setup-security-fingerprint Secures fingerprint enrollment identity.
bin/omarchy-install-service-tailscale Secures Tailscale operator selection.
bin/omarchy-dev-install-ydoo Secures input-group membership changes.
test/shell.d/privileged-user-identity-test.sh Adds identity-source regression checks.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

The remaining usermod call sites still interpolated $USER. Derive the
account from the euid so a spoofed environment cannot add nobody (or
anyone else) to input/nordvpn.
@chessing234

Copy link
Copy Markdown
Contributor

fyi the omarchy-sudo-passwordless id -un change is already in #12266 (folded from #9082). your PR still covers a bunch of other scripts we don't, so keep those if you want — just flagging the passwordless overlap.

omarchybot and others added 2 commits September 28, 2026 21:51
quattro rewrote omarchy-sudo-passwordless to resolve the account from id -u through getent and validate the name before it reaches sudoers, which is what this branch set out to do there. Take quattro's copy and drop the test's assertions about the old shape; the other call sites this branch fixes are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Both stubs printed the group list whatever id was asked, so once the commands took the account from id -un they got "wheel input docker" as a username and the two tests failed. The stubs now name the account for -un, and USER is set to a different name, so the tests fail if either command goes back to trusting the environment.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed and tested on a disposable Omarchy VM. The fix works. I pushed two commits to this branch, and it now waits on a second review before it goes to the maintainer.

Reproduced. I stubbed sudo to log what it was asked to run and set USER=nobody. Current quattro then ran sudo usermod -aG docker nobody, sudo usermod -aG nordvpn nobody and sudo tailscale set --operator=nobody. This branch names the real account in all three, and restoring those files to quattro brings the wrong account back.

Pushed to your branch:

  • ca08193e merges quattro, which resolves the conflict in bin/omarchy-sudo-passwordless. quattro has since rewritten that command to look up the account from id -u through getent and to validate the name before it reaches sudoers, so the passwordless half of this PR is already covered there. I kept quattro's copy and removed the three assertions in privileged-user-identity-test.sh that checked for the old shape. What this PR still adds is the other eight call sites, so the description's lead example no longer matches the diff.
  • 4bdb44ac fixes two existing tests that this change broke: test/shell.d/sudoless-docker-toggle-test.sh and test/shell.d/docker-group-migration-test.sh. Their id stub printed the group list no matter which flag it got, so id -un returned wheel input docker as the username and the gpasswd/usermod assertions failed. The stubs now answer -un, and USER is set to a different name. Both tests pass on this branch and fail when the two docker commands are restored to quattro, so they now cover the fix directly, beyond what the grep test checks.

Tests. I ran the full shell suite and test/cli on the VM for both this branch and quattro. The same six shell assertions and the same vscode theme check in test/cli fail on both, so none of them come from this change. Every test that touches the changed commands passes.

Second opinion. None. Codex Medium answered a ping, but the day's review budget was used up before it could review this PR. Nobody but me has checked it, so it is not marked verified or ready. It waits on that review, and nothing is needed from you.

@aholbreich

Copy link
Copy Markdown
Contributor

Rechecked on current quattro (4c1b4cb): this still merges cleanly. privileged-user-identity-test.sh, sudoless-docker-toggle-test.sh, docker-group-migration-test.sh, sudo-docker-test.sh and ./test/cli pass, and the first three fail with quattro's scripts. The passwordless sudo half is already on quattro (87625c2), so the eight remaining call sites are what this adds.

One regression to fix before merging: omarchy-sudo-docker --configured now runs id -nG with no name. Without a name, id reports the current process's groups, which are fixed at login, not the account's configured groups. The comment above that case says --configured exists for exactly the window between toggling sudoless Docker and the reboot. With this branch, after Setup > Security > Sudoless Docker and before rebooting, the menu still offers Setup rather than Remove (and the reverse after Remove). Naming the euid's account keeps both properties:

id -nG "$(id -un)" 2>/dev/null | grep -qw docker && exit 1

The same goes for omarchy-dev-install-ydoo: id -nG "$user", as the Xbox script already does. Otherwise it asks for pkexec again on every run until the next login.

The grep in privileged-user-identity-test.sh pins the no-name form. A behaviour check catches both this and the original bug: stub id so -un prints alice, -nG alice includes docker and a bare -nG doesn't, run --configured with USER=nobody, and expect exit 1. I tried that locally: it passes with the change above and fails with both this branch's and quattro's version.

Patch on top of 4bdb44a
diff --git a/bin/omarchy-dev-install-ydoo b/bin/omarchy-dev-install-ydoo
--- a/bin/omarchy-dev-install-ydoo
+++ b/bin/omarchy-dev-install-ydoo
@@ -13,7 +13,7 @@ if ! getent group input >/dev/null; then
 fi
 
 user=$(id -un)
-if ! id -nG | tr ' ' '\n' | grep -x input >/dev/null; then
+if ! id -nG "$user" | tr ' ' '\n' | grep -x input >/dev/null; then
   echo "Adding $user to the input group. You may need to log out and back in before this applies."
   pkexec usermod -aG input "$user"
 fi
diff --git a/bin/omarchy-sudo-docker b/bin/omarchy-sudo-docker
--- a/bin/omarchy-sudo-docker
+++ b/bin/omarchy-sudo-docker
@@ -28,7 +28,7 @@ DOCKER_SOCKET="${OMARCHY_DOCKER_SOCKET:-/var/run/docker.sock}"
 case "${1:-}" in
 --configured)
   # An account in the docker group will not need sudo after the next login.
-  id -nG 2>/dev/null | grep -qw docker && exit 1
+  id -nG "$(id -un)" 2>/dev/null | grep -qw docker && exit 1
   exit 0
   ;;
 "")
diff --git a/test/shell.d/privileged-user-identity-test.sh b/test/shell.d/privileged-user-identity-test.sh
--- a/test/shell.d/privileged-user-identity-test.sh
+++ b/test/shell.d/privileged-user-identity-test.sh
@@ -7,8 +7,23 @@ source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"
 ! grep -Fq '${USER}' "$ROOT/bin/omarchy-sudo-passwordless" ||
   fail "passwordless sudo does not interpolate USER into sudoers"
 
-grep -Fq 'id -nG 2>/dev/null' "$ROOT/bin/omarchy-sudo-docker" ||
-  fail "sudoless Docker --configured reads groups of the current euid"
+# --configured answers from the account's configured groups (not the session's,
+# which are fixed at login) and for the euid's account, whatever USER says.
+stub_dir=$(mktemp -d)
+trap 'rm -rf "$stub_dir"' EXIT
+cat >"$stub_dir/id" <<'STUB'
+#!/bin/bash
+case "$*" in
+  -un) echo alice ;;
+  "-nG alice") echo "alice wheel docker" ;;
+  -nG) echo "alice wheel" ;;
+  *) echo "nobody" ;;
+esac
+STUB
+chmod +x "$stub_dir/id"
+if USER=nobody PATH="$stub_dir:$PATH" "$ROOT/bin/omarchy-sudo-docker" --configured; then
+  fail "sudoless Docker --configured reads the euid account's configured groups"
+fi
 
 for cmd in \
   "$ROOT/bin/omarchy-setup-security-sudoless-docker" \

omarchybot and others added 3 commits October 13, 2026 00:33
A bare id -nG reports the running process's groups, which are fixed at login, not the account's entry in /etc/group. omarchy-sudo-docker --configured exists to answer about the account in the window between toggling sudoless Docker and the reboot, so it must name the euid's account; and omarchy-dev-install-ydoo would otherwise ask pkexec again on every run until the next login. The test now runs --configured against a stub id whose bare and named answers differ, with USER set to someone else, so it fails if either regression comes back.

Co-Authored-By: Alexander Holbreich <16252784+aholbreich@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Any non-zero status satisfied the check, so a syntax error or a missing command in omarchy-sudo-docker would have passed it without proving the account's configured groups were read.

Co-Authored-By: Codex Medium <noreply@openai.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The branch was 239 commits behind quattro, and three tests it carries (kernel-headers-migration, network-captive-portal and the vscode theme check in test/cli) had since been fixed there, so the branch alone failed them. Merging brings the tested tree and the head into line; it merged without conflicts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@omarchybot omarchybot added the verified Omarchy Triage has verified that this issue is ready for final review label Oct 12, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

@aholbreich is right about id -nG with no name, and I've pushed the fix to this branch. A bare id -nG lists the groups the session got at login, not the account's entry in /etc/group. On a disposable Omarchy VM I added the account to docker without logging in again: quattro's and this branch's previous omarchy-sudo-docker --configured both missed the change, and the fixed one sees it, whatever USER says.

Pushed to your branch:

  • 8854d87a passes the account name to id -nG in omarchy-sudo-docker --configured and in omarchy-dev-install-ydoo. Without it, ydoo asked for pkexec again on every run until the next login. The grep in privileged-user-identity-test.sh is replaced with a check that runs --configured against a stub id whose bare and named answers differ, with USER=nobody. This follows the patch in the comment above, and the commit credits its author.
  • 39e8aed5 makes that check require exit status 1, so a crash in the command can't pass it.
  • 4582dc54 merges quattro. The branch was 239 commits behind, and on its own it failed three tests quattro has since fixed: kernel-headers-migration, network-captive-portal, and the vscode theme check in test/cli.

Reproduced on the VM. I stubbed sudo and pkexec to log their arguments and set USER=nobody. quattro then ran usermod -aG docker nobody, usermod -aG nordvpn nobody, usermod -aG input nobody (both the Xbox and ydotool installers), and tailscale set --operator=nobody. This branch names the real account in all five. The new identity test fails against both quattro's omarchy-sudo-docker and the previous head's.

Tests. test/cli passes on this head. In the full shell suite, the same ten tests fail on this head and on quattro 4c1b4cb3. None of them touch the files changed here, and every test that does touch them passes.

Second opinion. Codex Medium reviewed it in three rounds. It flagged the exit-status check fixed above and found nothing else in the diff. It also named places outside this PR that still trust USER, which are left for the maintainer rather than added here:

  • bin/omarchy-apply-lock:19 falls back to $USER, and omarchy-setup-security-fingerprint calls it right after enrolling. With USER spoofed, this branch enrolls the real account's finger, but lock-screen setup then checks the other account and exits with an error. quattro is no better: it enrolls the wrong account. Switching the fallback to id -un would break a root shell from su, which keeps USER, so the right fallback there needs a decision.
  • bin/omarchy-upgrade-to-quattro:162 defaults to ${USER:-$(id -un)}. migrations/1787580187.sh:12 and migrations/1787865477.sh:14 gate or target on $USER.

This is now marked verified. It waits on the maintainer, and nothing is needed from you.

@greptile-apps

greptile-apps Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

Privileged account changes now use id -un instead of trusting USER.

  • Sudoless Docker checks and changes the account running the command.
  • ydotool and Xbox setup add the account running the installer to input.
  • NordVPN setup adds the account running the installer to its group.
  • Tailscale setup lets the account running the installer manage the service.
  • Fingerprint setup enrolls and checks the account running the command.

Reviews (4) · Last reviewed commit: "Test the account lookup in sudo-docker-t..." · Reviewed by Greptile

Comment thread bin/omarchy-setup-security-fingerprint Resolved
@omarchybot omarchybot removed the verified Omarchy Triage has verified that this issue is ready for final review label Oct 14, 2026
omarchybot and others added 2 commits October 14, 2026 12:08
Enrollment now names the euid's account, but omarchy-apply-lock still fell back to USER when deciding whether a print is enrolled. With USER naming another account, setup enrolled the real one, then apply-lock found no prints for the other, removed /etc/pam.d/omarchy-lock-fingerprint and the command failed. Pass the enrolled name through OMARCHY_INSTALL_USER, which apply-lock reads first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@omarchybot omarchybot added verified Omarchy Triage has verified that this issue is ready for final review ready Good to merge labels Oct 14, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

This branch stopped merging cleanly into quattro, so I merged quattro in, and fixed the fingerprint problem Greptile raised above.

Pushed to your branch:

  • 42dcb182 merges quattro. The only conflict was in omarchy-setup-security-sudoless-docker, where quattro translated the confirm prompt; it keeps quattro's prompt and this branch's "$user".
  • 4580d99c makes omarchy-setup-security-fingerprint pass the account it enrolled to omarchy-apply-lock through OMARCHY_INSTALL_USER, which that helper reads before falling back to USER. Greptile was right: with USER=nobody, the previous head enrolled the real account, then omarchy-apply-lock found no prints for nobody, removed /etc/pam.d/omarchy-lock-fingerprint and the setup exited with an error. privileged-user-identity-test.sh now checks the handoff.

Reproduced on a disposable Omarchy VM, with the fingerprint tools stubbed and USER=nobody: quattro enrolled nobody, the previous head enrolled the real account but left fingerprint unlock off and exited 1, and this head enrolls the real account and configures the lock screen for it. With the handoff removed again, the new test check fails.

Tests. test/cli passes on this head. On a fresh VM the full shell suite fails the same 12 tests on this head and on quattro 84cfb939; none of them touch the files changed here, and every test that does touch them passes.

Second opinion. Codex Medium reviewed the merge and the fingerprint fix and found no defects, including when setup runs under sudo or from a root shell. It agreed with my reading rather than adding a finding of its own, and its independence is not guaranteed. The places outside this PR that still trust USER (bin/omarchy-upgrade-to-quattro:162 and two migrations) are unchanged and left for the maintainer, as before.

This is verified again at this head and waits on the maintainer. Nothing is needed from you.

@omarchybot omarchybot removed ready Good to merge verified Omarchy Triage has verified that this issue is ready for final review labels Oct 21, 2026
quattro rewrote fingerprint enrollment to pipe fprintd-enroll through a progress filter. Keep that, and keep enrolling and configuring the lock screen for id -un's account rather than USER's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@omarchybot omarchybot added the verified Omarchy Triage has verified that this issue is ready for final review label Oct 21, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

This branch stopped merging cleanly into quattro again, so I merged quattro in once more.

Pushed to your branch: e58a7b8a merges quattro. The only conflict was in omarchy-setup-security-fingerprint, where quattro now pipes fprintd-enroll through a step-by-step progress filter and reads its status from PIPESTATUS. The merge keeps quattro's version and changes only the account: user=$(id -un) is set before the pipeline, enrollment names "$user", and omarchy-apply-lock still gets it through OMARCHY_INSTALL_USER.

Reproduced on a disposable Omarchy VM, with the fingerprint tools stubbed and USER=nobody: quattro 087f73d8 enrolls nobody, configures the lock screen for nobody, and omarchy-sudo-docker --configured reads nobody's groups. This head enrolls the real account, configures the lock for it and reads its groups. With this PR's bin/ changes reverted on top of the merge, all three go back to nobody.

Tests. test/cli passes on this head, and so do privileged-user-identity-test.sh, fingerprint-package-test.sh, the two sudoless Docker tests, security-polkit-faillock-test.sh, security-fingerprint-remove-test.sh and fingerprint-invitation-test.sh. The full shell suite fails 8 tests on this head and 8 on quattro. None of them touch the files changed here. The two failing only on this head pass again when re-run (t3code-install-test.sh) or fail on quattro as well (lock-appear-budget-test.sh, a timing budget).

Second opinion. Codex Medium reviewed the merge and found no defects. It checked that nothing from quattro or this branch was lost, that PIPESTATUS still reads fprintd-enroll's status, and that no "$USER" account argument remains in the files this PR touches. It agreed with my reading rather than adding a finding of its own, and its independence is not guaranteed.

This is verified at this head. It waits on CI for the new commit, and then on the maintainer. Nothing is needed from you.

@omarchybot omarchybot removed the verified Omarchy Triage has verified that this issue is ready for final review label Oct 31, 2026
quattro removed the migration tests (omacom#16302), so the docker group migration test this branch had adapted to id -un goes with them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@omarchybot omarchybot added the verified Omarchy Triage has verified that this issue is ready for final review label Oct 31, 2026
…sites

privileged-user-identity-test.sh grepped the scripts for the lines this branch adds and for a passwordless sudo change quattro already carries, which AGENTS.md rules out. sudo-docker-test.sh now runs --configured with USER naming another account, so its existing assertions fail when the groups are read for USER; setup and remove are already covered the same way by sudoless-docker-toggle-test.sh.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@omarchybot omarchybot added verified Omarchy Triage has verified that this issue is ready for final review and removed verified Omarchy Triage has verified that this issue is ready for final review labels Oct 31, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

This branch stopped merging cleanly into quattro again, so I merged quattro in once more and replaced the identity test with one that runs the command.

Pushed to your branch:

  • fcc0651c merges quattro. The only conflict was test/shell.d/docker-group-migration-test.sh, which quattro deleted along with the other migration tests (Remove migration tests #16302). The merge keeps it deleted. omarchy-setup-security-fingerprint merged cleanly with quattro's fingerprint changes (Let a platform turn its fingerprint reader on with the owner's agreement #16360, Delete the reader's own copy of the prints when removing fingerprints #16403) and still enrolls "$user" and passes it to omarchy-apply-lock through OMARCHY_INSTALL_USER.
  • e2ba8bdd removes test/shell.d/privileged-user-identity-test.sh. Quattro's AGENTS.md doesn't allow tests that grep the source for the lines a change adds, and the passwordless sudo check in that file already passes on quattro. Instead, sudo-docker-test.sh now runs with USER=spoofed while id -un names the real account, so its existing --configured assertions fail if the groups are read for USER. Setup and remove are already tested the same way in sudoless-docker-toggle-test.sh.

Reproduced on a disposable Omarchy VM. I added the account to docker and ran with USER=nobody. Quattro d367a568's omarchy-sudo-docker --configured says sudoless Docker is not configured. This head says it is. sudo-docker-test.sh and sudoless-docker-toggle-test.sh pass on this head and fail against quattro's bin/. test/cli passes. The full shell suite fails the same 5 files on this head and on quattro (agent-account-exec, ascii, branding-about-animation, first-run, runtime-smoke), and none of them touch the files changed here.

Second opinion. Codex Medium and muse-wonder (pi, thinking high) reviewed both commits and found no defects. They checked that the merge lost nothing, that no privileged call in the touched files still takes $USER, and that the new test meets quattro's test rules. They agreed with my reading rather than adding findings, and their independence is not guaranteed.

Waiting on you: the PR description no longer matches the diff. It describes an omarchy-sudo-passwordless rewrite that quattro already carries (so it isn't in this diff), says --configured uses id -nG with no name (it now uses id -nG "$(id -un)", so it reads the configured groups rather than the session's), names a test file that is gone, and doesn't mention the xbox controller and NordVPN changes. Could you update it to cover what the branch changes now? After that it goes to the maintainer.

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.

6 participants