Skip to content

Scope the dev-link secure_path drop-in to the linking user - #12883

Open
taufderl wants to merge 4 commits into
omacom:quattrofrom
taufderl:fix/devlink-scope-secure-path-to-user
Open

taufderl wants to merge 4 commits into
omacom:quattrofrom
taufderl:fix/devlink-scope-secure-path-to-user

Conversation

@taufderl

Copy link
Copy Markdown

This is the non-security hardening proposal invited by the closing review on #9081:

A future non-security hardening proposal could still be considered if it preserves a genuinely live checkout without requiring developers to maintain a separate command snapshot.

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 link on 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-link writes:

Defaults secure_path="<checkout>/bin:/usr/local/sbin:/usr/local/bin:/usr/bin"

A plain Defaults applies to every sudo invocation by every user on the machine. One developer's home directory therefore sits ahead of /usr/bin for root's own sudo -i, for a second admin account, and for any automation user, none of which ran omarchy 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 from id -un (the same convention proposed in #8534).

2. The message says omarchy-*; the rule covers every command

secure_path is a search path, not a list of Omarchy commands. While the link is up, sudo <anything> resolves out of the checkout's bin/ first, 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 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.sh rewrites 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 through sudo, because a checkout under another user's 0700 home is exactly the case it exists for. It only touches a file that is byte-for-byte what dev-link generated, 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.sh is updated for the new rule and message, plus two new assertions: that no machine-wide Defaults is written, and that the output states the override is not limited to omarchy-*. test/shell.d/dev-unlink-test.sh is 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:

before after
linking user, sudo systemctl checkout copy checkout copy
second wheel user, sudo systemctl checkout copy /usr/bin/systemctl
sudo -i, systemctl checkout copy /usr/bin/systemctl

A binary planted in the first user's home ran as uid=0 for the second user before the change and does not after, while the first user's live checkout is untouched. omarchy dev unlink still removes the drop-in. The migration was exercised against all five states it can meet: global, already scoped, hand-written secure_path, root-owned checkout, and missing checkout.

The username is backslash-escaped for the sudoers Defaults list, checked against names containing #, spaces, quotes, backslashes and @; all parse under visudo -c, and a leading # no longer reads as a uid. The staged file is still validated with visudo -cf before anything is installed.

🤖 Generated with Claude Code

`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>
@llstrk

llstrk commented Sep 22, 2026

Copy link
Copy Markdown

One migration retry issue was found at d003264b.

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:

Invoking account     Before          After
linking user         checkout path   checkout path
other user / root    checkout path   no dev-path override

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 migration

In migrations/1790064412.sh:14-20, sudo test -f ... || exit 0 treats a sudo failure like an absent file. The subsequent sudo grep ... || true also suppresses inspection errors.

A synthetic sudo failure against an existing global rule reproduced this sequence through the migration runner:

sudo test fails
  -> migration exits 0
  -> runner writes its completion marker
  -> retry after recovery skips the migration
  -> existing global secure_path remains

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 information

Test scope: Isolated baseline/head link and unlink tests, real visudo/cvtsudoers policy checks, and synthetic migration cases including completion-marker and retry inspection. Sudo effects and ownership were mocked. No real elevation, PAM, second-account execution, reboot, or reproduction of the reported VM experiment.

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>
@llstrk

llstrk commented Sep 23, 2026

Copy link
Copy Markdown

The earlier migration-retry finding is partly addressed at 6f4d760b. Its broad applicability should be narrowed, not treated as fully resolved.

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 migration

In migrations/1790064412.sh:29-39, status 1 is treated as “no matching lines.” However, sudo also returns 1 when authentication, policy or command execution fails.

The remaining conditional path, derived from source rather than executed:

Existing global drop-in: sudo test -f succeeds
  -> sudo grep itself fails with status 1, no stdout
  -> treated as an empty policy; migration exits 0
  -> runner writes completion marker
  -> later normal runs skip the migration

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 information

Test 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>
@llstrk

llstrk commented Sep 30, 2026

Copy link
Copy Markdown

Automated AI review

Community review: Independent automated community review, unaffiliated with the Omarchy team, intended to help prepare PRs for their review.

Outcome: At d696dd7b, two sudo steps can still retire the migration, and accounts without sudo cannot finish it.

Both earlier findings are resolved as cited.

Two sudo steps can still retire the migration

sudo stat ... || true (line 59) reads a failed sudo as an empty owner, and the probe (lines 19-22) exits 0 when only the first sudo test fails. Impact: in these uncommon cases, it is marked applied while the global rule stays.

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 test/shell.d/dev-link-migration-owner-lookup-test.sh in the PR checkout and run bash test/shell.d/dev-link-migration-owner-lookup-test.sh. It uses a sudo test double (never real sudo) and the PR's OMARCHY_DEV_SUDOERS_FILE override. The first case is a control (sudo working, rule gets scoped). The second makes only sudo call 3 (stat) fail, after test -f (call 1) and cat (call 2) succeeded.

#!/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):

ok - migration scopes the legacy rule when sudo works
exit 0, drop-in unchanged, output: Scope the dev-link sudoers drop-in to the linking user
Left $test_dir/omarchy-dev-path alone: cannot tell which user $test_dir/checkout belongs to.
Re-run 'omarchy dev link $test_dir/checkout' as that user, or 'omarchy dev unlink'.
not ok - a sudo failure at the owner lookup leaves the migration pending

With the owner lookup done in one elevated call that fails when sudo fails (for example sudo bash -c 'if [[ -e $1 ]]; then stat -c %U -- "$1"; fi' bash "$checkout", checked with if ! owner=$(...)), both cases print ok and the PR's own dev-link-migration-test.sh still passes (checked on a disposable copy of the migration).

Reproducer: probe retry (fails at d696dd7)

Save as test/shell.d/dev-link-migration-probe-retry-test.sh in the PR checkout and run bash test/shell.d/dev-link-migration-probe-retry-test.sh. It uses a sudo test double (never real sudo) and the PR's OMARCHY_DEV_SUDOERS_FILE override. Only sudo call 1 fails.

#!/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):

exit 0, drop-in unchanged, sudo calls: 2, output: Scope the dev-link sudoers drop-in to the linking user
sudo: timed out reading password
not ok - a failed first sudo prompt does not retire the migration with the global rule in place

With the probe done in one elevated call that prints the state (for example kind=$(sudo bash -c 'if [[ -f $1 ]]; then printf file; elif [[ -e $1 ]]; then printf other; else printf missing; fi' bash "$sudoers_file"), checked with if !, the pattern inspect_sudoers_file in migrations/1788025225.sh uses), this test prints ok and the PR's own tests still pass (checked on a disposable copy of the migration).

Accounts without sudo get stuck

The probe needs sudo even with no drop-in, and since 6f4d760b its failure exits 1. Impact: an account without sudo fails every run, halting its queue.

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 non-sudo-account-queue.sh in the root of the PR checkout and run bash non-sudo-account-queue.sh. It uses a sudo double that always refuses, a temporary OMARCHY_PATH and migration state directory, and the PR's OMARCHY_DEV_SUDOERS_FILE override pointed at a path that does not exist.

#!/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)"
done

Actual output at d696dd7:

Running migration (1790064412)
Scope the dev-link sudoers drop-in to the linking user
sudo: this account is not in the sudoers file
sudo: this account is not in the sudoers file
Could not inspect $test_dir/no-such-drop-in. Leaving this migration pending so it retries.
attempt 1: omarchy-migrate exit 1; completed:  later migration ran: no
Running migration (1790064412)
Scope the dev-link sudoers drop-in to the linking user
sudo: this account is not in the sudoers file
sudo: this account is not in the sudoers file
Could not inspect $test_dir/no-such-drop-in. Leaving this migration pending so it retries.
attempt 2: omarchy-migrate exit 1; completed:  later migration ran: no
Running migration (1790064412)
Scope the dev-link sudoers drop-in to the linking user
sudo: this account is not in the sudoers file
sudo: this account is not in the sudoers file
Could not inspect $test_dir/no-such-drop-in. Leaving this migration pending so it retries.
attempt 3: omarchy-migrate exit 1; completed:  later migration ran: no

Control (same setup, sudo double that works): the runner exits 0, both markers are written and the later migration runs.

Details

Note: The owner lookup has been in the migration since d003264b; earlier reviews did not name it. Both remaining paths need sudo to fail after earlier calls succeeded (for example a command-specific policy), or a failed first prompt followed by an answered one. The non-sudo exit 1 came in with 6f4d760b, which followed the first review's suggestion to propagate sudo errors. migrations/1788025225.sh has both patterns: one-call inspect_sudoers_file and a machine marker under /var/lib/omarchy/migrations/ that accounts without sudo can read; those accounts stay blocked until an administrator has run the migration once.

Verified:

  • A sudo failure at the read exits 1 with the drop-in unchanged. The same failure exited 0 in the 6f4d760b migration once it was pointed at the same drop-in.
  • Persistent sudo failure at the probe exits 1; an absent drop-in with working sudo is still a clean no-op.
  • Reading with sudo cat and filtering locally gave the same result as the previous sudo grep in 15 content cases, including empty, comment-only, CRLF and no final newline.
  • The PR's link, unlink and migration tests pass.

Optional test improvement: The new read-failure case also passes against the 6f4d760b migration, which ignores the override and fails at the probe instead; both failure messages contain "Leaving this migration pending". Asserting Could not read would pin it to the read.

Optional test improvement: The first two migration cases still use the real /etc/sudoers.d/omarchy-dev-path, so the absent-file case passes because an unprivileged test cannot see that file. Pointing them at $test_dir through OMARCHY_DEV_SUDOERS_FILE would make them hermetic.

Related open PRs: a three-way merge of the files conflicts with #8466 in bin/omarchy-dev-status (its status line still says omarchy-*) and with #13047 in docs/file-layout.md (its factory-reset paragraph).


Review information

Test scope: Sandbox, sudo test double, at d696dd7b.

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>
@greptile-apps

greptile-apps Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 0/5

[Critical risk] Changes sudo privilege escalation rules for development linking.

The PR is not ready to merge because the migration can scope the override to the wrong account or complete while a machine-wide override remains.

Findings

  1. P1 Security Wrong account gets sudo path ▶
  2. P1 Security Escaped paths remain machine-wide ▶
  3. P1 Security Root ownership leaves global rule ▶
  4. P1 Custom rules can be rewritten ▶
  5. P2 Migration edge cases lack tests ▶

Summary

The PR changes dev-link’s sudoers override from machine-wide to linking-user scope, updates the wording to describe all command names, and adds a migration for existing installations.

  • The direct link path preserves a live checkout while scoping its sudo search path.
  • The migration has attribution and legacy-rule cases that can leave the intended scope unresolved or change an administrator’s rule.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Existing dev-link sudoers drop-in] --> B{Matches legacy global rule?}
  B -- No --> C[Leave unchanged]
  B -- Yes --> D[Look up checkout owner]
  D --> E{Owner accepted?}
  E -- No --> F[Leave global rule; migration completes]
  E -- Yes --> G[Write Defaults:owner]
  H[New dev link] --> I[Write Defaults:linking user]
Loading

Reviews (1) · Last reviewed commit: "Do each privileged inspection in one sud..."

Comment thread migrations/1790064412.sh
Comment on lines +63 to +64
if ! owner=$(sudo sh -c '
if [ -e "$1" ]; then stat -c %U "$1"; else printf __missing__; fi

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.

P1 security 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

Comment thread migrations/1790064412.sh
# 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"$'

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.

P1 security 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

Comment thread migrations/1790064412.sh
Comment on lines +76 to +80
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

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.

P1 security 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

Comment thread migrations/1790064412.sh
Comment on lines +41 to +45
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

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.

P1 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.

Comment on lines +45 to +49
# 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" \

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.

P2 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

@omarchybot

Copy link
Copy Markdown
Collaborator

Read at dee6cf90: the diff, the description, the earlier community reviews and Greptile's findings. Nothing was run on a worker, because the classification did not settle, and an item is only verified once it has been classified.

The two models classifying it disagreed. Opus 5.5 (driving) read it as an enhancement: dev mode trusting a mutable checkout through a machine-wide secure_path is the documented design, #9081 was closed on that basis, and this PR presents itself as the non-security hardening proposal that closing review invited, so it changes existing behaviour on purpose. Codex Medium read it as a bug: a plain Defaults reaches sudoers who never ran omarchy dev link, and the help, status output and docs/file-layout.md say omarchy-* where the rule covers every command name. Both readings hold up, so neither label went on, and whether the current scope is a defect or a design choice is the maintainer's call.

Also open for whoever picks it up: the branch no longer merges cleanly into quattro, and Greptile's findings on the migration at this head (a checkout linked by someone other than its owner, escaped paths, a root-owned checkout with a group-writable bin/) have not been answered on the PR yet.

Waiting on the maintainer to say which it is.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants