Skip to content

feat(core): preflight explicit hard requirements - #64

Merged
senamakel merged 19 commits into
epic/8369-security-migrationfrom
sec-27-hard-constraints
Oct 27, 2026
Merged

senamakel merged 19 commits into
epic/8369-security-migrationfrom
sec-27-hard-constraints

Conversation

@senamakel

Copy link
Copy Markdown
Owner

Adds an explicit BoxSpec::hard_requirements list so callers can distinguish mandatory constraints from soft resource defaults. Existing specs deserialize with an empty list. New spec-aware check/require methods report the backend's enforcement, and create paths refuse unsupported or BestEffort requirements before mutating the store.

Tests cover Namespace CPU refusal before storage, acceptance of supported filesystem/network requirements, MicroVM BestEffort CPU refusal, passthrough refusal, and legacy spec deserialization.

Part of tinyhumansai#27
Part of tinyhumansai/openhuman#8369

Validation:

  • cargo fmt --all -- --check
  • cargo test -p tinybox-core
  • cargo clippy -p tinybox-core --all-targets -- -D warnings
  • cargo test -p tinybox-linux preflight
  • cargo clippy -p tinybox-linux --all-targets -- -D warnings
  • cargo test -p tinybox-microvm
  • cargo clippy -p tinybox-microvm --all-targets -- -D warnings
  • cargo test -p tinybox-docker
  • cargo clippy -p tinybox-docker --all-targets -- -D warnings

senamakel and others added 19 commits October 27, 2026 11:57
Update the vendored tinybus submodule to the latest upstream commit.

Auto-committed-on: cuttlefish
Co-authored-by: Medulla <medulla@tinyhumans.ai>
…constraints

Add tests asserting that a spec requiring CPU is refused before any box is
stored, and that requiring only supported constraints still allows creation.

Auto-committed-on: cuttlefish
Co-authored-by: Medulla <medulla@tinyhumans.ai>
Box specs can now carry a list of constraints the caller requires the
selected sandbox to enforce fully, and every backend refuses to create a
box whose hard requirements it cannot satisfy. The field defaults to
empty so previously stored specs still load.

Auto-committed-on: cuttlefish
Co-authored-by: Medulla <medulla@tinyhumans.ai>
Add a test asserting that a spec requiring CPU as a hard constraint is
rejected when the backend can only enforce it on a best-effort basis,
while the plan check still reports the best-effort enforcement.

Auto-committed-on: cuttlefish
Co-authored-by: Medulla <medulla@tinyhumans.ai>
Add a test asserting that a passthrough sandbox refuses a spec with explicit hard requirements, returning ConstraintNotEnforced, and that nothing is persisted to the store when it does.

Auto-committed-on: cuttlefish
Co-authored-by: Medulla <medulla@tinyhumans.ai>
Update the vendored tinybus submodule to the latest upstream commit.

Auto-committed-on: cuttlefish
Co-authored-by: Medulla <medulla@tinyhumans.ai>
Add an `# Errors` section to the `require_spec` doc comment explaining that it returns `Error::ConstraintNotEnforced` when an explicit requirement is unsupported or only best effort.

Auto-committed-on: cuttlefish
Co-authored-by: Medulla <medulla@tinyhumans.ai>
Add a test that deserializes a spec with the hard_requirements field removed and asserts it defaults to an empty collection, guarding backward compatibility with older serialized specs.

Auto-committed-on: cuttlefish
Co-authored-by: Medulla <medulla@tinyhumans.ai>
Replaced the `?` operators with `expect` calls in the older-specs default test so serialization and deserialization failures report which step failed.

Auto-committed-on: cuttlefish
Co-authored-by: Medulla <medulla@tinyhumans.ai>
Add serde_json to the dev-dependencies of tinybox-core so tests can build and inspect JSON values, with the lockfile updated to match.

Auto-committed-on: cuttlefish
Co-authored-by: Medulla <medulla@tinyhumans.ai>
The legacy spec test now returns boxed errors instead of panicking on
serialization and deserialization failures, and reports a non-object
serialization as an error rather than an expect. This keeps the test
consistent with the fallible style used elsewhere.

Auto-committed-on: cuttlefish
Co-authored-by: Medulla <medulla@tinyhumans.ai>
The v1 box spec now carries hard_requirements through to the v2 body instead of dropping them, and the driver record encoding round-trips the field so stored boxes keep their constraints.

Auto-committed-on: cuttlefish
Co-authored-by: Medulla <medulla@tinyhumans.ai>
Added a test asserting that stored records without a hard_requirements field decode with an empty list, and updated the serialization expectation to include the field. This guards backward compatibility for records written before the field existed.

Auto-committed-on: cuttlefish
Co-authored-by: Medulla <medulla@tinyhumans.ai>
Reformatted the JSON encoding setup in the test for older stored records so the error mapping closure is laid out consistently. No behaviour change.

Auto-committed-on: cuttlefish
Co-authored-by: Medulla <medulla@tinyhumans.ai>
Replace the is_empty assertions in the passthrough and sandbox tests with assert_eq against an empty slice, so a failure reports the actual stored contents instead of just false.

Auto-committed-on: cuttlefish
Co-authored-by: Medulla <medulla@tinyhumans.ai>
Replace the is_empty assertions in the spec and record tests with assert_eq against an empty array so a failure shows the actual contents of hard_requirements.

Auto-committed-on: cuttlefish
Co-authored-by: Medulla <medulla@tinyhumans.ai>
Add a test asserting that creating a sandbox with an unsupported hard requirement fails with ConstraintNotEnforced and leaves the store empty, confirming the check happens before anything is persisted.

Auto-committed-on: cuttlefish
Co-authored-by: Medulla <medulla@tinyhumans.ai>
The create path called require_spec right after spec.validate, which already
covers the same checks, so the extra call was removed to avoid duplicate work.

Auto-committed-on: cuttlefish
Co-authored-by: Medulla <medulla@tinyhumans.ai>
Call require_spec during create so unsupported specs are rejected before any network policy checks or container setup runs.

Auto-committed-on: cuttlefish
Co-authored-by: Medulla <medulla@tinyhumans.ai>
@senamakel
senamakel merged commit c1e308b into epic/8369-security-migration Oct 27, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant