-
Notifications
You must be signed in to change notification settings - Fork 0
Verify application sandbox at startup #10
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
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: Security | ||
| body: Package a trusted startup verifier into application images and fail closed unless seccomp, no-new-privileges, and empty capability sets are active before workload execution. |
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,102 @@ | ||
| package deploy | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "strconv" | ||
|
|
||
| "github.com/omry/reploy/internal/blueprint" | ||
| "github.com/omry/reploy/internal/canonical" | ||
| "github.com/omry/reploy/internal/providers" | ||
| ) | ||
|
|
||
| const ( | ||
| ApplicationStartupVerifierSchemaV1 = "application-startup-verifier-v1" | ||
| ApplicationStartupVerifierRecipeV1 = "linux-proc-status-verify-exec-v1" | ||
| ApplicationStartupVerifierPathV1 = "/reploy-probe" | ||
| ApplicationRuntimeLayerSchemaV1 = "application-runtime-layer-v1" | ||
| ) | ||
|
|
||
| type ApplicationStartupVerifierV1 struct { | ||
| Schema string `json:"schema"` | ||
| RecipeVersion string `json:"recipe_version"` | ||
| Path string `json:"path"` | ||
| Artifact canonical.Digest `json:"artifact"` | ||
| Size string `json:"size"` | ||
| } | ||
|
|
||
| type ApplicationRuntimeLayerV1 struct { | ||
| Schema string `json:"schema"` | ||
| Verifier ApplicationStartupVerifierV1 `json:"verifier"` | ||
| TransactionDigest canonical.Digest `json:"transaction_digest"` | ||
| Upstream providers.RealizedImageV1 `json:"upstream"` | ||
| Result providers.RealizedImageV1 `json:"result"` | ||
| } | ||
|
|
||
| func ApplicationStartupVerifierContractV1() ApplicationStartupVerifierV1 { | ||
| return ApplicationStartupVerifierV1{ | ||
| Schema: ApplicationStartupVerifierSchemaV1, RecipeVersion: ApplicationStartupVerifierRecipeV1, | ||
| Path: ApplicationStartupVerifierPathV1, | ||
| } | ||
| } | ||
|
|
||
| func ValidateApplicationStartupVerifierV1(verifier ApplicationStartupVerifierV1, requireArtifact bool) error { | ||
| want := ApplicationStartupVerifierContractV1() | ||
| if verifier.Schema != want.Schema || verifier.RecipeVersion != want.RecipeVersion || verifier.Path != want.Path { | ||
| return fmt.Errorf("application startup verifier does not use the supported fixed contract") | ||
| } | ||
| if !requireArtifact { | ||
| if verifier.Artifact != "" || verifier.Size != "" { | ||
| return fmt.Errorf("application startup verifier policy contract must not contain an artifact") | ||
| } | ||
| return nil | ||
| } | ||
| if err := verifier.Artifact.Validate(); err != nil { | ||
| return fmt.Errorf("application startup verifier artifact: %w", err) | ||
| } | ||
| size, err := strconv.ParseUint(verifier.Size, 10, 64) | ||
| if err != nil || size == 0 || strconv.FormatUint(size, 10) != verifier.Size { | ||
| return fmt.Errorf("application startup verifier size must be a canonical positive integer") | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func ApplicationRuntimeLayerTransactionDigestV1( | ||
| verifier ApplicationStartupVerifierV1, | ||
| upstream providers.RealizedImageV1, | ||
| platform blueprint.Platform, | ||
| ) (canonical.Digest, error) { | ||
| if err := ValidateApplicationStartupVerifierV1(verifier, true); err != nil { | ||
| return "", err | ||
| } | ||
| if err := upstream.Validate(); err != nil { | ||
| return "", fmt.Errorf("application runtime layer upstream: %w", err) | ||
| } | ||
| if err := platform.Validate(); err != nil { | ||
| return "", fmt.Errorf("application runtime layer platform: %w", err) | ||
| } | ||
| return canonical.Sum("application-runtime-layer", ApplicationRuntimeLayerSchemaV1, struct { | ||
| Verifier ApplicationStartupVerifierV1 `json:"verifier"` | ||
| Upstream providers.RealizedImageV1 `json:"upstream"` | ||
| Platform blueprint.Platform `json:"platform"` | ||
| }{Verifier: verifier, Upstream: upstream, Platform: platform}) | ||
| } | ||
|
|
||
| func ValidateApplicationRuntimeLayerV1(layer ApplicationRuntimeLayerV1, platform blueprint.Platform) error { | ||
| if layer.Schema != ApplicationRuntimeLayerSchemaV1 { | ||
| return fmt.Errorf("application runtime layer schema must be %q", ApplicationRuntimeLayerSchemaV1) | ||
| } | ||
| want, err := ApplicationRuntimeLayerTransactionDigestV1(layer.Verifier, layer.Upstream, platform) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| if layer.TransactionDigest != want { | ||
| return fmt.Errorf("application runtime layer transaction digest does not match its inputs") | ||
| } | ||
| if err := layer.Result.Validate(); err != nil { | ||
| return fmt.Errorf("application runtime layer result: %w", err) | ||
| } | ||
| if layer.Result.RootFSSubject == layer.Upstream.RootFSSubject { | ||
| return fmt.Errorf("application runtime layer result must add the verifier filesystem layer") | ||
| } | ||
| return nil | ||
| } |
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 have build locks already written with
schema: "lock-v1"that do not contain the newruntime_layerfield (and their embedded runtime policy also lacksstartup_verifier). After this change,ReadBuildLockstill decodes them aslock-v1butDecodeBuildLockV1/ValidateBuildLockV1rejects the zero-value verifier/runtime layer, andValidateCurrentBuildpropagates that error from build preparation instead of treating the old current build as stale. That means an upgraded user with a pre-verifier current generation can be blocked before Reploy gets a chance to rebuild the image with the new verifier; please add a schema migration/version bump or explicitly classify pre-verifier locks as rebuildable stale state.Useful? React with 👍 / 👎.