Repository navigation
Conversation
`omarchy dev link` writes /etc/sudoers.d/omarchy-dev-path as a plain `Defaults secure_path=`, which applies to every sudoer on the machine. The checkout one developer linked therefore sits ahead of /usr/bin for root's own `sudo -i` and for any other admin account on the box, none of which ran `omarchy dev link`. Write it as `Defaults:<user>` instead, for the account that ran the command, taken from `id -un`. The linked checkout stays exactly as live as before for the developer who linked it: same search path, same precedence, no separate snapshot to maintain. `secure_path` is also a search path rather than a list of Omarchy commands, so `sudo <anything>` resolves out of the checkout's bin/, not just `sudo omarchy-*`. The on-screen message, `omarchy dev link --help`, `omarchy dev status` and docs/file-layout.md all said "omarchy-*"; they now say what the drop-in covers, so the developer accepting it knows what they are accepting. A migration rewrites an existing global drop-in into the scoped form, attributing it to the owner of the checkout rather than to whoever happens to run migrations first, and leaves anything it did not generate alone. dev-link-test.sh covers the new rule and message and gains two assertions: that no machine-wide Defaults is written, and that the output says the override is not limited to omarchy-*. Verified in a VM: the linking user still resolves a planted `systemctl` out of the checkout, a second wheel user and `sudo -i` resolve /usr/bin, `omarchy dev unlink` still removes the drop-in, and the migration rescopes, no-ops or declines correctly across the global, already-scoped, hand-written, root-owned and missing-checkout cases. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
One migration retry issue was found at Verified: For an ordinary linking account, the generated sudoers policy preserves checkout-first lookup while excluding other invoking users. Real sudoers parser/filter checks produced: This describes policy matching, not live privileged execution. Focused link/unlink tests pass, and the updated link test rejects the old global rule. Failed inspection is recorded as a completed migrationIn A synthetic sudo failure against an existing global rule reproduced this sequence through the migration runner: The retry returned success without making another sudo call. Injecting a read failure at the grep step likewise left the global rule unchanged with a successful migration exit. Impact: An authentication or read failure can prevent the intended scoping change and also prevent an ordinary retry from applying it. Normal updates often have cached sudo credentials, reducing the authentication case's likelihood; standalone migration runs can still encounter it. This leaves the old behavior in place rather than introducing a new privilege grant. Suggested change: Distinguish confirmed file absence from failure to perform the privileged inspection. Propagate sudo/read errors as nonzero exits so the runner leaves the migration pending, while retaining successful no-ops for absent or intentionally unsupported policies. Review informationTest scope: Isolated baseline/head link and unlink tests, real Community review: Independent automated community review, unaffiliated with the Omarchy team, intended to help prepare PRs for their review. Automated AI review: Astra initial source inspection, independent Fable 5.1 High and separate Astra Xhigh technical reviews, followed by Astra synthesis checking the claims against saved targeted evidence. A fresh Astra Medium check assessed editorial compliance only. |
Raised in review. `sudo test -f` returns non-zero both when the drop-in is absent and when sudo could not be asked at all, and the migration exited 0 for both. The runner records any zero exit as applied, so an authentication or read failure retired the migration permanently and left the global secure_path rule in place, with no ordinary retry able to reach it. The `sudo grep ... || true` on the next line suppressed read errors the same way, turning them into an empty file that fell through as "not ours to rewrite". Tell the two apart. If sudo can run anything at all, an absent file really is absent and the migration retires cleanly; otherwise it exits non-zero so the runner leaves it pending for the next run. grep's exit 1 still means "no lines matched", and only greater than 1 is treated as a failure to read. Adds test/shell.d/dev-link-migration-test.sh covering both paths. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
The earlier migration-retry finding is partly addressed at Verified by source inspection: Persistent sudo failure at the initial inspection now exits nonzero, leaving the migration pending. A working sudo with an absent drop-in remains a successful no-op. Grep read errors with status greater than 1 also leave the migration pending. Sudo failure at the grep step can still retire the migrationIn The remaining conditional path, derived from source rather than executed: Impact: The global rule can remain despite the migration being recorded as completed. This requires sudo to fail after the first successful inspection, for example under command-specific permissions or changed authentication state. Normally cached credentials reduce its likelihood. It preserves the old behavior, rather than introducing a new privilege grant. Suggested change: Read the privileged file separately and propagate any failed read as a nonzero migration exit. Filter successfully read content locally, where grep's no-match result cannot be confused with a failed sudo invocation. Review informationTest scope: Source-only comparison of the follow-up, migration, runner and focused test, plus sudo exit-status documentation. No runtime reproduction, real authentication, marker creation or VM validation in this follow-up. Community review: Independent automated community review, unaffiliated with the Omarchy team, intended to help prepare PRs for their review. Automated AI review: Independent Opus 5.5 High and GPT 6 Sol Xhigh technical assessments, followed by Astra Medium source adjudication and synthesis. A fresh Astra Medium check assessed editorial compliance only. |
Follow-up to the review on omacom#12883. The migration inspected the drop-in with a single `sudo grep -vE`, treating status 1 as "no lines matched". sudo also exits 1 when authentication or policy denies the command, so a read that never happened was indistinguishable from a drop-in with no active lines: the migration exited 0, the runner recorded it as applied, and the global secure_path rule stayed in place permanently. This needs sudo to succeed at the `test -f` probe and then fail at the read, which cached credentials usually prevent, but a command-specific policy or an expired timestamp produces exactly that sequence. Read the file with `sudo cat` and filter it locally instead. `cat` exits 0 for an empty file, so a non-zero status can now only mean the read itself failed, and grep's "no lines matched" is evaluated on content already in hand where it is unambiguous. The parsing is unchanged: old and new forms produce identical `active` values across empty files, comment-only files, comments plus blanks, one and two rules, leading whitespace, and a file with no trailing newline. The test gains the case from the review. Its sudo stub grows a SUDO_FAIL_AFTER counter so it can serve the probe and fail the read, which is the sequence the old code got wrong; the test fails against the previous migration and passes against this one. The drop-in path is overridable via OMARCHY_DEV_SUDOERS_FILE so the case can run without touching /etc, matching what other migrations here already do for their markers. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Automated AI review
Outcome: At Both earlier findings are resolved as cited. Two sudo steps can still retire the migration
Suggested change: Do each privileged check in one sudo call that reports its state and fails when sudo fails. Reproducer: owner lookup (fails at d696dd7)Save as #!/bin/bash
set -euo pipefail
source "$(dirname "$0")/base-test.sh"
migration="$ROOT/migrations/1790064412.sh"
test_dir=$(mktemp -d)
trap 'rm -rf "$test_dir"' EXIT
stub_bin="$test_dir/bin"
mkdir -p "$stub_bin"
# The sudo double from dev-link-migration-test.sh, generalised: SUDO_FAIL_CALLS
# lists the call numbers that fail the way a denied or unanswered sudo does.
# `install` copies the staged file instead of changing ownership.
cat >"$stub_bin/sudo" <<'STUB'
#!/bin/bash
count=$(( $(< "$SUDO_CALL_COUNT") + 1 ))
printf '%s' "$count" >"$SUDO_CALL_COUNT"
for n in ${SUDO_FAIL_CALLS:-}; do
if (( n == count )); then
echo "sudo: a password is required" >&2
exit 1
fi
done
if [[ $1 == install ]]; then
cp "${@: -2:1}" "${@: -1}"
exit
fi
exec "$@"
STUB
chmod +x "$stub_bin/sudo"
checkout="$test_dir/checkout"
mkdir -p "$checkout/bin"
drop_in="$test_dir/omarchy-dev-path"
legacy="Defaults secure_path=\"$checkout/bin:/usr/local/sbin:/usr/local/bin:/usr/bin\""
run_migration() {
printf '%s\n' "$legacy" >"$drop_in"
printf '0' >"$test_dir/calls"
migration_status=0
migration_output=$(env PATH="$stub_bin:$PATH" SUDO_CALL_COUNT="$test_dir/calls" \
OMARCHY_DEV_SUDOERS_FILE="$drop_in" "$@" bash -euo pipefail "$migration" 2>&1) ||
migration_status=$?
migration_output=${migration_output//$test_dir/\$test_dir}
}
# Control: with sudo working, the legacy rule is scoped to the checkout owner.
run_migration
[[ $(<"$drop_in") == "Defaults:$(stat -c %U "$checkout") "* ]] ||
fail "migration scopes the legacy rule when sudo works" "exit $migration_status: $migration_output"
pass "migration scopes the legacy rule when sudo works"
# sudo serves `test -f` (call 1) and `cat` (call 2), then fails at `stat` (call 3).
# The migration must not retire while the global rule is still in place.
run_migration SUDO_FAIL_CALLS=3
if (( migration_status == 0 )) && [[ $(<"$drop_in") == "$legacy" ]]; then
fail "a sudo failure at the owner lookup leaves the migration pending" \
"exit $migration_status, drop-in unchanged, output: $migration_output"
fi
pass "a sudo failure at the owner lookup leaves the migration pending"Actual output at d696dd7 (exit status 1): With the owner lookup done in one elevated call that fails when sudo fails (for example Reproducer: probe retry (fails at d696dd7)Save as #!/bin/bash
set -euo pipefail
source "$(dirname "$0")/base-test.sh"
migration="$ROOT/migrations/1790064412.sh"
test_dir=$(mktemp -d)
trap 'rm -rf "$test_dir"' EXIT
stub_bin="$test_dir/bin"
mkdir -p "$stub_bin"
# SUDO_FAIL_CALLS lists the call numbers that fail the way a password prompt
# that timed out does; every other call runs. `install` copies instead of chown.
cat >"$stub_bin/sudo" <<'STUB'
#!/bin/bash
count=$(( $(< "$SUDO_CALL_COUNT") + 1 ))
printf '%s' "$count" >"$SUDO_CALL_COUNT"
for n in ${SUDO_FAIL_CALLS:-}; do
if (( n == count )); then
echo "sudo: timed out reading password" >&2
exit 1
fi
done
if [[ $1 == install ]]; then
cp "${@: -2:1}" "${@: -1}"
exit
fi
exec "$@"
STUB
chmod +x "$stub_bin/sudo"
checkout="$test_dir/checkout"
mkdir -p "$checkout/bin"
drop_in="$test_dir/omarchy-dev-path"
legacy="Defaults secure_path=\"$checkout/bin:/usr/local/sbin:/usr/local/bin:/usr/bin\""
printf '%s\n' "$legacy" >"$drop_in"
printf '0' >"$test_dir/calls"
# The first prompt (`sudo test -f`) fails, the second (`sudo test -d /`) succeeds:
# an unattended update whose first prompt timed out, answered on return.
migration_status=0
migration_output=$(env PATH="$stub_bin:$PATH" SUDO_CALL_COUNT="$test_dir/calls" SUDO_FAIL_CALLS=1 \
OMARCHY_DEV_SUDOERS_FILE="$drop_in" bash -euo pipefail "$migration" 2>&1) ||
migration_status=$?
migration_output=${migration_output//$test_dir/\$test_dir}
if (( migration_status == 0 )) && [[ $(<"$drop_in") == "$legacy" ]]; then
fail "a failed first sudo prompt does not retire the migration with the global rule in place" \
"exit $migration_status, drop-in unchanged, sudo calls: $(<"$test_dir/calls"), output: $migration_output"
fi
pass "a failed first sudo prompt does not retire the migration with the global rule in place"Actual output at d696dd7 (exit status 1): With the probe done in one elevated call that prints the state (for example Accounts without sudo get stuckThe probe needs sudo even with no drop-in, and since Suggested change: After a successful privileged pass, write a root-owned machine marker and exit 0 early when it exists. Reproducer: account without sudo (at d696dd7)Save as #!/bin/bash
# Demonstration, not a pass/fail test: an account that cannot use sudo runs
# omarchy-migrate on a machine that has no dev-link drop-in at all.
# Run from the PR checkout root: bash non-sudo-account-queue.sh
set -uo pipefail
root=$(pwd)
test_dir=$(mktemp -d)
trap 'rm -rf "$test_dir"' EXIT
mkdir -p "$test_dir/bin" "$test_dir/home" "$test_dir/state" "$test_dir/omarchy/migrations"
cat >"$test_dir/bin/sudo" <<'STUB'
#!/bin/bash
echo "sudo: this account is not in the sudoers file" >&2
exit 1
STUB
printf '#!/bin/bash\nexit 0\n' >"$test_dir/bin/omarchy-notification-dismiss"
chmod +x "$test_dir/bin"/*
cp "$root/migrations/1790064412.sh" "$test_dir/omarchy/migrations/"
printf 'echo "Later migration"\ntouch "$HOME/later-migration-ran"\n' >"$test_dir/omarchy/migrations/1799999999.sh"
for attempt in 1 2 3; do
env PATH="$test_dir/bin:$PATH" HOME="$test_dir/home" OMARCHY_PATH="$test_dir/omarchy" \
OMARCHY_MIGRATION_STATE="$test_dir/state" OMARCHY_DEV_SUDOERS_FILE="$test_dir/no-such-drop-in" \
bash "$root/bin/omarchy-migrate" >"$test_dir/out" 2>&1
status=$?
sed -e 's/\x1b\[[0-9;]*m//g' -e "s|$test_dir|\$test_dir|g" "$test_dir/out" | grep -v '^$'
echo "attempt $attempt: omarchy-migrate exit $status;" \
"completed: $(ls "$test_dir/state" | tr '\n' ' ')" \
"later migration ran: $([[ -e $test_dir/home/later-migration-ran ]] && echo yes || echo no)"
doneActual output at d696dd7: Control (same setup, sudo double that works): the runner exits 0, both markers are written and the later migration runs. DetailsNote: The owner lookup has been in the migration since Verified:
Optional test improvement: The new read-failure case also passes against the Optional test improvement: The first two migration cases still use the real Related open PRs: a three-way merge of the files conflicts with #8466 in Review informationTest scope: Sandbox, sudo test double, at AI process: Opus 5.5 Medium coordination and synthesis, Opus 5.5 Xhigh technical review and final fact check, GPT 6 Sol Xhigh search for related issues, Opus 5.5 Medium editorial check. Opt out: To stop receiving these reviews, reply to this comment saying so. |
Second follow-up to the review on omacom#12883. The previous commit fixed the grep/read conflation but left two privileged steps with the same flaw. sudo exits non-zero both when it is denied and when the underlying command legitimately reports nothing, so a denied sudo at either step read as a real result and let the migration exit 0, retiring it with the global secure_path rule still in place: - the owner lookup, `sudo stat -c %U ... || true`, turned a denial into an empty owner and the "cannot tell which user" no-op; - the existence probe used a `sudo test -d /` control that cannot see a policy denying only the `sudo test -f` before it. Both now run as a single sudo call whose own exit status is the sudo verdict, with the result carried in stdout: the inspection prints "absent" or "present" plus the body, and the owner call prints the owner or "__missing__". A non-zero exit from either can only mean sudo failed, so it leaves the migration pending; this also folds the separate read into the inspection call. Demonstrated: with the owner step's sudo denied, the old code exits 0 and rewrites nothing while recording the migration applied; the new code exits non-zero and stays pending. The test gains a generalised sudo double (SUDO_FAIL_CALLS lists the call numbers to deny) and now also covers the working path end to end, asserting the drop-in is rewritten to a user-scoped rule. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
| if ! owner=$(sudo sh -c ' | ||
| if [ -e "$1" ]; then stat -c %U "$1"; else printf __missing__; fi |
There was a problem hiding this comment.
Wrong account gets sudo path If a developer linked a shared checkout owned by another account, the migration uses the checkout owner's name instead of the developer's. The developer loses checkout command resolution under sudo, while the owner—who did not link it—gets the override. Dev-link permits this because it checks that the checkout exists, not who owns it. How this was verified: Dev-link identifies the invoking account, but the migration chooses the sudoers account solely from the checkout's filesystem owner.
Knowledge Base Used: Migration framework
| # With the content in hand, grep's "no lines matched" is unambiguous. | ||
| active=$(printf '%s\n' "$contents" | grep -vE '^[[:space:]]*(#|$)') || true | ||
|
|
||
| generated='^Defaults[[:space:]]+secure_path="([^"]*)/bin:/usr/local/sbin:/usr/local/bin:/usr/bin"$' |
There was a problem hiding this comment.
Escaped paths remain machine-wide If a legacy checkout path contains a quote or backslash, dev-link's sudoers rule contains an escaped value. This regex cannot capture an escaped quote, and a captured escaped backslash is passed to
stat without decoding. The migration can then finish without changing the global rule, so every sudoer keeps the checkout on their command path. How this was verified: Dev-link escapes quotes and backslashes in the rule, while the migration matches or stats that encoded value as though it were the filesystem path.
Knowledge Base Used: Migration framework
| if [[ $owner == root ]]; then | ||
| # Nothing to scope to: a root-owned checkout is no more writable than | ||
| # /usr/bin, and pinning the rule to root would not describe who linked it. | ||
| echo "Left $sudoers_file alone: $checkout is owned by root." | ||
| exit 0 |
There was a problem hiding this comment.
Root ownership leaves global rule If a root-owned checkout has a
bin/ directory or command writable by a developer group, its commands are not protected merely because the checkout itself belongs to root. This branch leaves the legacy machine-wide rule in place and exits successfully, so the migration is marked complete while other sudoers still use that checkout's command path. How this was verified: The migration checks only the checkout directory's owner before retaining the global rule; it does not check who can write commands under bin/.
Knowledge Base Used: Migration framework
| active=$(printf '%s\n' "$contents" | grep -vE '^[[:space:]]*(#|$)') || true | ||
|
|
||
| generated='^Defaults[[:space:]]+secure_path="([^"]*)/bin:/usr/local/sbin:/usr/local/bin:/usr/bin"$' | ||
|
|
||
| if (( $(printf '%s\n' "$active" | grep -c .) != 1 )) || [[ ! $active =~ $generated ]]; then |
There was a problem hiding this comment.
Custom rules can be rewritten If an administrator wrote an annotated global rule with the same path shape, or used tabs or extra space after
Defaults, this check can treat it as a dev-link-generated rule. The migration then silently replaces it with a user-scoped rule, changing command resolution for the other accounts the administrator intended to cover.
| # A fresh call counter per run keeps SUDO_FAIL_CALLS numbering predictable. | ||
| run_migration() { | ||
| printf '0' >"$test_dir/sudo-calls" | ||
| migration_status=0 | ||
| migration_output=$(env PATH="$stub_bin:$PATH" SUDO_CALL_COUNT="$test_dir/sudo-calls" \ |
There was a problem hiding this comment.
Migration edge cases lack tests The
visudo stub always succeeds, and the migration's success case uses only a plain path owned by the test user. Tests for escaped paths, a checkout owned by another account, and retained global rules would cover the parsing and ownership branches; without them, the suite can pass while a migration leaves the override machine-wide or assigns it to the wrong account.
Knowledge Base Used: Migration framework
|
Read at The two models classifying it disagreed. Opus 5.5 (driving) read it as an Also open for whoever picks it up: the branch no longer merges cleanly into Waiting on the maintainer to say which it is. |
This is the non-security hardening proposal invited by the closing review on #9081:
It is not a security report. The position stated there, that dev mode is outside the security threat model because enabling it explicitly trusts a mutable checkout, is taken as given for the developer who runs
omarchy dev linkon their own machine.Two things the current drop-in does are not covered by that position, and this PR fixes those and nothing else.
1. The rule is machine-wide, not per developer
omarchy-dev-linkwrites:A plain
Defaultsapplies to everysudoinvocation by every user on the machine. One developer's home directory therefore sits ahead of/usr/binfor root's ownsudo -i, for a second admin account, and for any automation user, none of which ranomarchy dev link.The consent that the out-of-scope position rests on is the linking developer's. It is not the other accounts' to give.
This PR writes
Defaults:<user>instead, for the account that ran the command, taken fromid -un(the same convention proposed in #8534).2. The message says
omarchy-*; the rule covers every commandsecure_pathis a search path, not a list of Omarchy commands. While the link is up,sudo <anything>resolves out of the checkout'sbin/first, not justsudo omarchy-*.The on-screen message,
omarchy dev link --help,omarchy dev statusanddocs/file-layout.mdall saidomarchy-*. They now say what the drop-in actually covers, so a developer accepting it knows what they are accepting.What does not change
The linked checkout stays exactly as live as before for the developer who linked it. Same directory, same search path, same precedence, no snapshot, no farm, no relinking when a command is added or renamed. This is the condition #9081's closing comment set, and the reason that PR's symlink-farm approach is not reused here.
Migration
migrations/1790064412.shrewrites an existing global drop-in into the scoped form. It attributes the rule to the owner of the checkout rather than to whoever happens to run migrations first, since on a machine with two developers those are different people. It stats the checkout throughsudo, because a checkout under another user's0700home is exactly the case it exists for. It only touches a file that is byte-for-byte whatdev-linkgenerated, and reports rather than rewrites anything else. A root-owned checkout and a checkout that no longer exists are both left alone with an explanation.Tests
test/shell.d/dev-link-test.shis updated for the new rule and message, plus two new assertions: that no machine-wideDefaultsis written, and that the output states the override is not limited toomarchy-*.test/shell.d/dev-unlink-test.shis unchanged and still passes; unlink already removes the drop-in whatever its scope.Verified in a VM
On a clean Omarchy install with a second wheel user:
sudo systemctlsudo systemctl/usr/bin/systemctlsudo -i,systemctl/usr/bin/systemctlA binary planted in the first user's home ran as
uid=0for the second user before the change and does not after, while the first user's live checkout is untouched.omarchy dev unlinkstill removes the drop-in. The migration was exercised against all five states it can meet: global, already scoped, hand-writtensecure_path, root-owned checkout, and missing checkout.The username is backslash-escaped for the sudoers
Defaultslist, checked against names containing#, spaces, quotes, backslashes and@; all parse undervisudo -c, and a leading#no longer reads as a uid. The staged file is still validated withvisudo -cfbefore anything is installed.🤖 Generated with Claude Code