Skip to content

Commit dbf68e8

Browse files
committed
feat(kubernetes): warm pool support
Signed-off-by: Gordon Sim <gsim@redhat.com>
1 parent e1084e1 commit dbf68e8

103 files changed

Lines changed: 15943 additions & 2374 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.agents/skills/helm-dev-environment/SKILL.md‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,19 @@ mise run helm:k3s:create
3030
Creates a k3d cluster and merges its kubeconfig into the worktree-local `kubeconfig` file.
3131
When the named cluster already exists, the task starts any stopped containers and refreshes
3232
same-named kubeconfig entries so a recreated load balancer's current API port takes effect.
33-
Also applies the upstream agent-sandbox CRDs/controller (pinned via `AGENT_SANDBOX_VERSION`
33+
Also applies the upstream agent-sandbox CRDs/controller and, for v0.5 and later,
34+
the `SandboxClaim`, `SandboxTemplate`, and `SandboxWarmPool` extension APIs
35+
(pinned via `AGENT_SANDBOX_VERSION`
3436
in `tasks/scripts/helm-k3s-local.sh`, fetched from `github.com/kubernetes-sigs/agent-sandbox`
3537
releases), enables its OTLP tracing on v0.5 and later, installs an OTLP trace
3638
collector and UI in the `observability` namespace,
3739
and preloads the default community sandbox image into k3d so the first sandbox create
3840
does not wait on a large registry pull. Traefik is disabled at cluster creation time.
3941

42+
For a v0.4.x Agent Sandbox release, deploy OpenShell with
43+
`server.warmPooling.enabled=false`. Verify a warm-capable installation with
44+
`kubectl api-resources --api-group=extensions.agents.x-k8s.io`.
45+
4046
**Multi-worktree support:** the cluster name is derived from the last component of the
4147
current git branch (e.g. branch `kube-support/local-dev/tmutch` → cluster
4248
`openshell-dev-tmutch`). Each worktree therefore gets its own isolated cluster and its

‎.github/workflows/branch-e2e.yml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,14 +371,17 @@ jobs:
371371
agent_sandbox_version: v0.5.0
372372
topology: combined
373373
extra_helm_values: ""
374+
e2e_task: e2e:kubernetes:warm-pool
374375
- agent_sandbox_api: v1alpha1
375376
agent_sandbox_version: v0.4.6
376377
topology: combined
377378
extra_helm_values: ""
379+
e2e_task: e2e:kubernetes:v1alpha1
378380
- agent_sandbox_api: v1beta1
379381
agent_sandbox_version: v0.5.0
380382
topology: sidecar
381383
extra_helm_values: deploy/helm/openshell/ci/values-sidecar.yaml
384+
e2e_task: e2e:kubernetes:warm-pool-sidecar
382385
permissions:
383386
actions: read
384387
contents: read
@@ -389,6 +392,7 @@ jobs:
389392
job-name: Kubernetes E2E (Rust smoke, ${{ matrix.topology }}, Agent Sandbox ${{ matrix.agent_sandbox_api }})
390393
agent-sandbox-version: ${{ matrix.agent_sandbox_version }}
391394
extra-helm-values: ${{ matrix.extra_helm_values }}
395+
e2e-task: ${{ matrix.e2e_task }}
392396
conformance-artifact-prefix: openshell-conformance
393397

394398
kubernetes-workspace-managed-e2e:

‎Cargo.lock‎

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎architecture/compute-runtimes.md‎

Lines changed: 146 additions & 29 deletions
Large diffs are not rendered by default.

‎architecture/gateway.md‎

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,9 @@ token is reported as connected but unauthenticated.
220220
Sandbox supervisor RPCs authenticate with explicit sandbox credentials; mTLS
221221
does not grant sandbox identity. Kubernetes deployments use the
222222
gateway-minted JWT bootstrap path: the supervisor starts with a projected
223-
ServiceAccount token, exchanges it for a gateway-minted sandbox JWT, and uses
224-
that JWT on subsequent gateway RPCs.
223+
ServiceAccount token, registers the pod with the gateway, receives a
224+
gateway-minted sandbox JWT after activation, and uses that JWT on subsequent
225+
gateway RPCs.
225226
User-facing RPCs are authorized by descriptor-declared role and scope policy
226227
when OIDC or edge identity is enabled. The OIDC admin role grants platform-wide
227228
access and bypasses workspace membership checks. Workspace Admin and Workspace
@@ -235,22 +236,43 @@ identity inspection without client-side token decoding.
235236
Sandbox secrets are gateway-signed JWTs bound to a single sandbox ID. Docker,
236237
Podman, and VM drivers deliver the initial token through supervisor-only
237238
runtime material; Kubernetes supervisors exchange a projected ServiceAccount
238-
token through `IssueSandboxToken`. The gateway delegates that opaque credential
239-
to the selected compute driver's `AuthenticateSandbox` RPC. A capable driver is
240-
trusted to return the authenticated sandbox ID, while the gateway still requires
241-
a matching durable sandbox record before minting a JWT. The Kubernetes driver
242-
uses its own named configuration to run TokenReview and verify the live pod and
243-
controlling Sandbox CR. The bootstrap path accepts
244-
both `agents.x-k8s.io/v1beta1` ownerReferences from newer Agent Sandbox
245-
controllers and `agents.x-k8s.io/v1alpha1` ownerReferences from existing
246-
deployments. Supervisors renew gateway JWTs in memory before expiry only while
247-
the sandbox record still exists. Older tokens are not server-revoked; shared
248-
deployments bound replay exposure with short `gateway_jwt.ttl_secs` lifetimes.
239+
token through `RegisterSupervisor`. The gateway delegates that opaque
240+
credential to the selected compute driver's `AuthenticateSandbox` RPC. The
241+
driver verifies the credential and returns either a bound sandbox ID or a
242+
warm-pending supervisor instance with an opaque activation guard. For
243+
already-bound pods, the gateway still requires a matching durable sandbox record
244+
before sending an activation message with the gateway JWT. For warm-pooled
245+
Kubernetes sandboxes, the same check is re-anchored through the claim that
246+
adopted the warm pod: the live pod must still be controlled by a live
247+
`Sandbox`, that `Sandbox` must be associated with the live `SandboxClaim`, and
248+
the sandbox-id metadata on that claim must identify the same OpenShell sandbox
249+
record before activation can complete. Activation must present the same opaque
250+
guard returned during registration. Both paths depend on the same Kubernetes
251+
RBAC boundary: sandbox workloads and untrusted users must not be able to create
252+
or mutate trusted Agent Sandbox objects, pod metadata, or the configured
253+
sandbox ServiceAccount in the gateway-managed namespace. `IssueSandboxToken`
254+
remains as a compatibility shim for older supervisor images and mints through
255+
the same driver authentication path, but only for already-bound responses.
256+
Supervisors renew gateway JWTs in
257+
memory before expiry only while the sandbox record still exists. Older tokens
258+
are not server-revoked; shared deployments bound replay exposure with short
259+
`gateway_jwt.ttl_secs` lifetimes.
249260
The config default is
250261
`gateway_jwt.ttl_secs = 0` for local single-player Docker, Podman, and VM
251262
gateways; those tokens carry `exp = 0` and do not expire. Kubernetes and other
252263
shared deployments should set a positive TTL.
253264

265+
Warm supervisors begin capturing logs before activation but do not open the log
266+
stream until registration supplies the authoritative sandbox ID and installs
267+
the gateway JWT. A bounded pre-activation queue is rebound to that identity,
268+
which avoids both missing startup records and a second bootstrap race. In
269+
sidecar topology, the registering network supervisor also sends the activated
270+
sandbox ID and name together with the main-process command, TTY, and attachment
271+
state to the process supervisor over the authenticated local control socket.
272+
The process supervisor applies that identity before initializing its OCSF
273+
context and rejects conflicts with any identity already present in its
274+
environment.
275+
254276
Gateway JWT signing-key rotation is currently an offline operator action. The
255277
runtime loads one active signing key and one matching public verification key
256278
from the configured secret at startup. To rotate that key material today,
@@ -375,6 +397,15 @@ created from a template resolves that resource once and persists an ordinary
375397
name, labels, annotations, provider attachments, and policy. The sandbox stores
376398
template provenance as the template name and resource version used for the
377399
snapshot, so later template edits or deletes do not mutate existing sandboxes.
400+
For drivers that opt into template reconciliation, a background worker reads
401+
the complete template set and sends it as authoritative desired state through
402+
the optional `SandboxTemplateReconciler` driver service. The required
403+
`ComputeDriver` service remains limited to common sandbox lifecycle operations.
404+
The worker runs at startup, after template mutations, and periodically, so a
405+
failed driver call or missed notification is retried from the source of truth.
406+
The driver applies the supplied set idempotently and prunes backend resources it
407+
owns for absent templates. Template create and delete therefore need no hidden
408+
delivery rows or tombstones.
378409

379410
OAuth refresh failures retain a gateway-owned recovery classification alongside
380411
the refresh state. The gateway reads only a bounded error response and maps

‎crates/openshell-cli/tests/ensure_providers_integration.rs‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,17 @@ impl OpenShell for TestOpenShell {
631631
Err(Status::unimplemented("not implemented in test"))
632632
}
633633

634+
type RegisterSupervisorStream = tokio_stream::wrappers::ReceiverStream<
635+
Result<openshell_core::proto::SupervisorActivationMessage, Status>,
636+
>;
637+
638+
async fn register_supervisor(
639+
&self,
640+
_request: tonic::Request<openshell_core::proto::RegisterSupervisorRequest>,
641+
) -> Result<Response<Self::RegisterSupervisorStream>, Status> {
642+
Err(Status::unimplemented("not implemented in test"))
643+
}
644+
634645
async fn refresh_sandbox_token(
635646
&self,
636647
_request: tonic::Request<openshell_core::proto::RefreshSandboxTokenRequest>,

‎crates/openshell-cli/tests/mtls_integration.rs‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,17 @@ impl OpenShell for TestOpenShell {
494494
Err(Status::unimplemented("not implemented in test"))
495495
}
496496

497+
type RegisterSupervisorStream = tokio_stream::wrappers::ReceiverStream<
498+
Result<openshell_core::proto::SupervisorActivationMessage, Status>,
499+
>;
500+
501+
async fn register_supervisor(
502+
&self,
503+
_request: tonic::Request<openshell_core::proto::RegisterSupervisorRequest>,
504+
) -> Result<Response<Self::RegisterSupervisorStream>, Status> {
505+
Err(Status::unimplemented("not implemented in test"))
506+
}
507+
497508
async fn refresh_sandbox_token(
498509
&self,
499510
_request: tonic::Request<openshell_core::proto::RefreshSandboxTokenRequest>,

‎crates/openshell-cli/tests/provider_commands_integration.rs‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,17 @@ impl OpenShell for TestOpenShell {
10611061
Err(Status::unimplemented("not implemented in test"))
10621062
}
10631063

1064+
type RegisterSupervisorStream = tokio_stream::wrappers::ReceiverStream<
1065+
Result<openshell_core::proto::SupervisorActivationMessage, Status>,
1066+
>;
1067+
1068+
async fn register_supervisor(
1069+
&self,
1070+
_request: tonic::Request<openshell_core::proto::RegisterSupervisorRequest>,
1071+
) -> Result<Response<Self::RegisterSupervisorStream>, Status> {
1072+
Err(Status::unimplemented("not implemented in test"))
1073+
}
1074+
10641075
async fn refresh_sandbox_token(
10651076
&self,
10661077
_request: tonic::Request<openshell_core::proto::RefreshSandboxTokenRequest>,

‎crates/openshell-cli/tests/sandbox_create_lifecycle_integration.rs‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,17 @@ impl OpenShell for TestOpenShell {
844844
Err(Status::unimplemented("not implemented in test"))
845845
}
846846

847+
type RegisterSupervisorStream = tokio_stream::wrappers::ReceiverStream<
848+
Result<openshell_core::proto::SupervisorActivationMessage, Status>,
849+
>;
850+
851+
async fn register_supervisor(
852+
&self,
853+
_request: tonic::Request<openshell_core::proto::RegisterSupervisorRequest>,
854+
) -> Result<Response<Self::RegisterSupervisorStream>, Status> {
855+
Err(Status::unimplemented("not implemented in test"))
856+
}
857+
847858
async fn refresh_sandbox_token(
848859
&self,
849860
_request: tonic::Request<openshell_core::proto::RefreshSandboxTokenRequest>,

‎crates/openshell-cli/tests/sandbox_name_fallback_integration.rs‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,17 @@ impl OpenShell for TestOpenShell {
582582
Err(Status::unimplemented("not implemented in test"))
583583
}
584584

585+
type RegisterSupervisorStream = tokio_stream::wrappers::ReceiverStream<
586+
Result<openshell_core::proto::SupervisorActivationMessage, Status>,
587+
>;
588+
589+
async fn register_supervisor(
590+
&self,
591+
_request: tonic::Request<openshell_core::proto::RegisterSupervisorRequest>,
592+
) -> Result<Response<Self::RegisterSupervisorStream>, Status> {
593+
Err(Status::unimplemented("not implemented in test"))
594+
}
595+
585596
async fn refresh_sandbox_token(
586597
&self,
587598
_request: tonic::Request<openshell_core::proto::RefreshSandboxTokenRequest>,

0 commit comments

Comments
 (0)