Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Introduction

SCTGDesk is a self-hosted remote-desktop server and client derived from RustDesk. This manual is for people who want to build, change or maintain it. For installing and running a server, see the README.

What this repository contains

One repository, kept as close to upstream as possible so that new RustDesk releases can be merged:

  • the RustDesk server (hbbs, hbbr, rustdesk-utils), taken from rustdesk/rustdesk-server;
  • our REST API server and Vue web console, embedded in hbbs (address books, users, groups, OIDC, software update endpoints);
  • the client, as a small overlay applied on a pristine upstream RustDesk release (client/).

What is ours and what is upstream’s is spelled out in Architecture and in the decision records.

Compatibility is the first rule

The client must keep working with official RustDesk clients, and our server with official clients. When in doubt, follow upstream’s behaviour and keep our changes small and isolated: that is what makes the monthly upstream sync cheap.

License and trademark

The project is AGPL-3.0, like upstream. A modified version offered over a network must offer its source to its users (AGPL section 13). “RustDesk” is a third-party name: we use it only to describe compatibility and origin (“a fork of RustDesk”), never as the name of our product. SCTGDesk is not affiliated with or endorsed by the RustDesk project or Purslane Ltd. See ADR 0004.

Status

The project is being consolidated. Anything marked not verified in this manual has not been exercised yet; the roadmap lists what is open.

Architecture

Components

BinaryRoleDefault ports
hbbsID / rendezvous server, with the REST API and web console embedded21116 TCP+UDP (rendezvous), 21115 TCP (NAT test), 21118 TCP (WebSocket), 21114 TCP (API, console)
hbbrrelay server21117 TCP, 21119 TCP (WebSocket)
rustdesk-utilskey pair generation and validation, connectivity check (doctor)–

The ports are defined in libs/hbb_common/src/config.rs and src/main.rs; rustdesk-utils doctor checks them.

hbbs stores peers and the API data in a SQLite database (db_v2.sqlite3, or the file given by DB_URL). Its key pair is id_ed25519 / id_ed25519.pub in the working directory; clients are given the public key.

Repository layout

PathContentOrigin
src/hbbs, hbbr, rustdesk-utilsupstream, with our changes in main.rs and rendezvous_server.rs
libs/hbb_commonshared protocol librarygit submodule on rustdesk/hbb_common, unmodified
crates/api-serverREST API, embedded into hbbsours
crates/api-{state,utils,oauth2,s3software}libraries of the API serverours
web/console, web/rapidocVue web console, API documentationours
client/patches, overlay and branding for the clientours, on top of upstream
deploy/helmHelm chart (to be refactored)ours
docs/this manualours

All the crates live in one Cargo workspace; see ADR 0005.

What is ours in upstream files

Kept deliberately small, see Syncing with upstream:

  • src/main.rs: starts the API server, defines API_PORT;
  • src/rendezvous_server.rs: the TCP key exchange and its tests;
  • src/common.rs: the --require-kx-v1 flag.

Transports

hbbs speaks UDP, TCP and WebSocket natively (upstream). On TCP and WebSocket, the connection is encrypted by a key exchange that our server implements and upstream’s server does not.

TCP key exchange

Clients that connect to hbbs over TCP or WebSocket expect an encrypted channel. Upstream’s server has no handler for it; ours does (key_exchange_phase1 and the phase-2 handler in src/rendezvous_server.rs).

The exchange

  1. The server sends a KeyExchange message: its ephemeral X25519 public key signed with the server key (id_ed25519), the version it speaks, and signed parameters (KxParams).
  2. The client verifies the signature with the public key it was given, generates a symmetric key and sends it sealed to the server’s ephemeral key (crypto_box), with its own ephemeral key and the version it picked.
  3. Both sides derive the stream keys.

Versions

VersionStream keysNotes
0one key for both directionsthe original scheme, what older clients speak
1one key per direction, derived from the transcriptsigned KxParams, defined in hbb_common (KX_VERSION_LATEST = 1)

The server advertises version 1 and accepts the version the client picks (the highest both speak). Bit 255 of the advertised public key is set: X25519 ignores it, so version-0 clients are unaffected, while version-1 clients take it as “signed parameters are required” and refuse a downgrade by a man in the middle.

--require-kx-v1 (or REQUIRE_KX_V1=Y) refuses clients that pick version 0. It is off by default.

Tests

cargo test -p hbbs key_exchange runs the unit tests: the key sealed by a client is recovered, a corrupted or foreign box is rejected without panicking, the advertised key still opens what the client sealed to it, and client and server version-1 streams interoperate.

The real check, done after each upstream sync, is to run the upstream client’s own key_exchange() code against a running hbbs and send one encrypted request. It negotiated version 1 on the day it was written; the harness is not in the repository yet (see the roadmap).

Not covered

A released official client binary, the WebSocket path and hbbr have not been tested with this exchange. The --require-kx-v1 refusal has no test. Reasoning behind the design: ADR 0003.

REST API

The API server (crates/api-server, Rocket) runs inside hbbs on port 21114. It serves the endpoints used by RustDesk clients (login, address books, heartbeat, system info, audit), the ones used by the web console (users, groups, peers, shared address books and their rules, OIDC settings) and a few for software updates.

  • Interactive documentation: http://<server>:21114/api/doc/ (RapiDoc, generated from the code with rocket_okapi); the specification is openapi.json next to it. This is the reference: the list below is a map.
  • Web console: http://<server>:21114/ (Vue app in web/console, embedded at build time).
  • Authentication: POST /api/login returns an access token; routes guarded by AuthenticatedUser or AuthenticatedAdmin expect it as a bearer token. A fresh database contains an admin user: change its password at first login (see the README).

Endpoint groups

PrefixPurpose
/api/login, /api/logout, /api/currentUser, /api/login-optionssessions: kept in the database (api_session, a hash of the token), so they survive a restart of hbbs for 90 days or until the logout
/api/oidc/*OpenID Connect login and settings
/api/ab*address books: personal, shared, peers, tags, rules
/api/user*, /api/enable-users, /api/group*users and groups
/api/device-group/accessiblethe groups, by name, for the “accessible devices” tab of the clients
/api/peers*, /api/heartbeat, /api/sysinfo, /api/audit, /api/stategiespeers and their reports
/api/software/*version and download endpoints, below

Access control

A bearer token only says who the user is; what the user may see and do depends on the user’s rights and group.

Address books. The right of a user on an address book is 0 (none), 1 (read), 2 (read and write) or 3 (everything, including the rules), the highest of the rules given to the user and to the group of the user. The owner and the administrators have 3; a personal address book is for its owner only. POST /api/ab/shared/profiles tells the client the right of the rule, and the server enforces it on every route that takes an address book: peers and tags need 1 to be read and 2 to be changed, and the rules need 3. A refusal answers 403, not 401, which the clients take for an ended session.

Groups. A group lists the groups its users may connect to (allowed_outgoings) and the groups that may connect to it (allowed_incomings), by uuid or by name; the API gives them back as access_to and accessed_from. The two lists are the two ends of the same links: a group always reaches itself. Users that are not administrators only get:

RouteWhat they get
GET /api/usersthe users of their group and of the groups their group may connect to
GET /api/device-group/accessiblethose groups
GET /api/peersthe devices of those users: a device belongs to the user who last logged in on it

/api/peers/count/* and /api/peers/cpus are for administrators, and a user cannot change their own rights or status (PUT /api/user ignores is_admin and status unless the caller is an administrator). Administrators see everything. A device on which nobody logged in belongs to nobody: only administrators see it.

Ownership only decides what is shown: it does not authorize a connection (the device’s own password and --logged-in-only do), and it is taken from the device id the client sends when it logs in, which the server cannot check. Do not rely on it to hide the existence of a device from a user that wants to find it.

Software update endpoints

RouteUsed by
POST /api/software/version/latestcurrent RustDesk clients: same request and response as api.rustdesk.com/version/latest; the body, device fingerprint included, is ignored and not logged
GET /api/software/releases/latestredirects to /api/software/releases/tag/<version>; imitates GitHub’s “latest release”
GET /api/software/releases/tag/<version>the target of the redirect
GET /api/software/downloadredirects to the download page
GET /api/software/version/serverversion of the server and of the latest client

The client download links, the latest client version and the download page come from s3config.toml (see crates/api-s3software).

A key of that file (Windows64Key, OSXKey, IOSKey, …) is either the object itself, or contains {version}:

Windows64Key = "master/sctgdesk-releases/sctgdesk-{version}-x86_64.exe"
OSXKey       = "master/sctgdesk-releases/sctgdesk-{version}-x86_64.dmg"
OSXArm64Key  = "master/sctgdesk-releases/sctgdesk-{version}-aarch64.dmg"
IOSKey       = "master/sctgdesk-releases/sctgdesk-{version}.ipa"
ListBucket   = "master"   # Oracle Cloud only, see below

The API then lists the bucket for the prefix before {version} and picks the key with the highest x.y.z: the whole key has to match, so sctgdesk-{version}-x86_64.dmg does not pick sctgdesk-1.4.0-web-basic.zip, and 1.10.0 is higher than 1.9.3. The answer is kept for five minutes. GET /api/software/version/latest reports the version found that way. A key without {version} works as before and does not call the bucket. If the bucket cannot be listed, the link answers 404 and the reason is in the log.

GET /api/software/download/<key> (w64, w32, osx, osx-arm64, ios) redirects to a freshly signed link of the newest client, so its address does not expire: the update card of the clients opens it for their platform.

On Oracle Cloud, Bucket is the namespace and the keys start with the real bucket (master/...): set ListBucket to that bucket, otherwise the listing goes to the wrong place and finds nothing.

Where the code is

crates/api-server/src/lib.rs holds the routes; the database layer and its migrations are in crates/api-state (db_v2/migrations, checked by sqlx at compile time, hence DATABASE_URL when building).

Building from source

How to build and test from a checkout. For your own binaries and packages see Custom builds; for running a server, Deploying a server.

Requirements

  • Rust (stable), a C toolchain (libsodium is built from source), git with submodules (git clone --recurse-submodules, or git submodule update --init)
  • Node.js 20 and npm, only to build the web console and the API documentation

Build and test

# the sqlx macros check queries against a database at compile time
export DATABASE_URL=sqlite://$(pwd)/db_v2.sqlite3

cargo build --workspace --locked
cargo test  --workspace --exclude oauth2 --locked -- --skip test_nat64

cargo build also builds web/console and web/rapidoc with npm and embeds the result into the API server. To build without Node.js, set SCTGDESK_SKIP_WEB_BUILD=1: the console and API docs are then placeholders.

A smaller binary

hbbs is about 33 MB for a MIPS router, and a router has little flash. What makes it smaller:

  • The web console and the JavaScript of the API documentation are embedded compressed (gzip, done by crates/api-server/build.rs): the server sends them as they are to the browsers that accept gzip and decompresses for the others. The 5 MB source map of the API documentation is not embedded.
  • The Cargo feature s3 (on by default) brings the AWS SDK, which signs the download links of the clients and weighs about 2 MB of code. cargo build --no-default-features leaves it out: the S3 settings can still be edited and validated, but the download links answer that S3 is not built in.
  • packaging/openwrt/build-mips.sh also compiles for size (opt-level = "z", no debug formatting text, no file and line of the panics): see the comments of the script. The log lines of such a build show <redacted>:0 instead of the place in the source.

Layout

PathContent
src/, libs/hbb_commonthe RustDesk server (upstream code, kept close to upstream)
crates/api-serverREST API server, embedded in hbbs
crates/api-{state,utils,oauth2,s3software}libraries of the API server
web/console, web/rapidocVue web console, API documentation

See docs/adr/ for the reasoning behind this layout.

Known gaps

  • The unit tests of crates/api-oauth2 do not compile; hbb_common’s test_nat64 needs network access.
  • s3software’s test that calls a live S3 bucket is ignored; run it explicitly with --ignored.
  • cargo audit reports known advisories; the CI job is informational until they are triaged.

Deploying a server

This guide takes a server from nothing to a production setup: install, key, ports, TLS, login, updates, backup and rollback. The README has the short version.

What runs where

BinaryRolePorts
hbbsID / rendezvous server, with the REST API and the web console21116 TCP+UDP, 21115, 21118 (WebSocket), 21114 (API)
hbbrrelay21117, 21119 (WebSocket)

One hbbs and one hbbr are enough for a team. hbbs is told where the relay is with -r <host[:port]> (or RELAY). Both keep their files in the working directory: the key pair id_ed25519 / id_ed25519.pub, and for hbbs the SQLite database db_v2.sqlite3 (or the file of DB_URL).

Install

Packages (Linux, amd64 and arm64)

sudo apt install ./sctgdesk-server-hbbs_*.deb ./sctgdesk-server-hbbr_*.deb ./sctgdesk-server-utils_*.deb
# Fedora, RHEL: sudo dnf install ./sctgdesk-server-*.rpm

The packages contain static musl binaries (/usr/bin/hbbs, hbbr, rustdesk-utils) and the systemd units rustdesk-hbbs.service and rustdesk-hbbr.service. They replace the former rustdesk-server-* packages, and use the same directories: /var/lib/rustdesk-server (data, mode 700) and /var/log/rustdesk-server (logs).

  • A first install on an empty data directory works at once: the services are enabled and started with the defaults, and hbbs creates a random key pair (id_ed25519, see the key pair). hbbr is started with -k _, which makes it use the same key.
  • An install that finds data starts nothing (a migration from rustdesk-server-*, or a reinstall): the options of the old unit are not carried over, and a default hbbs takes the API port 21114, which a reverse proxy may hold. Set the options, then systemctl enable --now rustdesk-hbbs rustdesk-hbbr.
  • An upgrade restarts the services that run; a removal stops and disables them and keeps the data.
  • Before every install, upgrade or migration the packages copy the data directory to /var/backups/sctgdesk-server/<date>/ (mode 700, the 3 latest are kept; the database with SQLite’s backup).

Migrating from the former rustdesk-server-* packages

Installing sctgdesk-server-* removes the former packages. Do not purge them (dpkg -P, apt purge): their postrm deletes the whole /var/lib/rustdesk-server, the database and the key pair included. If you do, restore from /var/backups/sctgdesk-server/. A removal without purge leaves the data and the old units’ drop-ins in place, and apt keeps a rc entry for them, which is harmless.

Options

The units read /etc/default/sctgdesk-hbbs and /etc/default/sctgdesk-hbbr (mode 600, kept by the package when you edit them). HBBS_ARGS and HBBR_ARGS replace the arguments of the program; the other lines are environment variables:

# /etc/default/sctgdesk-hbbs
HBBS_ARGS=-r relay.example.com -k <your-key> --logged-in-only --api-port=21113
OAUTH2_CREATE_USER=1

then sudo systemctl restart rustdesk-hbbs. The key is in this file, not in the unit, so keep it at mode 600: the units and their drop-ins in /etc/systemd/system are readable by every user of the machine. For more than options (a dedicated user, other limits) use sudo systemctl edit rustdesk-hbbs, which survives upgrades. The units run as root, like the former packages; to run as a dedicated user, create it, give it the two directories and set User= and Group=. The configuration files named in Environment= (oauth2.toml, s3config.toml) are relative to WorkingDirectory=/var/lib/rustdesk-server/.

Archives (Windows, macOS, Linux)

Download the zip of your platform from the release, check it against SHA256SUMS-*, unpack it in the directory that will hold the data and run hbbr and hbbs -r <relay> from there. On Windows, the programs run as services themselves (--windows-service, created with sc.exe): see On Windows; open the ports in the Windows firewall. The macOS binaries are not signed or notarized: Gatekeeper asks for confirmation (xattr -d com.apple.quarantine <file>).

Docker and Kubernetes

See the README for docker compose. The image keeps its data in /usr/local/share/sctgdesk: mount a volume there or the key pair is lost with the container. kubernetes/example.yaml and deploy/helm/sctgdesk are starting points, not tested recipes.

The key pair

Clients encrypt their traffic to the key of hbbs. On the first start, hbbs creates id_ed25519 and id_ed25519.pub if they are missing; the content of the .pub file is the key you give to clients. To prepare a pair yourself:

rustdesk-utils genkeypair
rustdesk-utils validatekeypair <public key> <secret key>

Write the two lines in id_ed25519.pub and id_ed25519 (mode 600) in the data directory of both hbbs and hbbr, or pass -k <public key> to both. Back up id_ed25519: if it changes, every client has to be configured again. Never publish it, nor put it in a repository or an image.

Ports and firewall

Open 21114-21119 (TCP) and 21116 (UDP) towards the Internet, or only 21115-21117 and 21116/UDP if you serve the console and the web client through a reverse proxy on 443 (next section). Direct peer-to-peer connections need UDP; ALWAYS_USE_RELAY=Y disables them if you prefer every session to go through your relay.

Check from another machine: rustdesk-utils doctor <your server>.

TLS reverse proxy

The embedded API server speaks plain HTTP and has no protection against abuse. Browsers need TLS for the web console and for the web client’s WebSockets. Put a reverse proxy in front: it terminates TLS and forwards to hbbs (API, 21114 or the --api-port you chose), 21118 (rendezvous WebSocket) and 21119 (relay WebSocket).

The web client (built by custom builds) talks to wss://<rendezvous>:21120 and wss://<rendezvous>:21121, so the proxy listens there. This HAProxy configuration is the one used in production, as an example; adapt names, certificates and addresses:

global
    log /dev/log    local0
    chroot /var/lib/haproxy
    stats socket /run/haproxy/admin.sock mode 660 level admin expose-fd listeners
    user haproxy
    group haproxy
    daemon

defaults
    log global
    retries 2
    timeout connect 3000ms
    timeout server 5000ms
    timeout client 5000ms

frontend hbbs_wss
    bind 0.0.0.0:21120 ssl crt /etc/haproxy/hbb.pem
    default_backend hbbs_wss_backend

frontend hbbs_api_443
    mode http
    option forwardfor
    bind 0.0.0.0:443 ssl crt /etc/haproxy/api.pem
    http-request set-header X-Forwarded-Proto https
    filter compression
    compression algo gzip
    compression type text/css text/html text/javascript application/javascript text/plain text/xml application/json
    compression offload
    default_backend hbbs_api_backend

frontend hbbr_wss
    bind 0.0.0.0:21121 ssl crt /etc/haproxy/hbb.pem
    default_backend hbbr_wss_backend

backend hbbs_api_backend
    mode http
    server srv_main 127.0.0.1:21113     # hbbs --api-port=21113

backend hbbs_wss_backend
    server srv_main 127.0.0.1:21118

backend hbbr_wss_backend
    server srv_main 127.0.0.1:21119

Here hbbs is started with --api-port=21113 so that the proxy can own 21114 and 443; the API is then not reachable without TLS from outside, as long as the firewall does not open 21113. The timeouts above are short: raise timeout client and timeout server if WebSocket sessions are cut. hbbs does not log the WebSocket rendezvous requests, so look at the proxy’s log when a web client cannot connect.

OIDC login builds its callback from the host the client used (<host>/api/oidc/callback), so the proxy has to pass the Host header and X-Forwarded-Proto unchanged.

Only logged-in users can control

--logged-in-only (LOGGED_IN_ONLY=Y) makes hbbs call POST /api/currentUser of its own API with the token the client sends in its connection request. Without a token the client gets “The connection is not allowed. You have not logged in.”; with a token the API refuses, “Your session expired.”; and “login server is unreachable” if the API does not answer. The API must therefore be reachable by hbbs on the --api-port it was given.

Sessions are stored in the database (a hash of the token, 90 days): restarting hbbs does not log anybody out.

Users, groups and the console

Open http://<server>:21114/ (or your TLS address), log in as admin with the default password Hello,world! and change it at once: it is public. The console manages users, groups, devices and address books (read-only, read-write or admin rules per user or group). The API reference is at /api/doc/ and in REST API.

Login with OpenID Connect and OAuth2

Providers are listed in a TOML file (oauth2.toml is a commented example) named by OAUTH2_CONFIG_FILE:

[[provider]]
provider = "Github"                       # Github, Gitlab, Google, Facebook, or Custom for any OIDC server (Dex...)
authorization_url = "https://github.com/login/oauth/authorize"
token_exchange_url = "https://github.com/login/oauth/access_token"
app_id = "<client id>"
app_secret = "<client secret>"
scope = "read:user"
op_auth_string = "oidc/github"            # what the client shows and sends
op = "github"

Register an application with the provider; its redirect (callback) URL is https://<your API host>/api/oidc/callback. With OAUTH2_CREATE_USER=1 the first login of an unknown user creates it, otherwise only users that already exist in the console can log in. The file holds secrets: keep it out of repositories and readable by the service user only. The native client and the web client both use this flow (the client opens the provider’s page, then polls /api/oidc/auth-query).

Software updates of your clients

The client can ask your server for new versions. hbbs reads S3CONFIG_FILE (s3config.toml: S3-compatible bucket, keys, and the object keys of the installers, with {version} as a placeholder) and answers the update check and the download links. Details and the format are in REST API. The file holds the credentials of your bucket: give it a read-only key, never commit the real one, and note that the copy in this repository is an example only.

Health probes

  • hbbs: GET /livez (the process answers) and GET /readyz (200 when the database answers, 503 otherwise) on the API port (21114), without authentication.
  • hbbr: set HEALTH_PORT to a free port; GET /livez and GET /readyz (200 when the relay port accepts a TCP connection) are then answered there. Off by default.

In Kubernetes: livenessProbe on /livez, readinessProbe on /readyz. The Helm chart sets them with --set probes.enabled=true (off by default: they exist in the images of this repository, not in the upstream image the chart still defaults to). Keep HEALTH_PORT and the API port off the internet.

Backup, upgrade, rollback

Back up id_ed25519, id_ed25519.pub, secret_key.txt, oauth2.toml, s3config.toml and the database (the packages also copy them to /var/backups/sctgdesk-server/ at each install, but that is on the same disk). Use SQLite’s own backup, which is safe while hbbs runs:

sqlite3 /var/lib/rustdesk-server/db_v2.sqlite3 ".backup '/root/backup/db_v2.sqlite3'"
cp -p /usr/bin/hbbs /usr/bin/hbbr /root/backup/

Download a backup

With --allow-remote-backup (or ALLOW_REMOTE_BACKUP=Y, in /etc/default/sctgdesk-hbbs for the packages) hbbs lets an administrator download a backup, from the console (page Backup) or with the API:

TOKEN=$(curl -s https://api.example.com/api/login -H 'Content-Type: application/json' \
  -d '{"username":"admin","password":"...","id":"","uuid":""}' | jq -r .access_token)
curl -fo backup.tar.gz -H "Authorization: Bearer $TOKEN" https://api.example.com/api/backup

The archive holds a consistent copy of the database (taken while hbbs runs, no -wal file to add), oauth2.toml, s3config.toml, id_ed25519, id_ed25519.pub, secret_key.txt (the files that exist) and a MANIFEST.txt. To restore, stop hbbs and hbbr, unpack the files in the data directory (mode 600, and no old db_v2.sqlite3-wal or -shm next to the database) and start them.

  • It is off by default: without the flag the endpoint answers 404, even to an administrator. A plain user, or no token, gets 401.
  • The archive holds the private key and the secrets of the server: an administrator who downloads it can impersonate the server. Only enable it if you trust every administrator, serve the API over TLS (a reverse proxy), and keep the archives encrypted. Each download is logged at warning level with the name of the administrator.
  • The files are those of the working directory of hbbs (OAUTH2_CONFIG_FILE and S3CONFIG_FILE are followed). With ROCKET_SECRET_KEY set there is no secret_key.txt. It does not include hbbr’s own files.

Upgrade with the packages, or replace the binaries and restart:

install -m755 hbbs-new /usr/bin/hbbs && systemctl restart rustdesk-hbbs

The schema changes of the database are migrations applied by hbbs at start; a new table stays in place if you go back, so rolling back the binary is enough unless a release note says otherwise:

install -m755 /root/backup/hbbs /usr/bin/hbbs && systemctl restart rustdesk-hbbs

After an upgrade: hbbs --version, the console loads, an official client connects, and with --logged-in-only a logged-in client connects and a logged-out one is refused. The key exchange check lists what to try with a released official client.

Troubleshooting

SymptomLook at
clients say “key mismatch” or never connectthe key in the client is not the content of id_ed25519.pub; hbbs and hbbr use different keys or -k values
only the relayed connection worksUDP 21116 is not open, or ALWAYS_USE_RELAY=Y
“You have not logged in.”the client has no token: it must log in (a web client needs the account of the API server of its own build)
“Your session expired.”the token is unknown to the API server: log in again; check that --api-port matches the API
web client cannot connectthe proxy’s log; certificates; 21120 and 21121 open; the Host header
nothing in hbbs’s logset RUST_LOG=debug; the WebSocket rendezvous requests are not logged by hbbs

Running the server on Windows

hbbs and hbbr are console programs. Started with --windows-service they also behave as Windows services: they move to their data directory, log to files and stop cleanly when the service manager asks. The services are declared with sc.exe, there is no installer to run.

Install the programs

With winget (the package keeps the three programs on the PATH; --scope machine puts them where a service can reach them):

winget install SCTG.SCTGDeskServer --scope machine

Or unzip sctgdesk-server-<version>-windows-x86_64.zip (or -aarch64) from the releases to a folder such as C:\Program Files\SCTGDesk.

Create the services

In an administrator PowerShell. Replace the paths if you unzipped the archive yourself; Get-Command finds the winget ones.

$hbbs = (Get-Command hbbs).Source
$hbbr = (Get-Command hbbr).Source

# note the space after "binPath=" and after "start=": sc.exe requires it
sc.exe create SCTGDeskHbbr binPath= "`"$hbbr`" --windows-service" start= auto DisplayName= "SCTGDesk relay server (hbbr)"
sc.exe create SCTGDeskHbbs binPath= "`"$hbbs`" --windows-service -r relay.example.com" start= auto depend= SCTGDeskHbbr DisplayName= "SCTGDesk signal server (hbbs)"

# restart by itself after a crash (after 10 s, forever)
sc.exe failure SCTGDeskHbbr reset= 86400 actions= restart/10000
sc.exe failure SCTGDeskHbbs reset= 86400 actions= restart/10000

sc.exe start SCTGDeskHbbr
sc.exe start SCTGDeskHbbs

Everything after --windows-service in binPath= is a normal option of the program (-r, -k, --logged-in-only, --api-port, …: see hbbs --help). To change them: sc.exe config SCTGDeskHbbs binPath= "..." then restart.

Open the ports in the firewall (21114 API and console, 21115, 21116 TCP and UDP, 21117, 21118, 21119):

New-NetFirewallRule -DisplayName "SCTGDesk" -Direction Inbound -Protocol TCP -LocalPort 21114-21119 -Action Allow
New-NetFirewallRule -DisplayName "SCTGDesk (UDP)" -Direction Inbound -Protocol UDP -LocalPort 21116 -Action Allow

Where the files are

WhatWhere
Key pair (id_ed25519*), database, secrets, oauth2.toml, s3config.toml%ProgramData%\SCTGDesk
Logs (rotated at 10 MB, 5 kept)%ProgramData%\SCTGDesk\logs\hbbs*.log, hbbr*.log
Environment variables of the programsa .env file in %ProgramData%\SCTGDesk (KEY=value lines, for example OAUTH2_CREATE_USER=1)

To use another folder, set SCTGDESK_DATA_DIR, either for the whole machine (a system environment variable) or for one service only, in its own Environment value in the registry (a service reads it when it starts, so restart it):

foreach ($service in 'SCTGDeskHbbr', 'SCTGDeskHbbs') {
  New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\$service" -Name Environment `
    -PropertyType MultiString -Value @('SCTGDESK_DATA_DIR=D:\SCTGDesk') -Force
}

Both services must use the same folder. Back it up: it holds the private key.

Stop and remove

sc.exe stop SCTGDeskHbbs ; sc.exe stop SCTGDeskHbbr
sc.exe delete SCTGDeskHbbs ; sc.exe delete SCTGDeskHbbr

The data folder is never deleted.

Notes

  • The flag only works when the service manager starts the program. Typed in a console it stops with a message saying so: to run the server by hand, leave it out.
  • The services run as LocalSystem by default. For a less privileged account, use sc.exe config ... obj= and give the account write access to the data folder.
  • The Windows binaries are not code-signed: SmartScreen or an antivirus may warn on the first run.

Package repositories

The releases are also published as signed package repositories on GitHub Pages, next to this manual:

RepositoryAddressFor
apthttps://sctg-development.github.io/sctgdesk-server/aptDebian, Ubuntu (amd64, arm64, armhf)
rpmhttps://sctg-development.github.io/sctgdesk-server/rpmFedora, RHEL and clones, openSUSE (x86_64, aarch64, armv7hl)
apkhttps://sctg-development.github.io/sctgdesk-server/apk/<architecture>OpenWrt and Alpine

Only the latest full releases are kept (the pre-releases are not).

Debian, Ubuntu

sudo mkdir -p /etc/apt/keyrings
sudo curl -fsSL https://sctg-development.github.io/sctgdesk-server/apt/sctgdesk.gpg -o /etc/apt/keyrings/sctgdesk.gpg
echo "deb [signed-by=/etc/apt/keyrings/sctgdesk.gpg] https://sctg-development.github.io/sctgdesk-server/apt stable main" |
  sudo tee /etc/apt/sources.list.d/sctgdesk.list
sudo apt update
sudo apt install sctgdesk-server-hbbs sctgdesk-server-hbbr

Fedora, RHEL, openSUSE

sudo tee /etc/yum.repos.d/sctgdesk.repo <<'EOF'
[sctgdesk]
name=SCTGDesk
baseurl=https://sctg-development.github.io/sctgdesk-server/rpm/
enabled=1
gpgcheck=0
repo_gpgcheck=1
gpgkey=https://sctg-development.github.io/sctgdesk-server/rpm/sctgdesk.asc
EOF
sudo dnf install sctgdesk-server-hbbs sctgdesk-server-hbbr

The signature covers the metadata of the repository (repo_gpgcheck), and through it the checksum of every package; the packages are not signed one by one, hence gpgcheck=0.

OpenWrt

For OpenWrt 25.12 and later, which use apk. Older releases (opkg) are not supported: use the static binaries of the releases there.

wget -O /etc/apk/keys/sctgdesk.rsa.pub https://sctg-development.github.io/sctgdesk-server/apk/sctgdesk.rsa.pub
. /etc/openwrt_release        # DISTRIB_ARCH: the architecture of the packages of your router, for example mips_24kc
echo "https://sctg-development.github.io/sctgdesk-server/apk/$DISTRIB_ARCH/APKINDEX.tar.gz" > /etc/apk/repositories.d/sctgdesk.list
apk update
apk add sctgdesk-server-hbbs sctgdesk-server-hbbr

DISTRIB_ARCH (from /etc/openwrt_release, the same value as in /etc/apk/arch) is the architecture of the packages of your router. Do not use apk --print-arch for it: the apk of OpenWrt only prints the generic family (mips, not mips_24kc). These are published:

OpenWrt architectureDevices (examples)
x86_64PCs, virtual machines
aarch64_generic, aarch64_cortex-a53, aarch64_cortex-a72, aarch64_cortex-a76Raspberry Pi 3 and later, MediaTek Filogic, Rockchip
arm_cortex-a7_neon-vfpv4, arm_cortex-a7_vfpv4, arm_cortex-a9, arm_cortex-a15_neon-vfpv4Raspberry Pi 2, many IPQ40xx and Marvell routers
mips_24kc, mips_4kecbig endian MIPS: Atheros / Qualcomm ath79
mipsel_24kc, mipsel_74kclittle endian MIPS: MediaTek / Ralink ramips (mt7621, mt76x8, rt305x)

If your router is not listed, use the static binary of the release.

The packages install a procd service for each program and a UCI file to configure it (/etc/config/sctgdesk-hbbs, /etc/config/sctgdesk-hbbr):

uci set sctgdesk-hbbs.main.args='-r relay.example.com -k <your-key>'
uci commit sctgdesk-hbbs
/etc/init.d/sctgdesk-hbbs restart
logread -e hbbs           # the log goes to the system log (the 1.1.16.8 packages show it under the name `sh`)

Things to know about a router:

  • Storage. The MIPS builds are made for size and without the S3 download links (see A smaller binary): hbbs is about 12.6 MB (a 5.6 MB package) and hbbr 2.8 MB (1.2 MB). The other architectures are not: hbbs is about 33 MB there. The flash of a router compresses programs about two to one, so hbbs needs a little more than 6 MB of free flash on a MIPS router, plus room for its database: on a router with 5 to 7 MB free it does not fit, install it on a USB disk or an extroot. hbbr fits any router. The key pair and the database go to datadir (/etc/sctgdesk-server by default, on the flash): put it on the disk too, a database writes a lot.
  • MIPS. The MIPS builds are a tier 3 target of Rust, compiled with zig. The mips_24kc build was tested on two real routers (OpenWrt 25.12.6, ath79, QCA9558 and QCA956X: install from the repository, hbbs answering the API, hbbr as a procd service). The other MIPS architectures are only run under QEMU in the CI: please report what you see.
  • Ports. Open 21115, 21116 (TCP and UDP), 21117, 21118 and 21119, and 21114 for the console, in the firewall of the router.

For the maintainer: signing keys

The repositories are built by .github/workflows/pages.yml (packaging/repos/build-repos.sh) when a release is published as a full release, or by hand (Actions, Pages, “Run workflow”, tick Deploy). It needs two keys, stored as secrets of the repository. Create them once, keep a copy of the private ones somewhere safe: users trust the public part, so losing the private key means asking everybody to import a new one.

# apt and rpm: a GPG key (add a passphrase if you want one, and the secret REPO_GPG_PASSPHRASE)
gpg --quick-generate-key "SCTGDesk packages <packages@example.org>" rsa4096 sign 5y
gpg --armor --export-secret-keys "SCTGDesk packages"        # -> secret REPO_GPG_PRIVATE_KEY

# apk: an RSA key, in PEM
openssl genrsa -out sctgdesk.rsa 4096
cat sctgdesk.rsa                                            # -> secret REPO_APK_PRIVATE_KEY

The public keys are derived from them and published in the repositories. To try the script without the CI: GPG_PRIVATE_KEY=... APK_PRIVATE_KEY=... packaging/repos/build-repos.sh <folder of packages> <output folder> (docker is needed).

Custom builds

How to produce your own binaries: the server (with your changes, your version string, your packages) and the client (your name, servers and key). Read Building from source first.

The server

Build

git clone --recurse-submodules https://github.com/sctg-development/sctgdesk-server
cd sctgdesk-server
export DATABASE_URL=sqlite://$(pwd)/db_v2.sqlite3
cargo build --release --locked --bins

target/release then holds hbbs, hbbr and rustdesk-utils. --locked makes the build use the versions of Cargo.lock. The web console and the API documentation are built with npm and embedded in hbbs; SCTGDESK_SKIP_WEB_BUILD=1 skips that (placeholders instead).

Your own version number

The version printed by hbbs --version is the version of Cargo.toml (and of crates/api-server/Cargo.toml, the web console package.json and Cargo.lock, which a release changes together). For a build of your own, follow Versions and releases: <upstream version>-<yourname>.<n>. Keep the upstream part, so that it is clear what the code is based on.

Static binaries (Linux)

Static musl binaries run on any Linux, which is why the packages use them:

sudo apt install musl-tools pkg-config            # Debian, Ubuntu
rustup target add x86_64-unknown-linux-musl       # or aarch64-unknown-linux-musl
cargo build --release --locked --bins --target x86_64-unknown-linux-musl
ldd target/x86_64-unknown-linux-musl/release/hbbs   # "statically linked" / "not a dynamic executable"

For arm64 build on an arm64 machine (the CI uses an arm64 runner); cross-compiling needs a cross C toolchain for libsodium, which this repository does not set up.

Windows and macOS

The same cargo build --release --locked --bins works on the platform itself. On Windows the release workflow links the C runtime statically (RUSTFLAGS="-C target-feature=+crt-static") so that the Visual C++ redistributable is not needed; in cmd.exe the database variable is set "DATABASE_URL=sqlite://%CD%/db_v2.sqlite3".

deb and rpm packages

packaging/ holds the nfpm configurations (nfpm-hbbs.yaml, nfpm-hbbr.yaml, nfpm-utils.yaml), the systemd units are in systemd/, and the maintainer scripts next to the configurations. After building the static binaries for an architecture:

export VERSION=1.1.16-sctg.3 NFPM_ARCH=amd64 BIN_DIR=target/x86_64-unknown-linux-musl/release   # arm64 for aarch64
mkdir dist
for p in hbbs hbbr utils; do for f in deb rpm; do nfpm package --config packaging/nfpm-$p.yaml --packager $f --target dist/; done; done

nfpm turns 1.1.16-sctg.3 into 1.1.16~sctg.3 (deb) and 1.1.16~sctg.3-1 (rpm), so that a prerelease sorts below the release. Change the maintainer, vendor and name in the three YAML files for a package of your own; keep replaces/conflicts consistent with the names you use.

Releases from GitHub Actions

Publishing a GitHub release runs release.yml, which builds and publishes everything for the tag of the release: the Docker image, the Linux packages, the Windows and macOS server binaries, and (full release) the clients on S3 and Cloudflare Pages. The jobs, the secrets and the pre-release rule are in Versions and releases.

packages.yml and binaries.yml can also be run by hand from the Actions tab. They ask for the tag (sctg-v<version>, which must match Cargo.toml or the run stops) and for publish (off: build and test only; on: upload to the release, created as a pre-release if missing):

WorkflowProduces
Linux packages (deb, rpm) (packages.yml)deb and rpm of hbbs, hbbr and utils for amd64 and arm64, installed in Debian and Fedora containers as a test
Windows and macOS binaries (binaries.yml)zip archives with the three binaries for Windows (amd64, arm64) and macOS (Intel, Apple Silicon)

To use them in a fork, fork the repository (submodules included), change the version and the names and run the two workflows by hand on a branch: they need no secret. The Docker and client jobs of release.yml need the secrets of the list in releases: set your own, or remove those jobs from your copy.

Docker image

The image is built from Dockerfile (and docker-classic/); the multi-architecture workflow publishes to Docker hub with credentials of the maintainer. For your own: docker build -t myrepo/sctgdesk-server . from a checkout. This path is not part of the verified release process.

The client

The client is upstream RustDesk plus an overlay (client/): patches, logos, and a branding script that replaces names, servers and the key in a clean checkout of the upstream tag. You never fork the upstream source.

Settings

branding.py reads its settings from the environment:

VariableMeaning
APP_NAMEapplication name, for example MyDesk
ORG_NAMEorganisation, used for the website and the bundle ids
RENDEZVOUS_SERVERhost of your hbbs, the default server of the client
RS_PUB_KEYthe public key: the content of your id_ed25519.pub
API_SERVERhost[:port] of your API server
API_SERVER_PROTOCOLhttp or https (default https)
COPYRIGHT_HOLDERoptional, added to upstream’s in the copyright
PROJECT_URLoptional, where “set up your own server” leads (default this repository)
MACOS_CODESIGN_IDENTITYoptional, Name (TEAMID)

The rules are strict: a rule that matches nothing fails the build, so that a client never ships with RustDesk’s servers by accident. The script can be run twice.

Desktop and mobile

client/apply.sh                       # clones the upstream tag of client/UPSTREAM_TAG, applies patches and overlay -> client/work
cd client/work
export APP_NAME=MyDesk ORG_NAME=myorg RENDEZVOUS_SERVER=rdv.example.com \
       RS_PUB_KEY="$(cat /path/to/id_ed25519.pub)" API_SERVER=api.example.com
python3 branding.py --check           # what would change, writes nothing
./build-sctg.py --flutter             # brands the tree, then runs upstream's build.py with the remaining arguments

The build needs the upstream toolchain (Flutter, vcpkg, a C++ toolchain, Xcode on macOS, …): follow RustDesk’s own build documentation for the tag in client/UPSTREAM_TAG. client/README.md lists what differs from upstream and what is not verified: the client was prepared against a clean checkout of upstream 1.5.3, and the iOS, Android and Linux clients have no workflow any more. Treat a first build of those as work to do, not as a recipe.

Your icons and logos go in client/overlay/ (copied over the tree). Windows, Android and iOS icons are still upstream’s.

The web client

It is built from an older upstream tag (client/UPSTREAM_TAG_WEB) because upstream removed the sources of its web client; it does not follow upstream any more.

client/apply.sh /tmp/web web          # upstream web client + client/web-overlay, no patches
cd /tmp/web
export APP_NAME=MyDesk RENDEZVOUS_SERVER=rdv.example.com RS_PUB_KEY="$(cat /path/to/id_ed25519.pub)" API_SERVER=api.example.com
python3 branding.py --web

Then build it as client-web.yml does (it uses a Flutter web build and the WebSocket ports of your reverse proxy, 21120 and 21121). The branding makes it talk to your servers, adds the login (including OAuth2 through your API server) and the device identity. After deploying a new build, browsers can keep the old one: its service worker caches the application, and index.js is served with a long cache-control. Serve flutter_service_worker.js and index.js with no-cache, or ask users to reload with the cache emptied.

Checking a custom client

  1. python3 branding.py --check finds every rule.
  2. After the build, search the output for the upstream values (rs-ny.rustdesk.com, upstream’s key): branding fails if one is left in a tree, but check the artifact too.
  3. Connect to your server with it and with an official client; compatibility with official clients is the first rule of this project.
  4. With --logged-in-only: logged-in connects, logged-out is refused with the message of the deployment guide.

Testing

export DATABASE_URL=sqlite://$(pwd)/db_v2.sqlite3
export SCTGDESK_SKIP_WEB_BUILD=1        # no Node.js needed
cargo test --workspace --exclude oauth2 --locked --no-fail-fast -- --skip test_nat64

This is what the CI runs (.github/workflows/ci.yml), together with rustfmt and clippy on crates/*, a cargo build --workspace --locked, the web console build and an informational cargo audit.

What is excluded, and why

TestReason
crates/api-oauth2 unit teststhey do not compile (they call functions that no longer exist); open issue
hbb_common test_nat64needs DNS64 and network access
s3software bucket testcalls the live S3 bucket of s3config.toml; ignored, run with --ignored

End-to-end tests of hbbs

tests/hbbs_e2e.rs starts the real hbbs binary in a temporary directory and talks to it the way the official client does: the key exchange of TCP key exchange is the client’s own code, then a punch hole request, and plain HTTP to the API. They exist because each of these failed in production and no unit test could see it:

TestWhat it prevents
a_malformed_bearer_token_does_not_stop_the_serverone request with Authorization: Bearer x aborted the whole process (the API server runs inside hbbs)
logged_in_only_answers_when_the_api_server_is_unreachablewith --logged-in-only the client waited forever for an answer
logged_in_only_checks_tokens_on_the_configured_api_portthe token check ignored --api-port and called port 21114
key_exchange_works_with_the_official_client_logica change that breaks the official client’s handshake
a_session_survives_a_restartevery restart of hbbs logged all users out (the sessions were only in memory); also checks /api/device-group/accessible and that a logout is final

hbbs listens on fixed ports (21115, 21116, 21118), so these tests run one after the other and need the ports free: stop a local hbbs first.

They are checked to fail without the fixes: with the previous code the first three fail (the server aborts, or no answer within 15 s). The last one is a guard and passes on both.

This does not replace a test with a released official client, which is still done by hand after an upstream sync or a change in rendezvous_server.rs.

Writing tests

  • Prefer small tests next to the code, like key_exchange_tests in src/rendezvous_server.rs.
  • Tests must not need the network or your production database: use a temporary SQLite file.
  • Do not commit generated files (s3config.toml credentials, databases touched by a build).

The client

SCTGDesk client

The client is upstream RustDesk plus a small overlay, not a fork of its source: this directory holds only what is ours (see ADR 0001 and the upstream-compatibility rule: the client stays as close to the official one as possible).

PathContent
UPSTREAM_TAGthe upstream release the overlay is built on (1.5.3)
patches/source changes, as git format-patch files applied on the pristine tag
overlay/files copied over the tree: logos and icons (our visual signature)
branding.pyname, servers, key, URLs: string replacements, strict (a rule that matches nothing fails the build)
build-sctg.pyentry point: brands the tree, then runs upstream’s build.py with the remaining arguments
../.github/workflows/client-{windows,macos,web}.ymlthe client builds: check out this repository, run apply.sh, brand, build, sign and (when publish is on, or from release.yml for a full release) copy to S3 and Cloudflare Pages. The iOS, Android and Linux builds of the former client-build.yaml were removed, see the git history
apply.shclones the tag, applies patches/ and overlay/

Build

client/apply.sh                      # -> client/work (git-ignored)
cd client/work
export APP_NAME=SCTGDesk ORG_NAME=sctg RENDEZVOUS_SERVER=... RS_PUB_KEY=... API_SERVER=...
python3 branding.py --check          # which rules match, writes nothing
./build-sctg.py --flutter            # upstream build.py options follow

The client needs the upstream toolchain (Flutter, vcpkg, …): see upstream’s documentation. branding.py needs only Python 3.

What differs from upstream

  • Update check. Upstream skips it for custom clients and posts to api.rustdesk.com. Patch 0001 posts the same request to our API server (POST /api/software/version/latest). Since 1.5.3 upstream only accepts the GitHub release of upstream in the answer (release_id_from_update_url): the patch takes the version from the release page of our API server instead. Patch 0002 makes the update card open the download of the platform, and patch 0003 turns the in-app update off for our client (it only downloads the GitHub releases of upstream and would fail at every check).
  • TCP only. The former enable-tcp-mode option is gone: use upstream’s disable-udp. Not yet tested against our server (upstream’s tip says the OSS server does not support it).
  • Branding at build time (branding.py), including the default servers and key.
  • The web client is built separately, from an older upstream tag: see below.

Web client and landing page

Upstream removed the sources of its web client (kept in flutter/web/v1, which apply.sh web moves up to flutter/web where its tooling and flutter build web expect them) after 1.4.0, so the web client is built from UPSTREAM_TAG_WEB (1.4.0), not from UPSTREAM_TAG. It does not follow upstream any more.

client/apply.sh /tmp/web web          # upstream 1.4.0 + web-overlay/, no patches
cd /tmp/web && python3 branding.py --web

web-overlay/flutter/web/ holds our own files: client.html, the landing page with the download links of the desktop clients (it asks API_SERVER for them), and its images/. The page has no text: a click on the Windows or the Apple icon opens a fan under it, two thin lines at 120° (--fan-angle) leading to two icons, 32 and 64 bits for Windows, Intel and Apple Silicon for the Mac (a bare chip, and a chip with the apple). The links come from /api/software/client-download-link/{w32,w64,osx,osx-arm64}; an icon without a link stays dimmed. page#windows and page#apple open a fan on load. The build renames it to index.html; the web client itself becomes sctgdesk.html. branding.py --web points the browser at our servers (WebSocket over TLS, ports 21120 and 21121 of a reverse proxy in front of hbbs 21118 and hbbr 21119), replaces the default servers and key of upstream, and fails if one is left. The workflow is .github/workflows/client-web.yml.

Launch from the web console

The console opens the web client with <WEB_CLIENT_URL>?id=<device>#access_token=<token>&user_name=<name>. The web client of 1.2.5 reads none of this, so branding.py --web adds consumeLaunchParams to its globals.js: before the Flutter app starts it stores the token and user as the local options the login dialog would have written, keeps the id in last_remote_id, sets a one-shot launch-connect flag and removes the id and the fragment from the address bar. A one-line addition to the desktop connection_page.dart (also a branding rule) makes the page connect when the flag is set. The native clients never set it. The server only hands WEB_CLIENT_URL to the console when it is a valid http(s) URL.

Known gaps

  • The web client was branded on a clean 1.4.0 checkout, not built yet. The upstream README of its sources says “v1 is not compatible with current Flutter source code”, a line that was already there in 1.2.7.
  • The client was not compiled while preparing this layout (it needs Flutter and vcpkg): only the patch application and the branding rules were checked against a clean 1.5.3 checkout (git am of the patches, branding.py --check, and branding.py with the submodule of hbb_common: every rule applies; the flatpak rule is optional and matches nothing).
  • Icons: only res/ and the macOS icon are overlaid. Windows, Android and iOS icons are upstream’s.
  • The macOS signing and dmg steps of build-sctg.py, the flatpak rule and the client workflow come from the former script and are unverified on 1.5.3.
  • deploy/helm/ (the Helm chart of the former client repository) deploys the server and was written for a TCP test: to be refactored.
  • Like upstream 1.5.3, client-macos.yml builds the Apple Silicon client with Flutter 3.44.9 (Flutter 3.24.5 crashes in the text input, rustdesk issue 16817) and the Intel client with 3.24.5. For arm64 the sources are patched on the fly by upstream’s .github/patches/apply_flutter_3.44_source_patches.sh and bridge.yml generates a second bridge (bridge-artifact-flutter-3.44). Not built yet: the first run of the workflow is the test. The Windows arm64 client, also on Flutter 3.44 upstream, is not built here.

Syncing with upstream

We follow rustdesk/rustdesk-server by release tag, one tag at a time (see ADR 0002).

scripts/sync-upstream.sh 1.1.17   # creates sync/upstream-1.1.17, merges, builds, tests

The script fetches upstream tags into refs/upstream-tags/* (our own tags are never overwritten), merges without committing, and stops on conflicts. It never pushes.

Conflict policy

FileResolution
Cargo.tomlkeep our version and authors; take upstream’s dependency changes. Upstream’s target-specific reqwest replaces any plain one. Keep our [target.'cfg(target_env = "musl")'.dependencies] block (vendored OpenSSL, needed by the static musl builds because hbb_common pulls native-tls).
Cargo.locknever hand-merge: take ours, then cargo build and commit the result
debian/changelog, README*.mdkeep ours
.github/workflows/* deleted on our sidestay deleted (our CI is ci.yml)
libs/hbb_commona submodule on rustdesk/hbb_common; take upstream’s pin, or bump it deliberately (the key exchange needs at least edefa08)
src/main.rs, src/rendezvous_server.rsour code (API server, TCP key exchange) on top of upstream’s; keep the diff small

What is ours in upstream files

  • src/main.rs: API server start-up, API_PORT; check_software_update() is deliberately not called (it queries RustDesk’s version endpoint).
  • src/rendezvous_server.rs: TCP key exchange (versions 0 and 1) and its tests.

After a sync, run the real check against a recent client: hbbs must complete the key exchange and answer an encrypted request.

Versions and releases

Version numbers

Server versions follow <upstream version>-sctg.<n>, for example 1.1.16-sctg.1: the upstream release the code is based on, then our own counter. The former 1.1.99-xx numbers were chosen to sort above upstream and caused collisions with upstream’s tags (issue #13); they are not used any more. (Decision proposed in ADR 0002.) The version is set in Cargo.toml, crates/api-server/Cargo.toml, Cargo.lock, web/console/package.json (and its lock file) and debian/changelog, in one commit.

Tags

  • Our release tags are prefixed sctg-v, for example sctg-v1.1.16-sctg.1.
  • Upstream tags are never fetched into the normal tag namespace. They live in refs/upstream-tags/* (scripts/sync-upstream.sh does this), so they cannot collide with ours.

Releasing

A release is a decision of the maintainer, made by publishing a GitHub release; the pipeline does the rest (next section). Before publishing: the default branch build is green, the key exchange check was run, the version is bumped everywhere (below), and the release notes say which upstream version it is based on.

  1. Bump the version in a pull request and merge it (Cargo.toml, crates/api-server/Cargo.toml, Cargo.lock, web/console/package.json and its lock, debian/changelog).
  2. Optionally run packages.yml and binaries.yml by hand without publish: they build and test, and publish nothing.
  3. Create the release sctg-v<version> on the default branch. Tick pre-release to publish the server side only.
  4. Check the assets, Docker Hub, and (full release) S3 and Cloudflare Pages.

The release pipeline

Publishing a release runs .github/workflows/release.yml, which calls the other workflows with the tag of the release (nothing to type) :

JobWorkflowResult
Docker image and Linux binariesmultiarch-docker-hub.ymlimage sctg/sctgdesk-server (amd64, arm64) tagged with the release tag, latest for a full release only; static Linux zips on the release
deb and rpmpackages.ymlpackages (amd64, arm64) and SHA-256 sums on the release
Windows and macOS binariesbinaries.ymlserver zips (Windows amd64 and arm64, macOS Intel and Apple Silicon) and SHA-256 sums on the release
Windows client, macOS clientclient-windows.yml, client-macos.ymlinstallers copied to S3: they become the downloads of the landing page and of the update check
Web clientclient-web.ymlarchives on S3, and the site on Cloudflare Pages (replaces the live page)

multiarch-docker-hub.yml also runs by hand (with the Docker Hub secrets): tick Extract binaries as test release to do a dry run of the release, which creates sctg-v<version> from Cargo.toml as a pre-release when it does not exist yet and uploads the static Linux zips to it. It needs no tag input, unlike packages.yml and binaries.yml.

A pre-release runs the server jobs and builds the clients, but publishes none of them: the clients on S3 and the web client change what users get, and latest moves the Docker tag. The tag guard of packages.yml and binaries.yml stops them if the tag does not match Cargo.toml. A failed job is re-run from the run’s page in the Actions tab (Re-run failed jobs): the called workflows read the release event, which a new manual run would not have. Drafts, pushes and tags alone start nothing. The clients are versioned by the upstream tag they are built on (client/UPSTREAM_TAG), not by the server version.

Secrets used (repository settings): DOCKER_USERNAME, DOCKER_PASSWORD; APP_NAME, APP_NAME_LOW, ORG_NAME, RS_PUB_KEY, RENDEZVOUS_SERVER, API_SERVER (branding); AWS_S3_ENDPOINT, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_S3_BUCKET; CLOUDFLARE_API_TOKEN, CLOUDFLARE_ACCOUNT_ID, CLOUDFLARE_PROJECT_NAME; MACOS_P12_BASE64, MACOS_P12_PASSWORD, MACOS_CODESIGN_IDENTITY, MACOS_NOTARIZE_JSON (and MACOS2_P12_BASE64, MACOS3_P12_BASE64 for the Windows signing certificates).

The former workflows (main.yml, macos-intel-build.yml, windows.yml, ubuntu.yml, client-build.yaml, client-release.yml) were removed: they are in the git history. The iOS, Android and Linux client builds were part of client-build.yaml and are not built any more.

Linux packages

The Linux packages (deb, rpm) workflow (.github/workflows/packages.yml, run by the release pipeline or by hand) builds static musl binaries of hbbs, hbbr and rustdesk-utils for amd64 and arm64 and packs them with nfpm (packaging/): sctgdesk-server-hbbs, sctgdesk-server-hbbr and sctgdesk-server-utils, as deb and rpm. It checks that the binaries are static and installs the packages in a Debian and a Fedora container.

  • The tag input (sctg-v<version>) must match the version of Cargo.toml, or the workflow stops.
  • Without publish nothing is published. With it, the packages and their SHA-256 sums go to the release of the tag, created as a pre-release when it does not exist.
  • The packages replace the former rustdesk-server-* ones. A first install on an empty data directory starts the services with a random key pair; one that finds data (a migration) starts nothing. Options are in /etc/default/sctgdesk-hbbs and -hbbr. Data is copied to /var/backups/sctgdesk-server/ before each install. An upgrade restarts the services that run.
  • The units run as root, like the former packages; the data is in /var/lib/rustdesk-server, the logs in /var/log/rustdesk-server.

Windows and macOS binaries

The Windows and macOS binaries workflow (.github/workflows/binaries.yml, run by the release pipeline or by hand, same tag and publish inputs) builds hbbs, hbbr and rustdesk-utils on GitHub runners for Windows amd64 and arm64 (windows-latest, windows-11-arm, C runtime linked statically) and macOS Intel and Apple Silicon (macos-15-intel, macos-15), checks that they run and report the version of the tag, and zips them as sctgdesk-server-<version>-<windows|macos>-<x86_64|aarch64>.zip. With publish the archives and SHA256SUMS-windows-macos go to the release of the tag, created as a pre-release if missing. The binaries are not signed (Windows) nor signed and notarized (macOS).

The release pipeline above runs both workflows with publish on.

Contributing

Contributing to SCTGDesk

Thanks for helping. This page is the short version; the developer manual (sources in docs/, built with mdBook) has the details.

Before you start

  • Compatibility first. The client and server must keep working with official RustDesk. Keep changes small and isolated; files that come from upstream (src/, libs/hbb_common) are changed as little as possible, because every change is paid for again at each upstream sync.
  • Not sure where a change belongs? Open an issue first. Changes to upstream-derived files, the wire protocol or the key exchange are worth discussing before you write them.
  • Read the code of conduct.

Build and test

export DATABASE_URL=sqlite://$(pwd)/db_v2.sqlite3
export SCTGDESK_SKIP_WEB_BUILD=1              # skips Node.js
git submodule update --init
cargo build --workspace --locked
cargo test --workspace --exclude oauth2 --locked -- --skip test_nat64

See Building from source and Testing. The CI also checks rustfmt and clippy on crates/*: run cargo fmt --manifest-path crates/<name>/Cargo.toml before you push.

Commits and pull requests

  • One logical change per commit, in English, following Conventional Commits: fix(rendezvous): ..., feat(api-server): ..., docs: ..., build:, ci:, test:, chore:.
  • Sign your commits off (git commit -s): by adding Signed-off-by, you certify the Developer Certificate of Origin. There is no CLA.
  • Branch from the default branch (tcpserver-master-build for now), open the pull request there, and describe what you tested and what you could not test.
  • Do not mix formatting changes with other changes, and do not reformat upstream-derived files.
  • Tests: add one for a bug you fix when it can be tested without the network. Do not commit databases, generated configuration or credentials.

License and names

The project is AGPL-3.0; your contribution is under the same license. “RustDesk” is a third-party name: use it to describe compatibility or origin only, not as a product name (ADR 0004).

Security

Do not report vulnerabilities in a public issue. See SECURITY.md.

Where to start

Issues labelled good first issue are meant for newcomers. The roadmap lists what is open.

Roadmap

Open work, roughly in priority order. Nothing here is a promise; each item is a candidate for an issue.

Make the consolidation trustworthy

  • Run the CI on GitHub. ci.yml and the release pipeline (release.yml) were written and checked locally only; the clients, packages and binaries workflows have run on GitHub.
  • Fix crates/api-oauth2 tests, which do not compile, and re-enable them in CI.
  • Triage cargo audit (dozens of advisories, informational for now) and add cargo-deny for licenses.
  • Adapt or remove what was inherited and never checked: docker/, docker-classic/, kubernetes/, update-api-server.sh, the legacy macOS and Windows build workflows (now manual).
  • Docker image (Dockerfile, multiarch-docker-hub.yml, on the shared multi-arch action; 32-bit ARM and the .deb packages are dropped): the build of amd64 and arm64 and the manifest merge succeeded once on CI (2026-10-28). Not yet checked: that the image runs, the Linux zips and their attestation (they only run on a release).
  • Translated READMEs (README-*.md) are stale.

Protocol

  • Put the key-exchange check in CI: a test that runs a client’s key_exchange() against hbbs and sends one encrypted request (ADR 0003).
  • Test a released official client against the server, including WebSocket and hbbr.
  • A test for --require-kx-v1.
  • Decide whether --require-kx-v1 becomes the default once old clients are gone.

Client

  • Compile the client from client/ on CI, then fix what the first runs show.
  • Test upstream’s disable-udp against our server (upstream’s tip says the OSS server does not support it).
  • Icons for Windows, Android and iOS (only res/ and the macOS icon are overlaid).
  • Refactor deploy/helm (written for a TCP test, deploys the server).
  • Web client: absent from upstream 1.5.0; decide whether to bring one back.

Compliance

  • AGPL section 13: a source link in the web console footer and in --version, and exact sources per release.
  • Replace the credentials-looking values in s3config.toml with examples (the values in the repository are fake).
  • Non-affiliation notice in the README (ADR 0004).

Releases

  • First release under the <upstream>-sctg.<n> scheme, with sctg-v tags (Versions and releases).
  • Publish this manual.

Web console

The Vue console (web/console) is on old dependencies and built with npm install --force: a modernisation would be a good, well-bounded contribution.

History

Origin

SCTGDesk started as a RustDesk server fork (sctgdesk-server) with a separate API server (sctgdesk-api-server) and a client fork (sctgdesk). They were consolidated into this repository, keeping the commit history of the API server (imported under crates/ and web/).

Tags of the former API server repository

The former sctgdesk-api-server repository had three tags. The monorepo has tags of the same names for the server, so these were not copied: they stay in the archived repository, and the commits they pointed to are in this repository’s history.

Former tagCommit (in this repository)DateWhat it is
1.1.99-382c33baf2024-06-15first numbered release (“add openapi.json to release”)
1.1.99-39ef3d9262024-08-27generic OAuth2 provider
nightlya4eca2e2024-09-07moving tag (not meaningful after that date)

git show <commit> works for all of them. The hashes differ from the ones in the former repository because the history was rewritten to move the files under crates/ and web/.

Architecture Decision Records

Decisions that shape the consolidation of SCTGDesk (server, API server, client) into one repository. Evidence comes from the Phase 0 audit; every upstream claim was checked against the real repositories on 2026-10-27, and what could not be verified is stated as such.

ADRTopicStatusRecommendation
0001Where the client livesAcceptedclient/ overlay (patches + assets + CI) in the monorepo, not a full fork copy
0002Upstream synchronisation, hbb_commonAcceptedTag-by-tag merges into a mirror-based flow; hbb_common as a submodule pointing at a thin fork
0003Fate of the TCP codeAcceptedKeep and modernise the key exchange (v1); remove the duplicated client switch and key logging
0004AGPL compliance and the “RustDesk” markAcceptedStay AGPL-3.0, add source offer, nominative use of the mark only
0005Cargo workspace layoutAcceptedUpstream layout untouched at the root; our code in crates/ and web/

Status values: Proposed, Accepted, Superseded.

ADR 0001: Where the client lives

Status: Accepted (maintainer decision, 2026-10-27: overlay)

Context

Measured on 2026-10-27:

  • sctgdesk (client fork) diverges from rustdesk/rustdesk at 94addb1 (2024-07-04). It is 2,021 commits behind, i.e. upstream moves roughly 2.7 commits a day.
  • Our own change set is small: 191 non-merge commits but only 48 files. Rust changes are about 48 lines in 4 files under src/ (software-update check against our API server, a TCP switch). The rest is branding assets (res/), a Helm chart, a few flutter/web tweaks and about 120 CI/signing commits in .github/workflows.
  • The client is a Flutter + Rust build with signing, notarisation and several platforms. Whether the existing CI still works after two years is not verified.
  • sctgdesk has 12 stars and no push since 2024-07-04; the server and API server have 362 and 147.

Options

  1. Full client in the monorepo (subdirectory with its full history).
    • Pros: one place, one issue tracker, atomic cross-component changes.
    • Cons: the repository grows by the whole RustDesk client tree; every upstream sync touches thousands of files in the same repository that carries the server; git blame and bisect get noisy; conflicts in a 127k-star project’s hot files. Highest maintenance cost of the three options.
  2. Overlay: patches and assets applied onto an upstream tag.
    • Pros: our delta stays reviewable (about 48 files); updating the client means re-applying patches on a newer tag, and conflicts show up in a handful of files; upstream history is never copied.
    • Cons: patch maintenance discipline is required; a failing patch blocks the client build until fixed; contributors cannot just open the client in an IDE without running the apply step.
  3. Separate repository (status quo, kept alive).
    • Pros: no monorepo growth; independent release cadence.
    • Cons: the situation that already failed once: the client was left at 2024-07 while the server moved; cross-component changes need two PRs.

Recommendation

Option 2, hosted inside the monorepo under client/:

client/
  patches/        # git format-patch series, one patch per concern
  overlay/        # files copied over the upstream tree (res/, helm/, flutter/web tweaks)
  ci/             # client build/sign workflows (inputs: upstream tag)
  UPSTREAM_TAG    # the upstream tag the series is known to apply to
  apply.sh        # clones rustdesk/rustdesk at UPSTREAM_TAG, applies patches + overlay

This keeps the monorepo benefit you asked for (one repo, one tracker, one release story) while paying only for the 48-file delta instead of a copy of the upstream client. Candidly: a full-copy monorepo is the option I would expect to burn out a small team, because the client moves faster than the server and the sync work would land on the same few people.

The decision to build the client at all (signing certificates, store accounts) is separate and depends on whether you want to ship client binaries or only document the patches. I recommend shipping server binaries first and treating client binaries as a later milestone.

Consequences

  • Phase 3 imports sctgdesk-api-server with history; the client is not imported with history. The sctgdesk repository is archived with a pointer to client/.
  • The 191 client commits stay reachable in the archived repository; the patch series records authorship.
  • A CI job checks that apply.sh still applies on the latest upstream release tag, so drift is detected early.

ADR 0002: Upstream synchronisation and hbb_common

Status: Accepted (maintainer decision, 2026-10-27: recommendation adopted)

Context

  • The server fork is 65 commits behind rustdesk/rustdesk-server (base b37033d, 2024-09-28, between tags 1.1.11-1 and 1.1.12). Upstream tagged 1.1.12 to 1.1.16 since.
  • Our default branch is tcpserver-master-build; the old master is stale. Our tag 1.1.10-3 collides with an upstream tag of the same name at a different commit.
  • hbb_common: upstream replaced the vendored copy with a git submodule on 2025-01-20 (7a509f6) and pins 69cea8d (2026-07-26). Our server still carries a vendored, modified copy last synchronised in 2024-07, about 4,590 changed lines away from that pin. How much of that is our modification and how much is plain lag is not yet established.
  • The current upstream client uses key-exchange version 1 (KxParams, KX_PARAMS_DOMAIN). That landed in hbb_common on 2026-09-22, after the pin used by upstream’s server (see ADR 0003). The server therefore needs a newer hbb_common than upstream’s own server pins.

Options for the sync flow

  1. Merge upstream/master into our branch periodically (what we did before).
  2. Rebase our commits onto upstream master.
  3. Tag-by-tag merges from a read-only mirror branch.

Rebasing 176 commits that include many “wip” ones rewrites public history and was ruled out by your rules (no force-push). Merging master commit-by-commit conflates unreleased upstream work with releases.

Options for hbb_common

  1. Keep vendoring. Every upstream bump is a manual three-way merge; the copies already diverged.
  2. Submodule on upstream rustdesk/hbb_common, with our changes as patches.
  3. Submodule on a thin fork sctg-development/hbb_common whose branches are upstream (mirror) and sctg (upstream + our few commits).

Recommendation

Flow

  • Add remote upstream; keep a local mirror branch upstream/server that only fast-forwards and receives no commits of ours.
  • Merge by release tag into a sync branch (sync/1.1.12, sync/1.1.13, … sync/1.1.16), one at a time: build, test, then merge into the integration branch. Five small steps instead of one 65-commit conflict.
  • Upstream tags are fetched into refs/upstream-tags/* so they never collide with ours; our release tags use a different prefix (see below).
  • A scripts/sync-upstream.sh <tag> does: fetch, create sync branch, merge, run build/test, print the conflict list. Phase 4 delivers it with its documentation.

hbb_common: option 3, with the explicit goal of shrinking the fork to zero commits over time. The server pins a hbb_common commit at least as new as the client’s (edefa08 at the time of writing) because of the key-exchange version. If an audit of our vendored copy shows no change worth keeping, we use upstream directly (option 2) and drop the fork.

Versioning: our 1.1.99-xx numbers were chosen to sort above upstream and cause the tag clash and issue #13. I recommend <upstream-version>-sctg.<n> (for example 1.1.16-sctg.1) with tags prefixed sctg-v. This is your call (Phase 1 decision), because it changes package versions and the update check in the client.

Consequences

  • One-time cost: isolating our changes in hbb_common (three-way diff from the 2024 base) before the submodule switch.
  • Cargo.lock will conflict at every sync. Policy: never hand-merge it; take upstream’s version, re-apply our dependency changes, run cargo update -p <crate> as needed.
  • Because upstream CI files (.github/workflows/build.yaml, main.yml) overlap with ours, our workflows get distinct names to avoid permanent conflicts.

Update (2026-10-27, Phase 4)

The audit’s question “is anything of ours worth keeping in hbb_common?” has its answer: only API_PORT, which moved to src/main.rs. The server therefore uses rustdesk/hbb_common directly as a submodule (option 2), not a fork (option 3): there is no sctg-development/hbb_common. It is pinned to the commit that carries the key exchange version 1 (edefa08), newer than the one upstream’s own server pins. If we ever need a change in hbb_common, a fork is created at that point.

ADR 0003: Fate of the TCP code

Status: Accepted (maintainer decision, 2026-10-27: recommendation adopted)

Context

The initial assumption was that the TCP work (2024-04) was a failed attempt and dead code. The audit and a live test show otherwise.

Verified facts (2026-10-27):

  • Upstream hbbs already speaks TCP and WebSocket natively (Sink::TcpStream, Sink::Ws, WebSocket on port+2, reverse-proxy X-Real-IP handling).
  • Upstream hbbs has no KeyExchange handler in src/. Our fork implements it (key_exchange_phase1 and the phase-2 handler in src/rendezvous_server.rs).
  • The upstream client has secure_tcp, which tolerates a server without the exchange, and secure_tcp_required, which refuses such a server so that nothing is sent in clear.
  • Live test: our hbbs against the upstream client’s key_exchange() (copied verbatim, with the client’s exact hbb_common): the exchange succeeds at version 0, an encrypted TestNatRequest round-trips, and a wrong public key is rejected. Not tested: the full Flutter client, and upstream hbbs.
  • The client’s current scheme is version 1 (signed KxParams, transcript binding). Our server only speaks version 0 and offers no signed parameters.
  • Client side, our RendezvousMediator::is_udp_disabled() reads enable-tcp-mode == "N". Upstream now has its own is_udp_disabled() reading disable-udp == "Y". The two switches are different options with different meanings.
  • Both our client (src/common.rs) and our server (rendezvous_server.rs:570) log the session symmetric key at debug level.
  • Issue #16 shows users believe our “TCP mode” lets them cross an HTTPS proxy without UDP; that is a Pro-server feature.

Options

  1. Delete all TCP code. Breaks the secure_tcp_required path against our server; removes the only OSS server-side key exchange we know of.
  2. Isolate behind a Cargo feature flag. Keeps the code but ships it off by default; a feature that protocol clients require should not be optional.
  3. Keep, modernise, and trim.

Recommendation

Option 3:

  • Keep the server key exchange. Make it default-on.
  • Upgrade to version 1 (signed KxParams, transcript binding), answering version-0 clients as the legacy scheme. Depends on the hbb_common bump from ADR 0002 and must be re-tested with the same harness against a recent client.
  • Remove the symmetric-key debug logs in client and server. This is independent of everything else and can ship first.
  • Remove our client-side is_udp_disabled and enable-tcp-mode in favour of upstream’s disable-udp.
  • Add a regression test that runs the key-exchange round-trip in CI (the harness from the audit is the seed).
  • Document what “TCP mode” does and does not do, to close issue #16.

Consequences

  • No behaviour is removed from servers that exist today.
  • The server pins a newer hbb_common than upstream’s server does; this is the cost of staying compatible with current clients.
  • Open: whether upstream plans its own server-side exchange. If it lands, our implementation becomes a candidate for removal; the CI round-trip test tells us when.

ADR 0004: License, AGPL compliance and the “RustDesk” mark

Status: Accepted (maintainer decision, 2026-10-27: descriptive use only; no approach to the mark owner for now)

Context

Verified from the repositories:

  • All five repositories (our three, rustdesk, rustdesk-server) are AGPL-3.0. Our LICENCE / LICENSE.md files are not recognised by GitHub, which therefore reports no licence on our repositories.
  • Source files we wrote carry an AGPL header (“SCTGDesk”). debian/copyright and the README mention RustDesk (README: 21 mentions).
  • hbbs --help prints “Purslane Ltd. info@rustdesk.com” next to ours, and Cargo.toml lists a RustDesk address as author. Users of our binaries could end up sending fork bugs to upstream.
  • res/design.svg and res/logo-header.svg in the client still contain the “RUSTDESK” wordmark.
  • Not verified: RustDesk’s trademark policy. No such file exists in rustdesk, rustdesk-server or hbb_common; the rustdesk.com footer links only Terms, Privacy and cookie settings; the Terms page was not read. I make no claim about what the mark owner permits.

Decisions proposed

Licence

  • The monorepo stays AGPL-3.0-only (or “or later”, matching existing headers; to be confirmed against upstream’s LICENCE). Merging our AGPL API server into an AGPL server needs no relicensing.
  • Rename to LICENSE so GitHub and tooling detect it. Keep upstream’s copyright notices untouched.
  • AGPL section 13: a modified version offered over a network must offer its source to remote users. Add a source link in the web console footer, the /api version endpoint and --version, and publish exact sources per release tag.
  • Add cargo-deny (licences + advisories) to CI to track third-party licences, plus a THIRD_PARTY_LICENSES generation step for the console (gulp licenses already exists).
  • Contributions via DCO sign-off (Signed-off-by), not a CLA, so that nobody has to trust a single copyright holder.

Trademark (precautionary, pending the owner’s actual policy)

  • Treat “RustDesk” as a third-party mark. Use it only descriptively (“a fork of RustDesk”, “compatible with the RustDesk client”), never as our product name, and add a non-affiliation notice to the README.
  • Remove the RustDesk wordmark from any asset we ship; keep our own name and logo.
  • Replace upstream contact addresses in --help, Cargo.toml and packaging metadata with ours.
  • Binary names hbbs, hbbr and protocol identifiers stay: they are interface compatibility, not branding.
  • If you want certainty, ask the owner in writing; this should be your decision before the public announcement.

Consequences

  • A small, mostly mechanical clean-up PR (Phase 2/3) for licence file, headers, contact addresses and assets.
  • A legal review by someone qualified remains advisable; this ADR is an engineering position, not legal advice.

Decision record

The maintainer chose descriptive use only and no written request to the mark owner. The owner’s policy remains unread, so this carries residual risk; revisit before the public announcement (Phase 6).

ADR 0005: Cargo workspace and repository layout

Status: Accepted (maintainer decision, 2026-10-27: recommendation adopted)

Context

  • Upstream’s root Cargo.toml is the hbbs package with [workspace] members = ["libs/hbb_common"] and exclude = ["ui"]. Any change we make to those files conflicts at every sync.
  • Today the server depends on the API server with git = ".../sctgdesk-api-server.git", branch = "main". Consequence found in the audit: cargo build --locked fails because the lock no longer matches, and two builds on different days yield different binaries.
  • Build problems in the API server: libs/state/build.rs opens a SQLite database and inserts a test row at compile time, and requires DATABASE_URL as an absolute path (known only to CI); the root build.rs runs npm run build and rewrites the tracked webconsole/package.json.
  • Neither project runs meaningful tests today (0 executed by cargo test).

Options

  1. Move everything to crates/* and make the root a virtual workspace. Cleanest, but moves upstream’s files: every sync becomes a rename-conflict exercise.
  2. Keep upstream’s layout at the root, add our code as separate workspace members under crates/ and web/.
  3. Keep the git dependency. Rejected: reproducibility problem above.

Recommendation

Option 2:

Cargo.toml              # upstream root package (hbbs); only [workspace] and one dependency line differ
src/ ui/ libs/hbb_common  # upstream layout (hbb_common becomes a submodule, ADR 0002)
crates/
  api-server/           # was sctgdesk-api-server (history preserved)
  api-oauth2/ api-s3software/ api-state/ api-utils/   # its former libs/*
web/console/            # Vue console (was webconsole/), own package.json, own build
client/                 # overlay, ADR 0001
docs/                   # mdBook + ADRs
scripts/                # sync-upstream.sh, dev helpers
  • The server depends on crates/api-server by path: reproducible, --locked works.
  • Fix the build before the import is considered done: replace the compile-time SQLite access with sqlx offline mode (.sqlx/ query metadata) and move the test row into a test fixture; run the console build from a xtask/Makefile target (cargo xtask console) with the built assets either committed or embedded through an explicit feature, and never mutate tracked files.
  • [workspace] members = [".", "libs/hbb_common", "crates/*"]; the one-line Cargo.toml edit is the entire diff to an upstream file.
  • CI minimum (Phase 3): cargo fmt --check, cargo clippy, cargo build --locked, cargo test --workspace, cargo audit, cargo deny, console build, and the key-exchange round-trip test from ADR 0003.

Consequences

  • The import in Phase 3 renames paths inside the API server history (using git filter-repo --to-subdirectory-filter or git subtree; the choice is made and justified in Phase 3 after looking at the noisy “wip” history).
  • Known blocker: audit R1 (33-41 RUSTSEC advisories). The workspace lets us run one cargo update and one audit for everything; advisories that need real work (for example sodiumoxide, unmaintained) are tracked as separate issues.