Skip to content

feat(fleet-proxy): raw byte splice for RustDesk direct-access port (#6221) - #7703

Closed
dezren39 wants to merge 2 commits into
mainfrom
queue/10516-6221-rustdesk-raw-stream-splice
Closed

dezren39 wants to merge 2 commits into
mainfrom
queue/10516-6221-rustdesk-raw-stream-splice

Conversation

@dezren39

@dezren39 dezren39 commented Nov 8, 2026 •

Copy link
Copy Markdown
Member

Implements the first build from #5694's recommendation B: the fleet proxy gains a raw byte splice, so RustDesk's direct-access port (21118) reaches the sandbox as a loopback listener instead of through the dedicated raw SSH forward.

Closes #6221.

What this adds

The wire (fleet-proxy-proto): a splice is its own negotiated capability and its own frame.

client → { "splice": { "port": 21118 } }
broker → { "splice": { "status": 200 } }              ← then raw bytes, both ways
broker → { "splice": { "status": 502, "error": "…" } } ← refusal, shapes only

After a 200 the connection stops being a frame stream in both directions. Capability ids: proxy-splice (client) and splice-serve (broker).

The gate is negotiation. A pre-splice fleet broker — and every proto-0 Python broker — advertises neither id, so fleet proxy desktop reports it and exits 69. It never sends a splice frame to a broker that would try to parse it as a request. The SSH forward stays the fallback until this is verified live.

Broker half (serve_splice): the requested port must be in the broker's own routing table (the table is the negotiation — a splice must never become a way to reach an arbitrary laptop port), then one fresh tunnel is opened and the connection is handed to the relay. The tunnel is spent: it never returns to the pool, because the pool holds reusable HTTP conns and this one has another peer's protocol on it.

Client half (fleet proxy desktop): binds 127.0.0.1:21118 (RustDesk's own default, so the sandbox client needs no configuration), one splice per accepted connection, loopback-only enforced at bind time rather than trusted to the operator.

The 660 s fix (TunnelMode): tune() was HTTP-shaped, and applying it to a splice would kill every desktop session at 11 minutes. TunnelMode::Raw clears both timeouts; Http keeps today's values. This is the whole reason the timeouts became a caller choice.

Acceptance from #6221

Criterion Where
New and old broker capability negotiation; old brokers keep behaviour a_broker_without_the_capability_is_never_asked, the_legacy_dialect_is_never_asked
Bidirectional byte-stream transparency relay_is_byte_transparent_in_both_directions (all 256 byte values, 64 KiB+7), relay_carries_both_directions_concurrently
Concurrent splices concurrent_splices_do_not_interfere
Idle session past the 660 s timeout raw_tunnels_clear_the_http_timeouts, a_raw_tunnel_really_has_no_timeouts, an_idle_splice_survives_past_the_http_timeout
No RustDesk credential in config or logs structural: the relay never inspects payload, nothing reads a token file, errors name shapes only
forward.sh untouched as fallback not modified

The >30-minute live session and the start-latency comparison against the forward.sh baseline are activation checks, not unit tests — they need the laptop's RustDesk host and a real session. Recording them on #5694 as the activation caveat rather than claiming them here.

Notes for review

  • The relay is hand-rolled read/write, deliberately not std::io::copy: on Linux that lowers to splice(2), which stalled mid-stream in this sandbox for the SSH ProxyCommand relay (fleet step 3: proxy domains — hello/capability frame, PATH shim regeneration, fleet init #5431).
  • Half-close semantics are preserved: EOF in one direction sends FIN in that direction only, so the other direction keeps flowing.
  • fleet-config's built-in services table grows to four entries (21118 rustdesk), so services_default_to_the_live_table moves from 3 to 4.

Tests

cargo test -p fleet-proxy -p fleet-proxy-proto -p fleet-config -p fleet-registry   → 136 passed
cargo test -p fleet --no-default-features --features "proxy-serve,queue,secrets-broker,search-serve,secrets" → 29 passed

cargo test -p fleet with default features does not compile on current main — fleet-queue/src/validate.rs declares FLEET_REPOS: [&str; 10] with 9 entries (pre-existing, untouched by this branch; verified against origin/main). The feature-scoped run above is the same capability set without the broken crate.


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

…6221)

First build of #5694's recommendation B: let the fleet proxy expose a
laptop TCP service through a loopback-only raw byte stream, using the
existing CONNECT tunnel path, so RustDesk's direct-access port 21118
stops needing the dedicated raw SSH forward.

- fleet-config: register port 21118 as `rustdesk` in the routing table
  (its presence is what makes a splice request for it legal), plus
  PORT_RUSTDESK and SPLICE_LISTEN_HOST.
- fleet-proxy-proto: the `{ "splice": { "port": N } }` request and
  `{ "splice": { "status": …, "error": … } }` reply, with the
  `proxy-splice` / `splice-serve` capability ids. After a 200 the
  connection stops being a frame stream in both directions.
- fleet-registry: ProxySplice and SpliceServe capabilities; the proxy
  domain gains the `desktop` subcommand.
- fleet-proxy/tunnel: `TunnelMode` makes the post-setup timeouts a
  caller choice. `Raw` clears them — this is what stops a desktop
  session dying at the 660 s HTTP read timeout.
- fleet-proxy/splice: the relay (opaque, bidirectional, hand-rolled
  read/write like the stdio relay — not io::copy, which stalled in this
  sandbox at #5431), the broker half (`serve_splice`, port must be in
  the routing table, spent tunnels never return to the pool) and the
  client half (`fleet proxy desktop`, loopback-only listener).
- fleet-proxy/serve: advertise `splice-serve`; hand a splice frame to
  the raw relay instead of the request/response loop.

Capability negotiation is the gate: a pre-splice broker (and every
proto-0 Python broker) advertises neither id, so `fleet proxy desktop`
reports it and exits 69 while the SSH forward stays the fallback.

No RustDesk credential is read, stored, or logged anywhere in this
path: the relay never inspects payload, and the permanent password's
proof travels inside the spliced bytes.

Tests: 13 new splice tests (byte transparency across all 256 values,
concurrent bidirectional streams, two concurrent splices, raw mode
clearing live socket timeouts, an idle splice outliving the HTTP
timeout shape, loopback-only listener enforcement, and the negotiation
gate proving a non-splice broker is never sent a splice frame), plus
protocol, config, registry and CLI coverage.

Refs #6221, #5694
@dezren39
dezren39 requested a review from a team as a code owner November 8, 2026 13:30
@coderabbitai

coderabbitai Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 16 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b4ad49ea-ad8c-4658-a84f-eb99987b5cf5
Commits

Reviewing files that changed from the base of the PR and between 1fd4695 and c98c33d.

Files selected for processing: 10

  • pkgs/fleet/README.md
  • pkgs/fleet/crates/fleet-config/src/lib.rs
  • pkgs/fleet/crates/fleet-proxy-proto/src/lib.rs
  • pkgs/fleet/crates/fleet-proxy/src/client.rs
  • pkgs/fleet/crates/fleet-proxy/src/lib.rs
  • pkgs/fleet/crates/fleet-proxy/src/serve.rs
  • pkgs/fleet/crates/fleet-proxy/src/splice.rs
  • pkgs/fleet/crates/fleet-proxy/src/tunnel.rs
  • pkgs/fleet/crates/fleet-registry/src/lib.rs
  • pkgs/fleet/crates/fleet/src/main.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-12T20:54:51.737766Z c98c33d New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5fb62b1e91

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +756 to +760
if is_splice_frame(&frame) {
crate::splice::serve_splice(
&broker.config,
broker.egress.as_ref(),
stream,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep the broker alive while a splice is active

When a desktop session runs without unrelated HTTP requests, the broker still exits after idle_exit_secs (3600 seconds by default), terminating the session even while bytes are flowing. This branch bypasses do_request, the only path that updates Broker.last_used, while keepalive_loop calls process::exit(0) when that timestamp expires. Clearing the tunnel timeouts therefore does not make desktop sessions long-lived. Track active splices and prevent idle shutdown until they finish, including while an established desktop session is idle.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in c98c33d (task 10516, lane code-a). The broker now counts live splices: Broker.active_splices (AtomicUsize) is passed to serve_splice, which holds an RAII SpliceGuard from the 200 handshake until the relay ends. keepalive_loop exits only via idle_exit_due(last_used, now, idle, active_splices), which is false while any splice is active — including an established but idle desktop session. Tests: serve::tests::idle_exit_waits_for_active_splices and splice::tests::splice_guard_counts_live_splices; full fleet-proxy suite 85 lib + 14 bin tests pass, rustfmt clean.

Comment on lines +157 to +160
None => connect_tunnel_mode(
None,
target,
req.port,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Require explicit direct mode before bypassing the egress proxy

When proxy_direct() is false but HTTPS_PROXY is missing or invalid, broker startup also stores egress = None. This branch interprets that state as permission to connect directly to the laptop, silently bypassing the configured proxy route. The existing HTTP path in Broker::open_conn_raw distinguishes explicit direct mode from missing egress configuration and refuses the latter. Apply the same check here so a splice reports the configuration failure rather than attempting an unintended direct connection.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in c98c33d (task 10516, lane code-a). serve_splice now refuses before dialling when egress is None and config.proxy_direct() is false, returning the same message the HTTP path uses in Broker::open_conn_raw: "HTTPS_PROXY must be set (runtime proxy env)". Explicit direct mode (proxy_direct true, egress None) still dials directly. Test: splice::tests::serve_splice_refuses_missing_egress_when_not_direct asserts the 502 refusal frame over a UnixStream pair with Config::default(); full fleet-proxy suite passes.

@dezren39

Copy link
Copy Markdown
Member Author

🤖 Agent note · parked (resumable — Codex fixes landed, rebase/port is the next step)

  • Agent: queue worker (repo-worker-code), lane code-a
  • Session / ID: task 10516 (small_fix, issue Implement RustDesk raw-stream splice through fleet proxy #6221)
  • Done this shift: both Codex findings on head 5fb62b1 fixed and pushed as c98c33d:
    • P1 (broker idle-exit kills active splices): Broker.active_splices counter + RAII SpliceGuard held for the relay's life; keepalive_loop exits only when idle_exit_due(...) is true, which requires zero active splices. Thread replies: 4556187389.
    • P2 (missing egress treated as direct mode): serve_splice refuses with "HTTPS_PROXY must be set (runtime proxy env)" when egress is None and proxy_direct() is false — the same rule/message as Broker::open_conn_raw. Thread replies: 4556187746.
    • Tests: cargo test -p fleet-proxy — 85 lib + 14 bin pass (3 new tests: guard accounting, missing-egress refusal, idle-exit predicate); rustfmt clean.
  • Why not merged: the branch is 2143 commits behind current main and a trial rebase (aborted, branch restored to c98c33d) conflicts in 6 files — README, fleet-config/src/lib.rs, fleet-proxy/src/serve.rs, fleet-proxy/src/tunnel.rs, fleet-registry/src/lib.rs, fleet/src/main.rs. splice.rs itself applies clean. This is a port, not a mechanical rebase: main's serve/tunnel/config have evolved since the branch base.
  • Exact next steps for the resuming lane: (1) rebase/port the two commits onto current main resolving the 6 files above; (2) re-run cargo test for fleet-proxy, fleet-config, fleet-registry, fleet; (3) run the >660s live splice verification from Implement RustDesk raw-stream splice through fleet proxy #6221's acceptance (long-lived splice beyond the old 660s tunnel timeout); (4) disposition the fresh Codex review on the rebased head; (5) merge and close Implement RustDesk raw-stream splice through fleet proxy #6221.
  • Links: task 10516 · PR feat(fleet-proxy): raw byte splice for RustDesk direct-access port (#6221) #7703 · issue Implement RustDesk raw-stream splice through fleet proxy #6221

@dezren39

Copy link
Copy Markdown
Member Author

🤖 Agent note · closing as superseded by PR #8618

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement RustDesk raw-stream splice through fleet proxy

1 participant