Skip to content

fix: restore green main - #2533

Merged
abrichr merged 8 commits into
mainfrom
fix/red-main-1122
Nov 22, 2026
Merged

abrichr merged 8 commits into
mainfrom
fix/red-main-1122

Conversation

@abrichr

@abrichr abrichr commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Fixes the failures that have kept main red since 2092fc0 (#2484).

Failures, causes and fixes

The two Flow failures (test_cli_hints and test_every_module_imports_alone) were fixed on main by #2530 and #2519. This branch merged main and no longer changes Flow.

Desktop Windows engine tests, py3.11 and py3.12 (tests/test_engine/test_stop_queue_exceptions.py)

Cause: the card reader's safety checks were POSIX-only. On Windows, O_NOFOLLOW is 0, there is no getuid, and the mode-bit check runs only when os.name == "posix". So on Windows a linked card was followed and read (test_a_linked_card_is_not_read), and a card any user could read was shown. The checks failed open there.

  • test_the_window_signs_and_writes_the_runs_answer (438 == 384) compares mode bits, not byte counts: 438 is 0o666 and 384 is 0o600. Windows reports 0o666 for any writable file.
  • test_a_card_other_users_can_read_is_not_shown used chmod(0o644). On Windows that only clears the read-only flag, so it never made the card readable by others.

Fix (fail closed, the Windows way): in openadapt_desktop/exception_queue.py:

  • Links: before opening, lstat the card and refuse a symlink or any reparse point (FILE_ATTRIBUTE_REPARSE_POINT, which covers junctions). The run folder gets the same check.
  • Same file: after opening, fstat's (st_dev, st_ino) must match the checked file and must be nonzero.
  • ACL: read the owner and DACL from the open handle (GetSecurityInfo through msvcrt.get_osfhandle, added as a handle= option to the existing ctypes reader approver_anchor._windows_security). The owner must be this process's user, or the owner its token gives new files. Only this user, SYSTEM and Administrators may hold rights, which matches the default ACL of a user's profile folder. OWNER RIGHTS (S-1-3-4) is allowed too: it grants rights only to the owner, who must already be this user. An elevated process's temp files carry it, as the Windows CI runner showed.
  • What is refused: a NULL DACL, an unknown entry type, or any failure to read the security. No card is shown in those cases.
  • Answers: written only where the new file comes out private by the same rule. Otherwise the result is registry_unwritable.
  • Binary mode: card and answer files open with O_BINARY, so Windows doesn't translate newlines or treat Ctrl-Z as end of file.

Tests: the POSIX assertions are unchanged. On Windows they now exercise the real condition:

  • "Other users can read" grants and removes read for Everyone (icacls *S-1-1-0).
  • The answer file must pass the same private-ACL check the product uses, and must contain no CRLF.
  • A parametrized test covers the ACL rule itself on every platform: owner, NULL DACL, Everyone and Users grants, callback, inherit-only, deny and unknown entry types.

Desktop is bumped to 0.31.1 as desktop-release-intent requires.

Rust locked dependencies

Cause: a new advisory, RUSTSEC-2026-0592, covers url 2.5.8 in src-tauri/Cargo.lock.

Fix: cargo update -p url --precise 2.5.9, which also moves form_urlencoded to 1.2.3. cargo audit finds no vulnerabilities.

Earlier red checks on this PR

Flow core unit shard 1/4 failed on this branch's own dispatch_cli import of cli_hints, an upward import. That change is gone after the merge. The launcher run-ci job failed only because the packages job failed.

Other jobs on main

The latest finished Packages runs on main (45013930658, 45010820726, 45010093446, 45007372801, 45007074484) fail only in the jobs above (plus packages-gate, which reports them). No other workflow on main failed in the last 60 runs. The Windows native row census failure in #2484 comes from the 11-21 nightly. It passes on the push runs above.

Verification

  • Local (macOS): tests/test_engine/test_stop_queue_exceptions.py passes, 42 passed and 1 skipped.
  • Windows: the pull-request tier runs Desktop tests on Ubuntu only, so I ran Packages on this branch with workflow_dispatch.
    • Run 45027541702, at 9147602: Python engine tests pass on windows-latest py3.11 and py3.12, and on Ubuntu and macOS.
    • The earlier dispatch run 45019134260 failed on Windows: every card was refused because of the OWNER RIGHTS entry, so the check failed closed. A temporary diagnostic test (since removed) captured the runner's real ACL, and the fix above is based on it.

- Flow: printed next steps for handoff, ledger and wrap-dispatch use
  cli_hints.command(), so they follow the launcher spelling.
- Flow: openadapt_flow.txplan.__main__ runs only as a script, so importing
  it alone no longer parses pytest's argv and exits.
- Desktop: exception cards are checked on Windows too. A link or other
  reparse point is refused before opening, the opened file must be the one
  checked, and the owner and DACL are read from the open handle (only this
  user, SYSTEM and Administrators). Answers are written only where they come
  out private. Card and answer files are opened in binary mode.
@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

From: Claude
Reviewed-Head: d2b0231

@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Claude
Reviewed-Head: d2b0231

Nothing blocking. The pull-request tier runs Desktop tests on Linux only (.github/workflows/desktop-test.yml:75), so the Windows branch is verified only by reading the code until a Windows run finishes.

Each failure

  • test_cli_hints: the three offenders print through command() (cli_deferred.py:220-222, run_ledger/cli.py:198-200, wrap/dispatch_cli.py:655-657), with unchanged text. The test passes locally.
  • test_every_module_imports_alone: the txplan/__main__.py guard keeps python -m openadapt_flow.txplan working and stops import from parsing argv. The test is untouched.
  • 438 == 384: this is 0o666 vs 0o600. On Windows the assertion becomes the real ACL check, and it is still exactly 0o600 on POSIX. A new CRLF assertion makes the test stronger. O_BINARY stops the CRT's text-mode newline translation.
  • Other users can read: icacls grants *S-1-1-0:(R) and removes it with /remove:g, which changes the real ACL. The old chmod only flipped the read-only attribute.
  • Linked card: the test is unchanged. _is_link refuses S_ISLNK or FILE_ATTRIBUTE_REPARSE_POINT (junctions) before opening.

Windows safety: no fail-open found

  • Read order: lstat (refuse a link, reparse point or non-regular file), open, compare fstat's (st_dev, st_ino) and refuse a 0 inode, GetSecurityInfo on the open handle, then read from the same fd. A swap changes the inode and is refused.
  • Handle rights: GENERIC_READ and GENERIC_WRITE both include READ_CONTROL, so GetSecurityInfo works on read and write handles.
  • Rule:
    • The owner must be the token's user or its default owner.
    • A NULL DACL is refused, deny entries are skipped, and unknown entry types are refused.
    • Inherit-only entries are skipped.
    • Any right held by another SID, other than SYSTEM or Administrators, is refused.
    • This accepts the inherited profile ACL Flow's cards get, and rejects Everyone, Users and Authenticated Users.
  • Failures: every failure in _windows_private returns False. _write_exclusive raises PermissionError, an OSError the caller already handles, before writing any bytes, and removes the temp file.
  • ctypes: TokenUser=1, TokenOwner=4 and TOKEN_QUERY=0x0008 are correct. restype/argtypes are set, handles are wrapped in wintypes.HANDLE, the buffer stays alive during SID conversion, and the token is closed in finally.
  • POSIX: no regression. Desktop release intent is consistent at 0.31.1. Ruff check is clean on the changed files.

Not blocking

  1. Windows not yet run: run the Windows desktop lane on this branch before merging, or watch the push run.
  2. Possible false refusals: all fail closed.
    • On some volumes (FAT, SMB) on Python 3.12+, lstat and fstat may report different st_dev/st_ino.
    • An elevated Flow writer with a non-elevated Desktop gives cards an Administrators owner, which is refused.
    • Cloud-file and dedup reparse points are refused.
  3. New advisory: RUSTSEC-2026-0592 (url 2.5.8, fixed in 2.5.9) fails the Desktop Rust dependency audit. This PR didn't cause it, and it will show on main for Desktop paths until src-tauri/Cargo.lock is bumped.
  4. Folder swap: the run folder could be swapped for a junction between open_cards and the read. This is the same as the POSIX gap (O_NOFOLLOW covers only the last component), needs write access to the user's own registry, and the handle ACL check still applies.
  5. Temp-name collision: with os.open inside the try, a FileExistsError on the uuid temp name would unlink an existing entry. The odds are negligible.
  6. Circular helper: the test's _private_to_this_user uses the product check. The Everyone-grant test covers an always-True bug.
  7. CHANGELOG: extra blank lines after the 0.31.1 entry.
  8. Protected-path gate: "Evaluate protected-path evidence" fails on this PR. It is the review gate, not a code defect.

@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Gemini
Reviewed-Head: 9147602

Independent cross-vendor adversarial review of 914760283feda69895a0d9dd1c3854d721786793 (Claude-authored; I authored none of this PR).

Findings & fail-closed verification

  • Windows exception-card & answer-file safety (exception_queue.py, approver_anchor.py):
    • _is_link refuses both symlinks (S_ISLNK) and Windows reparse points/junctions (FILE_ATTRIBUTE_REPARSE_POINT) on both run folders and card files.
    • _read checks lstat before os.open(..., _binary(...)), verifies non-zero (st_dev, st_ino) matches fstat(fd) (blocking path-swap races), and queries the owner and DACL from the open Win32 handle via GetSecurityInfo(msvcrt.get_osfhandle(fd)) rather than by path.
    • windows_private_reason fails closed on non-matching owner SID (TokenUser/TokenOwner), NULL DACL, unknown ACE types, or any non-inherit-only allow ACE for SIDs outside {me, SYSTEM, Administrators, OWNER RIGHTS}; _windows_private catches all errors and returns False.
    • _write_exclusive enforces _binary(...) and refuses to write/link an answer file on Windows unless _windows_private(fd, tmp) passes. POSIX O_NOFOLLOW, st_uid, and 0o077 checks are untouched.
  • Rust locked dependencies & release hygiene: Cargo.lock cleanly updates url 2.5.8 → 2.5.9 (RUSTSEC-2026-0592) and form_urlencoded 1.2.2 → 1.2.3; openadapt-desktop is consistently bumped 0.31.0 → 0.31.1 across all manifests, lockfiles, and CHANGELOG.md.
  • Tests: Parametrized ACL rule tests (12 cases) and platform-appropriate icacls / private-ACL / no-CRLF checks cover the real Windows security boundary.

Generality gate

  1. No per-app code in engine: Verified; operates solely on OS filesystem/ACL boundaries and Rust lockfile dependencies.
  2. Fix the class, not the instance: Verified; closes the Windows reparse-point, handle-bound ACL, and binary-mode class for both card reads and answer writes.
  3. Held-out evidence: 60/60 CI checks green (unit and cross-platform tests); no customer environment was exercised.

@abrichr
abrichr merged commit 7afc296 into main Nov 22, 2026
120 of 122 checks passed
@abrichr
abrichr deleted the fix/red-main-1122 branch November 22, 2026 13:58
@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

From: Claude
Reviewed-Head: 9147602

@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Claude
Reviewed-Head: 9147602

(Review done after the merge as 7afc296.) Nothing blocking. The exception-queue tests pass on macOS (42 passed, 1 skipped). At this head, Packages run 45027541702 shows the Desktop Python engine tests green on Windows py3.11 and py3.12.

Fail-closed on Windows

  • Read order: _read checks the path with lstat and refuses a reparse point or non-regular file. After opening, it requires fstat to match the lstat (st_dev, st_ino) and refuses an inode of 0. It then reads the owner and DACL from the open handle with GetSecurityInfo. A swap changes the id and is refused. A hard link to another user's file still fails the owner check.
  • Errors: any exception in _windows_private gives False.
  • Rule: windows_private_reason refuses a wrong owner, a NULL DACL and unknown ACE types. It skips deny and inherit-only entries.
  • ctypes: TokenUser and TokenOwner both begin with a SID pointer. GetSecurityInfo gets an explicit HANDLE.

Trusted SIDs

  • OWNER RIGHTS (S-1-3-4): it applies only to the file's owner, and the owner check runs first. A non-admin user's file fails the owner check whatever its ACL says.
  • Administrators as owner: this passes only when this process's token gives new files that owner, which means it is elevated. A non-admin user cannot assign Administrators as a file's owner.
  • ACL entries: Everyone, Users and other users' SIDs are refused.

Bytes: O_BINARY on reads and writes. The new CRLF assertion is meaningful because the answer is written with indent=2 and a trailing newline.

Answer write: refused unless the new file comes out private. The PermissionError is an OSError, which the caller maps to registry_unwritable, never ok. POSIX behaviour is unchanged.

Tests and release:

  • Tests are not weakened: the chmod toggle becomes an icacls grant and removal for Everyone on Windows, and there are 12 rule cases.
  • 0.31.1 is consistent across every version source, and release intent passed.
  • url 2.5.9 clears RUSTSEC-2026-0592.

Not blocking

  1. Test gap: add a case where the file is owned by Administrators and me is not elevated. It must be refused.
  2. Wording: the docstring and CHANGELOG say the owner must be "this user". The code also accepts the token's default owner (Administrators when elevated), and the text should say so.
  3. Elevation mismatch: cards from an elevated Flow are hidden from a non-elevated Desktop, and the reverse. This fails closed but is a functional gap.
  4. Real-file coverage: the CI runner is always an elevated admin, so the standard-user case is covered only by the rule tests. The Windows branch of _private_to_this_user is circular.
  5. File-id match: if a future Python reports Windows file ids differently, every card would be hidden. This fails closed.
  6. Folder swap: the run folder is not re-checked after listdir. POSIX has the same limit, and the file-level checks still hold.
  7. Performance: _windows_me() runs once per card read.

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.

1 participant