-
Notifications
You must be signed in to change notification settings - Fork 176
fix(sandbox): take Everyone out of the restricted-SID list (does not work yet) #1005
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Vasanthdev2004
wants to merge
2
commits into
feat/windows-sandbox-identity
Choose a base branch
from
fix/windows-denyread-world-sid
base: feat/windows-sandbox-identity
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| package sandbox | ||
|
|
||
| import ( | ||
| "path/filepath" | ||
| "strings" | ||
| "testing" | ||
| ) | ||
|
|
||
| // THE STRICT TOKEN MUST CARRY THE GRANT ITS READ ROOTS NAME. | ||
| // | ||
| // A profile with DenyRead drops WRITE_RESTRICTED, which puts reads under the | ||
| // restricted-SID check as well. Everyone used to satisfy that check, and taking | ||
| // it away without putting the read capability in its place leaves a token that | ||
| // cannot open cmd.exe: the command dies at launch with an access denial that | ||
| // says nothing about the profile. | ||
| // | ||
| // The ACL plan grants this same capability on every read root, so the two halves | ||
| // have to be decided together. This pins the token half; the plan half is pinned | ||
| // by the plan tests, and the kernel behaviour by the impersonation test beside | ||
| // this one. | ||
| func TestTheStrictTokenCarriesTheReadCapability(t *testing.T) { | ||
| home := t.TempDir() | ||
| want, err := WindowsReadAllowSID(home) | ||
| if err != nil { | ||
| t.Fatalf("SETUP INVALID: no read capability for %s: %v", home, err) | ||
| } | ||
|
|
||
| base := []string{"S-1-15-3-1024-workspace"} | ||
| got, err := windowsRestrictedTokenSIDsForProfile(base, home, false) | ||
| if err != nil { | ||
| t.Fatalf("windowsRestrictedTokenSIDsForProfile: %v", err) | ||
| } | ||
| if !carriesSID(got, want) { | ||
| t.Fatalf("the strict token's restricted SIDs %v omit the read capability %s, so the command cannot open its own executable", got, want) | ||
| } | ||
| if !carriesSID(got, base[0]) { | ||
| t.Fatalf("the workspace capability was dropped: %v", got) | ||
| } | ||
| } | ||
|
|
||
| // And the WRITE_RESTRICTED token does not get it: reads are already unrestricted | ||
| // there, so adding a SID would widen the write jail for nothing. | ||
| func TestTheWriteRestrictedTokenDoesNotCarryTheReadCapability(t *testing.T) { | ||
| home := t.TempDir() | ||
| readSID, err := WindowsReadAllowSID(home) | ||
| if err != nil { | ||
| t.Fatalf("SETUP INVALID: no read capability for %s: %v", home, err) | ||
| } | ||
| got, err := windowsRestrictedTokenSIDsForProfile([]string{"S-1-15-3-1024-workspace"}, home, true) | ||
| if err != nil { | ||
| t.Fatalf("windowsRestrictedTokenSIDsForProfile: %v", err) | ||
| } | ||
| if carriesSID(got, readSID) { | ||
| t.Fatalf("the WRITE_RESTRICTED token carries the read capability %s, widening the write jail to every read root", readSID) | ||
| } | ||
| } | ||
|
|
||
| // Not containsSID: #886 adds a package-level helper by that name, and the two | ||
| // branches would stop compiling the moment both land. | ||
| func carriesSID(values []string, want string) bool { | ||
| for _, value := range values { | ||
| if strings.EqualFold(value, want) { | ||
| return true | ||
| } | ||
| } | ||
| return false | ||
| } | ||
|
|
||
| // THE PLAN AND THE TOKEN DECIDE THE READ CAPABILITY SEPARATELY. | ||
| // | ||
| // The ACL plan asks whether the profile configures DenyRead; the runner asks | ||
| // whether the token keeps WRITE_RESTRICTED. Both are read off the same field | ||
| // today, in two files, with nothing tying them together. Drift either way is | ||
| // silent and bad: a token carrying a SID no DACL names cannot open its own | ||
| // executable, and a plan granting a SID no token carries leaves reads confined | ||
| // by nothing. | ||
| // | ||
| // So this pins the equivalence rather than either half. | ||
| func TestThePlanAndTheTokenAgreeOnTheReadCapability(t *testing.T) { | ||
| for _, testCase := range []struct { | ||
| name string | ||
| denyRead []string | ||
| }{ | ||
| {name: "with denyRead", denyRead: []string{filepath.Join("secrets")}}, | ||
| {name: "without denyRead"}, | ||
| } { | ||
| t.Run(testCase.name, func(t *testing.T) { | ||
| workspace := t.TempDir() | ||
| config := WindowsSandboxCommandConfig{ | ||
| SandboxHome: t.TempDir(), | ||
| CommandCWD: workspace, | ||
| WorkspaceRoots: []string{workspace}, | ||
| PermissionProfile: PermissionProfile{ | ||
| FileSystem: FileSystemPolicy{ | ||
| Kind: FileSystemRestricted, | ||
| WriteRoots: []WritableRoot{{Root: workspace}}, | ||
| ReadRoots: []string{workspace}, | ||
| DenyRead: prefixEach(workspace, testCase.denyRead), | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| planned, err := windowsReadAllowCapabilitySID(config) | ||
| if err != nil { | ||
| t.Fatalf("windowsReadAllowCapabilitySID: %v", err) | ||
| } | ||
| writeRestricted := len(config.PermissionProfile.FileSystem.DenyRead) == 0 | ||
| tokenSIDs, err := windowsRestrictedTokenSIDsForProfile(nil, config.SandboxHome, writeRestricted) | ||
| if err != nil { | ||
| t.Fatalf("windowsRestrictedTokenSIDsForProfile: %v", err) | ||
| } | ||
|
|
||
| inPlan := planned != "" | ||
| inToken := len(tokenSIDs) > 0 | ||
| if inPlan != inToken { | ||
| t.Fatalf("the plan grants the read capability = %t but the token carries it = %t; one side confines reads the other side never checks", inPlan, inToken) | ||
| } | ||
| if inPlan && !carriesSID(tokenSIDs, planned) { | ||
| t.Fatalf("the plan grants %s but the token carries %v, so the command cannot read what setup allowed", planned, tokenSIDs) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func prefixEach(root string, relatives []string) []string { | ||
| if len(relatives) == 0 { | ||
| return nil | ||
| } | ||
| out := make([]string, 0, len(relatives)) | ||
| for _, relative := range relatives { | ||
| out = append(out, filepath.Join(root, relative)) | ||
| } | ||
| return out | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For a
DenyReadprofile using the provisioned sandbox principal,windowsRestrictedTokenSIDsForProfileadds the read capability beforewindowsPrincipalJailSIDscopies the list, and the principal branch then appends the same SID again. The resulting restricted token carries a redundant SID entry and leaves ownership of this capability split across two preparation paths.