-
Notifications
You must be signed in to change notification settings - Fork 0
Unify application sandbox planning #8
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
Open
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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| kind: Changed | ||
| body: Route persistent and transient application containers through one canonical sandbox plan, and rename the system-install identity field from `run_as` to `account`. |
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 |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| kind: Added | ||
| body: Support Linux `reploy install --scope user` as an invoking-user Docker-managed install and add `install.system.run_as` as the system-scope app account field. | ||
| body: Support Linux `reploy install --scope user` as an invoking-user Docker-managed install and add `install.system.account` as the system-scope app account field. |
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
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
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
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
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,42 @@ | ||
| package dockerdeploy | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "path" | ||
| "strconv" | ||
| ) | ||
|
|
||
| // ApplicationSandboxPlanV1 is the common security boundary consumed by every | ||
| // application-container renderer. It contains only policies that Reploy | ||
| // currently enforces; later sandbox slices extend this plan rather than adding | ||
| // renderer-specific flags. | ||
| type ApplicationSandboxPlanV1 struct { | ||
| RuntimeUser RuntimeUserPlan | ||
| ReadOnlyRoot bool | ||
| TemporaryHome string | ||
| } | ||
|
|
||
| func newApplicationSandboxPlanV1(runtimeUser RuntimeUserPlan) ApplicationSandboxPlanV1 { | ||
| return ApplicationSandboxPlanV1{ | ||
| RuntimeUser: runtimeUser, | ||
| ReadOnlyRoot: true, | ||
| TemporaryHome: environmentTemporaryHome, | ||
| } | ||
| } | ||
|
|
||
| func ValidateApplicationSandboxPlanV1(plan ApplicationSandboxPlanV1) error { | ||
| if plan.RuntimeUser.UID < 0 || plan.RuntimeUser.GID < 0 { | ||
| return fmt.Errorf("application sandbox requires a non-negative numeric UID and GID") | ||
| } | ||
| wantUser := strconv.Itoa(plan.RuntimeUser.UID) + ":" + strconv.Itoa(plan.RuntimeUser.GID) | ||
| if plan.RuntimeUser.DockerUser != wantUser { | ||
| return fmt.Errorf("application sandbox Docker user must match its numeric UID and GID") | ||
| } | ||
| if !plan.ReadOnlyRoot { | ||
| return fmt.Errorf("application sandbox requires a read-only container root") | ||
| } | ||
| if plan.TemporaryHome != environmentTemporaryHome || !path.IsAbs(plan.TemporaryHome) || path.Clean(plan.TemporaryHome) != plan.TemporaryHome { | ||
| return fmt.Errorf("application sandbox temporary home must be %s", environmentTemporaryHome) | ||
| } | ||
| return nil | ||
| } |
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,92 @@ | ||
| package dockerdeploy | ||
|
|
||
| import ( | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/omry/reploy/internal/blueprint" | ||
| "gopkg.in/yaml.v3" | ||
| ) | ||
|
|
||
| func TestApplicationRenderersConsumeCanonicalSandboxPlan(t *testing.T) { | ||
| platform, err := blueprint.ParsePlatform("linux/amd64") | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| workspace := testPreparedProbeWorkspace(t, platform, t.TempDir()) | ||
| plan := DockerExecutionPlan{ | ||
| EnvironmentID: "demo", | ||
| DeploymentDir: t.TempDir(), | ||
| Phase: blueprint.PhaseStaged, | ||
| Image: "reploy/demo:staging", | ||
| ContainerName: "demo-staging-abcd", | ||
| NetworkName: "demo-staging-abcd", | ||
| Sandbox: newApplicationSandboxPlanV1(RuntimeUserPlan{ | ||
| UID: 501, GID: 20, DockerUser: "501:20", | ||
| }), | ||
| } | ||
|
|
||
| persistent, err := RenderDockerInputs(plan, "demo") | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| var compose composePlanDocument | ||
| if err := yaml.Unmarshal(persistent.Compose, &compose); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| service := compose.Services["environment"] | ||
| if service.User != plan.Sandbox.RuntimeUser.DockerUser || !service.ReadOnly { | ||
| t.Fatalf("persistent sandbox identity/read-only = user %q, read-only %t", service.User, service.ReadOnly) | ||
| } | ||
| if service.Environment["HOME"] != plan.Sandbox.TemporaryHome || service.Environment["TMPDIR"] != plan.Sandbox.TemporaryHome { | ||
| t.Fatalf("persistent sandbox environment = %#v", service.Environment) | ||
| } | ||
| if !containsString(service.Tmpfs, temporaryHomeMountForPlan(plan)) { | ||
| t.Fatalf("persistent sandbox temporary home = %#v", service.Tmpfs) | ||
| } | ||
|
|
||
| transient, err := TransientCommandSpec( | ||
| plan, | ||
| ResolvedEnvironmentCommand{Argv: []string{"/bin/true"}}, | ||
| workspace, | ||
| nil, | ||
| false, | ||
| false, | ||
| ) | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| if !containsInOrder(transient.Args, []string{"--read-only", "--mount", transientHomeMountForPlan(plan)}) { | ||
| t.Fatalf("transient sandbox read-only root/home = %#v", transient.Args) | ||
| } | ||
| if !containsInOrder(transient.Args, []string{ | ||
| "--env", "HOME=" + plan.Sandbox.TemporaryHome, | ||
| "--env", "TMPDIR=" + plan.Sandbox.TemporaryHome, | ||
| }) { | ||
| t.Fatalf("transient sandbox environment = %#v", transient.Args) | ||
| } | ||
| if !containsInOrder(transient.Args, []string{ | ||
| "--entrypoint", ProbeContainerExecutable, | ||
| plan.Image, "run-transient", "501", "20", "/bin/true", | ||
| }) { | ||
| t.Fatalf("transient sandbox runtime identity = %#v", transient.Args) | ||
| } | ||
|
|
||
| invalid := plan | ||
| invalid.Sandbox.ReadOnlyRoot = false | ||
| if _, err := RenderDockerInputs(invalid, "demo"); err == nil || !strings.Contains(err.Error(), "read-only container root") { | ||
| t.Fatalf("persistent invalid sandbox error = %v", err) | ||
| } | ||
| if _, err := TransientCommandSpec(invalid, ResolvedEnvironmentCommand{Argv: []string{"/bin/true"}}, workspace, nil, false, false); err == nil || !strings.Contains(err.Error(), "read-only container root") { | ||
| t.Fatalf("transient invalid sandbox error = %v", err) | ||
| } | ||
| } | ||
|
|
||
| func containsString(values []string, want string) bool { | ||
| for _, value := range values { | ||
| if value == want { | ||
| return true | ||
| } | ||
| } | ||
| return false | ||
| } |
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
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.
Existing deployments become unreadable after upgrading: every previously encoded
blueprint-resolved-v1document contains aRunAsJSON member (even when empty), whileDecodeResolvedDocumentV1usesDisallowUnknownFieldsand the schema identifier remains unchanged. Consequently, staging, install, runtime, and recovery operations fail while decoding any pre-changestate-v1; preserve the old wire name or add an explicit state migration/schema transition before renaming this field.Useful? React with 👍 / 👎.