Skip to content

Commit a3385af

Browse files
committed
test(conformance): use Alpine workload image
Signed-off-by: Evan Lezar <elezar@nvidia.com>
1 parent 796c19e commit a3385af

7 files changed

Lines changed: 53 additions & 29 deletions

File tree

‎crates/openshell-conformance/src/scenarios/sandbox_lifecycle.rs‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,6 @@ async fn create_running_sandbox(
141141
"create",
142142
"--name",
143143
sandbox_name,
144-
"--from",
145-
"base",
146144
"--detach",
147145
"--no-tty",
148146
"--",

‎crates/openshell-conformance/src/scenarios/smoke.rs‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,7 @@ async fn run_smoke_inner(runner: &mut OpenShellRunner) -> Result<(), String> {
5555
.step("create")
5656
.description("sandbox creation succeeds")
5757
.with_timeout(CREATE_TIMEOUT)
58-
.run(&[
59-
"sandbox",
60-
"create",
61-
"--name",
62-
&sandbox_name,
63-
"--from",
64-
"base",
65-
"--detach",
66-
])
58+
.run(&["sandbox", "create", "--name", &sandbox_name, "--detach"])
6759
.await
6860
.map_err(|error| error.to_string())?;
6961
create.require_success()?;

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,7 @@ pub fn restrictive_default_policy() -> SandboxPolicy {
988988
filesystem: Some(FilesystemPolicy {
989989
include_workdir: true,
990990
read_only: vec![
991+
"/bin".into(),
991992
"/usr".into(),
992993
"/lib".into(),
993994
"/proc".into(),
@@ -2128,6 +2129,10 @@ network_policies:
21282129
let policy = restrictive_default_policy();
21292130
let fs = policy.filesystem.expect("must have filesystem policy");
21302131
assert!(fs.include_workdir);
2132+
assert!(
2133+
fs.read_only.iter().any(|p| p == "/bin"),
2134+
"read_only should contain /bin"
2135+
);
21312136
assert!(
21322137
fs.read_only.iter().any(|p| p == "/usr"),
21332138
"read_only should contain /usr"

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,13 @@ impl LocalBoundaryExec {
6969
let (session_user, session_home) =
7070
crate::process::session_user_and_home(&self.policy, effective_workdir);
7171
let path = std::env::var("PATH").unwrap_or_else(|_| "/usr/local/bin:/usr/bin:/bin".into());
72+
let shell = openshell_core::shell::detect_login_shell();
7273
command
7374
.env_clear()
7475
.env(openshell_core::sandbox_env::SANDBOX, "1")
7576
.env("HOME", session_home)
7677
.env("USER", session_user)
77-
.env("SHELL", "/bin/bash")
78+
.env("SHELL", shell)
7879
.env("PATH", path)
7980
.env("TERM", if spec.pty { "xterm-256color" } else { "dumb" });
8081
for (key, value) in &self.user_environment {

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

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -892,21 +892,11 @@ impl SshHandler {
892892
let no_login_shell = state.no_login_shell;
893893
let pty = state.pty_request.take();
894894
let pty_requested = pty.is_some();
895-
let (program, args) = command.map_or_else(
896-
|| {
897-
if pty_requested {
898-
("/bin/bash".to_string(), vec!["-i".to_string()])
899-
} else {
900-
("/bin/bash".to_string(), vec![])
901-
}
902-
},
903-
|command| {
904-
(
905-
"/bin/bash".to_string(),
906-
vec![login_shell_flag(no_login_shell).to_string(), command],
907-
)
908-
},
909-
);
895+
// The supervisor shares the workload filesystem, so select a shell
896+
// that actually exists in the image. Alpine and other minimal images
897+
// provide `/bin/sh` but not `/bin/bash`.
898+
let shell = openshell_core::shell::detect_login_shell();
899+
let (program, args) = shell_command(shell, command, pty_requested, no_login_shell);
910900
let env = pty
911901
.as_ref()
912902
.map(|request| vec![("TERM".to_string(), request.term.clone())])
@@ -1084,6 +1074,25 @@ const fn login_shell_flag(no_login_shell: bool) -> &'static str {
10841074
if no_login_shell { "-c" } else { "-lc" }
10851075
}
10861076

1077+
fn shell_command(
1078+
shell: String,
1079+
command: Option<String>,
1080+
pty_requested: bool,
1081+
no_login_shell: bool,
1082+
) -> (String, Vec<String>) {
1083+
let args = command.map_or_else(
1084+
|| {
1085+
if pty_requested {
1086+
vec!["-i".to_string()]
1087+
} else {
1088+
Vec::new()
1089+
}
1090+
},
1091+
|command| vec![login_shell_flag(no_login_shell).to_string(), command],
1092+
);
1093+
(shell, args)
1094+
}
1095+
10871096
#[allow(dead_code)]
10881097
#[derive(Clone)]
10891098
struct PtyRequest {
@@ -1400,6 +1409,27 @@ mod tests {
14001409
main_session.end_terminal_attachment();
14011410
}
14021411

1412+
#[test]
1413+
fn shell_command_uses_the_resolved_image_shell() {
1414+
let (program, args) = shell_command(
1415+
"/bin/sh".to_string(),
1416+
Some("printf ready".to_string()),
1417+
false,
1418+
false,
1419+
);
1420+
1421+
assert_eq!(program, "/bin/sh");
1422+
assert_eq!(args, ["-lc", "printf ready"]);
1423+
}
1424+
1425+
#[test]
1426+
fn interactive_shell_uses_the_resolved_image_shell() {
1427+
let (program, args) = shell_command("/bin/sh".to_string(), None, true, false);
1428+
1429+
assert_eq!(program, "/bin/sh");
1430+
assert_eq!(args, ["-i"]);
1431+
}
1432+
14031433
#[cfg(unix)]
14041434
fn file_mode(path: &Path) -> u32 {
14051435
use std::os::unix::fs::PermissionsExt;

‎tests/ansible/roles/openshell_gateway/templates/gateway-docker.toml.j2‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
{% block driver %}
55
[openshell.drivers.docker]
66
socket_path = "{{ openshell_runtime_socket }}"
7-
default_image = "ghcr.io/nvidia/openshell-community/sandboxes/base:latest"
87
image_pull_policy = "if_not_present"
98
sandbox_label = "tmachine"
109
grpc_endpoint = "http://127.0.0.1:17670"

‎tests/ansible/roles/openshell_gateway/templates/gateway-podman.toml.j2‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
{% block driver %}
55
[openshell.drivers.podman]
66
socket_path = "{{ openshell_runtime_socket }}"
7-
default_image = "ghcr.io/nvidia/openshell-community/sandboxes/base:latest"
87
image_pull_policy = "if_not_present"
98
sandbox_runtime_image = "docker.io/openshell/sandbox:tmachine"
109
supervisor_image = "docker.io/openshell/supervisor:tmachine"

0 commit comments

Comments
 (0)