Skip to content

fix(policy): harden landlock.compatibility validation - #2541

Open
letv1nnn wants to merge 6 commits into
NVIDIA:mainfrom
letv1nnn:policy-compatibility-bug
Open

fix(policy): harden landlock.compatibility validation#2541
letv1nnn wants to merge 6 commits into
NVIDIA:mainfrom
letv1nnn:policy-compatibility-bug

Conversation

@letv1nnn

Copy link
Copy Markdown
Contributor

Summary

  1. Invalid compatibility values (e.g. hard-requirement) were accepted without error and silently treated as best_effort. Fixed by parsing into an enum at YAML parse time and TryFrom implementation at the proto conversion layer.
  2. hard_requirement with no filesystem paths configured was a silent no-op, Landlock skipped entirely. Fixed by erroring before the early return when hard_requirement is set and both path lists are empty.

Related Issue

closes #2356

Changes

Two fixes to landlock.compatibility enforcement. Invalid values now fail at YAML parse time instead of silently falling back to best_effort. Configuring hard_requirement with no filesystem paths now aborts sandbox startup instead of skipping Landlock entirely. Docs updated to reflect the new behavior.

Testing

  • mise run pre-commit passes
  • Unit tests added/updated
  • E2E tests added/updated (if applicable)

Checklist

  • Follows Conventional Commits
  • Commits are signed off (DCO)
  • Architecture docs updated (if applicable)

letv1nnn added 2 commits July 27, 2026 15:44
Signed-off-by: Artem Lytvyn <alytvyn@redhat.com>
…ystem paths

Signed-off-by: Artem Lytvyn <alytvyn@redhat.com>
@copy-pr-bot

copy-pr-bot Bot commented Jul 29, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@letv1nnn

Copy link
Copy Markdown
Contributor Author

@krishicks, could you PTAL

@krishicks

Copy link
Copy Markdown
Collaborator

/ok to test 49a6eec

@krishicks

Copy link
Copy Markdown
Collaborator

Review findings

Verdict: Request changes

  1. [P1] Gateway validation still accepts invalid protobuf values.

    LandlockPolicy::try_from rejects invalid values only when the sandbox converts the stored protobuf policy (crates/openshell-core/src/policy.rs:117). The gateway create path calls validate_policy_safety() before persistence, but that validator never examines landlock.compatibility (crates/openshell-server/src/grpc/validation.rs:704). A direct SDK/gRPC client can therefore submit and persist an invalid value; rejection occurs later during sandbox startup rather than returning INVALID_ARGUMENT as required by bug(policy): invalid landlock.compatibility values silently fall back to best_effort #2356. Additionally, from_proto() silently serializes any invalid value as best_effort (crates/openshell-policy/src/lib.rs:817), concealing the stored typo. Please add validation to the shared policy validator or gateway request path.

  2. [P2] Neither regression has automated coverage.

    Despite the PR checklist claiming updated unit tests, the four changed files contain no test changes. At minimum, please cover:

    • Invalid YAML enum values are rejected with accepted values in the error.
    • Invalid protobuf values fail conversion/server validation.
    • Empty paths plus hard_requirement fails.
    • Empty paths plus best_effort remains a no-op.
    • An included workdir counts as a configured path.
  3. [P2] Readiness logging contradicts the new failure behavior.

    For zero paths, log_sandbox_readiness() still emits a successful skipped: no paths configured OCSF event (crates/openshell-supervisor-process/src/sandbox/linux/mod.rs:101). Immediately afterward, the new check aborts startup under hard_requirement (crates/openshell-supervisor-process/src/sandbox/linux/landlock.rs:146). Operators receive a misleading success event for a configuration that fails. The readiness branch should account for compatibility and emit the appropriate failure/security event.

The typed serde enum is the right approach for YAML validation, and fallible protobuf-to-runtime conversion prevents silent enforcement downgrade inside the sandbox. The zero-path guard also closes the identified Landlock no-op. Gateway validation, logging, and regression coverage need completion before merge.

Verification

  • openshell-policy: 148 tests passed.
  • The affected crates compiled.
  • Full openshell-core run: 346 passed; 10 unrelated socket tests failed because socket binding is prohibited in the restricted environment.
  • Linux-only Landlock tests were unavailable on this host.
  • The agent-maintenance map was checked; no companion skill update appears necessary.

@letv1nnn
letv1nnn requested a review from sjenning as a code owner August 18, 2026 20:51
@krishicks

Copy link
Copy Markdown
Collaborator

/ok to test a13f9d0

…path logging

Signed-off-by: Artem Lytvyn <alytvyn@redhat.com>
@letv1nnn
letv1nnn force-pushed the policy-compatibility-bug branch from a13f9d0 to 948ad15 Compare August 19, 2026 08:25
@krishicks

Copy link
Copy Markdown
Collaborator

Re-review of 948ad15

Verdict: Changes still requested.

Commit 948ad15 fixes the Linux test compilation issue by replacing expect_err() with an explicit match, but it does not address the two substantive findings from the previous re-review:

  1. [P2] Serialization still silently converts invalid values to best_effort.

    In crates/openshell-policy/src/lib.rs:817, from_proto() uses a debug_assert! and then maps every unknown value to BestEffort. Existing policies persisted before this fix can contain exactly these invalid values. Debug builds panic while release builds silently misrepresent them in policy get output. Since the public serialization functions already return Result, this path should return an error for invalid values rather than normalize them.

  2. [P2] The updated documentation does not match Kubernetes/current-user behavior.

    The table and explanation in docs/reference/policy-schema.mdx:96 say hard_requirement aborts when any individual path is inaccessible. However, try_open_path() returns Ok(None) for every PathOpenMode::CurrentUser failure before considering compatibility (crates/openshell-supervisor-process/src/sandbox/linux/landlock.rs:397). Kubernetes sidecar mode can therefore skip an inaccessible path under hard_requirement and continue when another valid rule remains. Either qualify the documentation or change the runtime behavior if aborting is intended.

Previous findings now resolved

  • Gateway validation rejects invalid direct gRPC/SDK values.
  • Regression coverage was added.
  • Zero-path readiness logging now emits the correct failure and paired security-finding events.

Cleanup

The root-level node_modules/ entry in .gitignore remains unrelated to this policy fix and should preferably be removed or submitted separately.

Verification

  • openshell-core policy tests: 3 passed.
  • openshell-policy: 152 passed.
  • Diff whitespace checks passed.
  • Linux cross-compilation could not run locally because aarch64-linux-gnu-gcc is unavailable.
  • Branch Checks and Helm Lint were pending; E2E and GPU E2E reported success.
  • Relevant policy skills were checked; no companion skill update is needed.

@krishicks

Copy link
Copy Markdown
Collaborator

Re-review of 2992ee1d

Verdict: Approve — no remaining code findings.

The latest update resolves both outstanding review comments:

  • Invalid persisted protobuf values now return an error during YAML/JSON serialization rather than becoming best_effort (crates/openshell-policy/src/lib.rs:839).
  • Documentation now qualifies hard_requirement behavior for Kubernetes current-user mode (docs/reference/policy-schema.mdx:98).
  • The unrelated root .gitignore change is no longer present in the final diff.

Earlier findings remain resolved: gateway validation, regression coverage, zero-path handling, and accurate OCSF failure logging.

Verification

  • openshell-core policy tests: 3 passed.
  • openshell-policy: 226 passed.
  • Supervisor prepare_* tests: 18 passed.
  • Diff whitespace checks passed.

Branch Checks and Helm Lint remain pending because the updated head is waiting for /ok to test.

@krishicks

Copy link
Copy Markdown
Collaborator

/ok to test 2992ee1

Signed-off-by: Artem Lytvyn <alytvyn@redhat.com>
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.

bug(policy): invalid landlock.compatibility values silently fall back to best_effort

2 participants