Skip to content

feat(k8s): implement the external network enforcer and native-network mode (RFC 0029) #6122

Backlog

Description

@Gal-Zaidman

User Story

I use OpenShell on Kubernetes in a deployment where network policy is enforced outside the workload, by a component that owns each sandbox's network interface.
I need that component to enforce each sandbox's OpenShell network policy and inject its provider credentials, and I need OpenShell to hold the agent until the component has applied the sandbox's policy.

Problem Statement

RFC 0029 (#6024, #6117) proposes native-network mode and the external network enforcer role. OpenShell doesn't implement either yet: the gateway has no way to give a trusted enforcer the policy and credentials of each sandbox or to wait for it to apply them, and the sandbox runtime always proxies agent traffic through the supervisor.

Impact / Why This Matters

Until this lands, deployments that enforce network policy outside the workload must run two enforcement points whose policies can diverge, or give up per-sandbox policy.

Proposed Design

Implement RFC 0029 behind the gateway's experimental feature. Without the Kubernetes driver's external_enforcer table, nothing changes. With it:

  • Sandbox network. Every new workload Pod gets the configured Multus network as its only interface, the configured extended resource and the configured nameservers. Agent connections and DNS leave directly on that network instead of through the supervisor. Pods schedule only to nodes labeled node-restriction.kubernetes.io/openshell-external-enforcer-ready: "true", which the enforcer keeps on the nodes it covers.
  • Supervisor network. Optionally, sandboxes reach their node's supervisor over a second Multus network instead of the supervisor Service.
  • Enforcer identity. The enforcer runs in its own namespace with its own token, accepted only beside a Pod-bound token for its ServiceAccount. It can only learn which sandboxes exist, read their configuration and report whether it accepted it, and only for sandboxes created in native-network mode.
  • Enforcer scale-out. Enforcer replicas can each take a share of the nodes and receive only those nodes' sandboxes.
  • Activation and policy holds. A new sandbox reports EnforcerPending until the enforcer accepts its configuration, and EnforcerRejected with the enforcer's message if it refuses. A policy revision becomes current only after both the supervisor and the enforcer load it.
  • Credentials. The supervisor installs a rotated provider revision only after the enforcer accepts it. The enforcer can accept a rotation under the policy it already enforces while a policy update is rejected.
  • Default policy. A sandbox created without a policy gets the restrictive default policy, stored on the gateway, since the enforcer can't read the image's policy file.
  • Supported modes. The mode works with both shared supervisor topologies. The gateway refuses push configuration delivery and dedicated supervisors.
  • Mode switches. A sandbox keeps the mode it was created in. After the operator adds or removes external_enforcer, sandboxes created under the other mode are suspended and can't be restarted.

Out of scope: the enforcer itself, which the deployment provides, and compute drivers other than Kubernetes.

Suggested UX

externalEnforcer:
  enabled: true
  namespace: openshell-enforcer
  serviceAccountName: external-enforcer
  network:
    sandbox:
      networkAttachment: openshell-sandboxes/sandbox-vf
      resource: example.com/sandbox-vf
      nameservers: ["192.168.100.1"]
    supervisor:
      networkAttachment: openshell/supervisor-vf
      resource: example.com/supervisor-vf

gatewayConfig:
  openshell.gateway:
    config_delivery_mode: poll
  openshell.drivers.kubernetes:
    supervisor_topology: node
openshell sandbox create --name agent -- claude
openshell sandbox get agent
#   Conditions:
#     - ConfigurationReady: False EnforcerPending

openshell policy set agent --policy ./policy.yaml --wait
# Returns once both the supervisor and the enforcer load the revision,
# and fails with the enforcer's message if it rejects it.

Acceptance Criteria

  • Without external_enforcer, behavior is unchanged for every compute driver and supervisor topology. Agent traffic still goes through the supervisor's proxy, sandboxes never report EnforcerPending or EnforcerRejected, and the existing sandbox and Kubernetes e2e suites pass unchanged.
  • A gateway built without the experimental feature refuses to start with external_enforcer configured.
  • In native-network mode, a sandbox's agent traffic leaves on the configured network from the sandbox's own address, and its DNS goes to the configured nameservers.
  • A new sandbox reports EnforcerPending, and its agent doesn't start until the enforcer accepts its configuration. A rejection is reported as EnforcerRejected with the enforcer's message.
  • With no enforcer attached, new sandboxes stay pending and running sandboxes keep running.
  • openshell policy set --wait returns only after both the supervisor and the enforcer load the revision, and fails if the enforcer rejects it.
  • The sandbox doesn't receive a rotated credential until the enforcer accepts it.
  • The enforcer's identity can't launch or take over sandboxes, act as a sandbox's supervisor, call the gateway on a sandbox's behalf, or read sandboxes created outside native-network mode.
  • Helm rendering of externalEnforcer, gateway configuration validation and the enforcer's admission rules are covered by Helm and unit tests.
  • docs/how-it-works/gateways/configuration.mdx describes the configuration, what agents see in the mode, and the guarantees the enforcer and the deployment must provide for it to be safe.

Open Questions

  • The enforcer path has no e2e test, since it needs an enforcer on a Multus network. Should this PR add one with a stub enforcer, or is unit and Helm coverage enough while the mode is experimental?

Alternatives Considered

RFC 0029 covers these in full:

  • Gateway interceptors. An interceptor only sees API writes, not the global policy, the restrictive default or gateway-refreshed credentials. It can't hold an agent or report whether a revision was applied. The design uses an interceptor only to refuse policies the enforcer can't honor.
  • Supervisor middleware. Middleware runs in the supervisor's proxy, so agent traffic would still leave from the supervisor's address and an enforcer on the wire couldn't tell sandboxes apart.
  • Providers. Provider credentials are unchanged. The enforcer reads each sandbox's existing provider environment instead of a new provider type.
  • A supervisor isolation backend that calls the enforcer. It would make the enforcer depend on the supervisor, which the agent can reach, and duplicate the built-in runtime's controls.

For the rollout, the earlier plan split the work into two PRs, sandbox side then gateway side. Neither half is useful or testable alone, and both are inert without external_enforcer, so it lands as one PR behind experimental.

Related Work

Agent Investigation

  • A prototype exists on top of feat(k8s): run one shared supervisor per node #6074 and feat(k8s): support the additional destination CA with shared supervisors #6080: 18 commits, about 86 files, with unit and Helm tests and docs. The main changes:
    • crates/openshell-driver-kubernetes/src/config.rs and driver.rs: the external_enforcer table and its validation, the Pod network, resource, DNS and node selector, and the mode mark on each Sandbox.
    • crates/openshell-server/src/auth/supervisor_token.rs: the enforcer token, accepted only beside a Pod-bound token for the enforcer's ServiceAccount.
    • crates/openshell-supervisor-control/src/controller.rs: enforcer sessions on the host stream and shard filtering.
    • crates/openshell-server/src/grpc/policy/enforcer.rs and grpc/policy.rs: enforcer configuration reads and reports, and the activation, policy and credential holds.
    • crates/openshell-supervisor/ and crates/openshell-sandbox/src/network_broker.rs: no proxy or policy DNS, and agent sockets left to the kernel.
    • crates/openshell-sandbox-backend/src/runtime_routed.rs: one handshake per source past the shared cap, since agent sockets now reach the routed listener directly.

Checklist

  • I've reviewed existing issues and the published docs
  • This is a design proposal, not a "please build this" request

Activity

  1. added
    state:triage-needed
    on Dec 1, 2026
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

    state:triage-needed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions