Skip to content

fix(policy): allow npm child process and Vertex AI egress for opencode - #92

Open
yvonnedevlinrh wants to merge 1 commit into
NVIDIA:mainfrom
yvonnedevlinrh:fix/opencode-policy-npm-vertex-egress
Open

fix(policy): allow npm child process and Vertex AI egress for opencode#92
yvonnedevlinrh wants to merge 1 commit into
NVIDIA:mainfrom
yvonnedevlinrh:fix/opencode-policy-npm-vertex-egress

Conversation

@yvonnedevlinrh

Copy link
Copy Markdown

Refs #91

Summary

The opencode network policy (in both sandboxes/base/policy.yaml and sandboxes/gemini/policy.yaml) has two egress gaps that break real-world OpenCode usage. This PR fixes both, applied identically to the base and gemini sandbox policies.

1. npm installs fail with ECONNRESET (binary allowlist gap)

registry.npmjs.org is already allowlisted as an endpoint, but the npm binary is not in the policy's binaries: list. Policy pairs are (binary, endpoint), so when opencode spawns a background npm install (arborist), the connecting process is /usr/local/bin/npm (or /usr/bin/npm) — not the allowlisted opencode/node binaries - and its CONNECT to registry.npmjs.org is denied.

This is not TLS-MITM: registry.npmjs.org is a plain CONNECT tunnel (no tls: terminate). It is purely a binary allowlist gap. The droid and ollama sandboxes already ship dedicated npm policies; opencode never allowlisted npm.

Fix: add /usr/local/bin/npm and /usr/bin/npm to the binaries: allowlist.

2. No Google / Vertex AI egress

The opencode policy had zero Google hosts, so running OpenCode against a google-vertex-* provider (Vertex AI, including GitHub-OIDC Workload Identity Federation) could not reach the required Google endpoints - both token exchange and inference fail.

Fix: add the Vertex AI + Google token hosts (mirroring the gemini policy) plus sts.googleapis.com, which GitHub-OIDC WIF additionally requires for token exchange. Also add models.opencode.ai so opencode does not silently fall back to its built-in default model.

Changes

  • *-aiplatform.googleapis.com, sts.googleapis.com, oauth2.googleapis.com,www.googleapis.com, iamcredentials.googleapis.com, accounts.google.com added to endpoints
  • models.opencode.ai added to endpoints
  • /usr/local/bin/npm, /usr/bin/npm added to binaries

Environment

  • Base image: nvcr.io/nvidia/base/ubuntu:noble-20251013 (Ubuntu 24.04)
  • Node 22.22.1-1nodesource1, npm 11.11.0, opencode-ai@1.2.18 (global)

Testing

  • python3 -c "import yaml; yaml.safe_load(...)" passes for both files.

The opencode network policy allowlists registry.npmjs.org as an endpoint
but not the npm binary, so opencode's background dependency install
(arborist) connects as /usr/local/bin/npm and is denied (ECONNRESET).
Add /usr/local/bin/npm and /usr/bin/npm to the binaries allowlist,
matching the dedicated npm policies in the droid and ollama sandboxes.

The policy also had no Google egress, so running opencode against a
google-vertex-* provider could not reach Vertex AI or the Google token
endpoints. Add the Vertex AI + token hosts (mirroring the gemini policy)
plus sts.googleapis.com, which GitHub-OIDC Workload Identity Federation
requires for token exchange. Also add models.opencode.ai so opencode
does not silently fall back to its built-in default model.

Applied identically to the base and gemini sandbox policies.

Signed-off-by: Yvonne Devlin <ydevlin@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.

1 participant