Skip to content

feat: add cross-platform userspace Tailscale support with per-server accounts - #2053

Draft
rock2z wants to merge 3 commits into
lollipopkit:mainfrom
rock2z:feat/userspace-tailscale
Draft

rock2z wants to merge 3 commits into
lollipopkit:mainfrom
rock2z:feat/userspace-tailscale

Conversation

@rock2z

@rock2z rock2z commented Dec 3, 2026

Copy link
Copy Markdown

Ref #2040

What this changes

Adds cross-platform userspace Tailscale / Headscale support without occupying the OS VPN slot, backed by a dedicated Tailscale accounts list under Credentials so different servers can connect through different Tailscale accounts / tailnets simultaneously.

Out of scope: Tailcat is intentionally excluded from this PR.

Architecture

  1. Stripped Go tsnet userspace engine (native/tailscale/ + hook/tailscale_build.dart)

    • Uses official tailscale.com/tsnet (v1.104.1) compiled with Tailscale's ts_omit_* feature tags (native/tailscale/build_tags.txt — omitting logtail, aws, kube, ssh, drive, taildrop, webclient, systray, etc.) and telemetry disabled (TS_NO_LOGS_NO_SUPPORT=true, logger.Discard).
    • Exposes a thin C ABI (sbm_ts_*) with process-wide handle tables (so background SFTP/SCP transfer isolates reuse the active node via sbm_ts_lookup) and direct sbm_ts_dial_tcp + sbm_ts_conn_{read,write,close} stream I/O (avoiding Unix-only socketpair(2) and iOS loopback-listener suspension issues).
    • Compiled via Dart's native assets build hook (c-archive / StaticLinking on iOS; c-shared / DynamicLoadingBundled on Android, macOS, Linux, Windows; -trimpath -buildvcs=false -ldflags="-s -w -buildid=" + 16 KB Android page alignment). Stripped macOS arm64 libserverbox_tsnet.dylib measures 16 MB.
    • Opt-out available via hooks.user_defines.server_box.tailscale: false or SBM_SKIP_TAILSCALE_NATIVE=1 (runtime degrades cleanly with TailscaleManager.shared.isAvailable == false).
  2. Schema v48, Store, Backup & Sync

    • Adds TailscaleAccount (id, name, controlUrl, hostname, authMode [interactive / authKey], authKey, ephemeral) and tailscale_account table (WITHOUT ROWID, unique name).
    • Adds server.ssh_tailscale_account_id and server.monitor_tailscale_account_id foreign keys (ON DELETE SET NULL) + TailscaleAccountMigration (m047_tailscale_account.dart, SchemaVersion.current = 48), following the SshProxy (m046) pattern including fail-closed pending links during out-of-order sync.
    • Sync safety: account configuration syncs across devices (authKey is stripped from unencrypted backups and QR server shares, preserved only in encrypted backups/sync), while each account's tsnet node state directory (<appSupport>/tailscale/<accountId>/) stays strictly device-local to avoid WireGuard node-key collisions.
  3. Transport Parity, Discovery & UI

    • SSH: TailscaleSocket implements SSHSocket wired into SshClient, HostKeyProbe, SshTransferCreds/transfer_worker, and ControlMaster (disabled on userspace Tailscale routes; mutually exclusive with Jump/Proxy/ProxyCommand and Mosh).
    • Monitor HTTP: bridgeTailscaleConnToSocket wired into MonitorHttpClient (connectionFactory + probePrimary() TLS certificate pinning).
    • Peer Discovery: UserspaceTailscaleDiscovery surfaces peers from running userspace accounts alongside local Tailscale CLI discovery.
    • UI & l10n: Credentials -> Tailscale accounts list and editor (TailscaleAccountsListPage, TailscaleAccountEditPage with interactive browser login, Auth Key mode with AppAuth.confirm reveal, session connect/disconnect/logout), plus Tailscale SSH route segment and Monitor HTTP Tailscale account picker in Server Edit. English and Simplified Chinese strings added.

How it was tested

Tested on macOS arm64 (Flutter 3.50.1, Rust 1.98.1, Go 1.27.4):

  • native/tailscale: go test -count=1 -race -v -tags="..." ./... & go vet — 4/4 passed.
  • flutter analyze lib test integration_test hook — 0 issues.
  • flutter pub get --enforce-lockfile — clean.
  • python3 scripts/check-l10n.py --app-only --dump zh — 0 issues.
  • Targeted unit, migration (m028–m047), backup/sync, widget, and real native libserverbox_tsnet.dylib FFI smoke tests — 106/106 passed.
  • Full non-e2e flutter test suite — 4,565+ passed (only local-env failures: missing tmux CLI in tmux_control_real_protocol_test.dart, unpulled Git LFS PNGs in theme_store_tree_test.dart).

Remaining before ready for review

  • GitHub Actions PR checks (Go Tailscale tests, check, tests shards, Build input checks)
  • Manual cross-platform build workflows (macOS build, Windows build, iOS Linux engine, Android reproducible build)
  • Permanent test/fixtures/schema/v47_store.db release migration fixture (matching v46_store.db)
  • Live end-to-end smoke test against Tailscale (interactive OAuth + auth key) and self-hosted Headscale for SSH/SFTP and Monitor HTTP

Checklist

  • make analyze and make test pass
  • make gen was run, if any model / ARB file changed
  • cargo test --workspace passes, if anything under crates/ or monitor/ changed (not modified)
  • No formatter was run over untouched code

@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: edda0885-167c-404e-a22f-a3f6e00a9fb5

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

@socket-security

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedgolang/​tailscale.com@​v1.104.171100100100100

View full report

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