SSH access and tunneling
ArcBox provides an SSH endpoint for entering a managed Linux machine without running sshd in that machine. The daemon accepts a local SSH connection, authenticates it with ArcBox-owned keys, selects the machine from the SSH login name, and carries sessions or TCP streams through the machine agent. This makes SSH a control-plane access path alongside the services described in Application control plane.
Access endpoint
The SSH endpoint is a loopback-only server owned by the ArcBox daemon. The daemon binds the requested SSH port or the default port, writes a matching OpenSSH configuration, and starts the server as part of daemon service startup. A requested port must be available; failure is a startup error. The default port is best effort, so another process using it disables SSH access without preventing the daemon from serving other workloads (app/…/ssh_service.rs• L19-55).
The generated client configuration keeps the client and server sides aligned. It points OpenSSH at 127.0.0.1, selects the current port, uses only the ArcBox client identity, and requires the generated host key from the ArcBox known_hosts file. The daemon rewrites the configuration on each start because an automatically selected port can change. If the default listener cannot start, it removes stale configuration so a client does not connect to an old endpoint (app/…/client_config.rs• L14-40, app/…/ssh_service.rs• L41-75).
The normal user flow is:
flowchart LR
C[OpenSSH client] -->|ArcBox config and key| L[Daemon loopback SSH listener]
L --> A[Public-key authentication]
A --> T[Machine and account target]
T --> S[Machine exec or TCP path]
S --> G[Managed Linux workload]
Key trust
The daemon creates two Ed25519 key roles in the data directory's ssh/ area. The host key identifies the local SSH endpoint. The client key is the only public key accepted for login. Both are reused across starts, and private key files are kept readable only by the owner (app/…/keys.rs• L12-57).
OpenSSH uses the generated known_hosts entry to pin the daemon host key. It also uses IdentitiesOnly yes so unrelated keys from the user's SSH agent do not change the authentication result. A damaged existing key fails setup rather than being silently replaced (app/…/client_config.rs• L31-40, app/…/keys.rs• L61-95).
References: app/…/keys.rs• L12-57 app/…/client_config.rs• L14-40 app/…/server.rs• L24-48
Target selection
The SSH user field identifies both the ArcBox machine and the account inside it. OpenSSH removes the final @arcbox host part before the server sees the login name, so the server accepts these forms:
| SSH login form | Machine | Account |
|---|---|---|
ubuntu@arcbox | ubuntu | Machine default, normally root |
dev@ubuntu@arcbox | ubuntu | dev |
The target parser splits at the last @. Empty machine or account names are rejected before a session starts. After successful public-key authentication, every channel on that SSH connection uses the same target (app/…/target.rs• L1-40, app/…/connection.rs• L78-84).
References: app/…/target.rs• L1-40 app/…/connection.rs• L22-38 app/…/connection.rs• L153-167
Session access
An SSH session becomes a machine-exec session. The daemon does not start or contact an SSH server inside the guest. Instead, the guest agent runs the selected account's login shell or command and returns framed output through the existing machine execution path. The daemon connects to the agent only when the session or tunnel needs the target machine (app/…/ssh_service.rs• L99-135, app/…/host.rs• L9-37).
Session startup
SSH clients may prepare a session with a terminal request and environment requests before starting a shell or command. ArcBox records those requests until shell or exec arrives, then sends one machine-exec request with the target, login mode, standard input attached, terminal state, environment, and command. A shell uses an empty command so the machine chooses the account's login shell; exec carries the command line (app/…/session.rs• L23-29, app/…/session.rs• L80-140).
The session preserves the SSH environment expected by programs that run under SSH. It adds SSH_CLIENT and SSH_CONNECTION from the local connection and places TERM and terminal dimensions in the request when a PTY was requested. Environment names and values with unsafe separators or NUL bytes are refused (app/…/connection.rs• L41-65, app/…/session.rs• L93-126).
When a machine cannot be reached, the channel is accepted far enough to report a useful error on stderr and exits with status 255. A missing machine and a machine in the wrong lifecycle state are translated into guidance for the SSH user (app/…/ssh_service.rs• L139-149, app/…/session.rs• L143-169).
References: app/…/ssh_service.rs• L99-149 app/…/connection.rs• L86-113 app/…/session.rs• L104-169
Session streams
Machine-exec output maps to SSH channel output. Standard output uses normal channel data, standard error uses SSH extended data, and the final machine exit code becomes the SSH exit status. If the process ends because of a signal, the signal name is reported through the SSH exit-signal message. The channel sends EOF before it closes, following normal SSH session ordering (app/…/session.rs• L198-249, app/…/session.rs• L252-295).
Client input travels in the opposite direction as machine-exec input frames. Stdin EOF is an empty stdin frame. PTY resize becomes a resize frame, and SSH signals become signal-name frames. Signal names cross the host and guest boundary as names instead of numeric values because the two sides may number signals differently; names not represented by the SSH library remain custom names (app/…/connection.rs• L298-346, app/…/signal.rs• L1-44).
The connection has one outbound path shared by all its channels. It must keep returning control to the SSH protocol while output waits on the client's window. Input can queue while a process catches up, but a session that exceeds 64 MiB of queued stdin is ended to protect daemon memory. This balance prevents a slow client from deadlocking the connection while still bounding unconsumed input (app/…/input.rs• L1-13, app/…/input.rs• L24-32, app/…/connection.rs• L116-150).
References: app/…/session.rs• L18-21 app/…/session.rs• L198-249 app/…/connection.rs• L298-355 app/…/input.rs• L38-153
Subsystems
SSH subsystems reuse the same target and machine-exec transport while assigning a protocol-specific command. ArcBox currently supports the sftp subsystem and refuses other subsystem names (app/…/connection.rs• L274-295, app/…/server.rs• L513-522).
SFTP access
SFTP runs the machine's own sftp-server as the selected account's login command. Before it accepts the subsystem request, ArcBox checks a small set of standard distribution paths inside the machine. If no executable server is present, the request is refused instead of starting a non-working session. This means SFTP availability depends on the workload image, not on a separate host-side file service (app/…/subsystem.rs• L9-49).
The SFTP byte protocol then uses the ordinary session input and output streams. OpenSSH versions that use SFTP for file copy therefore follow the same availability rule as an explicit SFTP client (app/…/subsystem.rs• L1-2, app/…/connection.rs• L282-294).
References: app/…/subsystem.rs• L1-49 app/…/connection.rs• L274-295
Network tunnels
SSH direct-tcpip channels provide client-side forwarding such as ssh -L and tools such as VS Code Remote-SSH. The requested destination is interpreted from inside the selected machine, so a name such as localhost means the workload's network view rather than the Mac's. The daemon asks the guest agent to open the TCP connection and carries its bytes over the same framed path used by session input and output (app/…/tunnel.rs• L1-12, app/…/ssh_service.rs• L127-135).
The tunnel lifecycle is independent of shell sessions but shares the authenticated connection and its target. ArcBox opens the channel only after the machine-side connect succeeds. A failed connect returns SSH ConnectFailed while leaving the parent SSH connection usable. Once open, data flows in both directions, peer EOF becomes SSH channel EOF, and the channel closes after both sides finish or the connection breaks (app/…/tunnel.rs• L22-63, app/…/tunnel.rs• L65-98).
This flow is intentionally started in the background. A slow machine-side connect must not block protocol handling for other channels on the same SSH connection. The shared outbound path also keeps tunnel output moving without making the SSH handler wait on a process or socket (app/…/tunnel.rs• L22-47, app/…/input.rs• L1-13).
References: app/…/tunnel.rs• L1-98 app/…/connection.rs• L188-220 app/…/host.rs• L27-37
Shutdown behavior
The daemon serves the SSH listener until its shutdown signal resolves. It then asks the SSH server to disconnect all clients, which ends their session and tunnel channels and releases the associated machine-exec streams (app/…/server.rs• L51-75). A client closing a channel has the same ownership effect for that channel: ArcBox drops its session state and output task, and the machine-side input closes so the guest process can stop (app/…/session.rs• L45-49, app/…/session.rs• L182-187).
References: app/…/server.rs• L51-75 app/…/session.rs• L38-49 app/…/session.rs• L182-187
Change checklist
When these files or sections are changed, remember to consider these:
- Keep target syntax, generated OpenSSH comments, and the daemon's host alias aligned. A change to one side can make
user@machine@arcboxselect the wrong account or make the client config unusable. - Keep the generated client identity, accepted server key,
known_hostspin, andIdentitiesOnlypolicy aligned. Changing only one trust artifact can make all existing clients fail authentication or host-key checks. - Preserve the machine-exec contract for stdin EOF, output EOF, exit status, exit signal, PTY size, and signal names. These fields cross from SSH frames into guest-agent frames.
- Preserve the loopback bind policy and stale-config removal behavior. A failed optional listener must not leave a client configuration that points at an endpoint this daemon does not serve.
- Keep tunnel acceptance and refusal tied to the same connection state. A failed
direct-tcpipconnect must release its channel state without closing unrelated sessions. - If a new SSH channel type is added, keep it off the handler's blocking path and ensure its byte stream respects the shared connection backpressure rules.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| The requested SSH port cannot bind | Daemon startup fails | Treat an explicit --ssh-port as required and report the bind error (app/…/ssh_service.rs• L25-55) |
| The default SSH port is already in use | SSH is unavailable, but the daemon continues serving other services | Remove the old client config when the optional listener is disabled (app/…/ssh_service.rs• L41-53) |
| The client key does not match the daemon-generated public key | Authentication is rejected | Accept only the configured client public key (app/…/connection.rs• L78-84, app/…/server.rs• L28-38) |
| The target names no machine or the machine is not usable | The session reports an error on stderr and exits 255 | Validate the target and translate machine lookup errors (app/…/target.rs• L23-40, app/…/ssh_service.rs• L139-149) |
A workload image has no executable sftp-server | The SFTP request is refused | Probe standard server paths before accepting the subsystem (app/…/subsystem.rs• L18-49) |
| A tunnel destination refuses or cannot be reached | The direct-tcpip channel is rejected while the SSH connection remains available | Return ConnectFailed and drop only the refused channel state (app/…/tunnel.rs• L44-59, app/…/connection.rs• L198-220) |
| A client reads output too slowly while sending input | Unbounded session memory growth could occur | Pause input after the high-water mark and end the session after the 64 MiB limit (app/…/input.rs• L24-32, app/…/connection.rs• L125-149) |
Key files
| File | Why to read it |
|---|---|
| app/…/ssh_service.rs | Shows how the daemon binds the loopback endpoint, manages generated client configuration, and maps SSH operations to guest-agent calls. |
| app/…/server.rs | Defines the server-level authentication policy, listener lifecycle, and shutdown behavior. |
| app/…/connection.rs | Connects one authenticated SSH connection to targets, sessions, subsystems, signals, and tunnel channels. |
| app/…/session.rs | Defines the session contract for login commands, PTYs, environment, streams, exit status, and process cleanup. |
| app/…/tunnel.rs | Defines how direct-tcpip channels become TCP connections inside a machine. |
| app/…/keys.rs and app/…/client_config.rs | Explain key persistence and the OpenSSH configuration that pins the local server. |
| app/…/input.rs | Explains shared connection output handling and the input backlog safety boundary. |
| app/…/subsystem.rs | Shows the workload-side SFTP availability rule. |
| app/…/host.rs | Defines the boundary between SSH protocol handling and the daemon's machine runtime. |