Skip to main content

Module terminal

Module terminal 

Source
Expand description

A terminal over a websocket: GET /orgs/<org>/api/v1/terminal?app=NAME (or ?instance=NAME) upgrades to a websocket bridged to a pseudo-terminal the embedder opens (isb serve: a shell in one of the app’s replicas, or in an instance of the org).

The gate is the REST surface’s: the caller authenticates as for any tool (session, API token, Access), and is admitted as if calling sandbox_exec in the org, so the org rules and --deny-tools apply. A browser’s cookie rides along on a cross-site websocket too, so a cookie-authenticated upgrade must come from this site (Origin naming the request’s Host).

On the wire: binary frames are terminal bytes both ways; text frames are JSON control messages: from the browser {"type": "resize", "cols", "rows"}, from the server {"type": "exit", "code"} and {"type": "error", "message"}.

Bounded: at most MAX_SESSIONS at once, IDLE without a byte either way, MAX_AGE in all, messages up to MAX_MESSAGE.

Structs§

Limits
How many sessions of one kind may be open at once, and for how long.
TermRequest
What the browser asked for.

Enums§

PtyOutput
One terminal session’s output, polled.

Constants§

IDLE
MAX_AGE
MAX_MESSAGE
MAX_SESSIONS

Statics§

TERMINALS
The web terminal’s limits.

Traits§

Pty
A pseudo-terminal the bridge drives.

Functions§

bridge
Shuttle bytes between the websocket and the terminal until either ends, the session idles for idle, or it reaches max_age.
origin_allowed
A cookie-authenticated upgrade must come from a page on this site. A bearer token is not sent by browsers on their own, so it needs no Origin.
pct_decode
Undo pct_encode (and a form’s + for a space); None when it is not valid UTF-8 or a % is not followed by two hex digits.
pct_encode
Percent-encode everything but unreserved characters.
plain_name
A lower-case name of letters, digits and dashes, at most 64 long (an app’s or an instance’s).
query_param
A query parameter’s raw value.
term_request
The request’s terminal parameters, or what is wrong with them.
upgrade
The 101 that hands the connection to a session opened by open. The opening happens after the upgrade, so its errors reach the browser as an error frame rather than a bare failed handshake.
upgrade_with
upgrade under limits (the SSH bridge has its own).
websocket_key
The client’s websocket key, if this is a websocket upgrade request.

Type Aliases§

Terminal
Opens a terminal for caller in org; refusals become an error frame.