From 23de35229abb812a17f58261d989af9f8e9b08db Mon Sep 17 00:00:00 2001 From: Gal Zaidman Date: Thu, 19 Nov 2026 01:07:31 +0200 Subject: [PATCH] docs(rfc): propose the external network enforcer and native-network mode 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 --- rfc/0012-isolation-backend/README.md | 10 +- rfc/0029-external-network-enforcer/README.md | 457 +++++++++++++++++++ 2 files changed, 464 insertions(+), 3 deletions(-) create mode 100644 rfc/0029-external-network-enforcer/README.md diff --git a/rfc/0012-isolation-backend/README.md b/rfc/0012-isolation-backend/README.md index 85385bdc50..61629e6391 100644 --- a/rfc/0012-isolation-backend/README.md +++ b/rfc/0012-isolation-backend/README.md @@ -320,7 +320,7 @@ struct PendingDnsQuery { Every backend may use the same supervisor-owned mediation libraries or services; the source does not require a backend-specific policy engine. -Shared implementations isolate each boundary's state and enforcement. Failure or teardown of one boundary cannot weaken another. Network-mediation unavailability never enables direct egress. +Shared implementations isolate each boundary's state and enforcement. Failure or teardown of one boundary cannot weaken another. Network-mediation unavailability never enables direct egress. The only exception is [native-network mode](#native-network-mode). ### Binary identity @@ -345,7 +345,7 @@ If binary identity cannot be resolved, the connection is denied. `ResolveError` Every identity field used for authorization is obtained by a trusted component from boundary or kernel state, rather than accepted as a workload claim. The result is bound to the active boundary and accepted connection; a transport tuple or workload-supplied identifier alone is not authoritative. Workload-supplied identity may be retained only as non-authorizing diagnostic context. If attribution is ambiguous or any required identity field cannot be established, the connection is denied. -Binary identity is mandatory conformance: RFC 0002 makes it part of the outbound-policy baseline. There is no capability flag and no mode that exempts a backend from resolving identity. +Binary identity is mandatory conformance: RFC 0002 makes it part of the outbound-policy baseline. There is no capability flag and no mode that exempts a backend from resolving identity for the connections it accepts; see [Native-network mode](#native-network-mode). ### The supervisor sequence @@ -389,6 +389,10 @@ Whenever a boundary ends, the backend terminates remaining workload processes an The contract fixes the roles; each compute driver decides where they run. Components may be co-located with the workload or hosted in trusted services, and one component may implement multiple roles. Every arrangement preserves the same lifecycle, interfaces, and invariants. Actual containment depends on the workload's kernel relationship to the trusted components. The non-normative [driver placement guide](./driver-placement.md) describes the supported mappings. +### Native-network mode + +*Amendment.* A backend may stop mediating agent egress only when a protected resource claim says an external enforcer enforces the sandbox's network policy ([RFC 0029](../0029-external-network-enforcer/README.md)). For agent egress in that mode, invariant 1, the network-mediation clause of invariant 3, the network-mediation sentence of invariant 6, and binary identity don't apply, and the supervisor calls `confirm` without connecting the boundary's network-mediation source (step 4 of its sequence). Every other control and invariant applies, and workload input can't select or change the mode. RFC 0029 also defines the selection, the behavior of the built-in backend, and the enforcer's requirements. + ## Conformance Every admitted backend and compute driver must pass tests for the six contract invariants plus descriptor verification, lifecycle ordering, runtime operations, and failure semantics. @@ -443,4 +447,4 @@ That would make known deployments explicit, but it would also encode current pla ## Open questions -None. +- Should the conformance suite gain a native-network profile that checks the in-boundary controls the mode keeps? diff --git a/rfc/0029-external-network-enforcer/README.md b/rfc/0029-external-network-enforcer/README.md new file mode 100644 index 0000000000..202e039bd0 --- /dev/null +++ b/rfc/0029-external-network-enforcer/README.md @@ -0,0 +1,457 @@ +--- +authors: + - "@Gal-Zaidman" +state: draft +links: + - https://github.com/ai-openshell/openshell/issues/6024 +--- + +# RFC 0029 - External Policy Enforcer + +## Summary + +Let an external policy enforcer, instead of the supervisor, enforce a +sandbox's network policy and inject its credentials. The external policy +enforcer attaches to the gateway on the existing `SupervisorHost` stream with +a separate external policy enforcer role and token. It learns which sandbox +generations exist from that stream, reads their configuration and provider +environment through the existing supervisor RPCs, and reports what it enforces +with `ReportSandboxConfiguration`. The gateway keeps the supervisor and the +external policy enforcer in step: a generation's agent doesn't start until the +external policy enforcer accepts its configuration, the supervisor doesn't +install a credential revision the external policy enforcer hasn't accepted, +and a policy revision stays pending until both have applied it. + +To give the external policy enforcer the agent's traffic, sandboxes it serves +run in native-network mode: the agent's sockets belong to the kernel and leave +on the network interface the external policy enforcer owns, without the +supervisor's proxy. The operator selects the mode by configuring the +Kubernetes driver's `external_enforcer`. Without an attached external policy +enforcer, new sandboxes stay pending rather than run unenforced. + +## Motivation + +Many products enforce network policy outside the workload, for example on a +device that owns each sandbox's network interface. Deployments that run one +want it to enforce the OpenShell policy rather than duplicate that enforcement +in the sandbox supervisor. To do so, the external policy enforcer needs each +sandbox's effective policy and credentials, and OpenShell needs to know the +external policy enforcer applied them before the agent runs, to prevent the +agent from running unenforced. OpenShell has no way to hand either to an +external component today. + +The stock data path also defeats such an external policy enforcer. The sandbox +runtime intercepts every socket the agent opens and the supervisor proxies the +connection, so all agent traffic leaves from the supervisor's address. An +external policy enforcer on the wire sees one source for every sandbox on a +node and can't apply each sandbox's policy. + +## Non-goals + +- How the external policy enforcer filters traffic or injects credentials on + the wire. +- A stable public API for external policy enforcers: the external policy + enforcer uses the private `SupervisorHost` service and is released alongside + it. +- Enforcing filesystem or process policy externally; the supervisor keeps + enforcing both in the sandbox. +- Compute drivers other than Kubernetes, and dedicated supervisors. +- Choosing the mode or the pod network per sandbox; both are deployment + decisions. + +## Proposal + +### Overview + +| Component | Owns | Credential | +| ------------------------ | -------------------------------------------------------------------------------------------------------------------- | ------------------------------- | +| Gateway | Desired state, the holds, and the two-sided status. | — | +| Supervisor host | Its assigned instances: launch, runtime control, `exec`, SSH, filesystem and process policy. | Supervisor token. | +| External policy enforcer | Network policy and credential injection for every native-network instance. | External policy enforcer token. | +| Gateway interceptor | Refuses requests the external policy enforcer can't honor, as in [RFC 0010](../0010-gateway-interceptors/README.md). | Gateway-minted extension token. | + +The gateway trusts the external policy enforcer to report what it enforces. +The external policy enforcer receives each sandbox's policy and provider +credentials, but never launch material, takeover grants or sandbox tokens, and +it can't act as a supervisor. + +Users see three differences from a stock sandbox. A new sandbox waits in +`EnforcerPending` until the external policy enforcer accepts it, or reports +`EnforcerRejected` with the external policy enforcer's message. `openshell policy set --wait` returns once both the supervisor and the external policy +enforcer apply the revision, and fails when the external policy enforcer +rejects it. A policy using a feature the external policy enforcer can't honor +is refused at the API. + +```mermaid +sequenceDiagram + participant U as User + participant G as Gateway + participant D as Kubernetes driver + participant E as External policy enforcer + participant S as Supervisor + participant A as Agent + U->>G: CreateSandbox + G->>G: store restrictive default policy + G->>D: provision generation + D->>D: schedule Pod to a node the external policy enforcer marks ready + E->>G: Attach (HostHello with EnforcerHello) + G-->>E: AssignmentSnapshot lists the generation + E->>G: GetSandboxConfig, GetSandboxProviderEnvironment + E->>G: ReportSandboxConfiguration ACCEPTED + S->>G: GetSandboxConfig (activation_pending until accepted) + S->>A: start the agent + A->>E: egress on the external policy enforcer's interface +``` + +### Native-network mode + +**Selection.** The mode is driver configuration: + +```toml +[openshell.drivers.kubernetes.external_enforcer] +namespace = "openshell-enforcer" +token_secret_name = "openshell-external-enforcer-token" +service_account_name = "external-enforcer" + +[openshell.drivers.kubernetes.external_enforcer.network.sandbox] +network_attachment = "openshell-sandboxes/sandbox-vf" +resource = "example.com/sandbox-vf" +nameservers = ["192.168.100.1"] + +# Optional. +[openshell.drivers.kubernetes.external_enforcer.network.supervisor] +network_attachment = "openshell/supervisor-vf" +resource = "example.com/supervisor-vf" +``` + +With `external_enforcer` configured, every new sandbox runs in +native-network mode, and a sandbox runs only under the mode it was created +in. `network.sandbox` makes a Multus network attachment the workload Pod's +only network, with an extended resource such as an SR-IOV device as its +interface. The optional `network.supervisor` attaches supervisors to a +network; in the node topology it points each sandbox runtime at its node +supervisor's address there. Both live under `external_enforcer` because neither is safe without +one: a sandbox network the supervisor doesn't mediate and no external policy +enforcer filters would leave egress unenforced. + +The mode requires a shared supervisor topology of [RFC +0018](../0018-multi-sandbox-ha-supervisors/README.md) and +`config_delivery_mode = "poll"`; the gateway refuses to start otherwise. In +both topologies the workload dials its supervisor, and the external policy +enforcer makes the supervisor's address reachable over the sandbox network. +The driver launches a sandbox only after its workload Pod is scheduled, and +records the node. It schedules workload Pods, and node supervisors, only to +nodes the external policy enforcer labels +`node-restriction.kubernetes.io/openshell-external-enforcer-ready=true`, and +refuses pod annotations that would add a network interface the external policy +enforcer doesn't own. The gateway reads the mode and the resolvers at startup, +and they can't change while it runs. + +**Data path.** The driver marks each instance with the protected resource +claim `openshell.native_network`, delivered to both the supervisor and the +sandbox runtime, which must agree. With the claim, the sandbox runtime stops +intercepting the agent's socket calls, so the kernel owns the agent's sockets. +Every other control is unchanged, including Landlock, the socket-domain +allowlist and the other seccomp blocks, `exec`, SSH and the freeze on control +loss, and the runtime emits one OCSF event recording the mode. The supervisor +starts neither the egress proxy nor policy DNS, and doesn't offer the agent +trace relay. Instead, the driver points the workload's DNS at the resolvers, +so the external policy enforcer sees names as well as connections. The +supervisor still writes the workload's trust files, whose bundle includes the +external policy enforcer's CA. + +### Connecting the external policy enforcer + +**Identity.** The driver keeps the external policy enforcer token in +`token_secret_name` in the external policy enforcer's own namespace, and the +gateway accepts that token only beside a Pod-bound token for +`service_account_name` there. The external policy enforcer needs nothing from +the supervisor's namespace. + +**Reporting.** The external policy enforcer reports through the supervisor's +`ReportSandboxConfiguration`, with the same rules: it reports `ACCEPTED` or +`REJECTED` with the `policy_version`, `policy_hash`, `config_revision` and +`provider_env_revision` it programmed. A report for another instance is +`FAILED_PRECONDITION`, one that doesn't match the current configuration is +`ABORTED`, and a rejection doesn't revoke an earlier acceptance. The gateway +stores the result in a new `SandboxStatus.enforcer_admission`, separate from +the supervisor's admission. + +The report differs from the supervisor's in three ways. + +- It names the runtime generation rather than a supervisor instance. +- Its rejection message reaches users, because the operator trusts the + external policy enforcer. +- The supervisor reports loading a revision separately with + `ReportPolicyStatus`, while the external policy enforcer has no such call. + Its acceptance lets the revision become current once the supervisor has + loaded it too, and its rejection of a newer revision marks that revision + failed. + +**Teardown.** Teardown isn't gated: when a generation leaves the snapshot, +the external policy enforcer removes its enforcement. + +**Replicas.** The external policy enforcer can run several replicas, and the +gateway takes any replica's report as the external policy enforcer's. Without +shards, every replica's stream receives the same snapshot and splitting work +between replicas is the external policy enforcer's concern; with +[node shards](#node-shards-optional), each replica receives only the +generations on its nodes. + +### Keeping the supervisor and external policy enforcer in step + +**Initial policy.** In stock OpenShell, the supervisor reads a sandbox's +policy from its image when it starts, or falls back to the restrictive +default, and writes it to the gateway. In this mode the external policy +enforcer must accept a policy before the workload can reach its supervisor, so +the gateway stores the restrictive default when it creates a sandbox with +neither its own nor a global policy, and the image's policy file isn't read. + +**Activation hold.** Until the external policy enforcer first accepts a +native-network generation, the supervisor waits without reporting a rejection, +and the sandbox's `ConfigurationReady` condition reports `EnforcerPending`. If +the external policy enforcer rejected the current configuration, the +configuration is unadmitted with its message and the condition reports +`EnforcerRejected`. After the first acceptance the hold no longer applies, +including across a supervisor takeover; the external policy enforcer keeps +enforcing the configuration it accepted until it accepts a newer one. + +**Two-sided policy status.** A sandbox's current policy version advances only +to the lowest version both the supervisor and the external policy enforcer +have applied, and `GetSandboxPolicyStatus` and `ListSandboxPolicies` report +the newer revision `PENDING` until then. + +**Credential install hold.** The supervisor's configuration carries the +provider revision the external policy enforcer accepted, and a native-network +supervisor doesn't install a newer one, so new processes don't present +placeholders the external policy enforcer doesn't know, outside the startup +window described in [Risks](#risks). This is why the mode requires poll +delivery: under push delivery the supervisor would acknowledge a revision it +hasn't installed. While the external policy enforcer holds back a policy +update, it may accept the current provider revision under the policy it +already enforces, so a rejected update doesn't stall credential rotation. + +**Middleware.** The supervisor runs no network middleware in this mode. +Middleware the external policy enforcer serves is registered as ordinary +supervisor middleware, so the gateway's existing `Describe` and +`ValidateConfig` checks apply, and policies naming built-in `openshell/` +middleware are refused. + +**Policy refusals.** An external policy enforcer may not support every policy +feature. It should also register as a gateway interceptor, as in +[RFC 0010](../0010-gateway-interceptors/README.md), and refuse policy and +provider requests it can't enforce, so users get the error from the API +instead of from a held sandbox. Anything that reaches a sandbox anyway is +reported `REJECTED`, and the holds keep the agent from running under it. + +Every failure leaves the agent stopped or restricted: + +| Situation | Result | +| --- | --- | +| No external policy enforcer attached | New generations stay `EnforcerPending` until the provisioning deadline; running sandboxes keep running. | +| No replica declares a node's shard | New generations on that node stay `EnforcerPending`; running ones keep the enforcement they have. | +| External policy enforcer rejects a new generation | The configuration is unadmitted with the external policy enforcer's message. | +| External policy enforcer hasn't applied a policy revision | The revision stays `PENDING`. | +| Credential rotation the external policy enforcer doesn't know | The supervisor doesn't install it. | +| Resolvers differ from the driver's | The external policy enforcer's hello is rejected. | +| Push delivery configured | The gateway refuses to start. | +| Sandbox from the other mode | The driver suspends it and refuses its restart. | + +### Security and deployment requirements + +The mode is safe only when the external policy enforcer: + +- denies all sandbox traffic by default, as the driver's NetworkPolicy + fences do in stock mode; +- checks every packet leaving the sandbox, of any IP protocol, against the + sandbox's policy and drops the rest; +- answers the workload's DNS at `network.sandbox.nameservers`; +- accepts traffic from a sandbox's interface via workload's source addresses only (anti-spoofing); +- admits no new inbound connections and drops sandbox-to-sandbox traffic; +- lets the workload reach only the supervisors' runtime port, rate-limited; +- terminates TLS itself when the policy intercepts TLS, publishing the CA the + sandbox trusts; +- injects the credentials of the sandbox's providers; +- doesn't accept a network interface whose previous holder it hasn't + cleared, and reports only for sandboxes it enforces. + +The sandbox network must have the external policy enforcer on its path and +must route to the supervisor's address. The driver still writes its deny-all +egress NetworkPolicy for every workload Pod, so the sandbox network must not +enforce Kubernetes NetworkPolicy; enforcing what those policies define in stock +mode is the external policy enforcer's responsibility. The external policy enforcer runs in its own +namespace under its dedicated service account, and only its Pods may run as +that account or read its token Secret. OpenShell can't verify these requirements; the deployment +documentation lists them. + +### Node shards (optional) + +Shards are optional: a replica that declares none receives every sandbox. +They let several replicas split the nodes, so each receives only its share. + +- A replica declares a shard `count` and its shard `ids` in + `HostStatus.enforced_shards`, on every status. +- A node's shard is `fnv1a_32(node_name) % count`. A sandbox's node is the + node its workload runs on, in either supervisor topology; a restart can + move it to another node and shard. +- The gateway sends the replica only sandboxes on nodes of its shards, and + a whole snapshot when the declaration changes. +- The gateway doesn't place, fence or rebalance shards; that is the external + policy enforcer's decision. + +When it declares shards, the external policy enforcer must: + +- use one shard count on every replica; +- let one replica at a time write a node, and stop a replica's writes before + another takes its shards; +- remove enforcement only on nodes of its own shards; +- adopt a taken-over node's enforcement and clean up sandboxes deleted or + moved off the node while no replica held the shard; +- keep every shard held, or new sandboxes on uncovered nodes stay + `EnforcerPending`. + +### Amendment to RFC 0012 + +[RFC 0012](../0012-isolation-backend/README.md) gains a native-network +section: a backend may stop mediating agent egress only when a protected +resource claim says an external policy enforcer enforces the sandbox's network +policy. For agent egress in that mode, invariant 1, the network-mediation +clause of invariant 3, the network-mediation sentence of invariant 6, and +binary identity don't apply, and the supervisor confirms the runtime without +connecting the network mediation source. Every other control and invariant +applies, and workload input can't select or change the mode. + +## Implementation plan + +The mode needs only the gateway supervisor topology of +[RFC 0018](../0018-multi-sandbox-ha-supervisors/README.md), which is already +on `main`. Support for the node topology lands separately, with that topology. The mode +ships behind the gateway's `experimental` feature until it has run end to end +against an external policy enforcer. Each phase below ships its docs and tests +and is inert without `external_enforcer`: + +1. Selection: the `external_enforcer` table, its sandbox and supervisor + networks and their validation, the push-delivery refusal, the claim, the + resolvers, the restrictive default policy, and the ready-node selector. +2. Data path: the supervisor without the egress proxy, policy DNS or trace + relay, and the sandbox runtime's reduced notification filter. +3. External policy enforcer identity: the external policy enforcer token, its + role, the method allow-list, the Secret, and the Pod-bound identity token. +4. External policy enforcer session: `EnforcerHello`, external policy enforcer + sessions in the supervisor host controller, the snapshot rules, each + generation's node, and the shard declaration and snapshot filter. +5. Holds: `GetSandboxConfig` by sandbox ID, the external policy enforcer's + report, the activation and credential install holds, two-sided status, + `workload_placeholder`, and the middleware rules. +6. A reference external policy enforcer, kept outside the core build. + +Validation: unit tests for Pod rendering, admission, the claim, the +resolvers, the filter, the skipped supervisor runtimes, the token, the +snapshot rules, the shard filter and its resend, and each hold; Helm unit +tests for the chart values; the stock sandbox and Kubernetes e2e unchanged +without the settings; and the full path against an external policy enforcer +that meets the requirements, including a supervisor Pod replacement and the +loss of the replica holding a node's shard. + +## Risks + +- **The external policy enforcer is trusted.** OpenShell trusts it to + implement the network controls the supervisor implements in stock mode, + including L7 rules, binary identity, middleware and credential injection, + and to refuse what it doesn't implement, as in + [Policy refusals](#keeping-the-supervisor-and-external-policy-enforcer-in-step). + An external policy enforcer that accepts without enforcing, or a deployment + that misses a requirement, leaves egress unenforced, and OpenShell can't + detect it. +- **Availability depends on the external policy enforcer.** New sandboxes + don't start while no external policy enforcer is attached, and an external + policy enforcer that stops answering DNS breaks name resolution for every + sandbox on its node. `EnforcerPending` and the provisioning deadline make + the first visible. +- **Policy windows.** A policy change, or a supervisor takeover, takes effect + only after both the supervisor and the external policy enforcer apply it. + Until both do, the new revision is reported `PENDING`, and the sandbox can + run under either the previous policy or the new one. Requests with + credential placeholders the external policy enforcer doesn't know yet fail + closed. +- **Misconfigured networks strand sandboxes.** A sandbox network that can't + reach the supervisor, or a supervisor network without stable addresses, + fails launches until the recovery timeout. The debug guide shows how to + check a Pod's network status. + +## Alternatives + +### Do nothing + +Without this mode, an external policy enforcer can only sit on the +supervisor's network, where every sandbox on a node shares the supervisor's +source address, so it can't apply each sandbox's policy. Deployments that +need one stay off OpenShell. + +### Other ways to select the mode + +The external policy enforcer could declare at gateway startup that it enforces +the network policy, and the declaration would select the mode. That needs the +external policy enforcer reachable before the gateway starts and a second +channel from the gateway to the external policy enforcer. The activation hold +already ties the mode to an external policy enforcer: configuring the mode +without one leaves new sandboxes pending, not unenforced. + +The mode could also be a new isolation backend name. It changes a few +behaviors of the built-in sandbox runtime and keeps everything else, so a new +backend would duplicate process launch, identity, and every other control. + +### A separate policy-provider service + +A new gRPC service the gateway calls to program each sandbox, with its own +capability negotiation, reconciliation loop and status. It duplicates the +supervisor protocol's desired state, admission and authentication, and puts +a synchronous dependency in the gateway's policy handlers. + +### The external policy enforcer as a supervisor + +The external policy enforcer could reuse the supervisor token, or connect once +per sandbox as a sandbox's supervisor does. Either way it would hold launch +material and sandbox tokens it shouldn't, could take over instances, and would +cost the gateway one session per sandbox per external policy enforcer. A role +claim on the supervisor token doesn't fix this: during a rolling upgrade, an +older replica that ignores the claim accepts the external policy enforcer as a +supervisor. + +### Gateway-assigned nodes + +The gateway could assign nodes to replicas itself, with per-node owner +records in the supervisor pool, rebalancing, a handover delay and a write +fence sent in `HostAccepted`. This puts placement, fencing and durable +records in the gateway for one consumer, and ties the fence to gateway view +staleness. The external policy enforcer can instead elect a writer per shard +with platform primitives such as Kubernetes Leases. + +## Prior art + +- Envoy's xDS protocol has the control plane push versioned configuration and + each data plane acknowledge or reject every version. The control plane + tracks what each consumer applied instead of assuming delivery; the external + policy enforcer's `ACCEPTED` and `REJECTED` reports and the two-sided policy + status follow the same model. +- Kubernetes NetworkPolicy is declared centrally and enforced by the cluster's + network plugin, and a cluster whose plugin doesn't implement it silently + ignores it. The activation hold avoids that failure: without an external + policy enforcer, sandboxes stay pending instead of running unenforced. +- Kubernetes controllers elect a single writer with a Lease and step down + before it expires; external policy enforcer replicas can hold one per shard + the same way. +- [RFC 0012](../0012-isolation-backend/README.md) defines the mediation + requirement this mode is the exception to. +- [RFC 0018](../0018-multi-sandbox-ha-supervisors/README.md) defines the + supervisor host, the pool and its snapshots, and the shared topologies + this mode depends on. +- [RFC 0009](../0009-supervisor-middleware/README.md) and [RFC + 0010](../0010-gateway-interceptors/README.md) define the middleware registry + the external policy enforcer's middleware joins and the interceptors its + refusals use; [RFC 0023](../0023-credential-issuer-service/README.md) + defines the provider environment and its placeholders. + +## Open questions + +None.