Skip to content

user: add/remove users, groups, sudo level + managing-users manual - #14366

Open
nightdevil00 wants to merge 7 commits into
omacom:quattrofrom
nightdevil00:user-admin-scripts
Open

nightdevil00 wants to merge 7 commits into
omacom:quattrofrom
nightdevil00:user-admin-scripts

Conversation

@nightdevil00

Copy link
Copy Markdown

Omarchy provisions one owner on first boot, but there is no supported path for a second login on the same machine (family member, handoff, separate work account).

This adds an 'omarchy user' command group:

  • user add: create login user, groups (default wheel), password via passwd, optional password sudo via a validated /etc/sudoers.d drop-in.
  • user groups: pick/add/remove/set supplementary groups; primary group never touched.
  • user privileges: password sudo or none through the same per-user drop-in model. Like the rest of Omarchy, sudo always asks for a password.
  • user remove: refuses root/system/self, terminates the session, drops home and the managed sudoers file on request.
    All four run interactively via gum or scripted with explicit flags plus --yes, validate with visudo -c, and are registered in GROUP_DESCRIPTIONS. manual/49-managing-users.md documents the group and contrasts the permanent grant with the expiring Passwordless Sudo toggle.

Verified: bash -n clean, --help smoke-tested, router lists all four under 'omarchy user', ./test/cli passes (117 ok).

Related: a companion PR (#14365) reworks the SDDM greeter with a user/session picker, keyboard nav, and focus highlight. The two stand alone - each merges and works independently; together they cover shared-machine logins end to end.

New 'omarchy user' command group for second logins on shared machines
(first boot still owns the single-owner flow via provision-owner):
- user add: create login user, groups (default wheel), password via
passwd, optional password sudo via validated sudoers drop-in
- user groups: pick/add/remove/set supplementary groups, primary kept
- user privileges: password sudo or none (per-user drop-in, validated)
- user remove: refuse root/system/self, terminate session, drop home
and managed sudoers file on request
All four: gum interactive + --yes scripted, visudo -c validated,
registered in GROUP_DESCRIPTIONS. Manual 49 documents the group and
contrasts permanent grants with the expiring Passwordless Sudo toggle.

Standalone companion: greeter multi-user picker (separate PR, each
merges independently).
@greptile-apps

greptile-apps Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Critical impact] The PR appears safe to merge; no new actionable issue was established.

Summary

Adds four commands for managing login accounts and documents their use.

  • Operators can create a login account with chosen groups and a password.
  • Operators can change supplementary groups without changing the primary group.
  • Operators can grant or remove password-based admin access through wheel.
  • Operators can remove a login account and choose whether to keep its home.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[omarchy user] --> B[add]
  A --> C[groups]
  A --> D[privileges]
  A --> E[remove]
  B --> F[Check name, groups, and stale sudoers file]
  C --> G[Check login account and wheel removal]
  D --> G
  E --> H[Check self, system account, and last administrator]
  F --> I[Confirm]
  G --> I
  H --> I
  I --> J[Run account commands through sudo]
Loading

Reviews (6) · Last reviewed commit: "Merge pull request #3 from EFrMG/port-us..." · Reviewed by Greptile

Comment thread bin/omarchy-user-privileges Resolved
Comment thread bin/omarchy-user-privileges Resolved
Comment thread bin/omarchy-user-privileges Resolved
Comment thread bin/omarchy-user-privileges Resolved
Comment thread bin/omarchy-user-remove Resolved
Comment thread bin/omarchy-user-groups Resolved
Comment thread bin/omarchy-user-remove Resolved
@jandrusk

jandrusk commented Oct 7, 2026

Copy link
Copy Markdown

Thanks for putting this together. A few things need fixing before this is safe to merge, mostly around how the sudo level is shown versus what the account can actually do:

  1. "No sudo" still gives full sudo (BLOCKING). omarchy-provision-owner writes %wheel ALL=(ALL:ALL) ALL to /etc/sudoers.d/00-omarchy-wheel, and user add puts new accounts in wheel by default, both interactively (--selected=wheel) and without a TTY. So an account created with "No sudo" is a full admin. user privileges --level none also leaves wheel alone. I'd make wheel the only switch, with no per-user drop-ins:

    # privileges
    case $LEVEL in
      password) sudo gpasswd -a "$USERNAME" wheel ;;
      none)     sudo gpasswd -d "$USERNAME" wheel ;;
    esac

    Then drop wheel from the default groups in user add and the curated list in user groups, so sudo is only granted through privileges.

  2. The rule goes live before visudo checks it (BLOCKING). The tee writes the real /etc/sudoers.d/<user> file first, and sudo visudo -c only runs afterwards. If the check fails, set -e exits and leaves the broken file in place, and sudo refuses to run at all while any sudoers file has a parse error. (privileges only checks the name with id, so names like ALICE or alice.bob get through.) Check a temp file first, the way omarchy-sudo-passwordless does:

    tmp=$(mktemp) && printf '%s\n' "$sudoers_line" >"$tmp"
    sudo visudo -cf "$tmp" >/dev/null || { rm -f "$tmp"; fail "invalid sudoers rule"; }
    sudo install -m 0440 -o root -g root "$tmp" "$sudoers_file"; rm -f "$tmp"
  3. The drop-in file can overwrite shipped rules. /etc/sudoers.d/$USERNAME with a valid name like omarchy-dns or omarchy-tzupdate replaces a file the package ships. A prefixed name such as /etc/sudoers.d/50-omarchy-user-$USERNAME avoids that. This goes away anyway if you go with the wheel approach in 1.

  4. Removal checks. grep -qE "^$USERNAME ALL=" deletes the whole file even if other rules are in it. Only remove it when the full contents match the rule you wrote. Also, the self-protection compares the raw argument with $SUDO_USER/whoami, so passing your own numeric UID gets past it, and loginctl terminate-user runs before userdel can fail. Compare UIDs instead ([[ $uid == "$(id -u "${SUDO_USER:-$USER}")" ]]).

  5. user groups can take away your own admin access. --remove wheel (or --set without it) on the account you're running as removes your sudo on the next login. I'd refuse to drop wheel from the caller or from the last member of wheel. It also needs # omarchy:requires-sudo=true.

Tests with stubbed sudo/useradd/visudo for these refusal paths would help a lot, since this is account and privilege code. Whether Omarchy wants an omarchy user group at all is a call for the maintainers.

Comment thread bin/omarchy-user-add Resolved
Comment thread bin/omarchy-user-add Resolved
Comment thread bin/omarchy-user-remove Resolved
Comment thread bin/omarchy-user-groups Resolved
Comment thread bin/omarchy-user-privileges Resolved
Comment thread bin/omarchy-user-groups Resolved
Comment thread bin/omarchy-user-groups Resolved
@jandrusk

jandrusk commented Oct 8, 2026

Copy link
Copy Markdown

Thanks for switching to wheel as the only sudo switch. That's the right model, and it removes the sudoers drop-in problems. The new push (c2b659a) has some regressions that stop the commands from running at all, though:

  1. omarchy user add exits before creating anyone (BLOCKING). SKIP_PASSWORD is no longer initialized or parsed, but ((SKIP_PASSWORD == 0)) and ((SKIP_PASSWORD)) still read it, so set -u aborts with unbound variable. The error text and the manual still mention --skip-password. Either restore SKIP_PASSWORD=0 and the flag, or drop both checks.
  2. No-groups default is rejected. Non-interactive runs now set GROUPS_ARG="", and the next line is [[ -n $GROUPS_ARG ]] || fail "no groups selected". The manual says the default is no groups. Allow an empty list, and skip usermod -aG when it's empty.
  3. omarchy user remove doesn't parse (BLOCKING). if interactive: then should be if interactive; then.
  4. omarchy user groups exits on the first wheel member. ((current_login_count++)) returns status 1 when the count is 0, so set -e kills the script before the last-admin check. Use ((++current_login_count)). The *wheel* substring checks also match a group like wheel-helper. Comparing whole names avoids that:
    [[ ,$final, == *,wheel,* ]]        # final is comma-separated
    [[ " $current " == *" wheel "* ]]  # current is space-separated
  5. omarchy user privileges --level none skips the protections. It runs gpasswd -d with no self/last-admin check, so on a one-owner machine the owner can still remove their own sudo. A shared helper used by both groups and privileges would keep the two in sync.

Running bash -n bin/omarchy-user-* would have caught 3. A test with stubbed sudo/useradd/gpasswd for each refusal path would catch the rest.

- Share self/last-admin wheel checks via omarchy-user-functions so groups
  and privileges enforce the same rules
- Only refuse group changes that actually remove wheel; match group names exactly
- Fix ((count++)) exiting under set -e, and 'if interactive:' syntax error
- Add --skip-password flag and allow creating users with no groups
- privileges --level none is a no-op with a warning when not in wheel
- Add user-admin shell test with stubbed id/getent/sudo
Comment thread bin/omarchy-user-groups Resolved
nightdevil00 and others added 3 commits October 8, 2026 18:37
Address the remaining review item on omacom#14366 (safety checks lack tests).
The user-remove script already refuses system accounts (UID<1000) and
resolves the target's UID before the self-check, but neither path was
covered. Add fixtures/tests for:
  - removing a system account (UID>=1000 required to proceed)
  - removing yourself by numeric UID (getent resolves it; UID self-check
    must still block it before any privileged command runs)

Also let the getent stub resolve a numeric UID argument, matching real
getent, so the numeric case is exercised end to end.

All 17 checks pass.
- omarchy-user-remove: drop the 'mail spool not found' notice from userdel
  output; other userdel errors still fail with their message
- user add/groups: gum checklist hint says 'x to toggle' (space does not toggle)
Preserve account safety in wheel-based administration
@paulogeyer

Copy link
Copy Markdown
Contributor

On my laptop this merges clean on quattro and user-admin-test.sh passes (43 ok). Two gaps: on ISO installs sudo may be granted to the owner by name rather than through %wheel (per #16100), in which case toggling wheel here would be a no-op; and with autologin still on, a second account has no way in without #14365. #16100 handles both and has tests for the by-name case that could be carried over.

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants