Skip to content

Commit ac22cde

Browse files
committed
refactor(sandbox): implement loopback connector
Signed-off-by: Drew Newberry <anewberry@nvidia.com>
1 parent 11bd52e commit ac22cde

7 files changed

Lines changed: 57 additions & 54 deletions

File tree

‎crates/openshell-sandbox/src/boundary_io.rs‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
//! Sandbox-local [`BoundaryPortForward`] implementation.
4+
//! Sandbox-local [`BoundaryLoopbackConnector`] implementation.
55
66
use async_trait::async_trait;
77
use openshell_isolation_interface::contract::{
8-
BackendError, BoundaryDuplexStream, BoundaryPortForward, LoopbackTarget,
8+
BackendError, BoundaryDuplexStream, BoundaryLoopbackConnector, LoopbackTarget,
99
};
1010
use std::collections::HashMap;
1111
use std::sync::atomic::{AtomicU8, Ordering};
@@ -168,19 +168,19 @@ impl RegisteredProcessGroup {
168168
}
169169

170170
/// Loopback port-forward owned by the sandbox process.
171-
pub struct LocalPortForward {
171+
pub struct LocalLoopbackConnector {
172172
runtime: Option<Arc<BoundaryRuntimeState>>,
173173
}
174174

175-
impl LocalPortForward {
175+
impl LocalLoopbackConnector {
176176
#[must_use]
177177
pub fn new(runtime: Option<Arc<BoundaryRuntimeState>>) -> Self {
178178
Self { runtime }
179179
}
180180
}
181181

182182
#[async_trait]
183-
impl BoundaryPortForward for LocalPortForward {
183+
impl BoundaryLoopbackConnector for LocalLoopbackConnector {
184184
async fn connect(&self, target: LoopbackTarget) -> Result<BoundaryDuplexStream, BackendError> {
185185
if let Some(runtime) = &self.runtime {
186186
runtime.ensure_active()?;
@@ -205,7 +205,7 @@ mod tests {
205205
/// Stands in for the SSH server's port-forward path: connect through the
206206
/// interface, write, and read the echo.
207207
#[tokio::test]
208-
async fn port_forward_connects_and_round_trips() {
208+
async fn loopback_connector_connects_and_round_trips() {
209209
let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();
210210
let addr = listener.local_addr().unwrap();
211211
tokio::spawn(async move {
@@ -215,7 +215,7 @@ mod tests {
215215
sock.write_all(&buf).await.unwrap();
216216
});
217217

218-
let pf = LocalPortForward::new(None);
218+
let pf = LocalLoopbackConnector::new(None);
219219
let target =
220220
LoopbackTarget::new(Ipv4Addr::LOCALHOST.into(), addr.port()).expect("loopback target");
221221
let mut conn = pf.connect(target).await.expect("connect through interface");
@@ -228,24 +228,24 @@ mod tests {
228228
/// Drive the port-forward interface through a generic `&dyn` consumer, proving a
229229
/// kernel-separated backend (tunneling into a guest) would use the same call.
230230
#[tokio::test]
231-
async fn port_forward_is_driven_via_dyn() {
232-
async fn forward_one(pf: &dyn BoundaryPortForward, target: LoopbackTarget) -> bool {
231+
async fn loopback_connector_is_driven_via_dyn() {
232+
async fn forward_one(pf: &dyn BoundaryLoopbackConnector, target: LoopbackTarget) -> bool {
233233
pf.connect(target).await.is_ok()
234234
}
235235
let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();
236236
let addr = listener.local_addr().unwrap();
237237
tokio::spawn(async move {
238238
let _ = listener.accept().await;
239239
});
240-
let pf = LocalPortForward::new(None);
240+
let pf = LocalLoopbackConnector::new(None);
241241
let target = LoopbackTarget::new(Ipv4Addr::LOCALHOST.into(), addr.port()).unwrap();
242242
assert!(forward_one(&pf, target).await);
243243
}
244244

245245
#[tokio::test]
246-
async fn port_forward_rejects_after_boundary_end() {
246+
async fn loopback_connector_rejects_after_boundary_end() {
247247
let runtime = BoundaryRuntimeState::new();
248-
let pf = LocalPortForward::new(Some(runtime.clone()));
248+
let pf = LocalLoopbackConnector::new(Some(runtime.clone()));
249249
runtime.deactivate();
250250
let target = LoopbackTarget::new(Ipv4Addr::LOCALHOST.into(), 1).unwrap();
251251
assert!(matches!(
@@ -255,9 +255,9 @@ mod tests {
255255
}
256256

257257
#[tokio::test]
258-
async fn failed_port_forward_keeps_boundary_active() {
258+
async fn failed_loopback_connector_keeps_boundary_active() {
259259
let runtime = BoundaryRuntimeState::new();
260-
let pf = LocalPortForward::new(Some(runtime.clone()));
260+
let pf = LocalLoopbackConnector::new(Some(runtime.clone()));
261261
// Port zero is never a connectable TCP destination. Reserving an ephemeral
262262
// port and dropping its listener races other parallel tests that may bind it.
263263
let target = LoopbackTarget::new(Ipv4Addr::LOCALHOST.into(), 0).unwrap();

‎crates/openshell-sandbox/src/boundary_server.rs‎

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ mod linux {
3939
};
4040
use openshell_core::provider_credentials::ProviderCredentialState;
4141
use openshell_isolation_interface::contract::{
42-
BoundaryExec, BoundaryPortForward, BoundaryProcess, BoundaryTerminal, CapabilityEvidence,
43-
ExecSession, LoopbackTarget, ResolvedWorkloadIdentity, SandboxConfirmEvidence,
42+
BoundaryExec, BoundaryLoopbackConnector, BoundaryProcess, BoundaryTerminal,
43+
CapabilityEvidence, ExecSession, LoopbackTarget, ResolvedWorkloadIdentity,
44+
SandboxConfirmEvidence,
4445
};
4546
use openshell_isolation_interface::mediation::{
4647
self, DnsQueryWire, MediationFrame, MediationFrameKind,
@@ -884,7 +885,7 @@ mod linux {
884885
.map_err(|error| format!("write process attachment response: {error}"))?;
885886
return runtime.stream_process(stream, attachment);
886887
}
887-
Request::PortForward { host, port } => {
888+
Request::LoopbackConnect { host, port } => {
888889
let target = match LoopbackTarget::new(host, port)
889890
.map_err(|error| format!("validate port-forward target: {error}"))
890891
.and_then(|target| {
@@ -1319,7 +1320,7 @@ mod linux {
13191320
),
13201321
Request::Exec { .. }
13211322
| Request::AttachProcess { .. }
1322-
| Request::PortForward { .. }
1323+
| Request::LoopbackConnect { .. }
13231324
| Request::AcceptNetwork => guest_error(
13241325
BoundaryErrorKind::Invalid,
13251326
"streaming request used on control path",
@@ -1527,15 +1528,15 @@ mod linux {
15271528
&self,
15281529
target: LoopbackTarget,
15291530
) -> Result<openshell_isolation_interface::contract::BoundaryDuplexStream, String> {
1530-
let port_forward = {
1531+
let loopback_connector = {
15311532
let state = lock(&self.state);
15321533
let RuntimeState::Running(process) = &*state else {
15331534
return Err("agent process has not been started".to_string());
15341535
};
1535-
process.port_forward()
1536+
process.loopback_connector()
15361537
};
15371538
self.process_runtime
1538-
.block_on(port_forward.connect(target))
1539+
.block_on(loopback_connector.connect(target))
15391540
.map_err(|error| error.to_string())
15401541
}
15411542

@@ -2121,7 +2122,7 @@ mod linux {
21212122
signaler: AgentSignaler,
21222123
exit: SharedProcessExit,
21232124
boundary_exec: Arc<dyn BoundaryExec>,
2124-
port_forward: Arc<dyn BoundaryPortForward>,
2125+
loopback_connector: Arc<dyn BoundaryLoopbackConnector>,
21252126
main_session: Arc<MainSession>,
21262127
attached: Arc<AtomicBool>,
21272128
boundary_runtime: Arc<BoundaryRuntimeState>,
@@ -2195,7 +2196,7 @@ mod linux {
21952196
.map_err(|error| format!("start process supervisor leaf: {error:?}"))?;
21962197
let signaler = spawned.signaler();
21972198
let boundary_exec = spawned.boundary_exec();
2198-
let port_forward = spawned.port_forward();
2199+
let loopback_connector = spawned.loopback_connector();
21992200
let main_session = spawned.main_session();
22002201
let exit = Arc::new((Mutex::new(None), Condvar::new()));
22012202
let reaper_exit = exit.clone();
@@ -2214,7 +2215,7 @@ mod linux {
22142215
signaler,
22152216
exit,
22162217
boundary_exec,
2217-
port_forward,
2218+
loopback_connector,
22182219
main_session,
22192220
attached: Arc::new(AtomicBool::new(false)),
22202221
boundary_runtime,
@@ -2266,8 +2267,8 @@ mod linux {
22662267
self.boundary_exec.clone()
22672268
}
22682269

2269-
fn port_forward(&self) -> Arc<dyn BoundaryPortForward> {
2270-
self.port_forward.clone()
2270+
fn loopback_connector(&self) -> Arc<dyn BoundaryLoopbackConnector> {
2271+
self.loopback_connector.clone()
22712272
}
22722273

22732274
fn main_session(&self) -> Arc<MainSession> {

‎crates/openshell-sandbox/src/delegated.rs‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use miette::WrapErr as _;
1212
use miette::{IntoDiagnostic as _, Result};
1313
use openshell_core::policy::SandboxPolicy;
1414
use openshell_core::provider_credentials::ProviderCredentialState;
15-
use openshell_isolation_interface::contract::{BoundaryExec, BoundaryPortForward};
15+
use openshell_isolation_interface::contract::{BoundaryExec, BoundaryLoopbackConnector};
1616
use openshell_ocsf::{
1717
ActionId, ActivityId, DispositionId, LaunchTypeId, Process as OcsfProcess,
1818
ProcessActivityBuilder, SeverityId, StatusId, ocsf_emit,
@@ -65,8 +65,8 @@ pub async fn spawn_workload(
6565
.and_then(|json| serde_json::from_str(&json).ok())
6666
.unwrap_or_default();
6767
user_environment.retain(|key, _value| !crate::process::is_proxy_env_var(key));
68-
let port_forward: Arc<dyn BoundaryPortForward> = Arc::new(
69-
crate::boundary_io::LocalPortForward::new(Some(boundary_runtime.clone())),
68+
let loopback_connector: Arc<dyn BoundaryLoopbackConnector> = Arc::new(
69+
crate::boundary_io::LocalLoopbackConnector::new(Some(boundary_runtime.clone())),
7070
);
7171
let boundary_exec: Arc<dyn BoundaryExec> =
7272
Arc::new(crate::boundary_exec::LocalBoundaryExec::new(
@@ -129,7 +129,7 @@ pub async fn spawn_workload(
129129
signal_lock,
130130
main_session,
131131
boundary_exec,
132-
port_forward,
132+
loopback_connector,
133133
boundary_runtime,
134134
})
135135
}
@@ -142,7 +142,7 @@ pub struct SpawnedAgent {
142142
signal_lock: Arc<std::sync::Mutex<()>>,
143143
main_session: Arc<crate::main_session::MainSession>,
144144
boundary_exec: Arc<dyn BoundaryExec>,
145-
port_forward: Arc<dyn BoundaryPortForward>,
145+
loopback_connector: Arc<dyn BoundaryLoopbackConnector>,
146146
boundary_runtime: Arc<crate::boundary_io::BoundaryRuntimeState>,
147147
}
148148

@@ -162,8 +162,8 @@ impl SpawnedAgent {
162162
}
163163

164164
#[must_use]
165-
pub fn port_forward(&self) -> Arc<dyn BoundaryPortForward> {
166-
self.port_forward.clone()
165+
pub fn loopback_connector(&self) -> Arc<dyn BoundaryLoopbackConnector> {
166+
self.loopback_connector.clone()
167167
}
168168

169169
/// Retained canonical-process I/O owned by the boundary.

‎crates/openshell-supervisor-process/src/delegated.rs‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ use std::sync::atomic::{AtomicBool, Ordering};
88
use std::time::Duration;
99

1010
use miette::Result;
11-
use openshell_isolation_interface::contract::{BoundaryExec, BoundaryPortForward, BoundaryProcess};
11+
use openshell_isolation_interface::contract::{
12+
BoundaryExec, BoundaryLoopbackConnector, BoundaryProcess,
13+
};
1214
use openshell_ocsf::{ActivityId, AppLifecycleBuilder, SeverityId, StatusId, ocsf_emit};
1315

1416
fn ocsf_ctx() -> &'static openshell_ocsf::SandboxContext {
@@ -82,7 +84,7 @@ pub async fn start_boundary_access(
8284
shared_ssh_socket: bool,
8385
ca_file_paths: Option<(std::path::PathBuf, std::path::PathBuf)>,
8486
boundary_exec: Arc<dyn BoundaryExec>,
85-
port_forward: Arc<dyn BoundaryPortForward>,
87+
port_forward: Arc<dyn BoundaryLoopbackConnector>,
8688
agent: Arc<dyn BoundaryProcess>,
8789
) -> Result<BoundaryAccess> {
8890
let instance_id = uuid::Uuid::new_v4().to_string();

‎crates/openshell-supervisor-process/src/ssh.rs‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ pub async fn run_ssh_server(
122122
ready_tx: tokio::sync::oneshot::Sender<Result<()>>,
123123
ca_file_paths: Option<(PathBuf, PathBuf)>,
124124
shared_socket: bool,
125-
port_forward: Arc<dyn openshell_isolation_interface::contract::BoundaryPortForward>,
125+
port_forward: Arc<dyn openshell_isolation_interface::contract::BoundaryLoopbackConnector>,
126126
boundary_exec: Arc<dyn openshell_isolation_interface::contract::BoundaryExec>,
127127
main_session: Option<Arc<MainSession>>,
128128
) -> Result<()> {
@@ -293,7 +293,7 @@ fn classify_ssh_accept_error(
293293
async fn handle_connection(
294294
stream: tokio::net::UnixStream,
295295
config: Arc<russh::server::Config>,
296-
port_forward: Arc<dyn openshell_isolation_interface::contract::BoundaryPortForward>,
296+
port_forward: Arc<dyn openshell_isolation_interface::contract::BoundaryLoopbackConnector>,
297297
boundary_exec: Arc<dyn openshell_isolation_interface::contract::BoundaryExec>,
298298
main_session: Option<Arc<MainSession>>,
299299
) -> Result<()> {
@@ -362,7 +362,7 @@ struct SshHandler {
362362
/// Loopback port-forward, injected by the orchestrator (RFC 0012). In-pod
363363
/// this connects from inside the workload netns; a delegated backend
364364
/// tunnels into its guest. The handler does not know which.
365-
port_forward: Arc<dyn openshell_isolation_interface::contract::BoundaryPortForward>,
365+
port_forward: Arc<dyn openshell_isolation_interface::contract::BoundaryLoopbackConnector>,
366366
boundary_exec: Arc<dyn openshell_isolation_interface::contract::BoundaryExec>,
367367
main_session: Option<Arc<MainSession>>,
368368
channels: HashMap<ChannelId, ChannelState>,
@@ -389,7 +389,7 @@ impl Drop for SshHandler {
389389

390390
impl SshHandler {
391391
fn new(
392-
port_forward: Arc<dyn openshell_isolation_interface::contract::BoundaryPortForward>,
392+
port_forward: Arc<dyn openshell_isolation_interface::contract::BoundaryLoopbackConnector>,
393393
boundary_exec: Arc<dyn openshell_isolation_interface::contract::BoundaryExec>,
394394
main_session: Option<Arc<MainSession>>,
395395
) -> Self {
@@ -1196,10 +1196,10 @@ mod tests {
11961196
}
11971197
}
11981198

1199-
struct TestPortForward;
1199+
struct TestLoopbackConnector;
12001200

12011201
#[async_trait::async_trait]
1202-
impl openshell_isolation_interface::contract::BoundaryPortForward for TestPortForward {
1202+
impl openshell_isolation_interface::contract::BoundaryLoopbackConnector for TestLoopbackConnector {
12031203
async fn connect(
12041204
&self,
12051205
target: openshell_isolation_interface::contract::LoopbackTarget,
@@ -1249,7 +1249,7 @@ mod tests {
12491249
server_config.keys.push(host_key);
12501250

12511251
let handler = SshHandler::new(
1252-
Arc::new(TestPortForward),
1252+
Arc::new(TestLoopbackConnector),
12531253
Arc::new(RejectingExec),
12541254
Some(MainSession::inert()),
12551255
);

0 commit comments

Comments
 (0)