Skip to content

fix(policy): load shared network policy schema#7533

Closed
apurvvkumaria wants to merge 1 commit into
mainfrom
codex/fix-network-policy-schema-runtime
Closed

fix(policy): load shared network policy schema#7533
apurvvkumaria wants to merge 1 commit into
mainfrom
codex/fix-network-policy-schema-runtime

Conversation

@apurvvkumaria

@apurvvkumaria apurvvkumaria commented Jul 25, 2026

Copy link
Copy Markdown
Collaborator

Summary

Restore sandbox policy validation after the shared network policy schema was extracted in #6877. The runtime now loads the referenced schema, and the npm package ships the schema that the validator consumes.

Changes

  • Register schemas/network-policy.schema.json with the runtime AJV instance before compiling the sandbox policy schema.
  • Include the shared network policy schema in the published npm package.
  • Assert that the packed package contains both policy schemas and can validate through the installed runtime.

Type of Change

  • Code change (feature, bug fix, or refactor)
  • Code change with doc updates
  • Doc only (prose changes, no code sample modifications)
  • Doc only (includes code sample changes)

Quality Gates

  • Tests added or updated for changed behavior
  • Existing tests cover changed behavior — justification:
  • Tests not applicable — justification:
  • Docs updated for user-facing behavior changes
  • Docs not applicable — justification: This restores the existing schema-validation behavior and package contents. It does not change policy syntax, CLI behavior, configuration, or a user procedure.
  • Sensitive paths changed (security, policy, credentials, preflight, onboarding, inference, runner, sandbox, or messaging)
  • Sensitive-path review completed or maintainer-approved waiver recorded — reviewer/approval link/justification: Maintainer review confirmed that the runtime registers only the trusted schema shipped by NemoClaw; policy semantics, rejected input handling, and bounded error disclosure are unchanged. Independent PR approval remains required before merge.
  • Non-success, skipped, or missing CI check accepted by maintainer — check name, approval link, and follow-up issue:

Documentation Writer Review

  • Documentation writer subagent reviewed the completed changes
  • Result: no-docs-needed
  • Evidence: The writer reviewed package.json, src/lib/policy/sandbox-policy-validation.ts, and test/package-contract/openshell-policy-boundary.test.ts against WRITING.md and docs/CONTRIBUTING.md. The fix restores the intended existing policy validation and does not change user-facing behavior.
  • Agent: Codex Desktop

DGX Station Hardware Evidence

  • Tested on DGX Station
  • Tested commit:
  • Station profile/scenario:
  • Result:
  • Supporting evidence:

Verification

  • PR description includes a Signed-off-by: line and every commit appears as Verified in GitHub
  • Normal pre-commit, commit-msg, and pre-push hooks passed, or npm run check:diff passed when hooks were skipped or unavailable
  • Targeted behavior tests pass for the current change set, or tests are marked not applicable above — command/result or justification: The packed validator contract passes 7/7, the policy persistence suite passes 29/29, and the independently observed stale-recovery case passes 5/5.
  • Applicable broad gate passed — npm test for broad runtime/test-harness changes; npm run check for repo-wide validation/coverage changes — command/result: npm run test:package passes 318/318 across 22 files; npm run build:cli passes.
  • Quality Gates section completed with required justifications or waivers
  • No secrets, API keys, or credentials committed
  • npm run docs builds without warnings (doc changes only)
  • Doc pages follow the style guide (doc changes only)
  • New doc pages include SPDX header and frontmatter (new pages only)

Follow-up to #6877. Unblocks #7529 and other PRs synchronized to current main.


Signed-off-by: Apurv Kumaria akumaria@nvidia.com

Summary by CodeRabbit

  • Bug Fixes

    • Improved sandbox policy validation by incorporating network policy rules.
    • Packaged distributions now include the network policy schema required for validation.
  • Tests

    • Added coverage to verify both policy schemas are included in packaged installations.

Signed-off-by: Apurv Kumaria <akumaria@nvidia.com>
@coderabbitai

coderabbitai Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The package now publishes network-policy.schema.json. Sandbox policy validator initialization loads and validates both schemas, registers the network schema with AJV, and compiles the sandbox schema. Package contract coverage verifies both schema files are present after installation.

Changes

Network policy schema integration

Layer / File(s) Summary
Ship and verify the network policy schema
package.json, test/package-contract/...
The npm package whitelist includes the network policy schema, and the package contract test verifies it is present in the unpacked distribution.
Load and register the network policy schema
src/lib/policy/sandbox-policy-validation.ts
Validator initialization reads and validates both schema files, registers the network schema with AJV, and compiles the sandbox policy schema.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • NVIDIA/NemoClaw#7531: Makes the same package, validator, and contract-test updates for the network policy schema.
  • NVIDIA/NemoClaw#7532: Also ships and registers the network policy schema and verifies its packaged presence.

Suggested reviewers: laitingsheng

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: loading the shared network policy schema.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix-network-policy-schema-runtime

Comment @coderabbitai help to get the list of available commands.

@apurvvkumaria apurvvkumaria added v0.0.96 Release target bug-fix PR fixes a bug or regression area: policy Network policy, egress rules, presets, or sandbox policy area: packaging Packages, images, registries, installers, or distribution labels Jul 25, 2026
@apurvvkumaria apurvvkumaria self-assigned this Jul 25, 2026
@github-code-quality

github-code-quality Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Code Coverage Overview

Languages: TypeScript

TypeScript / code-coverage/plugin

The overall coverage in commit aefb9ce in the codex/fix-network-po... branch remains at 96%, unchanged from commit 2ac4a0d in the main branch.

TypeScript / code-coverage/cli

The overall coverage in commit aefb9ce in the codex/fix-network-po... branch is 81%. The coverage in commit dbac677 in the main branch is 80%.

Show a code coverage summary of the most impacted files.
File main dbac677 codex/fix-network-po... aefb9ce +/-
src/lib/actions.../status-text.ts 47% 41% -6%
src/lib/policy/index.ts 58% 61% +3%
src/lib/agent/defs.ts 81% 85% +4%
src/lib/actions...ndbox/doctor.ts 84% 88% +4%
src/lib/onboard...tp-readiness.ts 94% 100% +6%
src/lib/onboard...ndbox-create.ts 83% 91% +8%
src/lib/policy/...ne-exclusion.ts 0% 97% +97%
src/lib/policy/...y-validation.ts 0% 100% +100%
src/commands/sa...licy/exclude.ts 0% 100% +100%
src/commands/sa...licy/restore.ts 0% 100% +100%

Updated July 25, 2026 20:47 UTC

@github-actions

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/lib/policy/sandbox-policy-validation.ts`:
- Around line 30-32: Move the NETWORK_POLICY_SCHEMA_PATH filesystem read out of
the policy validation code and into an adapter under src/lib/adapters/**, then
inject or call that loader from the policy validation flow for both schema
reads. Update the relevant validation symbols around parsedNetworkPolicySchema
to use the adapter boundary, preserving existing parsing and validation behavior
while allowing tests to provide fakes.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 7b15caa6-9058-4d0c-9965-16fd832ca9d1

📥 Commits

Reviewing files that changed from the base of the PR and between 2ac4a0d and aefb9ce.

📒 Files selected for processing (3)
  • package.json
  • src/lib/policy/sandbox-policy-validation.ts
  • test/package-contract/openshell-policy-boundary.test.ts

Comment on lines +30 to +32
const parsedNetworkPolicySchema: unknown = JSON.parse(
fs.readFileSync(NETWORK_POLICY_SCHEMA_PATH, "utf-8"),
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟠 Major | 🏗️ Heavy lift

Keep schema loading behind the adapter boundary.

The newly added fs.readFileSync in src/lib/policy/** couples policy validation directly to the host filesystem. Route both schema reads through an adapter or injected loader so this policy code remains testable with fakes.

As per path instructions, host-boundary work (filesystem/process/network/Docker/OpenShell) must be isolated in src/lib/adapters/** so policy code stays testable with injected fakes.

🧰 Tools
🪛 ast-grep (0.44.1)

[warning] 30-30: Filesystem path is not a string literal; a request-/variable-derived path can enable path traversal. Validate and normalize the path before use.
Context: fs.readFileSync(NETWORK_POLICY_SCHEMA_PATH, "utf-8")
Note: [CWE-22] Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').

(detect-non-literal-fs-filename-typescript)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/lib/policy/sandbox-policy-validation.ts` around lines 30 - 32, Move the
NETWORK_POLICY_SCHEMA_PATH filesystem read out of the policy validation code and
into an adapter under src/lib/adapters/**, then inject or call that loader from
the policy validation flow for both schema reads. Update the relevant validation
symbols around parsedNetworkPolicySchema to use the adapter boundary, preserving
existing parsing and validation behavior while allowing tests to provide fakes.

Source: Path instructions

@github-actions

github-actions Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

PR Review Advisor — Informational

Advisor assessment: Informational / high confidence
Next action: No advisor follow-up needed.
Findings: 0 blockers · 0 warnings · 0 suggestions
Status: No actionable findings remain in the canonical review ledger.

Model lanes

  • GPT-5.6 Terra (primary): Completed · high confidence · 0 blockers · 0 warnings · 0 suggestions
  • Nemotron 3 Ultra (second opinion): Completed · high confidence · 0 blockers · 0 warnings · 0 suggestions
  • Model comparison: normalized findings match; normalized E2E selections differ; severity counts match.

Nemotron output stays in workflow artifacts and does not change the assessment above.

E2E guidance

Advisory only. E2E / PR Gate selects and runs jobs independently.

Recommended E2E: cloud-onboard, credential-sanitization, security-posture, inference-routing, network-policy

Workflow run details

This automated review informs maintainers. Warnings and suggestions do not require a response. A maintainer decides whether to merge.

@apurvvkumaria

Copy link
Copy Markdown
Collaborator Author

Closing in favor of #7531.

#7531 is the earlier equivalent three-file fix from Ho Lim, the original #6877 author. It covers the same acceptance criteria:

  • register the trusted shared network-policy schema before sandbox-policy compilation;
  • ship the referenced schema in the npm package; and
  • prove the installed package contains both schemas and validates through the runtime.

This branch adds no unique behavior or regression coverage, so preserving the original author's credit is the correct choice. The suggestion to move both existing schema filesystem reads into a new adapter is not adopted: this policy module already owns the sandbox-schema read, and that unrelated refactor would enlarge a tactical current-main repair.

Validation performed on the equivalent fix shape: 318/318 package contracts, 29/29 policy persistence tests, 7/7 OpenShell policy package contracts, and the normal signed commit hooks.

cv pushed a commit that referenced this pull request Jul 25, 2026
<!-- markdownlint-disable MD041 -->
## Summary

Restore runtime sandbox-policy validation after #6877 extracted network
policy definitions into an external schema. The runtime validator now
registers that shared schema before compiling the sandbox schema, and
the published package ships both files.

## Changes

- Load and register `network-policy.schema.json` before compiling the
sandbox policy schema.
- Include the shared schema in the npm package.
- Extend the out-of-tree package contract to prove the referenced schema
is shipped and runtime validation succeeds.

## Type of Change

- [x] Code change (feature, bug fix, or refactor)
- [ ] Code change with doc updates
- [ ] Doc only (prose changes, no code sample modifications)
- [ ] Doc only (includes code sample changes)

## Quality Gates

<!-- Check one tests line and one docs line. Check other lines when
applicable. Add every requested justification or approval reference. -->
- [x] Tests added or updated for changed behavior
- [ ] Existing tests cover changed behavior — justification:
- [ ] Tests not applicable — justification:
- [ ] Docs updated for user-facing behavior changes
- [x] Docs not applicable — justification: This restores the existing
schema-validation behavior and package contents. It does not change
policy syntax, CLI behavior, configuration, or a user procedure.
- [x] Sensitive paths changed (security, policy, credentials, preflight,
onboarding, inference, runner, sandbox, or messaging)
- [x] Sensitive-path review completed or maintainer-approved waiver
recorded — reviewer/approval link/justification: Maintainer comparison
confirmed the runtime registers only the trusted schema shipped by
NemoClaw. Policy semantics, rejected input handling, and bounded error
disclosure remain unchanged. Independent PR approval remains required
before merge.
- [ ] Non-success, skipped, or missing CI check accepted by maintainer —
check name, approval link, and follow-up issue:

## Documentation Writer Review

<!-- Required for code and documentation changes after the changes and
applicable validation are complete. Keep one review checkbox and one
instance of each visible or hidden field. For Evidence, list changed
documentation paths. For documentation-only changes, also state that the
writing rules and documentation style were reviewed. For other results,
explain why no documentation change is needed or why the review is
blocked. For Agent, use a consistent product and surface name, such as
Codex Desktop, Codex CLI, Claude Code, or Cursor. After committing all
review changes, put `git rev-parse --short HEAD` and `git rev-parse
--short HEAD:AGENTS.md` in the hidden metadata below. Rerun the review
and refresh that metadata after any new commit. This receipt is advisory
during the data-collection pilot. -->
- [x] Documentation writer subagent reviewed the completed changes
- Result: `no-docs-needed`
- Evidence: The writer reviewed the live body and exact three-file diff
against `WRITING.md` and `docs/CONTRIBUTING.md`. The fix restores
existing policy validation and package contents without changing the
schema, configuration, supported behavior, or user workflow.
- Agent: Codex Desktop
<!-- docs-review-head-sha: d133ec1 -->
<!-- docs-review-agents-blob-sha: 9c9b36d -->

## DGX Station Hardware Evidence

<!-- Required only when scripts/prepare-dgx-station-host.sh changes.
Maintainers must review the linked evidence before approving or merging.
This is human-reviewed evidence, not authenticated hardware provenance.
Exceptional bypasses use existing repository governance and must be
documented on the PR. -->
- [ ] Tested on DGX Station
- Tested commit:
- Station profile/scenario:
- Result:
- Supporting evidence:

## Verification

<!-- Check each applicable item only when supported by the requested
evidence. Run targeted tests once per relevant change set and rerun
after later edits or hook autofixes that can affect the tested behavior.
Do not rerun hook-covered checks. -->
- [x] PR description includes a `Signed-off-by:` line and every commit
appears as `Verified` in GitHub
- [x] Normal `pre-commit`, `commit-msg`, and `pre-push` hooks passed, or
`npm run check:diff` passed when hooks were skipped or unavailable
- [x] Targeted behavior tests pass for the current change set, or tests
are marked not applicable above — command/result or justification: The
installed package validator contract passes 1/1, and the focused policy
suites pass 56/56.
- [ ] Applicable broad gate passed — `npm test` for broad
runtime/test-harness changes; `npm run check` for repo-wide
validation/coverage changes — command/result: Not applicable to this
focused three-file integration repair.
- [x] Quality Gates section completed with required justifications or
waivers
- [x] No secrets, API keys, or credentials committed
- [ ] `npm run docs` builds without warnings (doc changes only)
- [ ] Doc pages follow the [style
guide](https://github.com/NVIDIA/NemoClaw/blob/main/docs/CONTRIBUTING.md)
(doc changes only)
- [ ] New doc pages include SPDX header and frontmatter (new pages only)

Follow-up to #6877. Supersedes duplicate #7533 and preserves Ho Lim's
original-author credit.

---
<!-- DCO sign-off is required in this PR description, and every commit
must appear as Verified in GitHub. Run: git config user.name && git
config user.email -->
Signed-off-by: Ho Lim <subhoya@gmail.com>

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Bug Fixes**
* Improved sandbox policy validation by incorporating network policy
schema checks.
* Added clearer handling when required policy schemas are unavailable or
validation cannot be initialized.

* **Chores**
  * Ensured the network policy schema is included in published packages.
* Expanded package verification to confirm the schema is available after
installation.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Signed-off-by: Ho Lim <subhoya@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: packaging Packages, images, registries, installers, or distribution area: policy Network policy, egress rules, presets, or sandbox policy bug-fix PR fixes a bug or regression v0.0.96 Release target

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant