Repository navigation
Add truthful sandbox constraint preflight and strict jail spawning #28
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e1d0d6c
feat(sandbox): add truthful constraint preflight
senamakel 212b91c
fix: preserve jail containment across portable path forms
senamakel 668de4e
ci: pin workflow actions to reviewed commits
senamakel 2547338
fix: keep unverified Seatbelt denials conservative
senamakel a8e532b
fix: avoid unverified Seatbelt isolation claims
senamakel 3e6e0be
fix: normalize trusted registry bases before containment
senamakel 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
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,12 @@ | ||
| # Constraint preflight | ||
|
|
||
| The public model separates individual security boundaries from lifecycle | ||
| capabilities. `ConstraintSupport::NONE` is the conservative declaration. | ||
| Backends add only enforced or best-effort behavior they actually implement. | ||
| `plan_check` is diagnostic and performs no execution; `require` rejects every | ||
| requested boundary except `Enforced`, returning a typed error. Setup failures | ||
| must still propagate from the backend rather than degrading to passthrough. | ||
|
|
||
| The model is used by the object-safe `Sandbox` trait and by `tinybox-jail`. | ||
| See [the specification](../../../../docs/specs/constraint-preflight.md) for | ||
| backend limitations and the meaning of each hard requirement. |
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,138 @@ | ||
| //! Per-constraint preflight, independent of coarse lifecycle capabilities. | ||
| //! | ||
| //! A declaration describes implemented enforcement, not merely a configurable | ||
| //! knob. Callers must still handle setup failures. Best-effort support is never | ||
| //! accepted as a hard requirement. Unknown backends default to unsupported. | ||
|
|
||
| /// A security boundary requested before starting a workload. | ||
| #[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
| pub enum Constraint { | ||
| /// Confine filesystem reads and writes to the granted paths. | ||
| Filesystem, | ||
| /// Deny external network access. | ||
| Network, | ||
| /// Cap CPU consumption. | ||
| Cpu, | ||
| /// Cap resident memory. | ||
| Memory, | ||
| /// Cap total processes and threads. | ||
| Pids, | ||
| /// Cap writable disk usage. | ||
| Disk, | ||
| /// Forbid creating child processes. | ||
| Subprocess, | ||
| } | ||
|
|
||
| impl Constraint { | ||
| /// All modeled constraints, in diagnostic order. | ||
| pub const ALL: [Self; 7] = [ | ||
| Self::Filesystem, | ||
| Self::Network, | ||
| Self::Cpu, | ||
| Self::Memory, | ||
| Self::Pids, | ||
| Self::Disk, | ||
| Self::Subprocess, | ||
| ]; | ||
| const fn index(self) -> usize { | ||
| self as usize | ||
| } | ||
| } | ||
|
|
||
| impl std::fmt::Display for Constraint { | ||
| fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
| formatter.write_str(match self { | ||
| Self::Filesystem => "filesystem", | ||
| Self::Network => "network", | ||
| Self::Cpu => "cpu", | ||
| Self::Memory => "memory", | ||
| Self::Pids => "pids", | ||
| Self::Disk => "disk", | ||
| Self::Subprocess => "subprocess", | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| /// What a backend actually implements for one constraint. | ||
| #[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
| pub enum Enforcement { | ||
| /// No implementation, including unavailable platform mechanisms. | ||
| Unsupported, | ||
| /// Partial or advisory implementation, unsuitable for a hard requirement. | ||
| BestEffort, | ||
| /// Full implementation; failure to apply it must prevent execution. | ||
| Enforced, | ||
| } | ||
|
|
||
| impl std::fmt::Display for Enforcement { | ||
| fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
| formatter.write_str(match self { | ||
| Self::Unsupported => "unsupported", | ||
| Self::BestEffort => "best effort", | ||
| Self::Enforced => "enforced", | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| /// Independent enforcement declarations for all constraints. | ||
| #[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
| pub struct ConstraintSupport([Enforcement; 7]); | ||
| impl Default for ConstraintSupport { | ||
| fn default() -> Self { | ||
| Self::NONE | ||
| } | ||
| } | ||
| impl ConstraintSupport { | ||
| /// Conservative declaration for unknown and passthrough backends. | ||
| pub const NONE: Self = Self([Enforcement::Unsupported; 7]); | ||
| /// Declare the actual enforcement of one constraint. | ||
| #[must_use] | ||
| pub const fn with(mut self, constraint: Constraint, enforcement: Enforcement) -> Self { | ||
| self.0[constraint.index()] = enforcement; | ||
| self | ||
| } | ||
| /// Inspect an individual constraint. | ||
| #[must_use] | ||
| pub const fn enforcement(self, constraint: Constraint) -> Enforcement { | ||
| self.0[constraint.index()] | ||
| } | ||
| /// Inspect all requested constraints without executing anything. | ||
| #[must_use] | ||
| pub fn plan_check(self, requested: &[Constraint]) -> PlanCheck { | ||
| PlanCheck { | ||
| constraints: requested | ||
| .iter() | ||
| .map(|c| (*c, self.enforcement(*c))) | ||
| .collect(), | ||
| } | ||
| } | ||
| /// Refuse the first hard constraint that is not fully enforced. | ||
| /// | ||
| /// # Errors | ||
| /// Returns [`crate::Error::ConstraintNotEnforced`] for unsupported or | ||
| /// best-effort constraints. No workload is started. | ||
| pub fn require(self, backend: &str, requested: &[Constraint]) -> crate::Result<()> { | ||
| for &constraint in requested { | ||
| let enforcement = self.enforcement(constraint); | ||
| if enforcement != Enforcement::Enforced { | ||
| return Err(crate::Error::ConstraintNotEnforced { | ||
| sandbox: backend.to_owned(), | ||
| constraint, | ||
| enforcement, | ||
| }); | ||
| } | ||
| } | ||
| Ok(()) | ||
| } | ||
| } | ||
|
|
||
| /// Preflight diagnostics, including best-effort and unsupported constraints. | ||
| #[derive(Debug, Clone, PartialEq, Eq)] | ||
| pub struct PlanCheck { | ||
| /// Each requested constraint and its actual enforcement. | ||
| pub constraints: Vec<(Constraint, Enforcement)>, | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| #[path = "mod_tests.rs"] | ||
| mod tests; |
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,55 @@ | ||
| //! Hard requirements never accept partial enforcement. | ||
| use super::*; | ||
| #[test] | ||
| fn every_constraint_refuses_unsupported_and_best_effort() { | ||
| for constraint in Constraint::ALL { | ||
| for enforcement in [ | ||
| Enforcement::Unsupported, | ||
| Enforcement::BestEffort, | ||
| Enforcement::Enforced, | ||
| ] { | ||
| let support = ConstraintSupport::NONE.with(constraint, enforcement); | ||
| assert_eq!( | ||
| support.plan_check(&[constraint]).constraints, | ||
| [(constraint, enforcement)] | ||
| ); | ||
| let result = support.require("backend", &[constraint]); | ||
| if enforcement == Enforcement::Enforced { | ||
| assert!(result.is_ok()); | ||
| } else { | ||
| assert_eq!( | ||
| result.err(), | ||
| Some(crate::Error::ConstraintNotEnforced { | ||
| sandbox: "backend".into(), | ||
| constraint, | ||
| enforcement | ||
| }) | ||
| ); | ||
| } | ||
| } | ||
| } | ||
| assert_eq!(ConstraintSupport::default(), ConstraintSupport::NONE); | ||
| assert!(ConstraintSupport::NONE.require("backend", &[]).is_ok()); | ||
| } | ||
|
|
||
| #[test] | ||
| fn every_constraint_and_enforcement_has_a_lowercase_operator_label() { | ||
| for (constraint, expected) in Constraint::ALL.into_iter().zip([ | ||
| "filesystem", | ||
| "network", | ||
| "cpu", | ||
| "memory", | ||
| "pids", | ||
| "disk", | ||
| "subprocess", | ||
| ]) { | ||
| assert_eq!(constraint.to_string(), expected); | ||
| } | ||
| for (enforcement, expected) in [ | ||
| (Enforcement::Unsupported, "unsupported"), | ||
| (Enforcement::BestEffort, "best effort"), | ||
| (Enforcement::Enforced, "enforced"), | ||
| ] { | ||
| assert_eq!(enforcement.to_string(), expected); | ||
| } | ||
| } |
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.
Keep the resource-limit capability assertion
This removes
resource limitsfrom the expected capability list, allowing the test to pass when the Docker backend silently loses its resource-limit capability. Keep the assertion aligned with the declared capability contract, or add a separate assertion that resource limits remain declared.Additional
critiqueobservationKeep resource limits in the Docker capability assertion
[RULE] weakened-test
Docker's sandbox code translates resource limits into enforced Docker flags, so the inspection output should continue to advertise
resource limits. Removing it from this assertion allows a regression where Docker enforces limits but no longer declares the capability to pass unnoticed. Restore the capability text in the expected output.Suggested change for this observation (reference only)
[RULE] capability-regression ·