Repository navigation
OM-SEC-22: Isolate OCaml cleanup authorization - #10217
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Moderate gaps in credential-invalidation coverage and subordinate-ID mapping must be addressed.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Secures OCaml removal by isolating privileged cleanup from user-controlled opam execution.
Changes:
- Adds a cold, non-caching sudo boundary for OCaml cleanup.
- Adds namespace-based security regression coverage.
Review findings:
- Moderate: Success, failure, and signal tests do not verify final credential invalidation (lines 201, 217, 241).
- Moderate: Namespace mappings assume 65,536 subordinate IDs instead of parsing authorized counts (line 23).
- Nit: Use arithmetic conditionals for numeric tests (line 28).
- Nits: Quote string literals in
[[ ]]comparisons (lines 11, 147).
File summaries
| File | Description |
|---|---|
test/shell.d/remove-dev-env-sudo-security-test.sh |
Tests sudo isolation, cleanup, and failure paths. |
bin/omarchy-remove-dev-env |
Secures privileged OCaml cleanup. |
Review details
Suppressed comments (5)
test/shell.d/remove-dev-env-sudo-security-test.sh:217
reset_casealready removes the token, and the failing cleanup stub never creates one, so this assertion passes even if the EXIT invalidation is removed. Check for the secondinvalidateevent to cover the claimed failure-path cleanup.
[[ ! -e $token ]] || fail "failed OCaml cleanup left a reusable sudo credential"
test/shell.d/remove-dev-env-sudo-security-test.sh:241
- The token present at the start of this case is removed before
opamsignals readiness, so its absence after TERM does not exercise the signal-triggered EXIT cleanup. Verify the finalinvalidatecall explicitly; otherwise the signal trap could stop invalidating credentials without failing this test.
[[ ! -e $token ]] || fail "terminated OCaml removal left a reusable sudo credential"
test/shell.d/remove-dev-env-sudo-security-test.sh:28
- Repository shell style requires numeric tests to use arithmetic conditionals rather than
[[ ]](AGENTS.md:26-28).
[[ $(id -u) == 0 ]] || fail "OCaml sudo proof did not enter its root namespace"
test/shell.d/remove-dev-env-sudo-security-test.sh:11
- Repository shell style requires string literals in
[[ ]]comparisons to be quoted (AGENTS.md:27).
if [[ ${OMARCHY_REMOVE_DEV_ENV_SECURITY_NS:-0} != 1 ]]; then
test/shell.d/remove-dev-env-sudo-security-test.sh:147
- Repository shell style requires string literals in
[[ ]]comparisons to be quoted (AGENTS.md:27).
if [[ ${TEST_OPAM_BLOCK:-0} == 1 ]]; then
- Files reviewed: 1/2 changed files
- Comments generated: 2
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
0e559ef to
236a24e
Compare
236a24e to
73a0969
Compare
|
@robosayem review this pr |
robosayem
left a comment
There was a problem hiding this comment.
Reviewed the diff and cross-checked the sudo semantics against the sudo(8) docs. The core mechanism is sound.
Why this closes the window
sudo -N only stops creating or updating the timestamp record. Per sudo(8), with -N an existing valid credential is still used. That makes the cold start the load-bearing part: the initial sudo -k before opam runs is what removes anything a detached poller could reuse, and -N on the cleanup command is what keeps the authentication from creating a new record the poller could grab. The implementation gets both halves right, and the ordering is fail-closed (the -N -V capability probe runs before any user-controlled code).
Test quality
The namespace harness is a genuine regression test, not a mock parade: pre-placing the token file means the success-path test fails if the cold-start sudo -k is ever dropped, and the bind-mounted setuid stub reproduces the detached-poller reuse attempt for real. The node case correctly pins the boundary to OCaml only, matching the branch reality — no other dev-env branch pairs user-controlled commands with a direct sudo call.
Copilot's round-1 findings look addressed by 73a0969: assert_ocaml_invalidations now covers success, failure, signal, and unsupported-sudo paths (the exit trap's second invalidate event is what distinguishes a real cleanup from a reset), and the subuid/subgid mapping parses the authorized counts with a >= 1000 guard instead of assuming 65,536.
Two small notes, no blocker
exec unshare ...turns an unshare failure into a hard test error instead of a skip. On hosts where unprivileged user namespaces are restricted (containers with the default seccomp profile, Ubuntu 24.04+ AppArmor policy) the suite reports a failure from a capability gap. Consider probing first and degrading to a skip the way the subuid guard already does.- Behavior change worth a release-note line: OCaml removal now always prompts for the sudo password (cold start), where it previously rode a cached credential.
Out of scope, for the record
A hostile process that outlives the script, or a concurrent sudo authentication in another terminal during the removal window, can still ride a timestamp created later, and -N will happily use an existing valid credential. That is inherent to sudo's session-wide caching model and not fixable inside this script, so no change requested.
AFOliveira
left a comment
There was a problem hiding this comment.
Two minor test portability observations.
Summary
Fix OM-SEC-22 without changing the package-management workflows carried by #9476.
User-controlled
opamcode previously ran before a normalsudocleanup. A detached child could wait for that authentication and reuse the resulting timestamp.The OCaml removal path now:
opam--no-update/usr/local/bin/opamcleanup throughsudo -NThe boundary is installed only for OCaml removal. Other development-environment removals retain their existing non-sudo behavior.
Validation
./test/clitest/shell.d/remove-dev-env-sudo-security-test.shbash -non changed shell filesgit diff --checkThe focused namespace test covers the detached polling exploit, unsupported
sudo -N, root cleanup failure, signal cleanup, and a non-OCaml removal that must not invoke sudo.Supersedes #9476.