End-to-end encryption for tunneled connections
When the web console or the mobile and desktop apps reach devctrl through a public tunnel (Cloudflare, ngrok, localhost.run, Tailscale Funnel, a reverse proxy), the tunnel terminates TLS and can read every request, response and terminal byte. End-to-end encryption adds a second, independent encryption layer between the client and the devctrl web gateway, so the tunnel and every proxy between them relay only ciphertext.
The feature is optional. An administrator can make it mandatory for remote connections; local connections stay unaffected unless configured.
How it works
- Core (the controller) holds a server static key pair (X25519). Its private half is
kept in Core's encrypted credential store; only the colocated web gateway can read it,
through the launcher-only route
GET /v1/server/e2e/gateway(operator token, launcher header and a private infrastructure peer address are all required, and the gateway refuses to proxy that route for browsers). - Each device or user gets a client key pair (X25519). Core stores only its public key, its fingerprint, its owner and a label.
- The device receives a pairing code,
dce2e1.<client private key>.<server public key>. The user pastes it once in the web or mobile client (Console → End-to-end encryption). The client imports the private key as a non-extractableCryptoKeyand keeps it in IndexedDB, and pins the server public key. Pairing completes only after a successful handshake with that server key. - While an origin is paired, every request and WebSocket of that console goes through one
WebSocket to
/e2e/channel, protected as described below. The gateway decrypts each request and replays it against its own listener on the loopback interface, tagged with a per-process secret, so the existing sign-in, Origin, ticket and ownership checks apply unchanged. Plain HTTP API calls are therefore covered: the console API is tunneled over the encrypted WebSocket.
Handshake: Noise IK
The channel uses the standard
Noise Protocol Framework pattern
Noise_IK_25519_AESGCM_SHA256, unmodified:
<- s
...
-> e, es, s, ss
<- e, ee, se
- Server authentication. The client already knows the server static key (it was in the pairing code), so a server that does not hold the matching private key cannot complete the handshake. The client shows "Server identity check failed" and never falls back to plaintext.
- Client authentication. The client's static key travels encrypted in the first message. The gateway accepts it only if Core lists it as an active key.
- Forward secrecy. Both sides contribute fresh ephemeral X25519 keys (
ee,es,se). Recorded traffic stays confidential even if a static key leaks later. - Binding. The Noise prologue
devctrl-e2e/1binds the handshake to this protocol and version. The console is identified by its pinned server key; the device key is usable only by the origin that stored it (IndexedDB is origin-scoped), and the gateway admits the channel only for an allowed browser Origin. - First-message replay. IK's first message carries a timestamp. The gateway refuses messages older than five minutes and remembers each first-message ephemeral key for ten minutes, so a recorded first message cannot be replayed. (A replay could not complete the handshake anyway, because it lacks the client's ephemeral private key.)
"Another key pair for the reverse direction"
The request was to use a separate key pair for the reverse direction. Noise's Split()
already gives each connection two independent AES-256-GCM keys, one for client→server and
one for server→client, each with its own nonce counter. A second long-term key pair would
add nothing: the per-direction keys are derived fresh for every connection from ephemeral
keys, so the two directions never share a key and a compromise of one connection does not
expose another.
Message protection
- AEAD. Each WebSocket message is one Noise transport message: AES-256-GCM with the Noise nonce (four zero bytes followed by a 64-bit big-endian counter). Larger application messages are split into fragments of at most 65 535 bytes.
- Ordering and replay. Counters are strictly sequential per direction. A replayed, reordered, truncated, tampered or forged message fails authentication.
- Closing on failure. The first authentication failure closes the whole channel and fails every request on it. Clients reconnect with a fresh handshake.
- Rekeying. Both sides apply the Noise
Rekey()function after every 65 536 messages in a direction. A channel also ends after twelve hours; the client reconnects with new ephemeral keys.
Primitives and libraries
| Purpose | Primitive | Browser and Node | Fallback |
|---|---|---|---|
| Key agreement | X25519 | WebCrypto X25519 |
@noble/curves 2.0.1 |
| AEAD | AES-256-GCM | WebCrypto AES-GCM |
@noble/ciphers 2.0.1 |
| Hash, HKDF | SHA-256, HMAC-SHA-256 | WebCrypto | @noble/hashes 2.0.1 |
WebCrypto is used whenever the runtime supports X25519 end to end. Older browsers and web
views fall back to the pinned, independently audited noble packages; with the fallback the
private key is stored as raw bytes in IndexedDB instead of a non-extractable CryptoKey.
The implementation is checked byte for byte against vectors produced by the independent
Python noiseprotocol implementation (apps/tui/web/e2e-noise.test.ts).
Generate and pair a key
Over SSH on the server, or wherever devctl reaches Core:
./devctl e2e status # server fingerprint, policy, keys
./devctl e2e keygen --label "Anna phone" # key pair made here; only the public key goes to Core
keygen prints the device's pairing code (secret), its key fingerprint and the server
fingerprint. Paste the code on the device, then clear your terminal scrollback. Variants:
devctl e2e keygen --offline --server-key PUBLIC_KEYcreates a code without contacting Core; register the printed public key later withdevctl e2e register PUBLIC_KEY --label NAME.devctl e2e generate --label NAME [--user USER_ID]lets Core generate the pair and return the code once (the private key is not stored).- In Settings → End-to-end encryption (TUI and web) press
gto generate a key and show its pairing code once.
Generating a key for another user (--user, or the settings screen) hands over that
user's private key, so only the installation operator may do it; any other administrator,
and every user, generates only their own key and is refused (403, audited as
e2e.key.generate-refused) otherwise. The same applies to rotating another user's key.
Administrators may still register a public key for another user, and list or revoke
other users' keys; users manage only their own keys. A key belongs to one user: a channel opened with Alice's key
cannot sign in as Bob.
On the device, open Console → End-to-end encryption, paste the code and compare the
server fingerprint with the one shown by devctl e2e status or in Settings. The header
badge shows the server fingerprint while the console is paired.
Rotation and revocation
| Action | Command | Settings key | Audit event |
|---|---|---|---|
| Register a public key | devctl e2e register / keygen |
— | e2e.key.registered |
| Generate a key on Core | devctl e2e generate |
g |
e2e.key.generated |
| Rotate a key (new code, old key revoked) | devctl e2e rotate KEY_ID, keygen --replace KEY_ID |
r |
e2e.key.rotated |
| Revoke a key | devctl e2e revoke KEY_ID --confirm |
x, x |
e2e.key.revoked |
| Replace the server key (all devices pair again) | devctl e2e server-key rotate --confirm |
S, S |
e2e.server-key.rotated |
The gateway reloads Core's registry every ten seconds and immediately after a key change made through it. Revoking or rotating a key, disabling its user or replacing the server key closes the affected live channels. Revoked keys remain listed with their fingerprints for review. Fingerprints are the first 128 bits of the SHA-256 of the raw public key, shown as eight groups of four hexadecimal digits; the key ID is the first 24 hexadecimal digits.
Policy
| Setting | Who | Effect |
|---|---|---|
optional (default) |
administrator | Paired clients encrypt; plaintext stays allowed. |
required |
administrator | Core's gateway refuses plaintext remote requests and upgrades. |
| LAN included | administrator | Applies required to private-network peers as well. |
| My preference | each user | Refuses that user's plaintext remote requests after sign-in, regardless of the installation policy. |
devctl e2e policy required [--lan|--no-lan], devctl e2e prefer required|optional, or
m, l and u in Settings. Changes are audited as e2e.policy.updated and
e2e.preference.updated.
A plain request is local when it comes from loopback with a loopback Host and no proxy
headers; LAN when it comes from a private address without proxy headers; otherwise
remote. Tunnel connectors run beside the gateway and connect from loopback, so the
public Host or the forwarding headers they add (X-Forwarded-For, CF-Connecting-IP,
Forwarded and similar) mark their requests remote. An SSH port forward stays local. In
container installs the Docker host reaches a published port from a private bridge address,
so including LAN also covers browsers on the Docker host itself.
With required, remote plaintext is refused (403, code: E2E_REQUIRED,
X-Devctl-E2E: required) except for:
- the static console assets,
/healthz, CORS preflights and the/e2e/channelupgrade, so an unpaired browser can load the pairing screen; - machine routes with their own authentication: host-agent enrollment and connections, device transports, federation peer requests (signed), messenger webhooks, external MCP OAuth and the tunnel probe.
If the gateway has never been able to read Core's policy, remote plaintext is refused with
503 E2E_POLICY_UNAVAILABLE (fail closed). A controller without this feature (404) leaves
everything as before.
Threat model
What the tunnel or proxy can no longer see
- Request and response bodies, URLs and query strings, headers including bearer tokens, passwords typed at sign-in, invitation keys, terminal input and output, file uploads and downloads, Task Graph and event streams: everything sent through the channel.
- Which API routes are called, and which session or project is involved.
What it can still see (metadata)
- That a console exists at this hostname, the client IP address (to the tunnel provider), the time and duration of each channel, and the size and timing of encrypted messages. Traffic analysis can infer activity patterns, for example terminal typing rhythm.
- The static console assets (HTML, JavaScript, CSS) and the
/healthzresponse, which are not secret. - Plaintext machine routes listed above. Host agents and device transports are protected by their own credentials but are not part of this channel.
- Browser push notifications do not pass through the tunnel: the gateway sends them to the browser vendor's push service with Web Push encryption.
What it can still do
- Deny service: drop, delay or close connections, or forge close codes. It cannot make the client fall back to plaintext.
- Alter the page it serves. A browser that loads the console's JavaScript through the
tunnel trusts the tunnel for that code. An active attacker in the tunnel could replace the
application and read the key or the user's input. The channel fully protects against
passive tunnels, logging proxies and later compromise of recorded traffic; against an
active, code-modifying tunnel use the desktop or mobile app,
standalone.html, or a separately hosted static client, which do not load code through the tunnel. The pairing screen states this limitation.
Not in scope
- A compromised device or browser profile (the private key is usable there, even when it is non-extractable).
- A compromised Core host: the gateway decrypts on that host by design.
- The link between a gateway and a remote controller, and gateway-to-gateway console
forwarding (
/consoles/…), which keep their own transport security.
Limitations
- Session previews (
docs/session-preview.md) are served as separate browser origins and cannot use the channel. Withrequired, remote preview requests are refused; open previews locally, over an SSH forward or a tailnet. - Public session links (
docs/shared-sessions.md) are reachable through the tunnel only in plaintext unless the recipient's browser holds a paired key; withrequiredthey are refused for unpaired recipients. - Browser downloads through the channel are assembled in memory (up to 512 MB) before the browser saves them, and uploads report progress per chunk instead of continuously.
- Legacy HttpOnly-cookie gateway clients cannot use the channel; paired clients use bearer sessions.
- Saved consoles proxied by another gateway (
/consoles/…) reach the target console from that gateway without this channel. When the target requires encryption, connect the browser to it directly (?api=<origin>) and pair there. - The native TUI connects to Core over SSH or loopback and does not use this channel.
- When a channel ends (twelve-hour lifetime, revocation, network loss), its open terminals close like any interrupted connection; API requests reconnect with a new handshake.
- The pairing code is a secret. Anyone who obtains it can open a channel as that device until the key is revoked; sign-in is still required.