Files
OpenShell/crates/openshell-driver-kubernetes
Jesse Jaggars 2c31ac7e60 feat(network): support additional destination CAs (#3292)
* feat(network): support additional destination CAs

Signed-off-by: Jesse Jaggars <jjaggars@redhat.com>

* fix(network): harden additional CA propagation

Signed-off-by: Jesse Jaggars <jjaggars@redhat.com>

* fix(network): narrow additional CA review scope

Signed-off-by: Jesse Jaggars <jjaggars@redhat.com>

* fix(network): harden additional CA rotation

Signed-off-by: Jesse Jaggars <jjaggars@redhat.com>

* feat(network): complete additional CA delivery

Signed-off-by: Jesse Jaggars <jjaggars@redhat.com>

* fix(docker): remove stale runtime fixture field

Signed-off-by: Jesse Jaggars <jjaggars@redhat.com>

* fix(network): adapt additional CA series to upstream main

Resolve rebase fallout against current upstream main after the series was
rebased 214 commits forward:

- follow upstream #3110: supervisor→gateway TLS is CA-only, so
  configure_gateway_tls and its isolation tests drop the client identity
- follow upstream tls_secret_names reduction to [String; 1] in the Podman
  driver while keeping the network trust bundle delivery
- port [openshell.supervisor.network] rendering into the
  openshell.gatewayConfigToml serializer in _toml.tpl
- adapt tests to upstream struct/function changes (DriverStartupContext,
  SandboxRunConfig, IsolationSpecInput, supervisor_pod, VM bootstrap image)
- drop conformance-artifact-prefix plumbing removed upstream

Signed-off-by: Jesse Jaggars <jjaggars@redhat.com>

* refactor(network): adopt upstream additional CA bundle surface

Unify the additional destination CA series on the mechanism merged to
main in #3996: one operator pre-assembled PEM bundle, the
--additional-ca-bundle supervisor flag, and the
/etc/openshell/tls/additional/ca-bundle.pem staging path.

- Replace the gateway-level additional_ca_cert_paths list with a single
  additional_ca_bundle file validated and staged at gateway startup.
- Restore the upstream supervisor argument path and fold-into-roots
  behavior; drop the --network-additional-ca-bundle and
  --network-additional-ca-digest contracts.
- Keep gateway normalization bounds, content-addressed staging,
  digest-based driver reconciliation, and stop/start rotation; the
  freshness check now runs at the gateway/driver boundary instead of
  the supervisor boundary.
- Reject additional_ca_bundle in operator driver JSON config; standalone
  drivers self-source the bundle from --sandbox-additional-ca-bundle
  with the same validation.
- Extend the Kubernetes ConfigMap name digest segment to keep the full
  63-byte budget after the prefix rename.
- Box the persisted-sandbox reconciliation futures so callers stay
  under the clippy::large_futures threshold.

Updates Docker, Podman, Kubernetes, and VM delivery, Helm chart and
tests, e2e wiring, gateway configuration docs, and the cluster
debugging skill to the single mechanism.

Signed-off-by: Jesse Jaggars <jjaggars@redhat.com>

* fix(ci): make gateway startup tests wrap-tolerant and refresh example lockfile

The network trust startup tests asserted on raw substrings of gateway
diagnostics, but the CLI renderer wraps output at a fixed width with
continuation markers and hard-breaks long paths. Compare assertions on
whitespace- and continuation-squashed text so they hold regardless of
wrap position.

Format the e2e workspace (separate cargo workspace, not covered by the
root cargo fmt run) and refresh examples/isolation-backend-v8/Cargo.lock
for the libc dependency added to the network trust crate.

Signed-off-by: Jesse Jaggars <jjaggars@redhat.com>

* fix(podman): reuse TLS CA secret during stopped-pair trust replacement

The additional CA e2e never ran in CI before the first maintainer test
dispatch, and its local container inspection was broken in two ways: it
located the supervisor container through e2e network membership (the
supervisor is host-networked or runtime-bridged, so the filter matched
the CI job container instead), and it required the gateway mTLS CA as a
bind mount (Podman delivers it as a container secret when user
namespaces remap UIDs). Select the supervisor by managed labels and
accept the secret delivery form.

The lifecycle leg then exposed a driver bug: stopped-pair trust
replacement re-created the per-sandbox TLS CA secret, colliding with
the secret still owned by the renamed stopped pair. Mirror the token
and resolver secret handling: require and reuse the existing secret
during replacement instead of creating it.

Validated end-to-end with the Podman additional CA e2e lane.

Signed-off-by: Jesse Jaggars <jjaggars@redhat.com>

* fix(server): restore upstream recovery semantics for start-request failures

Recovery no longer marks sandboxes Error/InvalidPersistedSandbox when
driver_start_request fails during the startup or lifecycle sweeps.
Gateway configuration problems (for example a missing launch signer)
must not permanently fail unrelated sandbox records; the sweep logs a
warning and skips them, matching the behavior before the additional CA
work. Sandbox-record failures surface through the normal start path.

Signed-off-by: Jesse Jaggars <jjaggars@redhat.com>

* refactor(podman): refresh stale supervisors without replacing workloads

Replace the stopped-pair trust reconciliation with supervisor-only
recreation. The destination-trust generation label moves from the
workload to the supervisor container, and start_sandbox recreates only
the supervisor when its generation is missing or stale. The workload
container, its volumes, its secrets, and its workspace data are never
replaced: the additional CA bundle is mounted only into the supervisor.

Running sandboxes are never gated on trust labels, and recovery without
fresh launch credentials keeps the existing supervisor. The intentional
-removal fence machinery in the watcher existed only for workload
replacement and is removed with it.

Signed-off-by: Jesse Jaggars <jjaggars@redhat.com>

* refactor(docker): drop workload replacement for destination-trust changes

Delete the stopped-workload trust reconciliation path and all of its
machinery: the trust-generation label on workload containers, the
generation match check in the start fence, the stopped-sandbox
replacement, the bounded workspace archive copy with its 512 MiB cap
and regular-file-only validation, and the boundary-state rollback
helpers.

No replacement machinery is needed: the trusted supervisor container
is already re-created from the gateway's current configuration on
every start via ensure_control_process_for_container, so stop/start
picks up the current additional CA bundle while the workload
container, its volumes, and its workspace data are never replaced.

Signed-off-by: Jesse Jaggars <jjaggars@redhat.com>

* docs(configuration): drop reconciliation wording from additional CA lifecycle

The stop/start lifecycle description already matches the
supervisor-only refresh model; remove the two remaining references to
restart reconciliation of workload containers.

Signed-off-by: Jesse Jaggars <jjaggars@redhat.com>

* fix(network): port additional CA test fixtures to the crypto interface

Route the gateway TLS isolation test PKI, the destination CA source
fixtures, and the gateway startup trust tests through
openshell_crypto::pki now that rcgen access is centralized there:
generate_keypair/self_signed/signed_by replace the direct rcgen calls
and CertifiedKey field access follows the wrapper's shape.

Signed-off-by: Jesse Jaggars <jjaggars@redhat.com>

* fix(e2e): repair additional CA lane for Docker and non-container builds

The first maintainer test dispatch revealed two latent issues in the
additional CA e2e that no local run had exercised: the Podman gateway
CA secret helper referenced ContainerEngine without the container
feature gate, breaking Kubernetes and VM builds of the test, and the
Docker branch asserted a client ca.crt bind mount that the Docker
driver never creates. Gate the helper like its callers, and assert
Docker's actual delivery path instead: the gateway mTLS CA staged as
tls/ca.pem inside the read-only supervisor state volume, selected
through the OPENSHELL_TLS_CA environment pointer.

Signed-off-by: Jesse Jaggars <jjaggars@redhat.com>

* fix(helm): restore alphabetical README ordering for supervisor keys

The helm:docs check regenerates the chart README with helm-docs, which
orders rows alphabetically; a conflict resolution had placed
supervisor.network.additionalCaConfigMapName after the
supervisor.podSecurityContext rows. Regenerate with mise run
helm:docs.

Signed-off-by: Jesse Jaggars <jjaggars@redhat.com>

* chore: refresh testkit lockfile for openshell-core libc dependency

Signed-off-by: Jesse Jaggars <jjaggars@redhat.com>

* fix(driver-podman): stage operator CA bundle as driver-owned artifact

Standalone Podman drivers accepting --sandbox-additional-ca-bundle
previously kept the operator's source path as the trust artifact path.
The immutable-artifact verification performed on every create/start
requires exactly mode 0444, which an operator-owned source path cannot
guarantee, so a readable-but-writable source failed reconciliation.

Read the operator bundle with the same bounded, no-symlink validation,
then stage the normalized material into a driver-owned artifact inside a
private tempdir held for the driver process lifetime. The artifact is
created 0600, synced, and only then restricted to 0444 so no observer
ever sees a writable artifact. The operator source and its permissions
are never referenced after startup.

Addresses GATOR-291f43b2-02.

Signed-off-by: Jesse Jaggars <jjaggars@redhat.com>

* fix(driver-podman): pin retained workload image during supervisor refresh

Supervisor-only trust reconciliation re-entered
create_sandbox_with_existing_token, which re-pulled and re-resolved the
workload image tag even though the workload container is retained. If
the tag moved to a different image between stop and start, identity
resolution and child-environment construction would reflect the new
image while the retained workload still runs the original one, leaving
mode-0600 bootstrap files the retained user cannot read.

During a refresh with a retained workload, inspect the stopped container
and pin to the immutable image ID it was created from (Config.Image);
never pull or resolve the request tag. The requested reference is still
used for child metadata so the retained workload's environment is
byte-identical to its original launch.

Addresses GATOR-291f43b2-01.

Signed-off-by: Jesse Jaggars <jjaggars@redhat.com>

* test(e2e): verify host-only VM trust delivery and drop curl dependency

The additional-CA lane's VM assertions read the destination CA out of the
guest overlay and a guest-side supervisor-argv marker — artifacts from
the guest-supervisor design that no longer exist now that the VM driver
stages the CA host-only and runs the supervisor on the host. Inspect the
driver-staged host artifact (digest-compared against the source), assert
the guest overlay contains no CA material at the old mount paths, and
keep the serial-console no-disclosure check.

The workload validation scripts also ran curl, which exists only in the
container-engine fixture image; the Kubernetes and VM lanes use the
uv-based workload image and died instantly with "canonical main process
already finished". Rewrite the main-process, exec, and lifecycle
validation scripts in python3 (present in every lane's workload image).
The network-policy binary identity is the resolved /proc/<pid>/exe
target, so the versioned python3.12 binaries are allowlisted rather
than the unversioned symlinks. The hostname mismatch check keeps its
semantics: same reachable fixture, mismatched TLS SNI, and the failure
must specifically be hostname verification.

Addresses GATOR-291f43b2-04.

Signed-off-by: Jesse Jaggars <jjaggars@redhat.com>

* fix(kubernetes): allow admission-added labels on destination-trust ConfigMaps

The destination-trust ConfigMap validation compared the whole label map
for equality. A mutating admission webhook that attaches an
organizational label to the created ConfigMap made the create response
fail validation, and the retained ConfigMap then failed every subsequent
create/start through the existing-object path, blocking sandbox launches
despite the ownership labels, immutable flag, digest, and certificate
bytes remaining correct.

Validate the gateway-owned label pairs individually and allow unrelated
labels; the exact trust-material checks are unchanged. Covered by a
regression test with an admission-added label and a missing
gateway-owned label.

Signed-off-by: Jesse Jaggars <jjaggars@redhat.com>

* fix(podman): close supervisor-refresh rollback gaps

The supervisor-only trust refresh renamed the previous supervisor to a
random rollback name and then performed the token-secret lookup. A
transient lookup failure returned with the supervisor still renamed,
where a normal delete could never find it, and the rollback rename and
final rollback removal ignored their own failures, leaving orphans with
attached control and channel resources.

Complete every fallible preparation before the rename. On a failed
replacement, restore the canonical name; if the restore itself fails,
return an error naming the rollback container so the orphan stays
identifiable — a later retry still succeeds because the canonical name
is absent and the replacement path recreates a fresh supervisor. Treat
not-found during the final rollback removal as success and name the
orphan in both the log and the error on other removal failures; a retry
observes the fresh canonical supervisor and resumes the normal start
path.

Covered by failure-injection tests for each transaction boundary:
preparation failure before any rename, replacement failure restoring
the canonical name, and restore failure naming the orphaned rollback
container.

Signed-off-by: Jesse Jaggars <jjaggars@redhat.com>

* docs: address destination-trust review corrections

The gateway-configuration RFC documented an additional_ca_cert_paths
list that the strict configuration parser never accepted; document the
additional_ca_bundle single-path setting the parser actually enforces.

The debug-openshell-cluster skill named the wrong generation annotation
(openshell.ai/network-supervisor-trust-generation) and described digest
argv and network-init canonicalization checks the implementation does
not perform. Correct it to openshell.ai/additional-ca-generation and
describe the actual delivery: the supervisor Pod mounts the immutable
ConfigMap read-only and receives --additional-ca-bundle for the mount
path, with the driver validating the digest annotation and exact bytes
per creation.

Classify the destination-trust generation hashes as deterministic
identity derivation rather than authenticity proofs, following the
openshell-crypto exclusions table: trust decisions come from the
gateway's normalization, immutable staging, exact-byte validation, and
TLS verification. Record the classification in the crypto README and at
each hashing site.

Signed-off-by: Jesse Jaggars <jjaggars@redhat.com>

* fix(network): reconcile additional CA tests with suspend/resume and auth changes

Upstream's suspend/resume lifecycle took StartSandboxRequest fields 7
and 8, so the durable-snapshot field moves from 7 to 9; update the
wire-format test to assert the field-9 key (0x4a) and initialize the
new resume controls. Repair the cli test module after the auth opt-in
test merged alongside the environment-guard helpers, and initialize the
gateway driver-startup context's network-trust fields in the shared
supervision test.

Signed-off-by: Jesse Jaggars <jjaggars@redhat.com>

* fix(server): box start-recovery futures for clippy large-futures

The durable-snapshot field grows StartSandboxRequest enough that the
start-recovery match and the recovery-expiry test exceed the
large-futures limit under -D warnings. Box::pin both futures, matching
the pattern the recovery path used before the suspend/resume rework.

Signed-off-by: Jesse Jaggars <jjaggars@redhat.com>

---------

Signed-off-by: Jesse Jaggars <jjaggars@redhat.com>
2026-10-27 18:31:11 +00:00
..

openshell-driver-kubernetes

Kubernetes-backed compute driver for OpenShell cluster deployments.

Caller driver config is disabled by default. External resource references need administrator-controlled approval labels in every workspace mode, including before restart and scheduling-gate release. GPU devices are temporarily exempt. Image-pull Secrets are operator-selected gateway configuration rather than caller attachments. Managed mode stages an immutable copy for each sandbox runtime generation. See resource admission configuration.

Caller PVC mounts cannot overlap the driver-managed /.openshell control tree or /run, including nested subPath mounts. Resource approval labels do not permit mounting over these paths. Use data paths such as /data or a directory below /sandbox.

The driver uses the Kubernetes API to create, delete, fetch, and watch sandbox custom resources. It runs in-process with the gateway server and supports three workspace namespace modes via workspace_mode:

  • Shared (default): All sandboxes render into a single static namespace. Resource names use {workspace}--{name} for collision avoidance.
  • Managed: The driver auto-creates/deletes a K8s namespace per workspace (openshell-{gateway_id}-{workspace_name}) and creates a ServiceAccount in each. On OpenShift, it leaves SCC annotations to the namespace allocator and waits for the namespace's own MCS, UID-range, and supplemental-group annotations before provisioning sandbox resources. An existing namespace with a UID range but no MCS must be recreated so OpenShift can allocate a complete set of SCC annotations.
  • Operator: Workspace names map 1:1 to pre-provisioned namespaces discovered through exactly one source: either a label selector (operator_namespace_label) or a drop-in allowlist file (operator_namespace_file). Sandbox creation fails closed if the workspace namespace is not in the current allowlist. With a label selector, workspace checks that run before the watcher's first namespace listing wait up to 10 seconds for it and then return Unavailable, so a gateway restart does not reject labeled workspaces as unknown. Workspace deletion only removes gateway state; it never deletes or otherwise accesses the operator-managed Kubernetes namespace.

When the gateway configures [openshell.gateway.otlp], Kubernetes compute-driver spans export to the same OTLP/gRPC collector with the service name openshell-driver-kubernetes. The driver preserves the gateway trace context and uses the same compute-driver RPC span names in its in-process and standalone forms. Standalone deployments set --gateway-name or OPENSHELL_GATEWAY_NAME so exported spans carry the same openshell.gateway.name resource attribute as gateway spans.

When it creates an Agent Sandbox resource, the driver serializes the active W3C trace context into the controller-reserved opentelemetry.io/trace-context annotation. An OTLP-enabled Agent Sandbox controller can therefore attach its asynchronous reconciliation spans to the originating OpenShell create trace.

Workspace namespace modes assume exclusive control of the sandbox identity resource chain. In shared and managed modes, only the driver and its trusted Agent Sandbox controller may administer the sandbox namespace, Sandbox CRs, sandbox pods, or configured sandbox ServiceAccount. In operator mode, the platform operator owns namespace lifecycle but must prevent other principals from creating or mutating Sandbox CRs, creating sandbox pods with fabricated owner references, or using the configured sandbox ServiceAccount. Treat adding a namespace to the operator allowlist as granting this trust; the allowlist is not a tenant isolation boundary.

Runtime Model

The gateway stores platform state and delegates sandbox workload creation to this driver. Kubernetes owns scheduling and pod lifecycle. The workload Pod stages the statically linked musl openshell-sandbox binary from sandbox_runtime_image, while a directly managed Pod runs the dynamically linked glibc openshell-supervisor from supervisor_image.

The sandbox owns the agent process, applies Landlock and child seccomp filters, identifies the binary behind each network syscall, and relays mediated streams to the supervisor. The supervisor authenticates to the gateway with a JWT, loads policy and provider state, performs destination and L7 authorization, and opens upstream connections. The workload receives no gateway credential, provider identity socket, or corporate-proxy credential.

Both Pods run as the namespace-resolved non-root UID/GID with allowPrivilegeEscalation: false, capabilities.drop: [ALL], and the runtime default seccomp profile. The sandbox installs a nested seccomp user-notification filter without requesting a capability in the Pod spec. Startup fails closed when the runtime blocks the required seccomp or Landlock operations.

The supervisor Pod has a direct, non-controller owner reference to the Sandbox resource. This links its garbage-collection lifecycle to the sandbox without competing with the Agent Sandbox controller for workload-Pod ownership.

When the gateway exports OTLP traces, the driver sets OPENSHELL_OTLP_ENDPOINT on the supervisor Pod to the gateway's endpoint and TRACEPARENT to the trace context of the operation that created the Pod. The supervisor exports its spans there and parents its startup span on that context. The endpoint is not configurable in driver TOML.

The driver creates one namespace-wide NetworkPolicy before it releases any workload Pod. It selects every OpenShell workload, denies all workload egress, and permits OpenShell supervisor Pods to reach the sandbox TLS port. The authenticated Sandbox Protocol binds each connection to the exact sandbox and supervisor Pod identities. Supervisors have normal egress for gateway, DNS, and policy-approved upstream connections unless an operator policy restricts them. The cluster CNI must enforce ingress and egress NetworkPolicy for every sandbox namespace. Kubernetes accepts policy objects without confirming enforcement, so operators must verify CNI support before running sandboxes.

Control connection direction

Every new runtime generation uses runtime-initiated control. The Sandbox annotation openshell.ai/sandbox-runtime-control-connection records the mode, bound to openshell.ai/sandbox-runtime-control-generation. A missing marker or a different current runtime generation identifies a legacy, supervisor-initiated generation, which keeps working until replaced. Stop/start upgrades it automatically: with both old Pods removed, the driver adds the supervisor Service and records the new mode and generation before releasing the replacement workload. Gateway recovery that recreates both Pods also upgrades the generation. Reconciliation never migrates a running generation. An unknown annotation value fails closed; there is no rollout flag.

Only the dial direction differs. In both modes the sandbox runtime presents the generation-pinned TLS server identity and serves gRPC, and the supervisor verifies that identity, acts as the gRPC client, and sends the Sandbox Protocol JWT. The per-sandbox Service os-boundary-<id> always selects the paired workload Pod. A separate os-supervisor-<id> Service always selects the paired supervisor Pod. New gateways create both Services, retaining the legacy Service's UID, ClusterIP, and selector across restarts so an older gateway can still replace the generation during a rolling upgrade.

For runtime-initiated:

  • The bootstrap Secret gives the runtime the Service ClusterIP and port. The runtime retries with capped backoff until the supervisor listens, so neither Pod waits on the other during bootstrap. The Service sets publishNotReadyAddresses because the supervisor becomes Ready only after the runtime attaches through it. The workload still cannot reach the control port.
  • A per-sandbox NetworkPolicy os-control-<id> selects only this sandbox's two Pods and admits one flow, from its workload Pod to its supervisor Pod on boundary_port over TCP, as workload egress and supervisor ingress. Supervisors may already be ingress-isolated by the managed SSH ingress policy; when that policy is disabled, this one isolates them. Exec, file sync, and logs need no other supervisor ingress because the supervisor opens those connections. The CNI must still allow kubelet readiness probes. The namespace-wide policies are unchanged.
  • The policy's UID and resourceVersion are bound into the boundary resource claims and outer-fence evidence. Reconciliation suspends the workload if the policy disappears, diverges, or changes generation, or if the active control Service no longer selects the role the recorded mode requires.
  • Both Services and the control policy are owned by the Sandbox resource and are deleted only with that sandbox.

Deploy a gateway, supervisor image, and sandbox runtime image that all support runtime-initiated before using it. Older binaries reject the new descriptor shapes and fail closed.

During a mixed-version rollout, an old gateway can restart a sandbox by creating its own compatible supervisor/runtime pair through the legacy Service. It preserves unknown annotations, so the mode marker is accepted only for its recorded generation. Do not replace an individual generation's supervisor or runtime binary with one that cannot read its descriptor.

Each sandbox generation uses two immutable bootstrap Secrets. A trusted init container stages the sandbox bootstrap into memory, and the sandbox removes it before starting untrusted code. The other Secret is mounted only by the supervisor; when proxy_ca_bundle is configured it also carries the operator's corporate proxy CA bundle, which the gateway reads from its own filesystem so the anchor stays in the gateway's trust domain rather than the sandbox namespace. The TLS channel binds the namespace, Sandbox CR, workload Pod, supervisor Pod, and shared network-policy identities, plus the per-sandbox control policy for runtime-initiated sandboxes. Stop deletes the workload and supervisor Pods. Start rotates both Secrets and creates a new supervisor Pod before releasing a new workload Pod. It also renders the trusted init container again from gateway config, so a sandbox created by an older gateway starts with the current sandbox runtime image. The shared network fence remains for the lifetime of the namespace.

Kubernetes policies are additive, and the API does not attest that the CNI enforces them. Keep sandbox namespaces administrative: untrusted principals must not create permissive policies, create Pods, read bootstrap Secrets, or spoof the OpenShell role labels. Exact supervisor-to-sandbox authorization is still enforced by TLS, JWT claims, session generation, and recorded Pod UIDs.

Shared supervisor topology

With supervisor_topology = "gateway", each new runtime generation becomes a sandbox instance on one supervisor process that Helm deploys in the gateway namespace, instead of a supervisor Pod and boundary Service of its own. A sandbox instance is one running generation of a stable Sandbox resource. The generation's placement is recorded on the Sandbox resource (openshell.ai/sandbox-runtime-supervisor-topology: gateway and the instance route in openshell.ai/sandbox-runtime-supervisor-session, whose key keeps its established name) when the generation starts. Every later lifecycle decision reads the record, so changing the setting never reinterprets a running generation, and an unknown or incomplete record fails closed.

  • Ownership. The gateway owns which instances the shared supervisor hosts. It constructs an openshell_supervisor_control::SharedSupervision when the gateway binary builds this driver with KubernetesComputeDriver::with_shared_supervision, serves its assignments to the supervisor over the private openshell.supervisor.host.v1 stream, and mints the supervisor token the supervisor dials it with over TLS (see the openshell-supervisor README); that token authorizes only the assignment stream. The coordinator owns the control contracts (launch material is persisted before an instance is assigned, recovery is compare-and-replace against a baseline read before the list, an incomplete recovery never replaces the published set, host observations are interpreted once); this driver adapts them to Kubernetes objects. The standalone driver binary cannot host the topology and refuses a configuration that selects it.
  • Supervisor token delivery. The gateway renews the token at half its lifetime (the gateway_jwt extension-token TTL, 15 minutes by default, bounded to one hour) and the coordinator retries a failed delivery until it succeeds or a newer token supersedes it. The driver's part is the write: it replaces the token key of the chart-created shared_supervisor.token_secret_name Secret in service_namespace, which the supervisor Pod mounts, and names a missing Secret or a denied patch in the retried error.
  • Create and start. The driver creates a per-sandbox egress allowance os-shared-control-<id> from the workload Pod to the Pods the shared supervisor's Service selects, on the runtime port, binds its UID and resourceVersion into the boundary evidence, and builds the instance's registration (route, sandbox name, main process spec and agent image from the Sandbox resource, the provisioned runtime descriptor, the generation's launch credentials, its proxy CA, and the current trace context). The coordinator validates and encodes it, persists the launch material through the driver into the generation's os-supervisor-<id>-<generation> Secret (key instance.json, owned by the workload Pod), and then assigns the instance before the driver releases the workload Pod. Assignment does not wait for the supervisor, so create still returns before the gateway persists the generation. The runtime identity's last component is the instance route, which no Pod UID can equal, so authenticate_sandbox cannot vouch for a shared generation.
  • Readiness. A shared generation is available while the coordinator reports its instance as supervised and accepted by the gateway and the driver finds its fence and egress allowance. An instance the supervisor has reconciled past and does not host, hosts for another sandbox, or reports as ended is unavailable, and reconciliation suspends the workload. A disconnected supervisor is unknown and a supervisor that has not yet reconciled to the assignment is degraded; neither suspends anything. Bootstrap completion waits on the same verdict within the bootstrap grace.
  • Stop and delete. The driver withdraws the instance before suspending or deleting the workload, and the generation cleanup deletes its launch Secret. Every reconciliation also recovers the desired set from the Sandbox resources that may run: the driver begins the recovery before it lists them, lists the shared generations that may run with their routes, and reads each launch Secret's bytes on request; the coordinator reuses current assignments, decodes and binds persisted material to the recorded route and sandbox, keeps the previous set when any read fails, and refuses a list that raced a lifecycle edit. Instances of deleted Sandboxes and of stops made while the gateway was down are withdrawn, and a restarted gateway recovers its assignments before it sends anything.
  • Isolation. The supervisor token is a profile of its own, separate from every instance's credentials; the gateway refuses it on every other RPC and refuses every other identity on the assignment stream, and ends a stream when the token that opened it expires. Sandboxes cannot reach the stream, and the routing preface only selects which generation-pinned TLS identity the supervisor demands.

The topology does not support upstream proxies or provider SPIFFE identity, and the shared supervisor is a single point of failure for the sandboxes it hosts. Shared sandbox instances export no supervisor OTLP traces or OCSF events; the driver warns at startup when the gateway configures that export. When the setting is removed, reconciliation suspends shared generations, and a restart creates the dedicated generation's boundary Service the shared one never had.

Sandbox Resource

The driver works with the agents.x-k8s.io Sandbox custom resource. It detects the served Sandbox API at runtime, caches the selected API version for the gateway process, and uses v1beta1 when available before falling back to v1alpha1. Restart the gateway after an in-place Agent Sandbox upgrade so the driver can detect served API versions again. Driver events map Kubernetes object state and platform events into the shared compute-driver protobuf surface used by the gateway.

Kubernetes API calls use explicit timeouts so gRPC handlers do not block indefinitely when the API server is slow or unavailable. The request client's timeout starts when each request is sent, so time a pooled connection spends idle does not shorten it. Resource and Event watches recover in place with API-friendly backoff after transient watcher errors, avoiding a gateway-side watch restart and its associated watch gap.

Workspace Persistence

Sandbox pods use a PVC-backed /sandbox workspace. An init container seeds the PVC from the image's original /sandbox contents on first start and writes a sentinel so subsequent starts skip the copy.

This is a stopgap persistence model. It preserves user files across pod rescheduling but duplicates the base workspace and does not automatically apply image updates to existing PVCs. Future snapshotting should replace it.

Stop preserves the Agent Sandbox resource and workspace PVC while stopping its pod. The driver sets spec.operatingMode: Suspended for v1beta1 or spec.replicas: 0 for v1alpha1. Start sets Running or one replica for the same resource, so the replacement pod mounts the existing claim. Delete is the only lifecycle operation that removes the Sandbox resource and its owned storage. The driver confirms the stop from both the published Suspended condition and deletion of the backing pod. Legacy v1alpha1 controllers omit a usable stopped condition, so pod deletion alone confirms their stop.

The workspace PVC size defaults to workspace_default_storage_size. Set workspace_storage_class to pin the PVC to a specific StorageClass; an empty value omits storageClassName so the cluster's default StorageClass applies. Clusters with no default StorageClass must set this, otherwise the PVC stays Pending and the sandbox never starts. Both fields can also be supplied at runtime via OPENSHELL_K8S_WORKSPACE_DEFAULT_STORAGE_SIZE and OPENSHELL_K8S_WORKSPACE_STORAGE_CLASS. Both apply only to the workspace PVC that OpenShell provisions automatically; they have no effect when a driver_config mount attaches an existing PVC under /sandbox, which skips the default PVC.

Credentials, TLS, and Relay

Both Pods set automountServiceAccountToken: false. The supervisor receives an explicit audience-bound projected token for the one-shot IssueSandboxToken exchange. The driver verifies that token and returns an opaque runtime identity derived from the namespace, immutable Sandbox resource UID, and supervisor Pod UID. Restart requires exactly one matching Sandbox resource and preserves its namespace and UID while rotating the supervisor Pod UID. The gateway requires the authenticated identity to match the durable binding before returning the generation-bound session JWT used by the supervisor. The sandbox Pod receives neither token. For HTTPS gateway connections, the supervisor reads only the CA from the configured TLS Secret. Shared mode projects ca.crt directly; managed and operator modes stage only the CA into the supervisor bootstrap Secret. User client certificates and private keys are not mounted into either Pod.

The gateway uses the supervisor relay for connect, exec, logs, and file sync. Sandbox Pods do not need direct external ingress for SSH.

The driver sends the canonical main-process specification only to the supervisor. The supervisor passes admitted launch state over the protected channel. Provider environment updates apply to future exec sessions.

Container Security Context

The sandbox, trusted bootstrap init container, and supervisor request no added Linux capability. They run as the same numeric non-root identity, disable privilege escalation, drop all capabilities, and inherit RuntimeDefault seccomp. The sandbox and agent must use the same complete UID, GID, and supplementary-group identity because the capability-free sandbox cannot change credentials after launch and must inspect its same-identity descendants.

The workload Pod does not share host network, PID, IPC, or process namespaces. The driver uses a scheduling gate to inspect the admitted Pod and bind its UID into the bootstrap claims before kubelet starts it.

Lifecycle RPCs and runtime reconciliation share a per-sandbox mutation gate across clones of the driver. Reconciliation skips busy sandboxes and refreshes the Sandbox CR under that gate before cleanup, so a stopped or stopping LIST snapshot cannot delete a supervisor created by a concurrent restart in the same driver instance. The gate preserves concurrency across sandboxes; it does not provide distributed exclusion between separate gateway or driver processes.

GPU Support

When a sandbox requests GPU support, the driver checks node allocatable capacity for nvidia.com/gpu and requests the configured GPU count in the workload spec. When no count is set, the driver requests one GPU resource. The sandbox image must provide the user-space libraries needed by the agent workload.

Driver Config

Following RFC 0006, this driver accepts the selected SandboxTemplate.driver_config.kubernetes block as DriverSandboxTemplate.driver_config. The Kubernetes driver owns the nested schema and currently accepts:

  • pod.node_selector
  • pod.tolerations
  • pod.runtime_class_name
  • pod.priority_class_name
  • containers.agent.resources.requests
  • containers.agent.resources.limits
  • containers.agent.volume_mounts[].name
  • containers.agent.volume_mounts[].mount_path
  • containers.agent.volume_mounts[].sub_path
  • containers.agent.volume_mounts[].read_only
  • volumes[].name
  • volumes[].persistent_volume_claim.claim_name
  • volumes[].persistent_volume_claim.read_only

Nested keys inside the kubernetes block use snake_case. The top-level driver_config envelope is keyed by driver names, so kubernetes is not part of the nested schema.

Set this through the CLI with the public driver-keyed envelope. The gateway forwards only the kubernetes object to this driver:

openshell sandbox create \
  --driver-config-json '{"kubernetes":{"pod":{"runtime_class_name":"kata-containers","node_selector":{"pool":"gpu"}}}}' \
  -- claude

Resource keys use native Kubernetes resource names and quantity strings. The parser renders the keys listed above and rejects unknown fields. pod.runtime_class_name maps to PodSpec runtimeClassName and overrides the driver's configured default_runtime_class_name; the typed public SandboxTemplate.runtime_class_name still takes precedence when set. Use the public --gpu flag for the default GPU request, pass a count to --gpu for counted GPU requests, and use driver_config only for additional driver-owned resource details.

Use PVC volumes to mount existing Kubernetes PersistentVolumeClaims into the agent container. PVC volumes and mounts default to read-only unless read_only: false is set explicitly. Read-write access requires read_only: false on both the PVC volume and each writable mount. The driver rejects duplicate volume names, invalid DNS-1123 volume labels or PVC claim subdomain names, mounts that reference unknown volumes, non-normalized or protected mount paths, and absolute or parent-traversing sub_path values.

Any explicit driver-config mount under /sandbox disables the driver's default /sandbox workspace PVC injection for that sandbox. Only the explicit mount paths persist through the external PVC; other /sandbox paths come from the current sandbox image.

openshell sandbox create \
  --driver-config-json '{
    "kubernetes": {
      "volumes": [{
        "name": "user-data",
        "persistent_volume_claim": {
          "claim_name": "pvc-user-data-123",
          "read_only": false
        }
      }],
      "containers": {
        "agent": {
          "volume_mounts": [
            {
              "name": "user-data",
              "mount_path": "/sandbox/.openshell/workspace",
              "sub_path": "workspace",
              "read_only": false
            },
            {
              "name": "user-data",
              "mount_path": "/sandbox/.openshell/memory",
              "sub_path": "memory",
              "read_only": false
            }
          ]
        }
      }
    }
  }' \
  -- claude