Skip to content

🐛 Bugs around Openshell sandbox policy and normalization #1669

Closed

Description

@esnible

Describe the bug

Kagenti's OpenShell version seems to block traffic within the cluster (see #1647)

At some point, OpenShell changed the meaning of network_policies.<name>.endpoints[].port. Internally, there is a ports (plural), and OpenShell provides some legacy support to promote the old port: <int> to ports: [<int>].

If I submit a policy using ports with openshell sandbox create it should be preserved, but openshell sandbox get <sandbox> --policy-only does not show the list.

Steps To Reproduce

  1. Create a configuration normalized-example-policy-data.yaml:
version: 1
filesystem_policy:
  include_workdir: true
  read_only:
    - /usr
    - /lib
    - /lib64
    - /etc
    - /home
    - /bin
    - /sbin
  read_write:
    - /tmp
    - /app
    - /root
    - /var/log
process:
  run_as_user: ""
  run_as_group: ""
network_policies:
  internal:
    name: "Allow OpenTelemetry cluster services"
    endpoints:
      # Kagenti OpenTelemetry Collector
      - host: otel-collector.kagenti-system
        ports: [8335]
      # Kagenti OpenTelemetry Collector
      - host: otel-collector.kagenti-system.svc.cluster.local
        ports: [8335]
    binaries:
      - path: /usr/bin/curl
      - path: /**
  1. Deploy a sandbox:
target/release/openshell sandbox create \
   --policy ~/junk/ecs-normalized-example-policy-data.yaml \
   --name try-otel -- bash
  1. Check that the sandbox appears correctly:
openshell sandbox get try-otel --policy-only

Note that the output sandbox doesn't see ports: [8335], it sees port: 8335.

Expected Behavior

The policy that appears should like like the one that was supplied

Additional Context

ports is a list, not an integer, and sandbox-policy.rego#L100 only if endpoint.ports[_] == network.port.

With our policies, when I deploy a sandbox traffic to the OpenTelemetry collector is blocked, even if I explicitly enable it:

curl -v -X POST -H "Content-Type: application/json" "http://otel-collector.kagenti-system.svc.cluster.local/v1/traces" --data '=== TRACES ==='
{"detail":"POST otel-collector.kagenti-system.svc.cluster.local:80/v1/traces not permitted by policy","error":"policy_denied"}

Debugging policies is usually done interactively with regorus, e.g.:

regorus eval \
  -d crates/openshell-sandbox/data/sandbox-policy.rego \
  -d ecs-normalized-example-policy-data.yaml \
  -i ecs-example-opa-input.yaml \
  'data.openshell.sandbox.allow_network'

(It is very difficult to debug policies, especially when OpenShell components are "normalizing" the YAML).

cc @Ladas

Activity

  1. added
    kind/bug
    on May 26, 2026
  2. esnible commented on May 26, 2026

    @esnible
    MemberAuthor

    Note that Claude believes the openshell CLI calls GetSandboxConfig(sandbox_id=<uuid>) (run.rs:2186). This is the same RPC the supervisor makes inside the sandbox pod at startup.

    Thus, it seems that the sandbox really believes that network_policies.<policy-name>.endpoints[].port: is in the same port: <int>, which could explain the difficult with rego policies that seem to assume we have ports: <list of int>.

  3. esnible commented on May 26, 2026

    @esnible
    MemberAuthor

    Note that

    grpcurl \
      -import-path proto -proto proto/openshell.proto \
      -cacert "$GW/mtls/ca.crt" \
      -cert   "$GW/mtls/tls.crt" \
      -key    "$GW/mtls/tls.key" \
      -H "authorization: Bearer $(jq -r .access_token "$GW/oidc_token.json")" \
      -d '{}' \
      openshell-team1.localtest.me:9443 \
      openshell.v1.OpenShell/ListSandboxes

    shows the actual shape of the policy, and it does have both port and ports, unlike the CLI:

    ...
                  "endpoints": [
                    {
                      "host": "otel-collector.kagenti-system",
                      "port": 8335,
                      "ports": [
                        8335
                      ]
                    },
                    {
                      "host": "otel-collector.kagenti-system.svc.cluster.local",
                      "port": 8335,
                      "ports": [
                        8335
                      ]
                    }
    ...
    
  4. Ladas commented on May 27, 2026

    @Ladas
    Contributor

    Confirmed — our agent policy files in PR #1498 use port: 8080 (singular), which maps to the legacy path. The rego evaluator checks endpoint.ports[_] (plural list). The normalization from port → ports may silently fail or produce port: 0 entries.

    Our affected files:

    • deployments/openshell/agents/claude-sdk-agent/policy-data.yaml
    • deployments/openshell/agents/adk-agent-supervised/policy-data.yaml
    • deployments/openshell/agents/weather-agent-supervised/policy-data.yaml

    All use port: <int> (singular). Should be ports: [<int>] once the normalization bug is fixed upstream.

    This is a different issue from #1581 (Service creation race). Same symptom (in-cluster connectivity broken) but different root cause (OPA policy matching vs. K8s RBAC).

  5. esnible commented on May 27, 2026

    @esnible
    MemberAuthor

    @Ladas , I agree the analysis. However, using ports: [<int>] doesn't actually work either! Do you recall if this ever worked in the past? If so, I will use git bisect to see what caused it to fail. If not, I will continue diagnosing.

  6. Ladas commented on May 27, 2026

    @Ladas
    Contributor

    Checked upstream NVIDIA/OpenShell proto — the ports (plural) field exists at field 9 in NetworkEndpoint. The proto comments say: "If port is set and ports is empty, port is normalized to ports: [port]."

    The proto definition is correct, but the bug #1669 reports is in the gateway's response normalization — when you GET the sandbox policy back, it shows port (singular) instead of the submitted ports list. This is a display/serialization issue in the gateway, not the proto.

    ai-openshell/openshell#359 (closed Mar 16) added wildcard + multi-port support. Our fork at v0.0.36-kagenti.8 should include this, but the gateway normalization behavior may still strip ports → port in responses. Filed upgrade tracking at kagenti/openshell (issues disabled there, tracking here: #1695).

  7. pdettori commented on Jul 16, 2026

    @pdettori
    Member

    closing for now - upstream openshell is evolving rapidly and we are putting this work on the back burner until openshell stabilizes more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bug

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions