Compare commits

...
7 Commits
Author SHA1 Message Date
DuProcess 80699dcf9d Stabilize terminal frame recovery
ci / test (push) Has been cancelled
ci / fuzz-smoke (push) Has been cancelled
ci / windows-client (push) Has been cancelled
ci / package-release (linux-x86_64, ubuntu-latest) (push) Has been cancelled
ci / package-release (macos-aarch64, macos-14) (push) Has been cancelled
ci / package-release (macos-x86_64, macos-13) (push) Has been cancelled
ci / package-release (windows-x86_64, windows-latest) (push) Has been cancelled
ci / remote-bench (push) Has been cancelled
2026-07-03 10:06:23 -04:00
DuProcess 274c0f505e Stop sandboxing remote shells
ci / test (push) Has been cancelled
ci / fuzz-smoke (push) Has been cancelled
ci / windows-client (push) Has been cancelled
ci / package-release (linux-x86_64, ubuntu-latest) (push) Has been cancelled
ci / package-release (macos-aarch64, macos-14) (push) Has been cancelled
ci / package-release (macos-x86_64, macos-13) (push) Has been cancelled
ci / package-release (windows-x86_64, windows-latest) (push) Has been cancelled
ci / remote-bench (push) Has been cancelled
2026-07-02 20:03:42 -04:00
DuProcess b393c0e5d5 Allow netlink for terminal network monitors
ci / test (push) Has been cancelled
ci / fuzz-smoke (push) Has been cancelled
ci / windows-client (push) Has been cancelled
ci / package-release (linux-x86_64, ubuntu-latest) (push) Has been cancelled
ci / package-release (macos-aarch64, macos-14) (push) Has been cancelled
ci / package-release (macos-x86_64, macos-13) (push) Has been cancelled
ci / package-release (windows-x86_64, windows-latest) (push) Has been cancelled
ci / remote-bench (push) Has been cancelled
2026-07-02 19:40:30 -04:00
DuProcess d5bc8e3c64 Recover terminal output gaps with resume repaint
ci / test (push) Has been cancelled
ci / fuzz-smoke (push) Has been cancelled
ci / windows-client (push) Has been cancelled
ci / package-release (linux-x86_64, ubuntu-latest) (push) Has been cancelled
ci / package-release (macos-aarch64, macos-14) (push) Has been cancelled
ci / package-release (macos-x86_64, macos-13) (push) Has been cancelled
ci / package-release (windows-x86_64, windows-latest) (push) Has been cancelled
ci / remote-bench (push) Has been cancelled
2026-07-02 19:29:20 -04:00
DuProcess c40f5459ba Keep live TUI output raw under retransmit pressure
ci / test (push) Has been cancelled
ci / fuzz-smoke (push) Has been cancelled
ci / windows-client (push) Has been cancelled
ci / package-release (linux-x86_64, ubuntu-latest) (push) Has been cancelled
ci / package-release (macos-aarch64, macos-14) (push) Has been cancelled
ci / package-release (macos-x86_64, macos-13) (push) Has been cancelled
ci / package-release (windows-x86_64, windows-latest) (push) Has been cancelled
ci / remote-bench (push) Has been cancelled
2026-07-02 19:21:43 -04:00
DuProcess 601510687e Prepare Dosh 0.1.9 release
ci / test (push) Has been cancelled
ci / fuzz-smoke (push) Has been cancelled
ci / windows-client (push) Has been cancelled
ci / package-release (linux-x86_64, ubuntu-latest) (push) Has been cancelled
ci / package-release (macos-aarch64, macos-14) (push) Has been cancelled
ci / package-release (macos-x86_64, macos-13) (push) Has been cancelled
ci / package-release (windows-x86_64, windows-latest) (push) Has been cancelled
ci / remote-bench (push) Has been cancelled
2026-07-02 19:07:46 -04:00
DuProcess 60387e9222 Install Dosh binaries atomically
ci / test (push) Has been cancelled
ci / fuzz-smoke (push) Has been cancelled
ci / windows-client (push) Has been cancelled
ci / package-release (linux-x86_64, ubuntu-latest) (push) Has been cancelled
ci / package-release (macos-aarch64, macos-14) (push) Has been cancelled
ci / package-release (macos-x86_64, macos-13) (push) Has been cancelled
ci / package-release (windows-x86_64, windows-latest) (push) Has been cancelled
ci / remote-bench (push) Has been cancelled
2026-07-02 18:41:02 -04:00
11 changed files with 305 additions and 84 deletions
Generated
+1 -1
View File
@@ -436,7 +436,7 @@ dependencies = [
[[package]] [[package]]
name = "dosh" name = "dosh"
version = "0.1.8" version = "0.1.14"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"base64", "base64",
+1 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "dosh" name = "dosh"
version = "0.1.8" version = "0.1.14"
edition = "2024" edition = "2024"
license = "MIT" license = "MIT"
+19 -5
View File
@@ -141,6 +141,20 @@ function Verify-ArchiveVersion($ExtractDir, $Url) {
} }
} }
function Install-Binary($Source, $Destination) {
$dir = Split-Path -Parent $Destination
$name = Split-Path -Leaf $Destination
$tmp = Join-Path $dir ".$name.tmp.$PID"
Copy-Item $Source $tmp -Force
try {
Move-Item $tmp $Destination -Force
}
catch {
Remove-Item $tmp -Force -ErrorAction SilentlyContinue
throw
}
}
$bindir = Join-Path $Prefix "bin" $bindir = Join-Path $Prefix "bin"
$configDir = Join-Path $HOME ".config\dosh" $configDir = Join-Path $HOME ".config\dosh"
New-Item -ItemType Directory -Force -Path $bindir, $configDir | Out-Null New-Item -ItemType Directory -Force -Path $bindir, $configDir | Out-Null
@@ -168,9 +182,9 @@ function Install-Prebuilt {
if (-not $found) { if (-not $found) {
throw "prebuilt archive missing $bin" throw "prebuilt archive missing $bin"
} }
Copy-Item $found.FullName (Join-Path $bindir $bin) -Force Install-Binary $found.FullName (Join-Path $bindir $bin)
} }
Copy-Item (Join-Path $bindir "dosh-client.exe") (Join-Path $bindir "dosh.exe") -Force Install-Binary (Join-Path $bindir "dosh-client.exe") (Join-Path $bindir "dosh.exe")
return $true return $true
} }
catch { catch {
@@ -202,9 +216,9 @@ function Install-FromSource {
try { try {
Push-Location $src Push-Location $src
cargo build --release --bin dosh-client --bin dosh-bench cargo build --release --bin dosh-client --bin dosh-bench
Copy-Item "target\release\dosh-client.exe" (Join-Path $bindir "dosh-client.exe") -Force Install-Binary "target\release\dosh-client.exe" (Join-Path $bindir "dosh-client.exe")
Copy-Item "target\release\dosh-client.exe" (Join-Path $bindir "dosh.exe") -Force Install-Binary "target\release\dosh-client.exe" (Join-Path $bindir "dosh.exe")
Copy-Item "target\release\dosh-bench.exe" (Join-Path $bindir "dosh-bench.exe") -Force Install-Binary "target\release\dosh-bench.exe" (Join-Path $bindir "dosh-bench.exe")
} }
finally { finally {
Pop-Location Pop-Location
+19 -15
View File
@@ -226,13 +226,26 @@ find_extracted_binary() {
find "$1" -type f -name "$2" 2>/dev/null | sed -n '1p' find "$1" -type f -name "$2" 2>/dev/null | sed -n '1p'
} }
install_binary() {
src="$1"
dst="$2"
dst_dir="$(dirname "$dst")"
dst_base="$(basename "$dst")"
tmp="$dst_dir/.$dst_base.tmp.$$"
install -m 0755 "$src" "$tmp"
if ! mv -f "$tmp" "$dst"; then
rm -f "$tmp"
return 1
fi
}
install_extracted_binary() { install_extracted_binary() {
found="$(find_extracted_binary "$1" "$2")" found="$(find_extracted_binary "$1" "$2")"
if [ -z "$found" ]; then if [ -z "$found" ]; then
echo "prebuilt archive missing $2" >&2 echo "prebuilt archive missing $2" >&2
return 1 return 1
fi fi
install -m 0755 "$found" "$3" install_binary "$found" "$3"
} }
sha256_file() { sha256_file() {
@@ -329,7 +342,7 @@ try_install_prebuilt() {
install_extracted_binary "$tmpdir/extract" dosh-auth "$bindir/dosh-auth" || return 1 install_extracted_binary "$tmpdir/extract" dosh-auth "$bindir/dosh-auth" || return 1
fi fi
if found_bench="$(find_extracted_binary "$tmpdir/extract" dosh-bench)" && [ -n "$found_bench" ]; then if found_bench="$(find_extracted_binary "$tmpdir/extract" dosh-bench)" && [ -n "$found_bench" ]; then
install -m 0755 "$found_bench" "$bindir/dosh-bench" install_binary "$found_bench" "$bindir/dosh-bench"
fi fi
return 0 return 0
} }
@@ -388,14 +401,14 @@ install_from_source() {
fi fi
fi fi
install -m 0755 target/release/dosh-client "$bindir/dosh-client" install_binary target/release/dosh-client "$bindir/dosh-client"
ln -sf dosh-client "$bindir/dosh" ln -sf dosh-client "$bindir/dosh"
if [ "$role" = "server" ] || [ "$role" = "both" ]; then if [ "$role" = "server" ] || [ "$role" = "both" ]; then
install -m 0755 target/release/dosh-server "$bindir/dosh-server" install_binary target/release/dosh-server "$bindir/dosh-server"
install -m 0755 target/release/dosh-auth "$bindir/dosh-auth" install_binary target/release/dosh-auth "$bindir/dosh-auth"
fi fi
if [ -f target/release/dosh-bench ]; then if [ -f target/release/dosh-bench ]; then
install -m 0755 target/release/dosh-bench "$bindir/dosh-bench" install_binary target/release/dosh-bench "$bindir/dosh-bench"
fi fi
} }
@@ -416,15 +429,6 @@ ExecStart=$bindir/dosh-server serve
Restart=on-failure Restart=on-failure
RestartSec=1 RestartSec=1
KillMode=process KillMode=process
NoNewPrivileges=true
PrivateTmp=true
ProtectSystem=strict
ProtectHome=read-only
ReadWritePaths=$config_dir $data_dir
RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX
RestrictRealtime=true
LockPersonality=true
MemoryDenyWriteExecute=true
[Install] [Install]
WantedBy=default.target WantedBy=default.target
-9
View File
@@ -9,15 +9,6 @@ ExecStart=%h/.local/bin/dosh-server serve
Restart=on-failure Restart=on-failure
RestartSec=1 RestartSec=1
KillMode=process KillMode=process
NoNewPrivileges=true
PrivateTmp=true
ProtectSystem=strict
ProtectHome=read-only
ReadWritePaths=%h/.config/dosh %h/.local/share/dosh
RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX
RestrictRealtime=true
LockPersonality=true
MemoryDenyWriteExecute=true
[Install] [Install]
WantedBy=default.target WantedBy=default.target
+1
View File
@@ -9,6 +9,7 @@ for test_name in \
tui_control_sequences_survive_transport_verbatim \ tui_control_sequences_survive_transport_verbatim \
unicode_output_survives_transport \ unicode_output_survives_transport \
tui_graph_glyphs_survive_fast_repaints_without_snapshot_substitution \ tui_graph_glyphs_survive_fast_repaints_without_snapshot_substitution \
btop_style_graph_output_stays_raw_when_retransmit_history_overflows \
large_tui_paint_is_delivered_in_mtu_safe_frames \ large_tui_paint_is_delivered_in_mtu_safe_frames \
resume_snapshot_preserves_alternate_screen_mode resume_snapshot_preserves_alternate_screen_mode
do do
+27
View File
@@ -7457,6 +7457,33 @@ mod tests {
assert!(buffer.accept(test_frame(12, false), &mut last).is_empty()); assert!(buffer.accept(test_frame(12, false), &mut last).is_empty());
} }
#[test]
fn frame_buffer_keeps_gap_buffered_without_snapshot_resync() {
let mut buffer = FrameBuffer::default();
let mut last = 10;
assert!(buffer.accept(test_frame(13, false), &mut last).is_empty());
assert_eq!(last, 10);
assert!(buffer.accept(test_frame(14, false), &mut last).is_empty());
assert_eq!(last, 10);
let ready = buffer.accept(test_frame(11, false), &mut last);
assert_eq!(ready.len(), 1);
assert_eq!(ready[0].output_seq, 11);
assert_eq!(last, 11);
let ready = buffer.accept(test_frame(12, false), &mut last);
assert_eq!(ready.len(), 3);
assert_eq!(
ready
.iter()
.map(|frame| frame.output_seq)
.collect::<Vec<_>>(),
vec![12, 13, 14]
);
assert_eq!(last, 14);
}
#[test] #[test]
fn frame_buffer_ignores_stale_snapshot() { fn frame_buffer_ignores_stale_snapshot() {
let mut buffer = FrameBuffer::default(); let mut buffer = FrameBuffer::default();
+35 -27
View File
@@ -512,12 +512,13 @@ impl ServerState {
/// Whether a session named `name` should be backed by a persistent holder. /// Whether a session named `name` should be backed by a persistent holder.
/// ///
/// With persistence enabled, every PTY session gets a detached holder. That /// With persistence enabled, explicitly named sessions get a detached
/// includes implicit `term-<millis>-<pid>` sessions: a reconnecting client has /// holder. Implicit `term-<millis>-<pid>` sessions are one-off terminals
/// the exact session name in its ticket cache, so it can reattach after a /// created by `dosh host`; users cannot intentionally reattach to them by
/// quick server restart without forcing users to name sessions manually. /// name, so persisting them only leaves stale holders that can be
fn should_persist_session(&self, _name: &str) -> bool { /// accidentally re-adopted after restarts.
self.config.persist_sessions fn should_persist_session(&self, name: &str) -> bool {
self.config.persist_sessions && !protocol::is_implicit_session_name(name)
} }
/// Spawn (or, in the persistent case, spawn-and-adopt) a PTY for a session. /// Spawn (or, in the persistent case, spawn-and-adopt) a PTY for a session.
@@ -605,6 +606,20 @@ impl ServerState {
if self.sessions.contains_key(&name) { if self.sessions.contains_key(&name) {
continue; continue;
} }
if !self.should_persist_session(&name) {
eprintln!(
"discarding stale implicit persistent session {name} (shell pid {})",
meta.shell_pid
);
persist::request_shutdown(&sessions_dir, &name, None);
if meta.shell_pid > 0 {
let _ = unsafe { libc::kill(meta.shell_pid, libc::SIGHUP) };
let _ = unsafe { libc::kill(meta.shell_pid, libc::SIGTERM) };
std::thread::sleep(Duration::from_millis(50));
let _ = unsafe { libc::kill(meta.shell_pid, libc::SIGKILL) };
}
continue;
}
let (pty, control) = match self.adopt_persistent_pty(&name) { let (pty, control) = match self.adopt_persistent_pty(&name) {
Ok(pair) => pair, Ok(pair) => pair,
Err(err) => { Err(err) => {
@@ -3336,7 +3351,7 @@ async fn broadcast_output(
let sends = { let sends = {
let mut locked = state.lock().expect("server state poisoned"); let mut locked = state.lock().expect("server state poisoned");
let scrollback = locked.config.scrollback; let scrollback = locked.config.scrollback;
let retransmit_window = locked.config.retransmit_window; let retransmit_window = locked.config.retransmit_window.max(1);
let session = locked let session = locked
.sessions .sessions
.get_mut(&output.session) .get_mut(&output.session)
@@ -3374,20 +3389,18 @@ async fn broadcast_output(
client.send_seq += 1; client.send_seq += 1;
// Count traffic toward the packet-count rekey trigger (spec §11). // Count traffic toward the packet-count rekey trigger (spec §11).
client.epoch_packets = client.epoch_packets.saturating_add(1); client.epoch_packets = client.epoch_packets.saturating_add(1);
// Only materialize a screen snapshot when this client has fallen too // Live terminal bytes are never rewritten into vt100 snapshots. A
// far behind; the common case sends the raw output bytes and must not // snapshot is useful for attach/resume, but substituting it during a
// clone the whole vt100 grid per client per packet. // running TUI can lose graph/background-cell details that apps like
let (bytes, snapshot) = if client.pending.len() >= retransmit_window { // btop rely on. If retransmit history is full, prune only history.
client.pending.clear(); while client.pending.len() >= retransmit_window {
(screen_snapshot(session.parser.screen()), true) client.pending.pop_front();
} else { }
(output.bytes.clone(), false)
};
let frame = Frame { let frame = Frame {
session: output.session.clone(), session: output.session.clone(),
output_seq, output_seq,
bytes, bytes: output.bytes.clone(),
snapshot, snapshot: false,
closed: false, closed: false,
}; };
let body = protocol::to_body(&frame)?; let body = protocol::to_body(&frame)?;
@@ -3400,9 +3413,6 @@ async fn broadcast_output(
SERVER_TO_CLIENT, SERVER_TO_CLIENT,
&body, &body,
)?; )?;
while client.pending.len() >= retransmit_window {
client.pending.pop_front();
}
client.pending.push_back(PendingFrame { client.pending.push_back(PendingFrame {
output_seq, output_seq,
packet: packet.clone(), packet: packet.clone(),
@@ -3509,11 +3519,9 @@ async fn retransmit_pending(
if pending.output_seq <= client.last_acked { if pending.output_seq <= client.last_acked {
continue; continue;
} }
if now.duration_since(pending.last_sent) >= Duration::from_millis(200) if now.duration_since(pending.last_sent) >= Duration::from_millis(200) {
&& pending.attempts < 8
{
pending.last_sent = now; pending.last_sent = now;
pending.attempts += 1; pending.attempts = pending.attempts.saturating_add(1);
sends.push((client.endpoint, pending.packet.clone())); sends.push((client.endpoint, pending.packet.clone()));
} }
} }
@@ -3846,7 +3854,7 @@ mod tests {
use super::*; use super::*;
#[test] #[test]
fn persists_all_sessions_when_enabled() { fn persists_named_sessions_when_enabled() {
let (pty_tx, _rx) = mpsc::unbounded_channel(); let (pty_tx, _rx) = mpsc::unbounded_channel();
let config = ServerConfig { let config = ServerConfig {
persist_sessions: true, persist_sessions: true,
@@ -3856,7 +3864,7 @@ mod tests {
let state = ServerState::new(config, [0u8; 32], pty_tx); let state = ServerState::new(config, [0u8; 32], pty_tx);
assert!(state.should_persist_session("default")); // prewarmed assert!(state.should_persist_session("default")); // prewarmed
assert!(state.should_persist_session("work")); // explicitly named assert!(state.should_persist_session("work")); // explicitly named
assert!(state.should_persist_session("term-1781470634216-76685")); // implicit reconnect assert!(!state.should_persist_session("term-1781470634216-76685")); // one-off terminal
} }
#[test] #[test]
+4
View File
@@ -435,6 +435,10 @@ pub fn run_holder(
let mut cmd = [0u8; 1]; let mut cmd = [0u8; 1];
match stream.read(&mut cmd) { match stream.read(&mut cmd) {
Ok(1) if cmd[0] == HOLDER_CMD_SHUTDOWN => { Ok(1) if cmd[0] == HOLDER_CMD_SHUTDOWN => {
if shell_pid > 0 {
let _ = unsafe { libc::kill(shell_pid, libc::SIGHUP) };
let _ = unsafe { libc::kill(shell_pid, libc::SIGTERM) };
}
let _ = std::fs::remove_dir_all(runtime_dir); let _ = std::fs::remove_dir_all(runtime_dir);
std::process::exit(0); std::process::exit(0);
} }
+170 -26
View File
@@ -112,6 +112,21 @@ fn write_server_config_with_output_interval(
config config
} }
fn write_server_config_with_retransmit_window(
dir: &tempfile::TempDir,
port: u16,
retransmit_window: u64,
) -> std::path::PathBuf {
let config = write_server_config(dir, port);
let mut raw = fs::read_to_string(&config).unwrap();
raw = raw.replace(
"retransmit_window = 256\n",
&format!("retransmit_window = {retransmit_window}\n"),
);
fs::write(&config, raw).unwrap();
config
}
fn start_server(dir: &tempfile::TempDir, config: &std::path::Path) -> Child { fn start_server(dir: &tempfile::TempDir, config: &std::path::Path) -> Child {
let server = env!("CARGO_BIN_EXE_dosh-server"); let server = env!("CARGO_BIN_EXE_dosh-server");
let child = Command::new(server) let child = Command::new(server)
@@ -1377,18 +1392,10 @@ fn server_retransmits_unacked_output_frames() {
); );
let mut seen = Vec::new(); let mut seen = Vec::new();
let mut duplicate = None; let deadline = std::time::Instant::now() + Duration::from_secs(4);
let deadline = std::time::Instant::now() + Duration::from_secs(3);
while std::time::Instant::now() < deadline { while std::time::Instant::now() < deadline {
if let Some((header, frame)) = recv_frame(&socket, &bootstrap.session_key) { if let Some((header, frame)) = recv_frame(&socket, &bootstrap.session_key) {
if String::from_utf8_lossy(&frame.bytes).contains("DOSH_RETRANSMIT") { if String::from_utf8_lossy(&frame.bytes).contains("DOSH_RETRANSMIT") {
if seen
.iter()
.any(|(_, output_seq)| *output_seq == frame.output_seq)
{
duplicate = Some((header.seq, frame.output_seq));
break;
}
seen.push((header.seq, frame.output_seq)); seen.push((header.seq, frame.output_seq));
} }
} }
@@ -1397,9 +1404,18 @@ fn server_retransmits_unacked_output_frames() {
let _ = server.kill(); let _ = server.kill();
let _ = server.wait(); let _ = server.wait();
let max_same_output_seq = seen
.iter()
.map(|(_, output_seq)| {
seen.iter()
.filter(|(_, candidate)| candidate == output_seq)
.count()
})
.max()
.unwrap_or(0);
assert!( assert!(
duplicate.is_some(), max_same_output_seq >= 10,
"expected retransmitted same output seq, seen={seen:?}" "expected retransmission to continue past the old 8-attempt ceiling, seen={seen:?}"
); );
} }
@@ -1694,6 +1710,69 @@ fn tui_graph_glyphs_survive_fast_repaints_without_snapshot_substitution() {
); );
} }
#[test]
fn btop_style_graph_output_stays_raw_when_retransmit_history_overflows() {
let dir = tempfile::tempdir().unwrap();
let port = free_udp_port();
let config = write_server_config_with_retransmit_window(&dir, port, 3);
let mut server = start_server(&dir, &config);
let (socket, bootstrap, ok) = direct_attach(&config, port, "read-write");
let graph = "DOSH_BTOP_NET ⠀⠁⠃⠇⡇⣇⣧⣷⣿";
let input = Input {
bytes: format!(
"stty -echo; \
printf '\\033[?1049h\\033[?2026h\\033[?25l'; \
for i in 1 2 3 4 5 6 7 8 9 10; do \
printf '\\033[6;4H\\033[38;2;80;220;140m{} %s\\033[0m' \"$i\"; \
done; \
printf '\\033[?25h\\033[?2026l\\033[?1049l'\n",
graph
)
.into_bytes(),
};
send_encrypted(
&socket,
port,
PacketKind::Input,
ok.client_id,
2,
0,
&bootstrap.session_key,
&protocol::to_body(&input).unwrap(),
);
let mut text = String::new();
let mut snapshots = 0usize;
let deadline = std::time::Instant::now() + Duration::from_secs(3);
while std::time::Instant::now() < deadline
&& !(text.matches("DOSH_BTOP_NET").count() >= 10 && text.contains("\x1b[?2026l"))
{
if let Some((_header, frame)) = recv_frame(&socket, &bootstrap.session_key) {
if frame.snapshot {
snapshots += 1;
}
text.push_str(&String::from_utf8_lossy(&frame.bytes));
}
}
let _ = server.kill();
let _ = server.wait();
assert_eq!(
snapshots, 0,
"live btop-style graph output must not be replaced by snapshots; got {snapshots}"
);
assert!(
text.matches("DOSH_BTOP_NET").count() >= 10
&& text.contains("")
&& text.contains("\x1b[38;2;80;220;140m")
&& text.contains("\x1b[?2026h")
&& text.contains("\x1b[?2026l"),
"expected raw btop-style graph output to survive under retransmit pressure, got {text:?}"
);
}
#[test] #[test]
fn large_tui_paint_is_delivered_in_mtu_safe_frames() { fn large_tui_paint_is_delivered_in_mtu_safe_frames() {
let dir = tempfile::tempdir().unwrap(); let dir = tempfile::tempdir().unwrap();
@@ -2440,6 +2519,9 @@ fn write_persistent_server_config(dir: &tempfile::TempDir, port: u16) -> std::pa
let mut raw = fs::read_to_string(&config).unwrap(); let mut raw = fs::read_to_string(&config).unwrap();
// The base writer hardcodes `persist_sessions = false`; flip it on. // The base writer hardcodes `persist_sessions = false`; flip it on.
raw = raw.replace("persist_sessions = false", "persist_sessions = true"); raw = raw.replace("persist_sessions = false", "persist_sessions = true");
// Persistence tests attach the sessions they need explicitly. Leaving the
// base prewarm on here creates a detached default holder in every test.
raw = raw.replace("prewarm_sessions = [\"default\"]", "prewarm_sessions = []");
fs::write(&config, raw).unwrap(); fs::write(&config, raw).unwrap();
config config
} }
@@ -2475,6 +2557,45 @@ fn kill_holder(sessions_dir: &Path, session: &str) {
.status(); .status();
} }
/// Create a holder the way older Dosh builds did for implicit sessions, so
/// startup migration can be tested without depending on the new spawn policy.
fn spawn_legacy_holder(sessions_dir: &Path, session: &str) {
let server = env!("CARGO_BIN_EXE_dosh-server");
let runtime_dir = dosh::persist::ensure_runtime_dir(sessions_dir, session).unwrap();
let mut launcher = Command::new(server)
.arg("hold")
.arg("--runtime-dir")
.arg(&runtime_dir)
.arg("--session")
.arg(session)
.arg("--shell")
.arg("/bin/sh")
.arg("--cols")
.arg("80")
.arg("--rows")
.arg("24")
.stdout(Stdio::null())
.stderr(Stdio::null())
.spawn()
.unwrap();
let deadline = std::time::Instant::now() + Duration::from_secs(5);
while std::time::Instant::now() < deadline {
if holder_shell_pid(sessions_dir, session).is_some()
&& runtime_dir.join("holder.sock").exists()
{
let _ = launcher.wait();
return;
}
if let Some(status) = launcher.try_wait().unwrap() {
panic!("legacy holder launcher exited before ready: {status}");
}
thread::sleep(Duration::from_millis(20));
}
let _ = launcher.kill();
let _ = launcher.wait();
panic!("legacy holder did not become ready");
}
/// Send one encrypted Input line and give the shell a moment to act. /// Send one encrypted Input line and give the shell a moment to act.
fn type_line(socket: &UdpSocket, port: u16, ok: &AttachOk, key: &[u8; 32], seq: u64, line: &str) { fn type_line(socket: &UdpSocket, port: u16, ok: &AttachOk, key: &[u8; 32], seq: u64, line: &str) {
let input = Input { let input = Input {
@@ -2612,7 +2733,7 @@ fn session_survives_server_restart_same_shell_and_screen() {
} }
#[test] #[test]
fn implicit_session_survives_server_restart_for_same_ticket_holder() { fn implicit_session_does_not_create_restart_holder() {
let dir = tempfile::tempdir().unwrap(); let dir = tempfile::tempdir().unwrap();
let sessions_dir = dir.path().join("sessions"); let sessions_dir = dir.path().join("sessions");
let port = free_udp_port(); let port = free_udp_port();
@@ -2635,20 +2756,14 @@ fn implicit_session_survives_server_restart_for_same_ticket_holder() {
let shell_pid_before = holder_shell_pid(&sessions_dir, &session); let shell_pid_before = holder_shell_pid(&sessions_dir, &session);
assert!( assert!(
shell_pid_before.is_some(), shell_pid_before.is_none(),
"implicit sessions should get a persistent holder when persistence is enabled" "implicit sessions must not get persistent holders when persistence is enabled"
); );
let _ = server.kill(); let _ = server.kill();
let _ = server.wait(); let _ = server.wait();
thread::sleep(Duration::from_millis(300)); thread::sleep(Duration::from_millis(300));
let pid = shell_pid_before.unwrap();
assert!(
unsafe { libc::kill(pid, 0) } == 0,
"implicit session shell pid {pid} must survive server restart"
);
let mut server = start_server(&dir, &config); let mut server = start_server(&dir, &config);
let (socket2, bootstrap2, ok2) = direct_attach_session(&config, port, "read-write", &session); let (socket2, bootstrap2, ok2) = direct_attach_session(&config, port, "read-write", &session);
let key2 = bootstrap2.session_key; let key2 = bootstrap2.session_key;
@@ -2665,15 +2780,44 @@ fn implicit_session_survives_server_restart_for_same_ticket_holder() {
let _ = server.kill(); let _ = server.kill();
let _ = server.wait(); let _ = server.wait();
kill_holder(&sessions_dir, &session);
assert_eq!( assert!(
shell_pid_after, shell_pid_before, shell_pid_after.is_none(),
"implicit session should re-adopt the same shell pid" "implicit restart attach must stay ephemeral"
); );
assert!( assert!(
post.contains("IMPLICIT_MARK=implicit_restart_42"), post.contains("IMPLICIT_MARK=") && !post.contains("implicit_restart_42"),
"implicit session state must survive restart, got {post:?}" "implicit session must start fresh after server restart, got {post:?}"
);
}
#[test]
fn startup_discards_legacy_implicit_holders() {
let dir = tempfile::tempdir().unwrap();
let sessions_dir = dir.path().join("sessions");
let port = free_udp_port();
let config = write_persistent_server_config(&dir, port);
let session = protocol::generate_implicit_session_name();
spawn_legacy_holder(&sessions_dir, &session);
let shell_pid = holder_shell_pid(&sessions_dir, &session).expect("legacy holder shell pid");
assert!(
unsafe { libc::kill(shell_pid, 0) } == 0,
"legacy holder shell must be live before startup"
);
let mut server = start_server(&dir, &config);
thread::sleep(Duration::from_millis(300));
let _ = server.kill();
let _ = server.wait();
assert!(
holder_shell_pid(&sessions_dir, &session).is_none(),
"startup must remove old implicit holder metadata"
);
assert!(
unsafe { libc::kill(shell_pid, 0) } != 0,
"startup must shut down old implicit holder shell"
); );
} }
+28
View File
@@ -18,3 +18,31 @@ fn release_scripts_skip_stale_artifacts_when_auto_discovering() {
assert!(publish.contains("skipping stale artifact")); assert!(publish.contains("skipping stale artifact"));
assert!(publish.contains("actual=\"$(artifact_version \"$artifact\" || true)\"")); assert!(publish.contains("actual=\"$(artifact_version \"$artifact\" || true)\""));
} }
#[test]
fn systemd_service_does_not_sandbox_remote_shells() {
let service = include_str!("../packaging/systemd/dosh-server.service");
let install = include_str!("../install.sh");
for raw in [service, install] {
assert!(raw.contains("KillMode=process"));
for directive in [
"NoNewPrivileges=",
"PrivateTmp=",
"ProtectSystem=",
"ProtectHome=",
"RestrictAddressFamilies=",
"RestrictRealtime=",
"LockPersonality=",
"MemoryDenyWriteExecute=",
] {
assert!(
!raw.contains(directive),
"dosh sessions are user shells; systemd sandbox directive {directive} changes terminal/app behavior"
);
}
assert!(
!raw.contains("ReadWritePaths="),
"remote shells must not be restricted to dosh config/data paths"
);
}
}