feat: run sandbox transports in disposable workers

The control plane opened ssh connections itself, so a malicious ssh
server attacked the process that held the database, the master key, and
every room's keys. It now starts one worker per target and workspace.
The worker gets one target key on stdin, binds loopback behind a random
token, and serves exec, files, the pty, and the preview proxy. It has no
database and no master key, and a closed stdin ends it.

The preview HTTP client moved into the worker too. The app sees a typed
response, and the worker caps bodies, output tails, handshakes, and
transport waits.

Direct targets now reject loopback, private, link-local, multicast,
unspecified, carrier-grade NAT, and documentation addresses when a
target is created and again when its worker starts.
TOGETHER_ALLOW_PRIVATE_TARGETS=1 lifts the check for a server that runs
on one private network.
This commit is contained in:
vhaudiquet committed 2026-11-29 18:22:44 +01:00
1 parent a8f7e74ba0
commit fc684115b5
16 files changed
+1355 -208

No files matched your search

+18 -13
View File
@@ -12,7 +12,6 @@ use rhema_core::{Overlay, Session, ToolResolver};
use rhema_host_agent::{HostAgent, HostAgentConfig};
use rhema_sandbox::WorkspaceSeed;
use rhema_sandbox::{Sandbox, ShellSandbox};
use rhema_sandbox_ssh::SshSandbox;
use crate::error::{AppError, AppResult};
use crate::state::Shared;
@@ -44,6 +43,7 @@ pub struct ProviderRow {
}
/// The sandbox row, ciphertext included.
#[derive(Clone)]
pub struct TargetRow {
pub id: String,
pub host: String,
@@ -155,22 +155,27 @@ pub fn load_turn_config(state: &Shared, room_id: &str) -> AppResult<TurnConfig>
})
}
/// The ssh destination in the form the backend resolves.
fn destination(target: &TargetRow) -> String {
format!("{}@{}:{}", target.user_name, target.host, target.port)
}
/// A sandbox handle for this room.
pub fn build_sandbox(state: &Shared, config: &TurnConfig) -> AppResult<SshSandbox> {
/// A sandbox handle for this room. The control plane never opens the
/// ssh connection itself: the handle belongs to the room's disposable
/// worker, and every call crosses a loopback HTTP route.
pub fn build_sandbox(
state: &Shared,
config: &TurnConfig,
) -> AppResult<crate::worker::WorkerSandbox> {
sandbox_for(state, &config.workspace, &config.target)
}
/// A sandbox handle from a workspace and a target row.
pub fn sandbox_for(state: &Shared, workspace: &str, target: &TargetRow) -> AppResult<SshSandbox> {
let key = state.secrets.open_str(&target.private_key_ciphertext)?;
Ok(SshSandbox::new(destination(target))
.with_workspace(workspace.to_owned())
.with_private_key(key))
pub fn sandbox_for(
state: &Shared,
workspace: &str,
target: &TargetRow,
) -> AppResult<crate::worker::WorkerSandbox> {
Ok(crate::worker::WorkerSandbox::new(
state.clone(),
workspace,
target,
))
}
/// The room's workspace and target, for routes that do not need the