Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
416b9b2
feat(ocsf): guest-sourced markers and unmapped fields on activity bui…
jhjaggars Nov 18, 2026
cf0e665
feat(isolation-interface): allow zero-uid workload identity for privi…
jhjaggars Nov 18, 2026
0e63d8f
feat(policy): privileged restrictive default without in-guest sections
jhjaggars Nov 18, 2026
f97af22
feat(sandbox-backend): boundary protocol extensions for VM-backed bou…
jhjaggars Nov 18, 2026
388ec4a
feat(sandbox): root-workload boundary mode and transparent network relay
jhjaggars Nov 18, 2026
e623f03
feat(supervisor): privileged-mode supervision and guest-reported events
jhjaggars Nov 18, 2026
f1130b0
feat(driver-kubernetes): KubeVirt runtime mode
jhjaggars Nov 18, 2026
816d6f3
feat(helm): RBAC for KubeVirt virtual machines and fences
jhjaggars Nov 18, 2026
601f70c
test(e2e): KubeVirt acceptance demo and attack-surface probes
jhjaggars Nov 18, 2026
f11b70d
docs(gateways): document the Kubernetes driver's KubeVirt runtime mode
jhjaggars Nov 18, 2026
b8c2823
docs(kubevirt): the relay is functional routing, never a security con…
jhjaggars Nov 18, 2026
81bcf93
refactor!: drop the sandboxed KubeVirt workload mode — one untrusted …
jhjaggars Nov 18, 2026
3af969d
test(e2e): single root-mode demo lane, policy, and docs
jhjaggars Nov 18, 2026
5cf274c
fix(driver-kubernetes): pin KubeVirt lifecycle mutations to the check…
jhjaggars Nov 18, 2026
51c655e
feat(driver-kubernetes): CPU and memory limits for KubeVirt sandboxes
jhjaggars Nov 19, 2026
3281608
feat(driver-kubernetes): least-privilege RBAC for the KubeVirt runtime
jhjaggars Nov 19, 2026
38d39e5
fix(driver-kubernetes): keep transient KubeVirt states provisioning
jhjaggars Nov 20, 2026
a824ea4
chore(driver-kubernetes): clippy cleanups for the managed-mode listing
jhjaggars Nov 20, 2026
725d254
Merge upstream/main into the KubeVirt runtime mode branch
jhjaggars Nov 30, 2026
721d843
refactor!: drop the privileged root-workload guest mode
jhjaggars Nov 30, 2026
c698223
test(e2e): capability-free KubeVirt acceptance lane, run by hand
jhjaggars Nov 30, 2026
3e1d2a4
docs: describe the KubeVirt runtime mode as it now behaves
jhjaggars Nov 30, 2026
b2d32c8
test(e2e): pin the demo policy's binary identity
jhjaggars Dec 1, 2026
1f19c03
style(driver-kubernetes): rustfmt and doc-markdown fixups
jhjaggars Dec 1, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/openshell-driver-kubernetes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ tokio-stream = { workspace = true }
kube = { workspace = true }
kube-runtime = { workspace = true }
k8s-openapi = { workspace = true }
base64 = { workspace = true }
tower = { workspace = true, features = ["timeout"] }
serde = { workspace = true }
serde_json = { workspace = true }
Expand Down
52 changes: 52 additions & 0 deletions crates/openshell-driver-kubernetes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,58 @@ When the setting is removed, reconciliation suspends shared generations, and a
restart creates the dedicated generation's boundary Service the shared one never
had.

## KubeVirt Runtime Mode

`runtime = "kubevirt"` in `[openshell.drivers.kubernetes]` provisions
`kubevirt.io/v1` `VirtualMachine` objects instead of Agent Sandbox CRs: the
KubeVirt controller owns the VM and its virt-launcher Pod, and the driver owns
everything the gateway needs around it. It is an alternative substrate, not an
alternative product surface — the compute-driver RPCs, the sandbox API, and the
policy model are the same.

- **The guest is an ordinary sandbox.** The driver renders the same boundary
artifacts the pod path uses (`render_boundary_bootstrap`) into a
shell-sourceable cloud-init `userData`: the boundary config plus session TLS,
base64-encoded, with no gateway endpoint and no gateway token. The guest init
stages them on a tmpfs, removes the config disk's backing PCI function, and
runs `openshell-sandbox launch-capability-free <uid> <gid> <config>`. The
workload therefore keeps the container posture: capability drop,
`no_new_privs`, Landlock, and child seccomp, behind a per-sandbox egress
fence. The workload identity is `KUBEVIRT_WORKLOAD_UID`/`KUBEVIRT_WORKLOAD_GID`
(10001:10001), which the guest image provisions as its `sandbox` account.
- **One supervisor per sandbox.** A dedicated supervisor Pod per sandbox,
reusing the pod path's supervisor Pod, boundary Service, bootstrap Secret,
and control-policy renderers with `VirtualMachine` owner references.
`supervisor_topology = "gateway"` is rejected for this runtime.
- **Objects per generation.** Each create/start generation renders a fresh
bootstrap Secret (`<vm>-boot-<generation>`, immutable) and a supervisor
generation whose Pod UID is claimed back by the guest. Stop/start keeps the
VM UID and fence UID and rotates the supervisor Pod.
- **Fence.** A per-sandbox `NetworkPolicy` selects the virt-launcher Pod and
admits only that sandbox's supervisor; a namespace-wide default-deny policy
selects every virt-launcher Pod as the floor. The driver persists the
expected fence (UID + rendered spec) on the VM, verifies it on every start,
and a 30-second reconciler re-renders and restores a drifted, replaced, or
deleted fence. A VM whose generation ends while the guest keeps running is
halted.
- **Images.** `guest_image` is a bootable containerDisk (a guest rootfs plus a
kernel and initramfs), not an arbitrary sandbox OCI image. Once the launcher
Pod has pulled it, the driver pins the VM spec to the resolved
`repo@sha256:` digest on the reconcile tick, so a tag move cannot change what
a later start boots.
- **Workspace.** A per-sandbox PVC is attached over virtio-fs at `/sandbox`.
The guest idmaps the share to the workload uid because virtiofsd runs as the
launcher's fsGroup and cannot switch to the guest workload identity.
- **Acceptance lane.** `e2e/kubevirt/` is a manual lane: it needs a cluster
with nested KVM, a KubeVirt install, and a purpose-built guest image, so
nothing in CI or `e2e/rust` schedules it.

The implementation lives in `src/kubevirt.rs` (VirtualMachine rendering,
lifecycle state machine, resource mapping), `src/kubevirt_boundary.rs`
(bootstrap, fence, workspace PVC, supervisor Pod), and the `KubeVirt` branches
in `src/driver.rs`. `tests/` on the crate cover the rendering and the state
machine.

## Sandbox Resource

The driver works with the `agents.x-k8s.io` `Sandbox` custom resource. It
Expand Down
135 changes: 132 additions & 3 deletions crates/openshell-driver-kubernetes/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,66 @@ impl KubernetesSandboxRuntimeConfig {
}
}

/// How workspaces map to Kubernetes namespaces.
/// Runtime substrate the Kubernetes driver provisions sandboxes on.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum KubernetesRuntimeMode {
/// Provision sandboxes as `agents.x-k8s.io` Sandbox CRs reconciled into
/// pods by the upstream Agent Sandbox controller (default, production
/// path).
#[default]
Pod,
/// Provision sandboxes as `kubevirt.io/v1` `VirtualMachine` objects
/// reconciled by the `KubeVirt` controller.
#[serde(rename = "kubevirt", alias = "kube-virt")]
KubeVirt,
}

impl std::fmt::Display for KubernetesRuntimeMode {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Pod => f.write_str("pod"),
Self::KubeVirt => f.write_str("kubevirt"),
}
}
}

/// How the guest workload runs.
///
/// `KubeVirt` runtime mode settings.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(default, deny_unknown_fields)]
pub struct KubeVirtConfig {
/// containerDisk image providing the bootable guest filesystem. The image
/// must contain a Linux guest with the static `openshell-sandbox`
/// supervisor and an init that consumes the driver-rendered bootstrap
/// Secret (cloudInitNoCloud transport). Not an arbitrary sandbox OCI
/// image — see `e2e/kubevirt/` for the purpose-built image build.
pub guest_image: String,
/// Kubernetes `imagePullPolicy` for the guest containerDisk.
/// Empty string omits the field, using the Kubernetes default.
pub guest_image_pull_policy: String,
/// vCPU cores allocated to each guest.
pub cpu_cores: u32,
/// Guest memory request, e.g. `"1Gi"`.
pub memory: String,
/// Attach a per-sandbox PVC at `/sandbox` so the workspace survives
/// stop/start (mirrors the pod path's PVC-backed workspace).
pub workspace_pvc: bool,
}

impl Default for KubeVirtConfig {
fn default() -> Self {
Self {
guest_image: String::new(),
guest_image_pull_policy: String::new(),
cpu_cores: 1,
memory: "1Gi".to_string(),
workspace_pvc: true,
}
}
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum WorkspaceMode {
Expand Down Expand Up @@ -470,6 +529,12 @@ pub struct KubernetesComputeConfig {
/// When empty and `sandbox_uid` is set, defaults to the resolved UID.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub sandbox_gid: Option<u32>,
/// Runtime substrate the driver provisions sandboxes on. Defaults to
/// `pod` (Agent Sandbox CRs). `kubevirt` creates `KubeVirt`
/// `VirtualMachine` objects directly.
pub runtime: KubernetesRuntimeMode,
/// `KubeVirt` settings, used only when `runtime = "kubevirt"`.
pub kubevirt: KubeVirtConfig,
}

#[derive(Debug, Clone, Default, Serialize, Deserialize)]
Expand Down Expand Up @@ -558,6 +623,8 @@ impl Default for KubernetesComputeConfig {
provider_spiffe_workload_api_socket_path: String::new(),
sandbox_uid: None,
sandbox_gid: None,
runtime: KubernetesRuntimeMode::default(),
kubevirt: KubeVirtConfig::default(),
}
}
}
Expand All @@ -574,7 +641,8 @@ impl KubernetesComputeConfig {
self.validate_upstream_proxy_config()?;
self.validate_allowed_pod_annotations()?;
self.validate_allowed_pod_labels()?;
self.ipv6_egress_config().validate()
self.ipv6_egress_config().validate()?;
self.validate_kubevirt_config()
}

fn validate_bootstrap_windows(&self) -> Result<(), String> {
Expand Down Expand Up @@ -689,6 +757,66 @@ impl KubernetesComputeConfig {
)
}

/// Validate the `KubeVirt` runtime mode configuration.
///
/// The `KubeVirt` runtime supports one supervisor topology: a dedicated
/// supervisor Pod per sandbox, which is what an unset
/// `supervisor_topology` selects. The gateway-shared supervisor is
/// refused: it has never run against a `KubeVirt` guest, and the mode is
/// not a place to start.
///
/// `grpc_endpoint` is therefore required — the dedicated supervisor Pod
/// must reach the gateway, exactly as the pod path's supervisor Pods do.
/// Any scheme is accepted: a dedicated supervisor carries client TLS
/// material, so an `https://` endpoint is as valid as an `http://` one.
pub fn validate_kubevirt_config(&self) -> Result<(), String> {
if self.runtime != KubernetesRuntimeMode::KubeVirt {
return Ok(());
}
if self.supervisor_topology.is_none() && self.grpc_endpoint.trim().is_empty() {
return Err(
"kubevirt runtime with a dedicated supervisor Pod requires grpc_endpoint: the \
supervisor Pod must be able to reach the gateway"
.to_string(),
);
}
if self.kubevirt.guest_image.trim().is_empty() {
return Err(
"kubevirt runtime requires kubevirt.guest_image to be set to a bootable \
containerDisk image"
.to_string(),
);
}
if self.kubevirt.cpu_cores == 0 {
return Err("kubevirt.cpu_cores must be at least 1".to_string());
}
if self.kubevirt.memory.trim().is_empty() {
return Err("kubevirt.memory must be set (e.g. \"1Gi\")".to_string());
}
if !matches!(
self.workspace_mode,
WorkspaceMode::Shared | WorkspaceMode::Managed
) {
return Err(format!(
"kubevirt runtime supports the shared and managed workspace \
modes; configured mode is {}",
self.workspace_mode
));
}
// One supervisor per sandbox: the gateway-shared supervisor has
// never run against a KubeVirt guest, and only the dedicated Pod has
// ever been exercised end to end.
if self.supervisor_topology.is_some() {
return Err(
"kubevirt runtime requires the dedicated supervisor topology \
(supervisor_topology unset); the gateway-shared supervisor is not \
supported for KubeVirt VMs"
.to_string(),
);
}
Ok(())
}

pub fn validate_proxy_uid(&self) -> Result<(), String> {
self.sandbox_runtime.validate()
}
Expand Down Expand Up @@ -1183,8 +1311,9 @@ fn validate_provider_spiffe_workload_api_socket_path_value(

#[cfg(test)]
mod tests {

use super::*;
use std::collections::BTreeMap as HashMap;
use BTreeMap as HashMap;

#[test]
fn app_endpoint_configuration_has_one_port_source_and_explicit_enablement() {
Expand Down
Loading
Loading