Skip to content

Sectioned policy schema for profiles, CLI, and bindings#42

Open
congwang-mk wants to merge 2 commits intomainfrom
policy-schema
Open

Sectioned policy schema for profiles, CLI, and bindings#42
congwang-mk wants to merge 2 commits intomainfrom
policy-schema

Conversation

@congwang-mk
Copy link
Copy Markdown
Contributor

@congwang-mk congwang-mk commented May 7, 2026

Summary

Replaces sandlock's flat-keyed TOML profile format with a sectioned schema, then aligns the rest of the project — Policy, the CLI flags, FFI accessors, and Python bindings — with the schema's intent-shaped vocabulary. Pre-1.0 hard break: existing user profiles and downstream callers using the old field/flag names need to be rewritten.

Two commits, organized by phase:

  • ab4b0c3 Phase 1 — sectioned profile parser. New ProfileInput + 8 section structs ([config], [determinism], [program], [filesystem], [network], [http], [syscalls], [limits]). New parse_input translator producing (Policy, ProgramSpec). parse_profile / load_profile rewritten as thin wrappers; legacy flat-keyed parser deleted. CLI gains --profile-file and honors [program].exec/args from a profile when no trailing positional command is given (trailing command overrides).

  • 9eff365 Phase 2 — vocabulary alignment + canonical input. Renames Policy::https_ca/https_key/block_syscallshttp_ca/http_key/extra_deny_syscalls; drops allow_sysv_ipc (folded into a new extra_allow_syscalls: Vec<String> plus Policy::allows_sysv_ipc() helper). CLI flags renamed to match (--http-ca, --http-key, --extra-deny-syscall, new --extra-allow-syscall). New Policy::validate() owns cross-section invariants; PolicyBuilder::build_unchecked() runs per-field validation and build() collapses to build_unchecked()? + validate()?. PolicyBuilder carries a feature-gated clap::Args derive; the CLI's RunArgs flattens it via #[clap(flatten)], eliminating the duplicated parallel args struct. FFI, Python bindings, and READMEs updated for the rename.

Test Plan

  • cargo test --workspace passes — 278 core unit tests + 17 CLI tests + 5 profile integration tests + 2 policy-validate tests + integration suite.
  • pip install -e python/ && pytest python/tests/ passes — 228 Python tests.
  • cargo check --workspace --all-targets is clean.
  • Sectioned profile loads end-to-end: sandlock run --profile-file <profile>.toml exits 0 with a representative profile (see PR description's example).
  • Trailing command override: sandlock run --profile-file <profile>.toml -- /bin/echo override runs the trailing command, not the profile's [program].exec.
  • Renamed CLI flags work: --http-ca, --http-key, --extra-deny-syscall, --extra-allow-syscall sysv_ipc.
  • Old CLI flags rejected: --https-ca, --https-key, --block-syscall, --allow-sysv-ipc produce clap "unexpected argument" errors.
  • Cross-section invariant: [filesystem].isolation = "overlayfs" without [config].workdir returns the documented error mentioning workdir.

🤖 Generated with Claude Code

Signed-off-by: Cong Wang <cwang@multikernel.io>
Phase 2 of the sectioned-policy-schema effort. After Phase 1 introduced
the sectioned profile parser (translating into the legacy field names),
this phase aligns the rest of the project — Policy struct, CLI flags,
FFI, and Python bindings — with the schema's intent-shaped vocabulary,
and reshapes the Policy/PolicyBuilder/CLI relationship so a single
canonical input definition feeds both TOML profiles and clap argv
parsing.

Field and flag renames:
- Policy::https_ca       → Policy::http_ca   (CLI: --https-ca → --http-ca)
- Policy::https_key      → Policy::http_key  (CLI: --https-key → --http-key)
- Policy::block_syscalls → Policy::extra_deny_syscalls
                                            (CLI: --block-syscall → --extra-deny-syscall)
- Policy::allow_sysv_ipc removed; folded into
  Policy::extra_allow_syscalls = ["sysv_ipc"]
                                            (CLI: --allow-sysv-ipc → --extra-allow-syscall)

Signed-off-by: Cong Wang <cwang@multikernel.io>
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