Skip to content

Commit c60e2c0

Browse files
committed
feat(mxc): admit foreground sandbox create without a TTY
Signed-off-by: Rahool Paliwal <rpaliwal@nvidia.com>
1 parent f980e72 commit c60e2c0

2 files changed

Lines changed: 27 additions & 11 deletions

File tree

‎crates/openshell-driver-mxc/src/driver.rs‎

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -304,10 +304,10 @@ impl MxcComputeBackend {
304304
if sandbox
305305
.spec
306306
.as_ref()
307-
.is_some_and(|spec| spec.await_main_process_attachment)
307+
.is_some_and(|spec| spec.await_main_process_attachment && spec.tty)
308308
{
309309
return Err(tonic::Status::failed_precondition(
310-
"MXC does not support foreground attachment to the main process. Create the sandbox with --detach.",
310+
"MXC does not support an interactive terminal for the main process. Create the sandbox with --no-tty or --detach.",
311311
));
312312
}
313313
openshell_core::resource_admission::check_sandbox_driver_config(
@@ -1931,21 +1931,37 @@ mod tests {
19311931
}
19321932

19331933
#[tokio::test]
1934-
async fn foreground_attachment_is_rejected_before_provisioning() {
1934+
async fn foreground_terminal_attachment_is_rejected_before_provisioning() {
19351935
let (backend, mut sandbox, _dir) = preflight_fixture();
1936-
sandbox.spec.as_mut().unwrap().command =
1937-
vec!["cmd.exe".into(), "/c".into(), "exit 0".into()];
1938-
sandbox.spec.as_mut().unwrap().await_main_process_attachment = true;
1936+
let spec = sandbox.spec.as_mut().unwrap();
1937+
spec.command = vec!["cmd.exe".into(), "/c".into(), "exit 0".into()];
1938+
spec.await_main_process_attachment = true;
1939+
spec.tty = true;
19391940
let error = backend.validate_sandbox_create(&sandbox).unwrap_err();
19401941
assert_eq!(error.code(), tonic::Code::FailedPrecondition);
1941-
assert!(error.message().contains("--detach"));
1942+
assert!(error.message().contains("--no-tty"));
19421943
let error = backend.create_sandbox(&sandbox).await.unwrap_err();
19431944
assert_eq!(error.code(), tonic::Code::FailedPrecondition);
1944-
assert!(error.message().contains("foreground attachment"));
1945+
assert!(error.message().contains("interactive terminal"));
19451946
assert!(backend.get_sandbox(&sandbox.id).await.is_none());
19461947
assert!(!backend.config.state_dir.exists());
1947-
sandbox.spec.as_mut().unwrap().await_main_process_attachment = false;
1948-
assert!(backend.validate_sandbox_create(&sandbox).is_ok());
1948+
}
1949+
1950+
#[test]
1951+
fn non_terminal_foreground_and_detached_creates_are_admitted() {
1952+
let (backend, mut sandbox, _dir) = preflight_fixture();
1953+
let spec = sandbox.spec.as_mut().unwrap();
1954+
spec.command = vec!["cmd.exe".into(), "/c".into(), "exit 0".into()];
1955+
// Foreground without a terminal streams output over the SSH attachment.
1956+
for (await_attachment, tty) in [(true, false), (false, false), (false, true)] {
1957+
let spec = sandbox.spec.as_mut().unwrap();
1958+
spec.await_main_process_attachment = await_attachment;
1959+
spec.tty = tty;
1960+
assert!(
1961+
backend.validate_sandbox_create(&sandbox).is_ok(),
1962+
"await_main_process_attachment={await_attachment} tty={tty} must be admitted"
1963+
);
1964+
}
19491965
}
19501966

19511967
#[test]

‎crates/openshell-supervisor/src/lib.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ async fn run_sandbox_with_backend(
769769
} = config;
770770
// The current client attachment adapter is SSH; retaining a process's I/O
771771
// internally does not make it reachable by a foreground client.
772-
if await_main_process_attachment && (!cfg!(unix) || ssh_socket_path.is_none()) {
772+
if await_main_process_attachment && ssh_socket_path.is_none() {
773773
return Err(miette::miette!(
774774
"foreground attachment to the main process requires a supported SSH access adapter; create the sandbox with --detach"
775775
));

0 commit comments

Comments
 (0)