Skip to content

feat(ssh): add cross-platform native Tailcat transport via libtailcat FFI - #2052

Draft
rock2z wants to merge 1 commit into
lollipopkit:mainfrom
rock2z:feat/tailcat-ssh-transport
Draft

rock2z wants to merge 1 commit into
lollipopkit:mainfrom
rock2z:feat/tailcat-ssh-transport

Conversation

@rock2z

@rock2z rock2z commented Dec 3, 2026

Copy link
Copy Markdown

What this changes

Adds an optional, cross-platform Tailcat SSH route mode (Direct | Jump | Proxy | Command | Tailcat) backed by upstream github.com/tailscale/tailcat's versioned C ABI (cmd/libtailcat, ABI v1) via dart:ffi.

Related to #2040 — addresses the cross-platform requirement without an iOS-only Swift bridge, CocoaPods dependency, mobile Linux rootfs download, or Tailscale account/system VPN. (Cross-platform userspace Tailscale multi-account support is intentionally out of scope for this PR.)

  • Model, validation & storage (SchemaVersion v47 → v48, olderBuildsRead: true):
    • Added nullable tailcatAddress and tailcatDerpMapUrl fields to SshCredential (lib/data/model/server/ssh_credential.dart) and nullable columns ssh_tailcat_address / ssh_tailcat_derp_map_url to the server table (lib/data/store/db.dart, lib/data/store/server.dart, lib/data/store/migrations/m047_ssh_tailcat.dart).
    • Added SpiValidationError.tailcatConflict so Tailcat is mutually exclusive with jump servers, SSH proxies, and ProxyCommand, and disabled Mosh when Tailcat is active.
    • Redacted secret tc... addresses from Spix.displayAddr, TailcatSocket.toString(), diagnostic crumbs, and error messages.
  • Cross-platform FFI transport (lib/core/ssh/tailcat_ffi.dart, lib/core/ssh/tailcat_socket.dart):
    • Zero-pubspec dart:ffi bindings to upstream libtailcat ABI v1 (tc_abi_version == 1).
    • TailcatSocket implements SSHSocket using off-UI-thread dialing (Isolate.run), dedicated reader/writer isolates, TCP half-close, bounded tc_drain, and immediate interrupt-on-close (tc_close).
    • Wired into genClient (lib/core/ssh/client.dart) and probeHostKey (lib/core/ssh/host_key_probe.dart) so existing SSH auth, HostKeyVerifier, HostCertAuthority, SFTP/SCP, port forwarding, and terminal sessions work unchanged without silent fallback to direct TCP.
  • Server editor UI & l10n (lib/view/page/server/edit/, lib/l10n/app_en.arb):
    • Added the Tailcat route segment. When selected, Host/IP is hidden (Port defaults to 22, User defaults to root), and an obscured Tailcat address input (protected by _revealStored / AppAuth) plus an optional custom DERP map URL input are shown.
  • Build helper (tools/tailcat-lib/build.sh, tools/tailcat-lib/README.md):
    • Reproducible build script for upstream cmd/libtailcat across macOS, Linux, Windows, Android (jniLibs), and iOS (CTailcat.xcframework), with zero forked Go code. When libtailcat is not bundled, all existing connection types continue to work untouched and Tailcat connections report a clear SSHErr.

Open questions before marking Ready for Review

  1. Native library distribution: Should release builds fetch prebuilt libtailcat binaries (similar to packages/fl_tty/scripts/ensure-iul-libs.sh) or build cmd/libtailcat in CI workflows?
  2. iOS / Android packaging: Should CTailcat.xcframework / Android jniLibs wiring be added in this PR or a follow-up packaging PR once the Dart transport & UI land?

How it was tested

  • dart analyze on all 19 modified/added handwritten Dart files and new tests: No issues found.
  • flutter test --no-pub --concurrency=1 across 11 migration suites (m028–m047), proxy_socket_test.dart, server_edit_tailcat_test.dart, server_edit_ssh_route_test.dart, and server_edit_connection_test.dart: 112 passed.
  • Live end-to-end integration test (test/unit/ssh/tailcat_socket_test.dart against compiled macOS libtailcat.dylib from upstream tailscale/tailcat@9245129f + local loopback DERP/STUN relay + real Go Ed25519 SSH server): 9/9 passed, verifying tc_address_parse, bidirectional WireGuard/DERP TCP streaming, half-close, probeHostKey, and full genClient + HostKeyVerifier SSH handshake.
  • sh -n tools/tailcat-lib/build.sh and git diff --check: clean.
  • Manual native builds (iOS Linux engine, macOS build, Windows build in analysis.yml) were not needed for this pure-Dart + build-script diff (ios/, macos/, windows/, pubspec.*, crates/, packages/, hook/ are unchanged). iOS CTailcat.xcframework and Android jniLibs packaging have not been built/tested on-device yet.

Checklist

  • dart analyze and targeted flutter test suites pass (full CI suite pending on PR)
  • build_runner and flutter gen-l10n were run for ssh_credential.dart, db.dart, and app_en.arb
  • cargo test --workspace passes (not applicable — nothing under crates/ or monitor/ changed)
  • No formatter was run over untouched code

… FFI

Adds an optional Tailcat SSH route mode backed by upstream tailscale/tailcat
(cmd/libtailcat C ABI v1) via dart:ffi instead of an iOS-only Swift bridge or
mobile Linux ProxyCommand. Reuses ServerBox's existing SSHClient auth, SFTP/SCP,
port forwarding, HostKeyVerifier, and probeHostKey.

- Model & storage (schema v47 -> v48, olderBuildsRead: true): add nullable
  tailcatAddress and tailcatDerpMapUrl on SshCredential and server table;
  enforce mutual exclusivity with jump, proxy, ProxyCommand, and Mosh; redact
  secret Tailcat addresses in displayAddr, crumbs, logs, and errors.
- Transport: implement zero-pubspec-change dart:ffi bindings for libtailcat
  ABI v1 and isolate-backed TailcatSocket (SSHSocket), wired into genClient
  and probeHostKey.
- UI & build tooling: add Tailcat route segment to ServerEditPage with
  obscured secret input (AppAuth-protected reveal) and cross-platform build
  script tools/tailcat-lib/build.sh.

Co-authored-by: OpenBot <335604065+openbotgit[bot]@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 024b5246-6024-41a2-a693-0b1b5bd3e1d6

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@github-actions

github-actions Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

CLA signed

Everyone who authored a commit here has signed the Contributor License Agreement. Thank you.

@winnowl

winnowl Bot commented Dec 3, 2026

Copy link
Copy Markdown

CI failure root-cause analysis

The CI job is marked as a CLA failure, but no structured diagnostics were provided. The underlying cause cannot be determined from the available evidence.

Verifiable fix

Inspect the job's full log or CLA check details to identify the required action (for example, signing the contributor license agreement), then rerun the check.

Incremental value: root cause, verifiable fix; confidence 96%. Passing CI ≠ absence of defects (§29.4).

@rock2z

rock2z commented Dec 3, 2026

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

github-actions Bot added a commit that referenced this pull request Dec 3, 2026

This branch has not been deployed

No deployments
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.

1 participant