Skip to content

Commit 4d868e1

Browse files
committed
feat(compute): delegate sandbox authentication to drivers
Signed-off-by: Drew Newberry <385+drew@users.noreply.github.com>
1 parent 56088d0 commit 4d868e1

24 files changed

Lines changed: 558 additions & 1347 deletions

File tree

‎.agents/skills/debug-openshell-cluster/SKILL.md‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,10 @@ Then inspect sandbox resources in that namespace.
467467
Check the configured sandbox service account when TokenReview bootstrap or
468468
sandbox registration fails. Helm creates a dedicated sandbox service account by
469469
default and writes it to `[openshell.drivers.kubernetes].service_account_name`;
470-
the gateway rejects projected tokens from other service accounts.
470+
the selected Kubernetes compute driver rejects projected tokens from other
471+
service accounts. For an external driver, inspect its logs and confirm it
472+
advertises `supports_sandbox_authentication`; the gateway delegates the opaque
473+
credential over the driver socket and never interprets Kubernetes settings.
471474

472475
```bash
473476
helm -n openshell get values openshell | grep -A3 sandboxServiceAccount

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,9 @@ annotations to `spiffe://openshell.local/openshell/sandbox/<sandbox-id>`.
256256
OpenShell mounts the SPIFFE CSI Workload API socket at
257257
`/spiffe-workload-api/spire-agent.sock` into sandbox pods for provider token
258258
grants. Supervisor-to-gateway authentication remains on the Kubernetes
259-
ServiceAccount bootstrap and gateway-minted sandbox JWT path.
259+
ServiceAccount bootstrap and gateway-minted sandbox JWT path; the selected
260+
Kubernetes compute driver validates the projected token before the gateway
261+
mints its JWT.
260262

261263
---
262264

‎architecture/compute-runtimes.md‎

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,15 @@ The driver reports this behavior through
169169
in-process and external drivers. Older drivers omit the field and retain the
170170
conservative operator-managed behavior.
171171

172+
Drivers that can verify a platform-native sandbox credential advertise
173+
`GetCapabilities.supports_sandbox_authentication`. On the path-scoped
174+
`IssueSandboxToken` exchange, the gateway forwards the opaque bearer credential
175+
to that selected driver through `AuthenticateSandbox`. The driver returns only
176+
the authenticated sandbox ID. The gateway then verifies that its durable
177+
sandbox record exists and mints the gateway JWT. The driver socket is therefore
178+
a sandbox-identity trust boundary, but it does not grant user or administrator
179+
authority.
180+
172181
## Deletion Lifecycle
173182

174183
Lifecycle requests use per-sandbox gates to serialize stop, start, and
@@ -457,20 +466,23 @@ watcher emits only sandbox CR changes, not platform events.
457466

458467
### SA Token Authentication
459468

460-
The gateway's `K8sServiceAccountAuthenticator` adapts its `NamespaceValidator`
461-
per mode (`crates/openshell-server/src/auth/k8s_sa.rs`):
469+
The Kubernetes driver's `AuthenticateSandbox` implementation applies its named
470+
`[openshell.drivers.kubernetes]` configuration per mode:
462471

463472
- **Shared:** `Exact` — accepts only the single configured namespace.
464473
- **Managed:** `Prefix` — accepts any namespace starting with `openshell-{gateway_id}-`.
465474
- **Operator:** `Allowlist` — accepts namespaces present in the dynamic
466475
`BTreeSet` populated by the label/file watchers. Starts empty (fail-closed)
467476
until the first watcher update.
468477

469-
These checks rely on an ownership invariant. In shared and managed modes, the
470-
gateway and its trusted Agent Sandbox controller exclusively administer the
471-
sandbox namespace, Sandbox CRs, sandbox pods, and configured sandbox
472-
ServiceAccount. Other principals must not create or mutate those resources or
473-
use that ServiceAccount. In operator mode, the platform operator retains
478+
It validates the projected token with Kubernetes `TokenReview`, checks the live
479+
pod UID, and verifies the pod's controlling Sandbox CR UID and sandbox ID before
480+
returning the identity to the gateway. These checks rely on an ownership
481+
invariant. In shared and managed modes, the Kubernetes driver and its trusted
482+
Agent Sandbox controller exclusively administer the sandbox namespace, Sandbox
483+
CRs, sandbox pods, and configured sandbox ServiceAccount. Other principals must
484+
not create or mutate those resources or use that ServiceAccount. In operator
485+
mode, the platform operator retains
474486
namespace lifecycle ownership, but must preserve the same exclusive control of
475487
Sandbox CRs and the pods and ServiceAccount used for sandbox token bootstrap.
476488
An allowlisted namespace is therefore a trust grant, not a tenant isolation

‎architecture/gateway.md‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,12 @@ identity inspection without client-side token decoding.
225225
Sandbox secrets are gateway-signed JWTs bound to a single sandbox ID. Docker,
226226
Podman, and VM drivers deliver the initial token through supervisor-only
227227
runtime material; Kubernetes supervisors exchange a projected ServiceAccount
228-
token through `IssueSandboxToken`. The gateway validates that projected token
229-
with Kubernetes `TokenReview`, requires the configured sandbox service account,
230-
checks the returned pod binding against the live pod UID, and verifies the pod's
231-
controlling `Sandbox` ownerReference against the live Sandbox CR UID and
232-
sandbox-id label before minting the gateway JWT. The bootstrap path accepts
228+
token through `IssueSandboxToken`. The gateway delegates that opaque credential
229+
to the selected compute driver's `AuthenticateSandbox` RPC. A capable driver is
230+
trusted to return the authenticated sandbox ID, while the gateway still requires
231+
a matching durable sandbox record before minting a JWT. The Kubernetes driver
232+
uses its own named configuration to run TokenReview and verify the live pod and
233+
controlling Sandbox CR. The bootstrap path accepts
233234
both `agents.x-k8s.io/v1beta1` ownerReferences from newer Agent Sandbox
234235
controllers and `agents.x-k8s.io/v1alpha1` ownerReferences from existing
235236
deployments. Supervisors renew gateway JWTs in memory before expiry only while

‎crates/openshell-driver-docker/src/lib.rs‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,7 @@ impl DockerComputeDriver {
635635
driver_version: self.config.daemon_version.clone(),
636636
default_image: self.config.default_image.clone(),
637637
gateway_manages_lifecycle: true,
638+
supports_sandbox_authentication: false,
638639
}
639640
}
640641

@@ -1873,6 +1874,15 @@ impl ComputeDriver for ComputeDriverService {
18731874

18741875
#[tonic::async_trait]
18751876
impl ComputeDriver for DockerComputeDriver {
1877+
async fn authenticate_sandbox(
1878+
&self,
1879+
_request: Request<openshell_core::proto::compute::v1::AuthenticateSandboxRequest>,
1880+
) -> Result<Response<openshell_core::proto::compute::v1::AuthenticateSandboxResponse>, Status> {
1881+
Err(Status::unimplemented(
1882+
"docker does not authenticate sandbox credentials",
1883+
))
1884+
}
1885+
18761886
type WatchSandboxesStream = WatchStream;
18771887

18781888
async fn get_capabilities(

‎crates/openshell-driver-kubernetes/README.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ annotation. An OTLP-enabled Agent Sandbox controller can therefore attach its
3131
asynchronous reconciliation spans to the originating OpenShell create trace.
3232

3333
Workspace namespace modes assume exclusive control of the sandbox identity
34-
resource chain. In shared and managed modes, only the gateway and its trusted
34+
resource chain. In shared and managed modes, only the driver and its trusted
3535
Agent Sandbox controller may administer the sandbox namespace, Sandbox CRs,
3636
sandbox pods, or configured sandbox ServiceAccount. In operator mode, the
3737
platform operator owns namespace lifecycle but must prevent other principals
@@ -99,7 +99,9 @@ Sandbox pods run as `service_account_name` and keep
9999
`automountServiceAccountToken: false`. The only Kubernetes token exposed to the
100100
supervisor is an explicit, audience-bound projected token mounted at
101101
`/var/run/secrets/openshell/token` for the one-shot `IssueSandboxToken`
102-
bootstrap exchange.
102+
bootstrap exchange. The Kubernetes driver authenticates that token through the
103+
compute-driver protocol using its own `service_account_name` and workspace-mode
104+
namespace policy; the gateway receives only the verified sandbox ID.
103105

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

0 commit comments

Comments
 (0)