Skip to content

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

Draft
Gal-Zaidman wants to merge 26 commits into
ai-openshell:mainfrom
Gal-Zaidman:feat/6122-native-network-enforcer/Gal-Zaidman
Draft

Gal-Zaidman wants to merge 26 commits into
ai-openshell:mainfrom
Gal-Zaidman:feat/6122-native-network-enforcer/Gal-Zaidman

Conversation

@Gal-Zaidman

Copy link
Copy Markdown
Contributor

Summary

Draft PR to triage the implementation of RFC 0029: an external network enforcer that enforces a sandbox's network policy and injects its credentials, and the Kubernetes native-network mode that gives it the agent's traffic. It is open to show the work to maintainers and is not ready for review; it depends on three open PRs and will be rebased after they land.

Related Issue

Closes #6122

Depends on:

Commit Range

The branch carries its dependencies, so GitHub shows 26 commits. Only the last 18 belong to this PR:

Commits Source
a2243ab07..633b7883e (6) #6074
09fe9d415 (1) #6080, an earlier revision of that PR
51b3a8218 (1) #6117
0f661b192..081896ea1 (18) This PR

To review only this PR's changes, compare 51b3a8218...081896ea1.

Changes

  • Configuration: a [openshell.drivers.kubernetes.external_enforcer] table selects native-network mode for every new sandbox. It requires the gateway or node supervisor topology, config_delivery_mode = "poll", and a gateway built with the experimental feature.
  • Enforcer identity: the enforcer authenticates with its own host token, accepted only with a Pod-bound projected ServiceAccount token checked by TokenReview. It attaches to the SupervisorHost stream, receives snapshots filtered by the node shards it declares, and can read and acknowledge sandbox configuration only.
  • Holds: a generation's agent starts only after the enforcer accepts its configuration (EnforcerPending and EnforcerRejected). A policy revision is current only once both the supervisor and the enforcer apply it. The supervisor doesn't install a credential revision the enforcer hasn't accepted, and the enforcer can accept a credential rotation while it rejects a policy update.
  • Data path: with the openshell.native_network claim, the sandbox runtime leaves the agent's sockets to the kernel, and the supervisor starts neither the egress proxy nor policy DNS. Workload DNS points at the configured resolvers.
  • Scheduling and networks: sandbox Pods and node supervisors schedule only to nodes labeled node-restriction.kubernetes.io/openshell-external-enforcer-ready=true. The supervisor and sandbox Multus networks are configured under the external_enforcer table.
  • Policy: native-network sandboxes without their own or a global policy get a restrictive default policy, and the image's policy.yaml is ignored. Built-in openshell/ middleware is refused in this mode.
  • Helm: externalEnforcer values, the enforcer token Secret and Role, and node-topology wiring, with Helm unit tests.
  • Sandbox backend: admits one handshake per source past the shared cap, and warns once per handshake slot exhaustion episode.
  • Docs: gateway configuration, sandbox runtimes, high availability, proto/README.md, and the debug-openshell-cluster skill.

Testing

Not yet verified on this branch as a whole; it will be once its dependencies land and it is rebased.

  • Checks appropriate to the affected code and behavior pass
  • Unit tests added/updated (if applicable)
  • E2E tests added/updated (if applicable)

Checklist

  • Follows Conventional Commits
  • Commits are signed off (DCO)
  • Architecture docs updated (if applicable)

Record the per-node model as the next one after the per-gateway model.
Each shared supervisor proves its Pod with a pod-bound token, a per-node
supervisor can claim only its own node's member ID, and a per-node
sandbox never falls back to a supervisor on another node.

Signed-off-by: Gal Zaidman <gzaidman@nvidia.com>
All shared supervisor Pods present the same gateway-minted supervisor token,
so anyone holding a copy of the token Secret could attach as a supervisor.
The gateway now accepts the supervisor token only beside a projected
ServiceAccount token (audience openshell-supervisor) that TokenReview and a
live-Pod check resolve to a Pod of shared_supervisor.service_account_name.

- shared_supervisor.service_account_name is required; the driver registers
  it with the controller, and the gateway refuses to start the topology
  without it.
- The supervisor sends the token from --identity-token-file in the
  x-openshell-host-identity-token header, re-read on every attempt.
- Helm renders the supervisor ServiceAccount without RBAC, runs the
  supervisor as it, and mounts a 10-minute projected token.

Signed-off-by: Gal Zaidman <gzaidman@nvidia.com>
Accept supervisor_topology = "node". The gateway records the node that a
supervisor's pod identity token proves on HostIdentity, and in the node
topology the driver binds pool members to nodes, so the gateway refuses
host streams whose pool member ID is not that node. Launches stay refused
until node-local placement lands.

Signed-off-by: Gal Zaidman <gzaidman@nvidia.com>
Carry the pool member through SharedSupervision::launch,
PlacementRequest, the stored assignment record, and recovery, and
restrict launch, takeover, and unowned placement of a pinned instance to
that member. With members bound to nodes, the pool never places an
unpinned instance: one launched under the gateway topology stays where
it is until the recovery timeout ends it.

In the node topology the Kubernetes driver ungates the workload Pod,
waits for the scheduler to bind it, launches on that node's supervisor,
records the member on the Sandbox resource for recovery, and creates the
bootstrap Secret last. Supervisors started with --node-supervisor
(OPENSHELL_SUPERVISOR_NODE) no longer leave the pool on shutdown, and a
suspended generation forgets its member.

Signed-off-by: Gal Zaidman <gzaidman@nvidia.com>
With supervisor_topology = "node", the chart renders the supervisor as a
DaemonSet on every node, started with --node-supervisor and with the
node name as each Pod's pool member ID. The Service keeps runtimes on
their own node with internalTrafficPolicy: Local, and the node topology
renders no PodDisruptionBudget or HPA. supervisor.tolerations and
supervisor.nodeSelector place supervisors on tainted or selected sandbox
nodes, such as GPU nodes.

Adds the e2e:kubernetes:shared-supervisor-node task on a two-node k3d
cluster, and documents the topology, its platform preconditions, and
that switching topologies ends running shared sandboxes.

Signed-off-by: Gal Zaidman <gzaidman@nvidia.com>
With supervisor_topology = "node", create and restart now return after
the driver removes the scheduling gate. The bootstrap launches on the
node once the scheduler binds the workload Pod, and a failed launch or a
Pod that isn't scheduled within runtime_bootstrap_grace_seconds is
logged and rolls the bootstrap back like any stale bootstrap.

A shared supervisor now marks its boundary as stopping on every
requested stop, so stopping a workload that is already gone no longer
waits for a reconnect to time out and stall later instance removals.

Update the Kubernetes HA docs, the driver README, and the
debug-openshell-cluster skill to match.

Signed-off-by: Gal Zaidman <gzaidman@nvidia.com>
The gateway no longer refuses [openshell.supervisor.network]
additional_ca_bundle with the shared supervisor topology. The Kubernetes
driver carries the normalized PEM in each generation's launch material,
and the shared host writes it to the instance's private directory for
the network supervisor to append. With a shared topology the gateway
refuses at startup a bundle that, with the supervisor OTLP TLS files,
exceeds 192 KiB, leaving 64 KiB for the rest of the launch material.

Older supervisors refuse launch material carrying the bundle, so
upgrade supervisors before configuring it.

Signed-off-by: Gal Zaidman <gzaidman@nvidia.com>
RFC 0029 lets an external enforcer enforce a native-network sandbox's
network policy and inject its credentials. It connects to the gateway as
a supervisor host in an enforcer role, reads configuration and provider
environment through the supervisor RPCs, and acknowledges with
ReportSandboxConfiguration. The gateway holds a generation's agent until
the enforcer accepts it, holds credential rotations until the enforcer
has them, and makes a policy revision current once both sides apply it.

The Kubernetes driver selects the mode with an external_enforcer table,
and RFC 0012 admits it as the one exception to egress mediation.

Signed-off-by: Gal Zaidman <gzaidman@nvidia.com>
[openshell.drivers.kubernetes.external_enforcer] declares an external
enforcer that enforces network policy outside the Pod. Its presence
launches every new sandbox in native-network mode: the driver writes the
resource claim openshell.native_network = "true" into the boundary config
and runtime descriptor, on the shared supervisor path only.

network.sandbox names a Multus network attachment that replaces every new
workload Pod's cluster network, an optional extended resource that the
driver requests once on the agent container, overriding caller values,
and the sandboxes' one to three distinct nameservers. A resource in the
kubernetes.io domain is refused. Resource admission accepts the
configured resource next to nvidia.com/gpu at create and when reconcile
re-admits stored specs. Validation requires supervisor_topology = "node"
and refuses a Multus annotation domain in allowed_pod_annotations.
Without the table, Pods are unchanged.

The gateway learns the mode and the resolvers through the new
ComputeDriverFactory::native_network hook, stores them on the compute
runtime, and refuses config_delivery_mode = "push" with the mode.

Signed-off-by: Gal Zaidman <gzaidman@nvidia.com>
Add external_enforcer.network.supervisor to the Kubernetes driver. With it
set, each new sandbox dials its node supervisor's address on that Multus
network instead of the supervisor Service ClusterIP. After the scheduler
binds the workload Pod, the driver lists the Pods the supervisor Service
selects on that node and reads the address of the named attachment from
their network-status. The launch fails when the node has no Ready
supervisor or no single agreed IPv4 address; unroutable addresses in
network-status are ignored. The setting refuses the supervisor app
listener, whose endpoints require the advertised runtime address to be
the Pod IP.

The supervisor gains --pool-advertise-interface, which advertises the
only non-link-local IPv4 address of an interface in place of
--pool-advertise-ip.

Helm renders externalEnforcer into the driver's external_enforcer table
and refuses a hand-written one. externalEnforcer.network.supervisor also
reaches the node supervisor DaemonSet: the net1 network annotation, the
device resource and the advertise interface. The gateway's peer Role
gains list on Pods in the supervisor namespace only when the supervisor
network is set.

Signed-off-by: Gal Zaidman <gzaidman@nvidia.com>
…ost token

The gateway mints an enforcer token from the supervisor token's authority
under its own type and subject, maps it to a supervisor principal in the
enforcer role, and admits it only to the assignment stream and the sandbox
configuration methods.

external_enforcer gains namespace and token_secret_name. The enforcer runs
in its own namespace, distinct from the supervisor's, and the Kubernetes
driver delivers the enforcer token to the token Secret there. Helm creates
that Secret in externalEnforcer.namespace with a Role that lets the gateway
update it.

Host identity becomes per role: each role's host token is accepted only
beside a pod-bound token for that role's ServiceAccount, with the role's own
audience, and a role without a registered account has every token refused.

Signed-off-by: Gal Zaidman <gzaidman@nvidia.com>
…st stream

An enforcer attaches with the enforcer token, a pod-bound identity token for
external_enforcer.service_account_name, and the configured sandbox
nameservers. Its sessions are kept apart from pool members and are sent the
pool's whole desired set by sandbox and generation, once a view was listed
after the stream attached.

external_enforcer gains service_account_name, the enforcer's ServiceAccount
in its namespace. Helm renders it from externalEnforcer.serviceAccountName and
lets the gateway get the enforcer's Pods there.

Signed-off-by: Gal Zaidman <gzaidman@nvidia.com>
An enforcer replica may declare HostStatus.enforced_shards, a shard count
and shard IDs. The gateway then sends it only the instances on nodes of
those shards, where a node's shard is the FNV-1a 32-bit hash of its name
modulo the count, and resends that replica a whole snapshot when its
declaration changes. Declared IDs may come in any order and repeat. A
replica that declares nothing receives every instance, as before.

Signed-off-by: Gal Zaidman <gzaidman@nvidia.com>
Both built-in descriptor decoders, the dedicated one and the routed one
for shared instances, read the openshell.native_network resource claim
into LaunchIdentity.native_network, exposed as
SelectedBackend::native_network(). The supervisor and the sandbox decide
the mode with the same helper, native_network_claimed.

Signed-off-by: Gal Zaidman <gzaidman@nvidia.com>
… on the native-network enforcer

In native-network mode the enforcer becomes a second party to each
sandbox's configuration. It selects a sandbox with the new
GetSandboxConfigRequest sandbox_id, which other callers must leave empty
and which the enforcer can't combine with a name or workspace scope, and
reads the configuration without the activation hold, with the runtime
generation as its instance ID. Its ACCEPTED or REJECTED report is stored
as SandboxStatus.enforcer_admission. A report for another generation is
refused, a report on a configuration that changed or that the gateway no
longer admits returns Aborted, and a rejection of a configuration the
enforcer already accepted is ignored. A restart that claims a new
generation resets the supervisor's admission, and an enforcer admission
for an older generation no longer counts. The Kubernetes driver
publishes the gateway's runtime generation on the sandbox resource so
the enforcer can match workload Pods to it.

Until the supervisor first accepts a configuration, its snapshot is not
admitted and sets activation_pending while the enforcer hasn't accepted
the current generation; the supervisor waits without reporting and logs
the hold as an OCSF event. Readiness reports EnforcerPending during the
hold and EnforcerRejected, with a False DesiredConfigurationReady
condition, while the enforcer refuses the configuration; a provisioning
deadline that expires on a rejection keeps its reason.

A policy revision becomes current only once both sides accept it, and
policy status reports a revision only the supervisor loaded as PENDING. An
enforcer rejection names the revision by version and marks it failed
without overwriting a supervisor failure; a later acceptance returns it to
the status the supervisor's result gives it. The CLI policy wait explains
when only the enforcer is outstanding, and the TUI shows the rejection.

The enforcer substitutes static credentials for the placeholders the
workload holds, so its GetSandboxProviderEnvironment read carries each
static credential's workload placeholder, computed with the new
openshell_core::secrets::workload_placeholder helper the supervisor's
resolver also uses. A polling native-network supervisor installs a rotated
provider revision only once it equals the snapshot's
enforcer_provider_env_revision. The enforcer runs the middleware chain, so
native-network snapshots carry no supervisor middleware services and
built-in openshell/ middleware is rejected.

The enforcer must request the provider environment with both placeholder
capabilities. A supervisor that echoes an enforcer rejection keeps the
EnforcerRejected reason. The Kubernetes driver marks each Sandbox with the
mode it was created in and suspends, and refuses to restart, a sandbox
created under the other mode.

Signed-off-by: Gal Zaidman <gzaidman@nvidia.com>
Native-network mode no longer requires supervisor_topology=node. In the
gateway topology the driver launches a native-network sandbox once its
workload Pod is scheduled and records the node with the pool instance and in
the Sandbox's openshell.ai/sandbox-runtime-node annotation, so enforcer
shards select it. Records written before the node fall back to their pinned
member, which is the node in the node topology.

Signed-off-by: Gal Zaidman <gzaidman@nvidia.com>
…ndboxes

With LaunchIdentity.native_network, startup starts neither the egress
proxy nor policy DNS and skips the agent trace relay: the external
enforcer filters the workload's connections and answers its DNS. The
supervisor still writes the workload's trust files and never reads the
image's policy.

Signed-off-by: Gal Zaidman <gzaidman@nvidia.com>
A sandbox whose descriptor carries the openshell.native_network claim runs
in the native-network mode for its life. An external enforcer filters the
workload's connections, so the workload listener notifies only signals and
opens and the broker creates no INET sockets. The DNS relay is unchanged:
it serves only registered sockets, so it serves nothing in this mode. The
sandbox emits one ConfigStateChange event when the mode is enabled.

Node and Deno trust the combined CA bundle, so they accept the operator's
additional CA, which holds the enforcer's CA when it terminates TLS.

The gateway configuration docs describe the mode, what agents see in it,
and the guarantees the deployment must provide.

Signed-off-by: Gal Zaidman <gzaidman@nvidia.com>
A native-network workload's sockets reach the routed runtime listener
directly, so one sandbox could hold every shared handshake permit and
lock the other sandboxes out of their supervisor. Each canonicalized
source IP now gets one handshake outside the shared bound of 64, for up
to 1024 sources. The external enforcer pins each Pod's source address,
so a sandbox can't take other sources' slots.

Signed-off-by: Gal Zaidman <gzaidman@nvidia.com>
The workload Pod's dnsConfig of every native-network sandbox names the
sandbox network's nameservers instead of the supervisor's policy DNS, and
the launch posture check holds the Pod to them, so the enforcer answers and
filters the workload's DNS. A restart applies the current list.

Signed-off-by: Gal Zaidman <gzaidman@nvidia.com>
… sandboxes

In native-network mode a sandbox created without a policy gets the
restrictive default policy stored on the gateway. The external enforcer
programs the network from the stored policy, so the image's
/etc/openshell/policy.yaml is ignored in this mode.

Signed-off-by: Gal Zaidman <gzaidman@nvidia.com>
…odes

In native-network mode the Kubernetes driver adds
node-restriction.kubernetes.io/openshell-external-enforcer-ready: "true" to
every workload Pod's nodeSelector, overriding a caller's value for that
key, and Helm gives the node supervisor DaemonSet the same selector. The
enforcer must keep that label on exactly the nodes where it enforces, so a
sandbox never lands on a node it doesn't cover. Pods stay Pending while no
node carries the label.

Signed-off-by: Gal Zaidman <gzaidman@nvidia.com>
A gateway built without the experimental feature bundle refuses to start
with the Kubernetes driver's external_enforcer configured, so stable builds
never run sandboxes in native-network mode.

Signed-off-by: Gal Zaidman <gzaidman@nvidia.com>
…e credentials past a rejected policy

The enforcer reads and reports only for sandboxes created in native-network
mode that have a runtime generation, never a stock sandbox left from before
the mode was enabled.

While the enforcer holds back a policy update, it may accept the current
provider revision under the policy it already enforces. The supervisor then
installs the rotated credentials, and the rejected update stays reported.

Signed-off-by: Gal Zaidman <gzaidman@nvidia.com>
Signed-off-by: Gal Zaidman <gzaidman@nvidia.com>
…isode

Draining the free slots to half the cap re-arms the warning, so a listener
that is exhausted again later warns again.

Signed-off-by: Gal Zaidman <gzaidman@nvidia.com>
@github-actions github-actions Bot added the state:accepted A maintainer decided OpenShell should pursue this issue label Dec 2, 2026
@levyshira

levyshira commented Dec 3, 2026 •

Copy link
Copy Markdown

Medium / P2 — Require an exact supervisor load result before advancing the policy version

Taking the minimum of these version numbers can make a
revision current even though the supervisor never loaded that revision.

For example, start with v1 current. The enforcer accepts v2, then v3 is
published before the supervisor's next poll. The supervisor skips v2 and
reports v3 loaded. This expression selects min(3, 2) and advances
current_policy_version to v2, without checking whether v2 was loaded.

The gateway then reports v2 as current and resets endpoint status using
v2's inventory, although the supervisor loaded v3 and the enforcer
accepted v2.

Please require a successful supervisor load result for the exact revision
being advanced. A successful load of a higher-numbered revision does not
establish that an earlier revision was loaded.

crates/openshell-server/src/grpc/policy.rs, lines 5599–5601.

@levyshira

Copy link
Copy Markdown

Medium / P2 — Wait for enforcer acceptance of the provider revision during startup

Any accepted enforcer admission for the runtime generation
releases the startup hold, even when its provider_env_revision differs
from the revision in this snapshot.

If the enforcer accepts provider revision R1 and credentials rotate to R2
before supervisor startup completes, the supervisor can receive an admitted
R2 snapshot while enforcer_provider_env_revision is still R1. The startup
path only checks that the fetched environment matches the snapshot; it
does not check that the enforcer accepted that provider revision.

For credentials with revision-dependent placeholders, the agent can
therefore start using R2 placeholders before the enforcer has installed
the corresponding mapping in Tower. Tower still has the R1 configuration,
so provider requests can fail until it catches up.

Please apply the provider-revision acceptance gate during startup as well
as in ConfigRuntime's polling path. In native-network mode, do not install
a provider revision until the enforcer has accepted it.

crates/openshell-server/src/grpc/policy/enforcer.rs, lines 178–180.
crates/openshell-supervisor/src/lib.rs, lines 3307–3316.

This branch has not been deployed

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

Labels

state:accepted A maintainer decided OpenShell should pursue this issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants