An OpenShell sandbox's workload runs in an agent container that is privileged
— in the default "combined" topology it runs as root (uid 0) with the caps the
supervisor needs (SYS_ADMIN, NET_ADMIN). The confinement a user cares about
(non-root uid, Landlock filesystem/network policy, dropped caps) is applied by
the supervisor to the workload process, per-process, at runtime.
A plain kubectl exec does not go through the supervisor. The kubelet execs the
command directly in the container, so the shell lands as root, outside the
sandbox — it inherits the container's privileges, not the workload's
confinement. Gateway RBAC governs exec through the gateway API (see
operator-auth.md); it does not govern a direct kubectl exec against the pod, which is a pure Kubernetes operation.
Whether this is on by default depends on the install mode — see Enabling it.
Two admission webhooks, served by the operator process itself:
-
Mutating, on
pods/exec(CONNECT). The apiserver runs mutating admission on thePodExecOptions— including itscommand— before it dials the kubelet. The webhook rewrites the command for the sandboxed agent container, prepending the supervisor entrypoint:id → /opt/openshell/bin/openshell-sandbox --mode=process -- id--mode=processmakes the supervisor re-derive the sandbox's policy from the live gateway (via theOPENSHELL_SANDBOX_ID/ endpoint env already on the container) and re-enter the sandbox domain, then exec the user's command. The shell drops to the sandbox user under Landlock. Streaming/PTY is unaffected — only the argv is rewritten. -
Validating, on
pods/attach(CONNECT) andpods/ephemeralcontainers(UPDATE).attachconnects to the root supervisor's stdio, and akubectl debugephemeral container runs unwrapped as root — both sidestep the exec rewrite. The webhook denies them outright on sandbox pods. Without this, the exec confinement is theatre.
The confinement itself is entirely the upstream supervisor's; the operator only translates a Kubernetes mechanism (admission) into invoking it — consistent with its thin-front-end role.
The exec admission request carries PodExecOptions and the pod's
name/namespace, but not the pod's labels — so label-based objectSelector /
matchConditions can't classify it. The webhook therefore GETs the pod and
classifies by ownerReference to agents.x-k8s.io/Sandbox. That is the
authority: the gateway's Kubernetes driver always creates an agents.x-k8s.io
Sandbox, whose controller owns the pod — so this catches every sandbox,
including ones created directly against the gateway rather than through the
operator's CRD. Labels are user-controlled and would miss those.
Within a sandbox pod, only the container carrying the OPENSHELL_SANDBOX_ID env
(the agent) is wrapped; the target container is resolved the way the API server
does it (requested container, else the kubectl.kubernetes.io/default-container
annotation, else the first container). Exec into any other container of a
sandbox pod is denied — it shares the pod's namespaces and would be a bypass.
The decision is deliberately biased safe: wrongly wrapping a non-sandbox exec merely breaks that one exec; wrongly not wrapping a sandbox exec is a root escape. So every ambiguous branch — unresolved container, unfetchable pod — denies rather than passing through.
failurePolicy: Fail (fail-closed) is the default and the point: if the
operator is unreachable, exec/attach into a confined namespace is denied,
never silently downgraded to an unconfined root shell. Ignore is available for
those who want fail-open, but it reopens root exec exactly when an attacker can
induce webhook downtime.
The blast radius is bounded by a namespaceSelector, scoped by install mode:
- Bundled (
gateway.bundled=true): the selector targets the gateway's sandbox namespace —openshellGateway.server.sandboxNamespace, defaulting to the release namespace — via the built-inkubernetes.io/metadata.namelabel, so there's no labelling step and the fail-closed radius is that one namespace. Note the confined namespace is also where the operator and gateway run, so a webhook outage blockskubectl execinto those pods too (the ones you'd reach for to debug it) —kubectl logsstill works, and deleting the webhook config is the escape hatch. - BYO (
gateway.bundled=false): sandbox placement is outside our control, so the selector matches namespaces the admin opts in withopenshell.lenshq.io/exec-confinement: enabled(and neverkube-system/kube-node-lease). An unlabelled cluster sees zero webhook calls.
Crucially, the webhooks match only pods/exec, pods/attach, and
pods/ephemeralcontainers — never pod creation — so a webhook outage can
never wedge scheduling, node drains, or workload creation. The worst case is
"can't kubectl exec into a confined namespace until the operator is back," an
interactive operation that humans retry.
Because exec now re-derives policy from the gateway, exec into a sandbox depends on gateway availability — gateway down means exec fails (consistent with fail-closed).
Serve the webhook on ≥1 ready replica; with leader election on, the webhook runs on every replica (leader and standbys alike, outside the leader gate), so a rolling update or lease flap doesn't drop the listener.
The operator self-manages its serving cert — no cert-manager, no chart-baked
cert. On startup it generates a self-signed CA + leaf for the webhook Service
DNS, persists them in a Secret (<release>-webhook-tls, adopting a peer
replica's Secret if one raced ahead), and injects the CA into both webhook
configs' caBundle via a strategic-merge patch keyed on the webhook name. The
cert is long-lived (no rotation in v1, matching the bundled OIDC token); to
rotate, delete the Secret and restart. The chart never renders caBundle, so
helm upgrade leaves the injected value intact; under Argo/Flux, add caBundle
to ignoreDifferences so it isn't flagged as drift.
webhook.execConfinement.enabled is a tri-state. Left unset (the default) it
follows gateway.bundled:
-
Bundled install (the default): on automatically. The operator knows sandboxes land in the release namespace and scopes the webhook there — no further steps.
-
BYO gateway: off. Sandbox placement is outside our control, and the fail-closed availability tradeoff is the operator's to make deliberately, so opt in explicitly and label the sandbox namespaces:
gateway: bundled: false webhook: execConfinement: enabled: true
kubectl label namespace <ns> openshell.lenshq.io/exec-confinement=enabled
Set enabled: true/false to override the gateway.bundled-derived default
either way.
The wrapper argv defaults to the supervisor entrypoint baked into the sandbox
image (/opt/openshell/bin/openshell-sandbox --mode=process --); override it
only if that upstream image path changes. kubectl cp (exec + tar) keeps
working but writes as the sandbox user under Landlock — copies outside allowed
paths fail, which is the intended confinement, not a bug. port-forward reaches
only pod-local sockets and is left untouched.