omnet
aien-dev/omnet
Brought by drakestapleton
| 1 | # Install omnet Tailnet Lock on your Headscale server |
| 2 | |
| 3 | omnet adds the server half of Tailnet Lock to [Headscale](https://github.com/juanfont/headscale). |
| 4 | With Tailnet Lock, your own devices decide which new devices may join, not the server. A stolen |
| 5 | join key or a taken-over server can no longer quietly add a device that everyone else trusts. |
| 6 | |
| 7 | The Tailscale app on your devices already has the device half. It switches the Tailnet Lock |
| 8 | controls on only when the server says it supports them. Plain Headscale does not, so the app |
| 9 | greys them out. With omnet behind Headscale, the `tailscale lock` command works against your own |
| 10 | server (tested with the v1.102 command-line client on Linux; the graphical apps were not tested). Nothing new is installed on the devices. |
| 11 | |
| 12 | This page gets you from nothing to a working lock. [`runbook.md`](runbook.md) is the careful, |
| 13 | step-by-step version for turning it on over a tailnet you already use, and it is rehearsed by a |
| 14 | test. The full engineering detail is in [`integration/headscale/README.md`](../integration/headscale/README.md). |
| 15 | |
| 16 | ## What you need |
| 17 | |
| 18 | - A Linux **ARM64** machine to build on (the Omega compiler makes AArch64 Linux programs). |
| 19 | - Go 1.26.5 or newer that may fetch toolchains (`GOTOOLCHAIN=auto`); Headscale builds with Go 1.27.3. |
| 20 | - `git`, a POSIX shell, Python 3, and network access to the Go module proxy and to Headscale's |
| 21 | source for the first build. |
| 22 | - Headscale **v0.29.6** (the patch is made for that exact release) and Tailscale clients at v1.102.x |
| 23 | (the tested version; test others before you rely on them). |
| 24 | |
| 25 | ## Build |
| 26 | |
| 27 | From a checkout of this repository: |
| 28 | |
| 29 | ```sh |
| 30 | # The patched Headscale. Output: build/headscale |
| 31 | GO=/path/to/go sh integration/headscale/build.sh |
| 32 | |
| 33 | # The Omega daemon that holds the lock's records. Output: build/tkad |
| 34 | # (The first run builds the pinned Omega compiler from its seed, so it is slow once.) |
| 35 | sh tools/build-tkad.sh |
| 36 | |
| 37 | # Optional checks before you install anything: |
| 38 | GO=/path/to/go sh integration/headscale/leak-check.sh # the DERP memory fix (omnet#8) is in |
| 39 | sh tools/test.sh # every Omega unit suite |
| 40 | ``` |
| 41 | |
| 42 | ## Try it on a throwaway tailnet first |
| 43 | |
| 44 | Two tests run a complete private tailnet inside a fresh, empty network namespace with the stock |
| 45 | Tailscale client. They never touch your real tailnet, its sockets or your network interfaces. |
| 46 | |
| 47 | ```sh |
| 48 | GO=/path/to/go sh integration/e2e/build-clients.sh |
| 49 | HEADSCALE_STOCK=1 HEADSCALE_OUTPUT=build/headscale-stock GO=/path/to/go sh integration/headscale/build.sh |
| 50 | |
| 51 | sh integration/e2e/run.sh --sudo-netns # the lock's full lifecycle |
| 52 | sh integration/e2e/run.sh --sudo-netns --scenario runbook \ |
| 53 | --stock-headscale "$PWD/build/headscale-stock" # runbook.md, step by step |
| 54 | ``` |
| 55 | |
| 56 | Leave out `--sudo-netns` where your system lets ordinary users create user namespaces. |
| 57 | |
| 58 | ## Run |
| 59 | |
| 60 | tkad and Headscale run as the **same user**, in the **same network namespace**, tkad first. |
| 61 | |
| 62 | ```sh |
| 63 | build/tkad /var/lib/headscale/omnet --init # first start only: creates the state directory, then keeps running |
| 64 | build/tkad /var/lib/headscale/omnet # every later start (leave out --init) |
| 65 | |
| 66 | OMNET_TKAD_SOCKET=/var/lib/headscale/omnet/tkad.sock \ |
| 67 | OMNET_TKAD_ADMIN_USER_ID=<numeric Headscale user ID of the owner> \ |
| 68 | build/headscale --config /etc/headscale/config.yaml serve |
| 69 | ``` |
| 70 | |
| 71 | The owner is the Headscale user whose devices may start and switch off the lock. Pick the real |
| 72 | number from `headscale users list`; there is no default. Setting only one of the two variables is |
| 73 | an error. |
| 74 | |
| 75 | **Back up the Headscale database before the first start.** The first start adds two columns and a |
| 76 | table. Stock Headscale then refuses that database until, on SQLite only, |
| 77 | [`integration/headscale/downgrade.sql`](../integration/headscale/downgrade.sql) has removed them |
| 78 | again (see the rollback in the runbook). There is no tested way back for PostgreSQL. |
| 79 | |
| 80 | ## Turn the lock on |
| 81 | |
| 82 | Devices that joined before omnet have no lock key on record. They keep working, but the lock will |
| 83 | not start (the server answers the owner's `init` with `409`) until each of them has signed in once more, from its console or |
| 84 | a local-network session (see [`runbook.md`](runbook.md) step 3): |
| 85 | |
| 86 | ```sh |
| 87 | headscale preauthkeys create --user <ID of the device's own user> --expiration 1h # on the server |
| 88 | tailscale up --force-reauth --auth-key=file:<key file> --login-server=<URL> <its current settings> # on the device |
| 89 | ``` |
| 90 | |
| 91 | Then, on one of the devices that will approve new devices: |
| 92 | |
| 93 | ```sh |
| 94 | tailscale lock # shows this device's key: tlpub:... |
| 95 | tailscale lock disablement-kdf <secret-hex> # turns each escape secret you made into its value |
| 96 | tailscale lock init --confirm --gen-disablements=0 disablement:<value1> disablement:<value2> tlpub:<A> tlpub:<B> |
| 97 | ``` |
| 98 | |
| 99 | Type secrets and join keys only in a shell whose history is off (`unset HISTFILE`), and close it |
| 100 | afterwards. Make the escape secrets yourself beforehand (32 random bytes each, for example |
| 101 | `head -c 32 /dev/urandom | od -An -v -tx1 | tr -d ' \n'`) and keep them somewhere safe that is not |
| 102 | the server. Give `init` only their `disablement:` values, never the secrets. From then on a new |
| 103 | device stays invisible to the others until an approving device runs `tailscale lock sign`. |
| 104 | `tailscale lock disable disablement-secret:<secret>` from an owner device switches the lock off |
| 105 | everywhere. |
| 106 | |
| 107 | ## Before you rely on it |
| 108 | |
| 109 | - Tested: the protocol and stock-client behaviour in an isolated tailnet (the lifecycle test and the |
| 110 | runbook rehearsal, Linux command-line client v1.102.0), the Omega unit suites, and the DERP memory |
| 111 | fix. Not tested: packet |
| 112 | delivery, power loss, months of running, or a production security audit. |
| 113 | - tkad and Headscale share one user account. Whoever controls the server can read the daemon's |
| 114 | state. Keep the approving keys on your devices and the escape secrets off the server, and keep a way |
| 115 | into the server that does not depend on the tailnet (console, or SSH on the local network). |
| 116 | - The current daemon is sized for one tailnet of up to 64 devices and 128 lock changes. A change that |
| 117 | would not fit is refused, never half-written. |
| 118 | - The patch is pinned to Headscale v0.29.6. Re-qualify it before you upgrade Headscale. |