Skip to content

Commit 88e12a0

Browse files
committed
refactor(isolation): generalize loopback connector
Signed-off-by: Drew Newberry <anewberry@nvidia.com>
1 parent 24514b0 commit 88e12a0

3 files changed

Lines changed: 21 additions & 14 deletions

File tree

‎crates/openshell-isolation-interface/src/contract.rs‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -548,8 +548,8 @@ pub trait RunningBoundary: Send + Sync {
548548
fn agent(&self) -> Arc<dyn BoundaryProcess>;
549549
/// The in-boundary exec interface.
550550
fn exec(&self) -> Arc<dyn BoundaryExec>;
551-
/// The loopback port-forward interface.
552-
fn port_forward(&self) -> Arc<dyn BoundaryPortForward>;
551+
/// The loopback connection interface used by port forwarding and service exposure.
552+
fn loopback_connector(&self) -> Arc<dyn BoundaryLoopbackConnector>;
553553
}
554554

555555
// ============================================================================
@@ -687,9 +687,13 @@ impl<T: AsyncRead + AsyncWrite + Send + Unpin> DuplexStream for T {}
687687
/// An open connection into a boundary loopback target.
688688
pub type BoundaryDuplexStream = Box<dyn DuplexStream>;
689689

690-
/// Loopback port-forward, consumed by the SSH server and supervisor session.
690+
/// Protected connector to services listening inside the boundary.
691+
///
692+
/// Higher layers use this primitive for both end-user port forwarding and
693+
/// service exposure. Authentication, public listeners, routing, and exposure
694+
/// lifecycle remain outside the isolation backend.
691695
#[async_trait]
692-
pub trait BoundaryPortForward: Send + Sync {
696+
pub trait BoundaryLoopbackConnector: Send + Sync {
693697
/// Connect to `target` inside the boundary.
694698
async fn connect(&self, target: LoopbackTarget) -> Result<BoundaryDuplexStream, BackendError>;
695699
}

‎crates/openshell-isolation-interface/tests/backend_conformance.rs‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,10 @@ impl BoundaryExec for MockExec {
174174
}
175175
}
176176

177-
struct MockPortForward;
177+
struct MockLoopbackConnector;
178178

179179
#[async_trait]
180-
impl BoundaryPortForward for MockPortForward {
180+
impl BoundaryLoopbackConnector for MockLoopbackConnector {
181181
async fn connect(&self, _target: LoopbackTarget) -> Result<BoundaryDuplexStream, BackendError> {
182182
let (near, far) = tokio::io::duplex(64);
183183
tokio::spawn(async move {
@@ -205,7 +205,7 @@ struct MockReady<K> {
205205
struct MockRunning<K> {
206206
process: Arc<MockProcess>,
207207
exec: Arc<MockExec>,
208-
port_forward: Arc<MockPortForward>,
208+
loopback_connector: Arc<MockLoopbackConnector>,
209209
_k: PhantomData<K>,
210210
}
211211

@@ -229,7 +229,7 @@ impl<K: MockKind> ReadyBoundary for MockReady<K> {
229229
Ok(Box::new(MockRunning::<K> {
230230
process: MockProcess::new(),
231231
exec: Arc::new(MockExec),
232-
port_forward: Arc::new(MockPortForward),
232+
loopback_connector: Arc::new(MockLoopbackConnector),
233233
_k: PhantomData,
234234
}))
235235
}
@@ -242,8 +242,8 @@ impl<K: MockKind> RunningBoundary for MockRunning<K> {
242242
fn exec(&self) -> Arc<dyn BoundaryExec> {
243243
self.exec.clone()
244244
}
245-
fn port_forward(&self) -> Arc<dyn BoundaryPortForward> {
246-
self.port_forward.clone()
245+
fn loopback_connector(&self) -> Arc<dyn BoundaryLoopbackConnector> {
246+
self.loopback_connector.clone()
247247
}
248248
}
249249

@@ -695,7 +695,10 @@ async fn validated_port_forward_stream_remains_usable() {
695695
use tokio::io::{AsyncReadExt, AsyncWriteExt};
696696

697697
let target = LoopbackTarget::new("127.0.0.1".parse().unwrap(), 8080).unwrap();
698-
let mut stream = MockPortForward.connect(target).await.expect("connect");
698+
let mut stream = MockLoopbackConnector
699+
.connect(target)
700+
.await
701+
.expect("connect");
699702
stream.write_all(b"ping").await.expect("write");
700703
let mut response = [0_u8; 4];
701704
stream.read_exact(&mut response).await.expect("read");

‎rfc/0012-isolation-backend/README.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ trait ReadyBoundary: Send {
184184
trait RunningBoundary: Send + Sync {
185185
fn agent(&self) -> Arc<dyn BoundaryProcess>;
186186
fn exec(&self) -> Arc<dyn BoundaryExec>;
187-
fn port_forward(&self) -> Arc<dyn BoundaryPortForward>;
187+
fn loopback_connector(&self) -> Arc<dyn BoundaryLoopbackConnector>;
188188
}
189189
```
190190

@@ -232,7 +232,7 @@ struct ExecSession { // owned; outlives the exec ca
232232
}
233233

234234
#[async_trait]
235-
trait BoundaryPortForward: Send + Sync {
235+
trait BoundaryLoopbackConnector: Send + Sync {
236236
async fn connect(&self, target: LoopbackTarget) -> Result<BoundaryDuplexStream, BackendError>;
237237
}
238238

@@ -242,7 +242,7 @@ trait BoundaryTerminal: Send + Sync {
242242
}
243243
```
244244

245-
`ExecSpec` carries command, arguments, environment, working directory, and PTY settings. Streams are owned, non-PTY stdout and stderr remain separate, and PTYs support resize. Port forwarding accepts only validated loopback targets. Exit status and signals are explicit and placement-neutral; a local PID is never the process handle. These operations carry the existing agent, SSH, exec, and forwarding paths behind the contract, and all of them are mandatory conformance.
245+
`ExecSpec` carries command, arguments, environment, working directory, and PTY settings. Streams are owned, non-PTY stdout and stderr remain separate, and PTYs support resize. The loopback connector accepts only validated loopback targets and supplies the protected connection primitive used by both end-user port forwarding and service exposure. Public listeners, authentication, routing, and exposure lifecycle remain above the isolation backend. Exit status and signals are explicit and placement-neutral; a local PID is never the process handle. These operations carry the existing agent, SSH, exec, and forwarding paths behind the contract, and all of them are mandatory conformance.
246246

247247
`BoundaryProcess::wait` returns one stable exit status or `Terminated` error while the backend retains process-exit observation.
248248

0 commit comments

Comments
 (0)