Repository navigation
fix(windows): exclude the sandbox runtime root from the setup marker fingerprint - #1251
the-dreamsmith wants to merge 2 commits into
Conversation
|
No actionable comments were generated in the recent review. WalkthroughThe Windows sandbox setup marker now uses a normalized command configuration for ACL and network plans. Runtime state records whether permission augmentation added the runtime root. ACL mismatch errors include actual and expected entry counts and plan hashes. ChangesWindows setup marker
Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix Possibly related issues
Suggested reviewers: Merge Risk:
|
gnanam1990
left a comment
There was a problem hiding this comment.
One marker-validation regression reproduced on the exact head; details and before/after CI are inline.
| return command | ||
| } | ||
| roots := command.PermissionProfile.FileSystem.WriteRoots | ||
| if n := len(roots); n > 0 && windowsCapabilityPathKey(roots[n-1].Root) == root && !windowsRootMatchesWorkspace(runtime.Root, config.WorkspaceRoots) { |
There was a problem hiding this comment.
[P2] Preserve an existing non-workspace grant that matches the runtime root
When the profile already grants the runtime directory as its last non-workspace write root, permissionProfileWithRuntime returns without appending anything. This condition still removes that existing grant. The setup marker includes it, but command validation now computes a different ACL plan and refuses the command as out of date. Re-running setup repeats the mismatch. The workspace-root check protects only one kind of pre-existing grant.
The fixture uses the actual producer, asserts that it did not append a root, writes the setup marker, then validates the command profile. In Windows, Linux and macOS CI, main 2c509ce9 passes; head f015c7ed fails with acl entries 2, want 1.
Keep explicit grants in the marker and remove only an entry known to have been introduced by runtime augmentation. Please cover the existing-grant case outside the workspace as well as the newly appended case.
There was a problem hiding this comment.
Thanks for catching this — you were right, v1 stripped a pre-existing grant whenever it happened to be the last write root. Fixed by recording the augmentation itself: permissionProfileWithRuntime now sets SandboxRuntime.Appended only when it actually appends the runtime root, and markerCommandConfig strips the last entry only in that case. An explicit grant for the same root stays in the marker. Added TestWindowsSandboxSetupMarkerPreservesExistingRuntimeGrant covering your case (it fails on v1 with acl entries 2, want 1 and passes now); the existing appended-root test now goes through the real producer. Full internal/sandbox suite passes, including -race.
There was a problem hiding this comment.
Rechecked 8105fd63 with the original reproduction. The existing non-workspace runtime grant is retained: the producer leaves Appended false, and marker calculation keeps that grant.
The same fixture passes on main and this head, and still fails on f015c7ed, under the race detector on Windows and Linux. The supplemental macOS job was cancelled without running its steps. This resolves my original finding. This fixture checks marker calculation and grant provenance; it does not exercise a live restricted-token launch.
markerCommandConfig stripped the last write root whenever it matched the runtime root, even when that grant pre-existed and permissionProfileWithRuntime appended nothing. Record the augmentation in SandboxRuntime.Appended and strip only an entry the runtime actually introduced, so an explicit grant for the same root stays in the marker. The appended-root test now goes through the real producer; add a regression test for the pre-existing grant case (review feedback on Twigpine#1251).
Vasanthdev2004
left a comment
There was a problem hiding this comment.
Thanks for digging into this. I have #901 open for the same bug (#881), so weigh this with that in mind, but I think this change moves the failure rather than fixing it.
On the restricted-token tier the marker is the only check before launch. Nothing applies an ACL plan at command time there: runWindowsSandboxCommand validates the marker and starts the process. The capability ACLs are written only by zero sandbox setup, from a profile that never has the runtime root in it. So once the runtime root is left out of the marker, a command validates, its token carries a capability SID for the runtime root, and that SID is granted nowhere. The description says the runtime root's ACLs are still applied; I could not find where on this tier.
I checked it on Windows 11 by calling runWindowsSandboxCommand at WindowsSandboxLevelRestrictedToken. Setup's ACL plan applied and the marker written the way setup does, then a command whose profile went through permissionProfileWithRuntime, with TEMP pointing into the runtime root:
main 2c509ce9 |
this PR 8105fd63 |
|
|---|---|---|
echo x> <workspace>\a.txt |
exit 1, setup is out of date | exit 0, written |
echo x> <runtime root>\tmp\b.txt |
exit 1, setup is out of date | exit 1, not written |
| the same, after applying the plan that includes the runtime root | exit 1, setup is out of date | exit 0, written |
The last row is the control: the write fails only because the runtime root has no grant.
TEMP, TMP, GOCACHE, GOMODCACHE, CARGO_HOME and the npm, yarn and pip caches all point into the runtime root (sandboxRuntimeEnvironment). So a build or an install would now fail with access denied somewhere inside the tool, where today it fails up front with a message that names setup.
For this to hold, setup has to grant the root that commands will actually use, and the marker has to cover it. That is the part #901 adds: setup selects the runtime root the same way a command does, applies its grant and records it, and a later command uses that record. Happy to compare notes there.
Two smaller things. The PR does not link #881, and CONTRIBUTING asks for the approved parent issue. And the new tests only compare markers, so they pass whether or not anything is writable; a test that runs a command through the runner would have caught the table above.
Summary
zero sandbox setupwrites the Windows sandbox setup marker from a permissionprofile that never contains the sandbox runtime root, while every real command
validates the marker against a profile to which the runner appended one
(
permissionProfileWithRuntime). The two sides therefore never compute the sameACL plan: the stored marker has 10 entries, the validated plan has 15, so every
restricted-token spawn fails with:
No number of
zero sandbox setupruns can close the gap — the setup rewrites thesame 10-entry marker every time.
It gets worse for workspaces that contain the user cache directory
(
%LOCALAPPDATA%): there the deterministic runtime root falls under theworkspace, so
prepareSandboxRuntimefalls back to a fresh random temp directoryper process (
zero-runtime-*), and the validated plan carries a different root(with a freshly minted capability SID) on every run. A marker that includes the
runtime root could never validate there either.
Fix
BuildWindowsSandboxSetupMarkernow fingerprints the marker frommarkerCommandConfig(config): a copy of the command config whose permissionprofile no longer contains the runtime root appended by the runner. The setup path
is a no-op (it never carries a runtime root), so the marker it writes is
unchanged, and the validation path now computes the same plan the setup wrote.
Explicitly untouched: the real execution ACL plan.
BuildWindowsACLPlanforenforcement and the restricted token still receive the full profile including the
runtime root — its ACLs are applied and the token still carries its capability
SID. Only the marker fingerprint excludes the runtime root. As a side effect,
validation no longer mints a capability SID for the runtime root.
Also included: the ACL mismatch error now reports the numbers already computed
(
acl entries %d, want %d; acl plan hash %s, want %s), so the next persondebugging this sees immediately which side diverged instead of needing a source
dive.
Tests
TestWindowsSandboxSetupMarkerIgnoresRuntimeRoot: writes amarker as
zero sandbox setupwould (no runtime root), then validates a realcommand profile carrying the appended runtime root, asserts the marker is
identical with and without the runtime root, and asserts the caller's profile is
not mutated. It fails without this patch with the exact production error above,
and passes with it.
gofmtclean,go vet ./internal/sandbox/clean,go test ./internal/sandbox/passes.
Verified end-to-end on Windows 11 (zero 0.14.0): after the fix, a restricted-token
spawn with the real
execprofile passes marker validation, andzero sandbox setupstill writes the identical marker. This fixes markervalidation only; it does not change what the restricted token itself permits the
spawned process to do.
Summary by CodeRabbit