Skip to content

feat: add cargo, go, apt, and ghcr policy presets#141

Closed
brianwtaylor wants to merge 5 commits into
NVIDIA:mainfrom
brianwtaylor:feat/policy-presets-cargo-go-apt-ghcr
Closed

feat: add cargo, go, apt, and ghcr policy presets#141
brianwtaylor wants to merge 5 commits into
NVIDIA:mainfrom
brianwtaylor:feat/policy-presets-cargo-go-apt-ghcr

Conversation

@brianwtaylor

@brianwtaylor brianwtaylor commented Mar 17, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add 4 new network policy presets for package ecosystems with no existing coverage: Cargo (Rust), Go modules, apt (Debian/Ubuntu), and GHCR (GitHub Container Registry)
  • Each preset uses access: full with binary restrictions, consistent with the upstream direction for package manager presets (see fix: repair pypi and npm policy presets for package manager traffic #356)
  • Update preset count assertion and add endpoint validation tests for all 4 new presets

Related to #19 — expanding preset coverage so additional package managers work inside the sandbox out of the box

Motivation

The sandbox ships with presets for npm, PyPI, Docker Hub, and a few messaging services, but developers using Rust, Go, Debian-based system packages, or GitHub Container Registry have no preset available. These 4 presets cover the most common gaps.

Test plan

Automated Tests

node --test test/policies.test.js

18 tests covering preset listing, endpoint extraction, YAML schema validation, and new preset endpoint verification.

@brianwtaylor brianwtaylor force-pushed the feat/policy-presets-cargo-go-apt-ghcr branch from 74a27f3 to 1ade1da Compare March 17, 2026 06:33
@brianwtaylor brianwtaylor force-pushed the feat/policy-presets-cargo-go-apt-ghcr branch from 1ade1da to 2b4c6a5 Compare March 18, 2026 00:08
@coderabbitai

coderabbitai Bot commented Mar 18, 2026

Copy link
Copy Markdown
Contributor

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds four new network-policy preset YAMLs (apt, cargo, ghcr, go) defining registry endpoints (mostly on port 443) with protocol/ enforcement details and binaries lists. Tests updated to expect the expanded presets and validate the new preset endpoints.

Changes

Cohort / File(s) Summary
Policy Presets
nemoclaw-blueprint/policies/presets/apt.yaml, .../cargo.yaml, .../ghcr.yaml, .../go.yaml
Added four new preset YAMLs. apt.yaml defines apt_repositories endpoints (archive.ubuntu.com, security.ubuntu.com, deb.debian.org) with port: 443, protocol: rest, enforcement: enforce, tls: terminate, and per-endpoint GET access; includes binaries list. cargo.yaml adds cargo_registry endpoints (crates.io, static.crates.io, index.crates.io) on 443 with full access and binaries list. ghcr.yaml adds ghcr_registry with ghcr.io:443 (full access) and binaries. go.yaml adds go_proxy endpoints (proxy.golang.org, sum.golang.org, storage.googleapis.com) with TLS termination and GET access plus binaries.
Tests
test/policies.test.js
Expanded test expectations to account for the new presets, removed hard-coded preset count/names, and added a new suite validating endpoints for cargo, go, apt, and ghcr presets.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hopped through YAML rows tonight,
apt, cargo, go, ghcr aligned just right,
TLS snug, endpoints gleam bright,
Binaries ready for morning flight,
I nibble bytes and sigh with delight.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely summarizes the main change: adding four new policy presets (cargo, go, apt, ghcr) for package and registry management.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

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

@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

🧹 Nitpick comments (2)
test/policies.test.js (1)

12-27: Avoid dual source of truth for preset totals.

Line 14 hardcodes 13 while Line 26 already defines the expected preset set. Consider deriving the count assertion from the expected list length to keep these checks in sync.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/policies.test.js` around lines 12 - 27, The test contains a duplicated
source of truth: the hardcoded count 13 in the "returns all 13 presets"
assertion and the explicit expected array in the "returns expected preset names"
test; replace the numeric literal with a reference to the expected list length
so they stay in sync by deriving the count from the expected array (use the same
expected array used in the second test or move it to a shared variable) and
assert that policies.listPresets().length equals expected.length; reference
policies.listPresets, the presets/names variables and the expected array when
making the change.
nemoclaw-blueprint/policies/presets/ghcr.yaml (1)

18-19: Scope POST rule to specific OCI v2 API paths rather than /** (least privilege).

Line 19 currently allows POST on /**. While POST is necessary for push operations (e.g., starting blob uploads via POST /v2/<name>/blobs/uploads/), it should be scoped to the OCI Registry v2 API paths (e.g., /v2/**) instead of allowing it globally. This reduces the attack surface while still supporting docker push.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@nemoclaw-blueprint/policies/presets/ghcr.yaml` around lines 18 - 19, Replace
the overly-broad POST rule "- allow: { method: POST, path: "/**" }" with a
scoped rule that only permits POST to the OCI v2 registry paths (for example "-
allow: { method: POST, path: "/v2/**" }") so POST actions (like initiating blob
uploads) are limited to /v2/* endpoints; update the corresponding entry in the
YAML preset (the POST allow mapping) to use "/v2/**" instead of "/**".
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@test/policies.test.js`:
- Around line 144-148: The test title "ghcr preset has registry and token
endpoints" doesn't match its assertion; either rename the test to reflect that
it only checks registry hosts or add a token-related assertion: locate the test
using the it(...) string and the calls to policies.loadPreset and
policies.getPresetEndpoints, then either change the it(...) description to "ghcr
preset has registry endpoint" or extend the test to assert the token endpoint is
present (e.g., call the appropriate token endpoint extractor or inspect the
preset object returned by policies.loadPreset for the token host/URL and assert
it includes the expected token endpoint).

---

Nitpick comments:
In `@nemoclaw-blueprint/policies/presets/ghcr.yaml`:
- Around line 18-19: Replace the overly-broad POST rule "- allow: { method:
POST, path: "/**" }" with a scoped rule that only permits POST to the OCI v2
registry paths (for example "- allow: { method: POST, path: "/v2/**" }") so POST
actions (like initiating blob uploads) are limited to /v2/* endpoints; update
the corresponding entry in the YAML preset (the POST allow mapping) to use
"/v2/**" instead of "/**".

In `@test/policies.test.js`:
- Around line 12-27: The test contains a duplicated source of truth: the
hardcoded count 13 in the "returns all 13 presets" assertion and the explicit
expected array in the "returns expected preset names" test; replace the numeric
literal with a reference to the expected list length so they stay in sync by
deriving the count from the expected array (use the same expected array used in
the second test or move it to a shared variable) and assert that
policies.listPresets().length equals expected.length; reference
policies.listPresets, the presets/names variables and the expected array when
making the change.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 4e0809c3-c27c-42ee-8bf1-d35cf26a95b1

📥 Commits

Reviewing files that changed from the base of the PR and between 2a9afbc and 2b4c6a5.

📒 Files selected for processing (5)
  • nemoclaw-blueprint/policies/presets/apt.yaml
  • nemoclaw-blueprint/policies/presets/cargo.yaml
  • nemoclaw-blueprint/policies/presets/ghcr.yaml
  • nemoclaw-blueprint/policies/presets/go.yaml
  • test/policies.test.js

Comment thread test/policies.test.js Outdated
@brianwtaylor

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Mar 18, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@brianwtaylor brianwtaylor force-pushed the feat/policy-presets-cargo-go-apt-ghcr branch from 43957ba to ca5d144 Compare March 18, 2026 19:44
Add network policy presets for Rust Cargo, Go modules, Debian/Ubuntu
apt repositories, and GitHub Container Registry. Each follows the
existing YAML schema with minimal required permissions (GET-only for
package registries, GET+POST for auth token exchange on GHCR).

Signed-off-by: Brian Taylor <brian@briantaylor.xyz>
Signed-off-by: Brian Taylor <brian.taylor818@gmail.com>
- Scope storage.googleapis.com GET to /proxy-golang-org/** to prevent
  unrestricted access to arbitrary GCS content
- Scope ghcr.io POST to /v2/** (OCI Distribution API) instead of /**
- Derive preset count assertion from expected array to avoid dual
  source of truth
- Fix ghcr test title to match actual assertions
Switch all 4 new presets from protocol: rest + tls: terminate to
access: full (matches PR #36 fix for pypi/npm). Add binaries
restriction to each preset so only openclaw and the relevant package
manager can reach allowed endpoints (addresses #272).
…ethods

- apt/cargo/go: restrict to GET only (read-only registries)
- ghcr: GET globally + POST scoped to /v2/** (OCI distribution spec)
- go: scope storage.googleapis.com to /golang/** path prefix
- All presets now match the existing schema pattern (protocol, enforcement,
  tls, rules) used by npm/pypi/docker presets
@brianwtaylor brianwtaylor force-pushed the feat/policy-presets-cargo-go-apt-ghcr branch from 6e6d8d4 to 18f91b7 Compare March 19, 2026 01:12
…ng fix

Package managers use CONNECT tunneling which breaks under tls: terminate.
Align with ericksoa's PR #356 which switches npm/pypi to access: full
for the same reason.
@brianwtaylor brianwtaylor closed this by deleting the head repository Mar 20, 2026
@wscurran

Copy link
Copy Markdown
Contributor

Thanks for adding the new policy presets for Cargo, Go modules, apt, and GHCR, this expands the coverage of our network policies and could be helpful for users working with these package ecosystems.

@wscurran wscurran added feature PR adds or expands user-visible functionality and removed enhancement: feature labels Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature PR adds or expands user-visible functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants