fix(agent): a read-only folder stays read-only to the AppContainer when it inherits a low label #64

Merged
HumanBean merged 1 commit from HumanBean/Beanstalk:fix/readonly-medium-label into main 2026-11-16 11:58:15 +00:00
Owner

Why

In Longshot #1118 (Unity's PC: Windows 10.0.26200, Intel UHD, nightly-110), the AppContainer check failed write_granted: the sandbox wrote a file in the folder it was only given to read. So that PC has no sandbox and gets no jobs. Everything else in AppContainer mode passed.

An AppContainer runs at low integrity. A folder without a label is medium, and Windows' no-write-up rule keeps a low-integrity process from writing it, whatever its ACL says. So the sandbox could write there only because the folder carried a low label, inherited from a folder above, together with permissions that let it write.

The agent gives each read grant its ACE (read and execute) but never a label, so an inherited low label stood. A writable grant gets an explicit low label, on purpose. The granted folder is new on every check, so it can only have got the label by inheriting it.

What changed

  • WinAcl.KeepReadOnly, for the AppContainer sandbox's read grants:
    • If the folder or file has a low or untrusted label, its own or inherited (WinGrants.LowLabelled), it gets an explicit medium no-write-up label: S:(ML;OICI;NW;;;ME) for a folder, S:(ML;;NW;;;ME) for a file. The sandbox can't write there, whatever the permissions allow.
    • Without a low label it's medium already, the default, and nothing is set. That's every PC where the check passes today, so they see no change and no tree-wide permission rewrite.
    • A writable folder still gets its explicit low label, and an explicit label on a child folder wins over an inherited one, so writable folders under a read-only one keep working.
    • A label that can't be set fails the run. The sandbox refuses rather than leaving the folder writable.

Testing

  • Agent checks: 1875 passed, with new ones for LowLabelled: an inherited low label, one by SID, any case, none or medium ones. dotnet build agent/App -c Release: 0 warnings.
  • Not run on Windows. On Unity's PC, sandbox-check on the next nightly should pass write_granted. If it still fails, its write_granted_why line (#63) shows the drive's file system and the permissions; on a FAT32 or exFAT drive, nothing can keep a folder read-only.
## Why In [Longshot #1118](https://git.magicbean.dev/MagicBeanDev/Longshot/issues/1118) (Unity's PC: Windows 10.0.26200, Intel UHD, nightly-110), the AppContainer check failed `write_granted`: the sandbox wrote a file in the folder it was only given to read. So that PC has no sandbox and gets no jobs. Everything else in AppContainer mode passed. An AppContainer runs at **low** integrity. A folder without a label is medium, and Windows' no-write-up rule keeps a low-integrity process from writing it, whatever its ACL says. So the sandbox could write there only because the folder carried a **low** label, inherited from a folder above, together with permissions that let it write. The agent gives each read grant its ACE (read and execute) but never a label, so an inherited low label stood. A writable grant gets an explicit low label, on purpose. The granted folder is new on every check, so it can only have got the label by inheriting it. ## What changed - `WinAcl.KeepReadOnly`, for the AppContainer sandbox's read grants: - If the folder or file has a low or untrusted label, its own or inherited (`WinGrants.LowLabelled`), it gets an explicit **medium no-write-up** label: `S:(ML;OICI;NW;;;ME)` for a folder, `S:(ML;;NW;;;ME)` for a file. The sandbox can't write there, whatever the permissions allow. - Without a low label it's medium already, the default, and nothing is set. That's every PC where the check passes today, so they see no change and no tree-wide permission rewrite. - A writable folder still gets its explicit low label, and an explicit label on a child folder wins over an inherited one, so writable folders under a read-only one keep working. - A label that can't be set fails the run. The sandbox refuses rather than leaving the folder writable. ## Testing - Agent checks: 1875 passed, with new ones for `LowLabelled`: an inherited low label, one by SID, any case, none or medium ones. `dotnet build agent/App -c Release`: 0 warnings. - **Not run on Windows.** On Unity's PC, `sandbox-check` on the next nightly should pass `write_granted`. If it still fails, its `write_granted_why` line (#63) shows the drive's file system and the permissions; on a FAT32 or exFAT drive, nothing can keep a folder read-only.
fix(agent): a read-only folder stays read-only to the AppContainer when it inherits a low label
Some checks failed
CI / Conventional Commit title (pull_request) Successful in 4s
CI / Workflow lint (actionlint) (pull_request) Successful in 4s
CI / Coordinator tests (pull_request) Has been cancelled
CI / Agent build and checks (pull_request) Has been cancelled
CI / Coordinator image (pull_request) Has been cancelled
72fb3e486f
Longshot #1118: on one tester's PC the AppContainer wrote a file in the
folder it was only given to read, so the PC had no sandbox. An AppContainer
runs at low integrity, and a folder without a label is medium, which keeps
it out (no-write-up); it could write there only because the folder carried a
low label, inherited from a folder above, with permissions that let it. The
agent gave read grants their ACE but never a label, so an inherited low one
stood. Now a read grant whose folder or file is low-labelled, its own or
inherited, gets an explicit medium no-write-up label (WinAcl.KeepReadOnly);
one that is medium already, as on every PC where the check passes, is left
alone, so no tree is walked. A label that can't be set fails the run.

Assisted-by: Claude Opus 5.5
Co-Authored-By: Claude Opus 5.5 <[email protected]>
HumanBean deleted branch fix/readonly-medium-label 2026-11-16 11:58:16 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
MagicBeanDev/Beanstalk!64
No description provided.