Skip to content

Commit 9083078

Browse files
committed
feat(kubernetes): adopt shared supervisor boundary mode
Signed-off-by: Drew Newberry <anewberry@nvidia.com>
1 parent f3fd9d9 commit 9083078

4 files changed

Lines changed: 194 additions & 0 deletions

File tree

‎crates/openshell-driver-kubernetes/Cargo.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ path = "src/main.rs"
1616

1717
[dependencies]
1818
openshell-core = { path = "../openshell-core", default-features = false }
19+
openshell-isolation-interface = { path = "../openshell-isolation-interface" }
1920
openshell-otel = { path = "../openshell-otel" }
2021
openshell-policy = { path = "../openshell-policy" }
2122

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,35 @@ this driver. Kubernetes owns scheduling and pod lifecycle. The
4949
`openshell-sandbox` supervisor inside each workload owns agent isolation,
5050
credential injection, policy polling, logs, and the gateway relay.
5151

52+
### RFC 0012 proxy-pod prototype
53+
54+
The crate contains review-only provisioning for the `kubernetes-proxy-pod`
55+
Isolation Backend. It is not registered by the gateway and does not change the
56+
default runtime model. The proxy pod runs `openshell-sandbox --mode=control`;
57+
the workload pod runs the same binary with `--mode=boundary`. They use the
58+
shared authenticated boundary protocol over a TCP path scoped to the two pods.
59+
The Kubernetes-specific layer only provisions that placement:
60+
61+
- Matching protected configs carry the namespace, workload pod, proxy pod, and
62+
egress `NetworkPolicy` UIDs. They also bind the observed policy resource
63+
version so a mutation cannot silently reuse an old attachment.
64+
- The boundary listens on its pod interface. The control descriptor contains a
65+
concrete workload-pod address; the shared protocol rejects an unspecified or
66+
zero-port dial target.
67+
- The per-boundary bootstrap credential authenticates every operation. A
68+
Kubernetes `NetworkPolicy` must additionally restrict the listener to the
69+
paired proxy pod.
70+
- Lifecycle, process and exec control, signal and wait, PTY streaming,
71+
loopback forwarding, attributed egress, and binary identity all come from
72+
`openshell-isolation-interface` and `openshell-sandbox`.
73+
74+
Resource rendering and runtime registration remain follow-up work. The driver
75+
must keep the workload held while Kubernetes assigns the object UIDs, install
76+
both protected configs from that observed resource set, and release it only
77+
after shared `confirm` succeeds. A pod-level fence that also grants the workload
78+
direct DNS or gateway access, or an explicit proxy that drops process
79+
attribution, does not satisfy RFC 0012's egress and binary-identity invariants.
80+
5281
## Sandbox Resource
5382

5483
The driver works with the `agents.x-k8s.io` `Sandbox` custom resource. It
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
// SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
//! Kubernetes provisioning for the shared authenticated boundary protocol.
5+
//!
6+
//! This module deliberately contains no lifecycle, process, network, identity,
7+
//! or wire implementation. The driver chooses the proxy-pod placement, binds
8+
//! immutable Kubernetes resource identities, and provisions TCP coordinates;
9+
//! `openshell-isolation-interface` and `openshell-sandbox` provide the common
10+
//! control and boundary behavior.
11+
12+
use std::collections::{BTreeMap, HashMap};
13+
use std::net::{IpAddr, SocketAddr};
14+
use std::path::PathBuf;
15+
16+
use openshell_isolation_interface::boundary_protocol::{
17+
BOUNDARY_PROTOCOL_VERSION, BoundaryAgentIdentity, BoundaryConfig, BoundaryListener,
18+
BoundaryTopology, BoundaryTransport,
19+
};
20+
21+
/// Registered RFC 0012 backend name for the proxy-pod topology.
22+
pub const BACKEND_NAME: &str = "kubernetes-proxy-pod";
23+
24+
/// Driver-owned inputs that bind one workload/proxy pair to one boundary.
25+
///
26+
/// The driver constructs this only after Kubernetes has assigned every UID and
27+
/// after it has observed the exact egress policy resource version. The workload
28+
/// stays held until the matching boundary config and control topology have been
29+
/// installed.
30+
pub struct KubernetesProxyPodBoundarySpec {
31+
pub boundary_id: String,
32+
pub bootstrap_token: String,
33+
pub namespace_uid: String,
34+
pub workload_pod_uid: String,
35+
pub proxy_pod_uid: String,
36+
pub egress_policy_uid: String,
37+
pub egress_policy_resource_version: String,
38+
pub boundary_listener: SocketAddr,
39+
pub control_address: SocketAddr,
40+
pub host_gateway_ip: Option<IpAddr>,
41+
pub agent_uid: u32,
42+
pub agent_gid: u32,
43+
pub trusted_runtime_root: PathBuf,
44+
pub child_env: HashMap<String, String>,
45+
}
46+
47+
/// Protected workload-pod config and matching proxy-pod descriptor.
48+
pub struct KubernetesProxyPodBoundaryProvisioning {
49+
pub boundary_config: BoundaryConfig,
50+
pub topology: BoundaryTopology,
51+
}
52+
53+
impl KubernetesProxyPodBoundarySpec {
54+
/// Produce both sides of the common protocol from one observed Kubernetes
55+
/// resource set so a stale or recreated object cannot be attached.
56+
#[must_use]
57+
pub fn provision(self) -> KubernetesProxyPodBoundaryProvisioning {
58+
let resource_claims = BTreeMap::from([
59+
("kubernetes.namespace_uid".to_string(), self.namespace_uid),
60+
(
61+
"kubernetes.workload_pod_uid".to_string(),
62+
self.workload_pod_uid,
63+
),
64+
("kubernetes.proxy_pod_uid".to_string(), self.proxy_pod_uid),
65+
(
66+
"kubernetes.egress_policy_uid".to_string(),
67+
self.egress_policy_uid,
68+
),
69+
(
70+
"kubernetes.egress_policy_resource_version".to_string(),
71+
self.egress_policy_resource_version,
72+
),
73+
]);
74+
KubernetesProxyPodBoundaryProvisioning {
75+
boundary_config: BoundaryConfig {
76+
protocol_version: BOUNDARY_PROTOCOL_VERSION,
77+
boundary_id: self.boundary_id.clone(),
78+
bootstrap_token: self.bootstrap_token.clone(),
79+
listener: BoundaryListener::Tcp {
80+
address: self.boundary_listener,
81+
},
82+
resource_claims: resource_claims.clone(),
83+
agent_identity: BoundaryAgentIdentity::Resolved {
84+
uid: self.agent_uid,
85+
gid: self.agent_gid,
86+
},
87+
protect_config_file: true,
88+
trusted_runtime_root: self.trusted_runtime_root,
89+
child_env: self.child_env,
90+
},
91+
topology: BoundaryTopology {
92+
protocol_version: BOUNDARY_PROTOCOL_VERSION,
93+
boundary_id: self.boundary_id,
94+
transport: BoundaryTransport::Tcp {
95+
address: self.control_address,
96+
},
97+
host_gateway_ip: self.host_gateway_ip,
98+
resource_claims,
99+
bootstrap_token: self.bootstrap_token,
100+
},
101+
}
102+
}
103+
}
104+
105+
#[cfg(test)]
106+
mod tests {
107+
use super::*;
108+
109+
fn spec() -> KubernetesProxyPodBoundarySpec {
110+
KubernetesProxyPodBoundarySpec {
111+
boundary_id: "sandbox-1".to_string(),
112+
bootstrap_token: "a".repeat(64),
113+
namespace_uid: "namespace-uid".to_string(),
114+
workload_pod_uid: "workload-pod-uid".to_string(),
115+
proxy_pod_uid: "proxy-pod-uid".to_string(),
116+
egress_policy_uid: "network-policy-uid".to_string(),
117+
egress_policy_resource_version: "1945".to_string(),
118+
boundary_listener: "0.0.0.0:5500".parse().expect("valid listener"),
119+
control_address: "10.42.0.7:5500".parse().expect("valid target"),
120+
host_gateway_ip: Some("10.42.0.1".parse().expect("valid gateway IP")),
121+
agent_uid: 1000,
122+
agent_gid: 1000,
123+
trusted_runtime_root: PathBuf::from("/opt/openshell/bin/openshell-runtime"),
124+
child_env: HashMap::new(),
125+
}
126+
}
127+
128+
#[test]
129+
fn provisioning_binds_identical_kubernetes_resource_claims() {
130+
let provisioned = spec().provision();
131+
132+
assert_eq!(
133+
provisioned.boundary_config.resource_claims,
134+
provisioned.topology.resource_claims
135+
);
136+
assert_eq!(
137+
provisioned.topology.resource_claims["kubernetes.workload_pod_uid"],
138+
"workload-pod-uid"
139+
);
140+
assert_eq!(
141+
provisioned.topology.resource_claims["kubernetes.egress_policy_resource_version"],
142+
"1945"
143+
);
144+
}
145+
146+
#[test]
147+
fn provisioning_uses_one_shared_tcp_protocol_across_pods() {
148+
let provisioned = spec().provision();
149+
150+
assert_eq!(
151+
provisioned.boundary_config.listener,
152+
BoundaryListener::Tcp {
153+
address: "0.0.0.0:5500".parse().expect("valid listener"),
154+
}
155+
);
156+
assert_eq!(
157+
provisioned.topology.transport,
158+
BoundaryTransport::Tcp {
159+
address: "10.42.0.7:5500".parse().expect("valid target"),
160+
}
161+
);
162+
}
163+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
pub mod config;
55
pub mod driver;
66
pub mod grpc;
7+
pub mod isolation;
78
pub mod otel_tracing;
89

910
pub use config::{

0 commit comments

Comments
 (0)