Skip to content

Join a self-hosted Tailscale coordination server - #13533

Open
z23 wants to merge 4 commits into
omacom:quattrofrom
z23:fix/tailscale-login-server
Open

z23 wants to merge 4 commits into
omacom:quattrofrom
z23:fix/tailscale-login-server

Conversation

@z23

@z23 z23 commented Sep 28, 2026 •

Copy link
Copy Markdown

The Tailscale installer can join a self-hosted coordination server through OMARCHY_TAILSCALE_LOGIN_SERVER, use a pre-auth key through OMARCHY_TAILSCALE_AUTH_KEY, and install an optional admin web app through OMARCHY_TAILSCALE_ADMIN_URL. Hosted Tailscale remains the default.

Each join includes the invoking user's operator setting, obtained with id -un, so a retry after an earlier installer run does not fail because sudo's user differs. Package installation, daemon startup, and join failures stop setup before the remaining services, plugin, and web app are configured.

Auth keys use Tailscale's --auth-key=file:/dev/stdin support and a pipe. The key is removed from the child-process environment and kept out of sudo/Tailscale command arguments. URLs without a hostname or with an invalid port, and keys containing whitespace are rejected before installation. After a successful self-hosted join without an admin URL, the installer removes the exact hosted-console launcher it verified, while preserving custom launchers and shared icons. The networking manual documents all three variables, menu environment requirements, and an explicit logout before switching an already connected node to another coordination server.

Validation: 17 installer scenarios pass, including hosted/self-hosted joins, custom admin URLs, validation before side effects, key handling, failure propagation, URL parsing, and launcher transitions. The Tailscale model, installed-service, bin-style, syntax, diff, and CLI metadata checks pass. A real Tailscale 1.102.3 CLI against a separate userspace daemon reproduces the old retry refusal/key echo and confirms that explicit operator plus stdin key passes that guard and changes the control URL. The test servers are unreachable; no live join was performed. The full CLI suite stops at a pre-existing VS Code symlink assertion.

Upstream copy of the feature requested in omacom/omarchy-mac#484.

OMARCHY_TAILSCALE_LOGIN_SERVER is passed to tailscale up, and the hosted admin web app is skipped unless OMARCHY_TAILSCALE_ADMIN_URL is set. An optional auth key joins without a browser login. Unset variables keep the hosted install.
@llstrk

llstrk commented Sep 29, 2026

Copy link
Copy Markdown

Automated AI review

Community review: Independent automated community review, unaffiliated with the Omarchy team, intended to help prepare PRs for their review.

Outcome: A retry with the new variables after an earlier install fails at tailscale up, yet the installer exits 0.

A retry is refused, echoes the key and reports success

After a run reaches sudo tailscale set --operator="$USER", a later sudo tailscale up like the installer's fails ("requires mentioning all non-default flags") because sudo resets USER; with a key set, the error prints --auth-key=<key>. The script ignores the failure and exits 0. Impact: the likely recovery from the reported hang does not join the server: an interrupted menu install still reaches the operator step (simulated), and the menu row is disabled once installed, so the retry comes from a terminal.

Suggested change: add --operator="$USER" to up_args, stop with sudo tailscale up "${up_args[@]}" || exit 1, and update the test's exact-match tailscale up lines.

Reproducer (fails at 5589555)

Reproducer: retrying with the new variables after an earlier run

Two parts. Part A uses the real tailscale CLI against a throwaway userspace tailscaled. Part B is a test case in the style of test/shell.d/tailscale-install-test.sh that fails at 5589555.

Part A: the tailscale up command the PR builds, on a node where the installer already reached tailscale set --operator

Needs no root, uses temporary state and a private socket, turns log upload off, and points at .invalid control servers, so it cannot join anything. env USER=root stands in for sudo, which resets USER to the target user. Run with tailscale 1.102.3 (cmd/tailscale/cli/up.go is identical in 1.102.4, the current Arch package), in an isolated sandbox with no network and USER=nobody.

#!/bin/bash
work=$(mktemp -d)
sock="$work/tailscaled.sock"
tailscaled --tun=userspace-networking --no-logs-no-support --port=0 \
  --statedir="$work/state" --socket="$sock" >"$work/tailscaled.log" 2>&1 &
daemon=$!
until tailscale --socket="$sock" status --json >/dev/null 2>&1; do sleep 0.1; done

as_sudo() { env USER=root tailscale --socket="$sock" "$@"; }

# 1. The first run: `tailscale up` never completes (here it times out; on the
#    menu install it is interrupted at the login URL), then the installer
#    carries on to its operator step.
as_sudo up --accept-routes --login-server=https://first.invalid --timeout=3s
as_sudo set --operator="$USER"

# 2. The retry, with OMARCHY_TAILSCALE_LOGIN_SERVER=https://headscale.invalid and
#    OMARCHY_TAILSCALE_AUTH_KEY=tskey-auth-EXAMPLEKEY: the command the PR builds.
as_sudo up --accept-routes --login-server=https://headscale.invalid --auth-key=tskey-auth-EXAMPLEKEY
echo "tailscale up exit status: $?"

kill "$daemon"
wait "$daemon" 2>/dev/null
rm -rf "$work"

Actual output:

timeout waiting for Tailscale service to enter a Running state; check health with "tailscale status"
Error: changing settings via 'tailscale up' requires mentioning all
non-default flags. To proceed, either re-run your command with --reset or
use the command below to explicitly mention the current value of
all non-default settings:

	tailscale up --accept-routes --auth-key=tskey-auth-EXAMPLEKEY --login-server=https://headscale.invalid --operator=nobody

tailscale up exit status: 1

A second script ran the same steps with step 1 replaced by the unchanged hosted menu command (as_sudo up --accept-routes --timeout=3s, default control URL, no network), printed the node state, and then retried once more with --operator="$USER" --timeout=3s added. Actual output:

== hosted first run (menu command)
timeout waiting for Tailscale service to enter a Running state; check health with "tailscale status"
exit=1
== operator step
exit=0
== state
  "BackendState": "NeedsLogin",
	"ControlURL": "https://controlplane.tailscale.com",
	"RouteAll": true,
	"OperatorUser": "nobody",
== retry with the PR's variables
Error: changing settings via 'tailscale up' requires mentioning all
non-default flags. To proceed, either re-run your command with --reset or
use the command below to explicitly mention the current value of
all non-default settings:

	tailscale up --accept-routes --auth-key=tskey-auth-EXAMPLEKEY --login-server=https://headscale.invalid --operator=nobody

exit=1
== retry with --operator added
timeout waiting for Tailscale service to enter a Running state; check health with "tailscale status"
exit=1
	"ControlURL": "https://headscale.invalid",
	"OperatorUser": "nobody",

With --operator named, the settings check passes and the control URL switches; the timeout is only the unreachable .invalid server.

Part B: the installer ignores a failed tailscale up

Change the sudo stub in test/shell.d/tailscale-install-test.sh to:

cat >"$stub_bin/sudo" <<'SH'
#!/bin/bash
printf 'sudo %s\n' "$*" >>"$OMARCHY_TEST_CALL_LOG"
if [[ ${1-} == tailscale && ${2-} == up && -n ${OMARCHY_TEST_FAIL_UP-} ]]; then
  echo "tailscale up failed" >&2
  exit 1
fi
SH

and append:

status=$(OMARCHY_TEST_FAIL_UP=1 run_install "https://headscale.example.com" "tskey-auth-secret")
[[ $status != 0 ]] || fail "a failed tailscale up fails the install" "$(cat "$call_log")"
pass "a failed tailscale up fails the install"

Actual output at 5589555 (the sandbox had no USER, hence the empty --operator=):

ok - hosted Tailscale install is unchanged
ok - self-hosted install joins the given server and skips the hosted admin web app
ok - pre-auth key and custom admin URL are honored without printing the key
ok - a hosted pre-auth key does not drop the admin web app
ok - a login server that is not an http(s) URL is rejected before install
ok - an auth key containing whitespace is rejected
pkg-add tailscale
sudo systemctl enable --now tailscaled.service
sudo tailscale up --accept-routes --login-server=https://headscale.example.com --auth-key=tskey-auth-secret
sudo tailscale set --operator=
systemctl --user enable --now omarchy-tailscale-receive.service
plugin omarchy.tailscale
not ok - a failed tailscale up fails the install

With sudo tailscale up "${up_args[@]}" || exit 1 in the script, the same test file passes.

More findings

The auth key is a sudo argument

The key is visible in the process list while tailscale up runs, and sudo's default log_allowed writes every argument to the system journal (from sudo 1.9.17p2 source, not executed). Impact: "is not printed" holds only for the script's own output.

Suggested change: pass --auth-key=file:<path> from a root-only temporary file (untested end to end), or narrow the description.

Reproducer:

Reproducer: where the auth key ends up

  • Command line. The PR's own test asserts it (line 76 of test/shell.d/tailscale-install-test.sh): the key is an argument to sudo, and so to tailscale, for as long as tailscale up runs:

    grep -Fx 'sudo tailscale up --accept-routes --login-server=https://headscale.example.com --auth-key=tskey-auth-secret' "$call_log" >/dev/null || fail "auth key is passed as one argument" "$(cat "$call_log")"

    That test passes at 5589555.

  • Printed by tailscale on a retry. See the first reproducer (retry refusal), part A: the refusal prints --auth-key=tskey-auth-EXAMPLEKEY to stderr. With --auth-key=file:<path> instead, the same refusal printed the path:

    	tailscale up --accept-routes --auth-key=file:/tmp/tmp.NpkTcFaB3a/key --login-server=https://headscale.invalid --timeout=3s --operator=nobody
    
  • sudo's log. Not reproduced (sudo cannot run in the isolated sandbox). From sudo 1.9.17p2 source, the version in Arch: log_allowed defaults to on (plugins/sudoers/defaults.c, def_log_allowed = true), and each log line carries COMMAND= followed by every argument (lib/eventlog/eventlog.c, new_logline). Omarchy's etc/sudoers.d does not change this.

  • The userspace tailscaled log from the same run did not contain the key (0 matches).

Details

Verified:

  • With the variables unset or empty, the calls and web app match the merge-base script.
  • Every rejected value exits 1 before omarchy-pkg-add or any other side effect.
  • --login-server= and --auth-key= are the right forms for tailscale 1.102.x; a key such as --reset stays inside --auth-key=.
  • The new test passes at the head and fails with the merge-base script.
  • bin-style-test.sh, tailscale-test.sh and installed-service-test.sh pass at the head.

Optional notes:

  • Four changes to the script leave the new test at 6/6 ok: validation moved after omarchy-pkg-add, the admin URL check removed, the admin URL ignored without a login server, and the key echoed on the hosted path. Line 71 (! grep -F 'secret-auth-key' ...) can never fail under set -e. The tightened assertions below catch all four and pass at the head.
  • manual/35-networking.md and the omarchy:summary line still say the install always adds the admin web app, and only script comments name the variables. The menu can pass them only through the session environment.
  • A node already Running on another server also needs --force-reauth to switch (cmd/tailscale/cli/up.go).

Reproducer: changes the new test does not catch

Each change below was applied to bin/omarchy-install-service-tailscale at 5589555, and the PR's unchanged test/shell.d/tailscale-install-test.sh was run with bash. Every run exits 0 with the same six ok lines:

ok - hosted Tailscale install is unchanged
ok - self-hosted install joins the given server and skips the hosted admin web app
ok - pre-auth key and custom admin URL are honored without printing the key
ok - a hosted pre-auth key does not drop the admin web app
ok - a login server that is not an http(s) URL is rejected before install
ok - an auth key containing whitespace is rejected
  1. Validation moved after the package install (the description says a bad value exits before omarchy-pkg-add):
@@ -20,6 +20,10 @@
   [[ $1 =~ ^https?://[^[:space:]/?#]+(/[^[:space:]]*)?$ ]]
 }
 
+
+echo -e "\nInstalling Tailscale..."
+omarchy-pkg-add tailscale
+
 if [[ -n $login_server ]] && ! valid_http_url "$login_server"; then
   echo "OMARCHY_TAILSCALE_LOGIN_SERVER must be an http(s) URL, for example https://headscale.example.com." >&2
   exit 1
@@ -35,9 +39,6 @@
   exit 1
 fi
 
-echo -e "\nInstalling Tailscale..."
-omarchy-pkg-add tailscale
-
 echo -e "\nStarting Tailscale..."
 sudo systemctl enable --now tailscaled.service
 

(Moving it after sudo systemctl enable --now tailscaled.service also passes.)

  1. OMARCHY_TAILSCALE_ADMIN_URL validation removed:
@@ -30,10 +30,6 @@
   exit 1
 fi
 
-if [[ -n $admin_url ]] && ! valid_http_url "$admin_url"; then
-  echo "OMARCHY_TAILSCALE_ADMIN_URL must be an http(s) URL." >&2
-  exit 1
-fi
 
 echo -e "\nInstalling Tailscale..."
 omarchy-pkg-add tailscale
  1. The key printed on the hosted path:
@@ -49,6 +49,7 @@
 if [[ -n $auth_key ]]; then
   up_args+=(--auth-key="$auth_key")
 fi
+[[ -z $login_server && -n $auth_key ]] && echo "Joining with key $auth_key"
 sudo tailscale up "${up_args[@]}"
 
 echo -e "\nAllowing $USER to manage Tailscale..."
  1. The admin URL ignored unless a login server is also set:
@@ -60,7 +60,7 @@
 echo -e "\nAdding Tailscale to the bar..."
 omarchy-plugin-enable omarchy.tailscale
 
-if [[ -n $admin_url ]]; then
+if [[ -n $admin_url && -n $login_server ]]; then
   omarchy-webapp-install "Tailscale" "$admin_url" "$admin_icon"
 elif [[ -z $login_server ]]; then
   omarchy-webapp-install "Tailscale" "https://login.tailscale.com/admin/machines" "$admin_icon"
  1. Line 71 of the test, ! grep -F 'secret-auth-key' "$stdout_log" >/dev/null, cannot fail: Bash's set -e ignores a pipeline that starts with !, and no case passes secret-auth-key. Adding echo "secret-auth-key" before echo -e "\nInstalling Tailscale..." in the script also passes. The set -e part on its own:
bash -c 'set -euo pipefail; ! grep -F x <<<"x" >/dev/null; echo "reached after a failing ! grep line"'

Actual output (exit 0):

reached after a failing ! grep line

Tightened assertions that catch 1 to 4. Against the PR's test file: delete line 71; in the two rejection cases replace the grep -F 'sudo tailscale' ... && fail lines with [[ ! -s $call_log ]] || fail "... is rejected before anything is installed" "$(cat "$call_log")"; in the hosted auth-key case add ! grep -F 'tskey-auth-hosted' "$stdout_log" "$stderr_log" >/dev/null || fail "hosted auth key was printed" "$(cat "$stdout_log" "$stderr_log")"; and append:

status=$(run_install "" "" "admin.example.com")
[[ $status != 0 ]] || fail "an admin URL without a scheme is rejected"
[[ ! -s $call_log ]] || fail "invalid admin URL is rejected before anything is installed" "$(cat "$call_log")"
pass "an admin URL that is not an http(s) URL is rejected before install"

status=$(run_install "" "" "https://admin.example.com")
[[ $status == 0 ]] || fail "hosted install with an admin URL succeeds" "$(cat "$stderr_log")"
grep -Fx 'sudo tailscale up --accept-routes' "$call_log" >/dev/null || fail "admin URL alone keeps the hosted join" "$(cat "$call_log")"
grep -F 'webapp Tailscale https://admin.example.com ' "$call_log" >/dev/null || fail "admin URL is used without a login server" "$(cat "$call_log")"
pass "an admin URL alone replaces the hosted admin web app"

Actual results: the tightened file passes at 5589555, and fails on each change above with, in order:

not ok - invalid login server is rejected before anything is installed
not ok - an admin URL without a scheme is rejected
not ok - hosted auth key was printed
not ok - admin URL is used without a login server

Overlapping open PRs:


Review information

Test scope: Source and sandbox tests at 55895558, with the real tailscale 1.102.3 CLI against an offline daemon; sudo was not run.

AI process: Opus 5.5 Medium coordination and synthesis, Opus 5.5 Xhigh technical review and final fact check, GPT 6 Sol Xhigh search for related issues, Opus 5.5 Medium editorial check.

Opt out: To stop receiving these reviews, reply to this comment saying so.

@z23

z23 commented Oct 1, 2026

Copy link
Copy Markdown
Author

@llstrk Thanks for the detailed retry reproducer and the checks on key handling. Both the missing operator and the ignored join failure were real.

Addressed in 6028036:

  • Every tailscale up names the operator, using id -un. The redundant later tailscale set call is removed.
  • A failed package install, daemon start, or join exits before further setup.
  • The key travels through a pipe with --auth-key=file:/dev/stdin, using Tailscale's supported file form. This keeps it out of command arguments without a temporary secret file. The key variable is also removed from the environment inherited by child commands.
  • The tests now check validation before any side effect, hosted-key output and arguments, an invalid admin URL, admin URL without a custom server, literal flag-shaped keys, and failed joins with and without a key. The ineffective negative assertion is removed.
  • The summary and networking manual now describe the optional admin app and all three variables. Switching an already connected node has an explicit logout step; forced re-authentication can interrupt its active connection.

The 11 installer scenarios and the focused Tailscale, installed-service, style, syntax, diff, and metadata checks pass. A real 1.102.3 CLI with temporary userspace-daemon state reproduced the previous refusal/key echo. With explicit operator and stdin key, it passed the settings guard and changed ControlURL; the unreachable test server then timed out as expected. No live join was performed.

The broader CLI suite stops at a pre-existing VS Code test that expects a symlink while the committed sync command writes a regular file.

@greptile-apps

greptile-apps Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[High risk] Adds self-hosted Tailscale coordination server support to the installer.

The PR appears safe to merge; the remaining icon cleanup issue is non-blocking.

Findings

  1. P2 Hosted icon remains behind ▶

Summary

The PR adds optional self-hosted Tailscale joins, stdin-based pre-auth keys, URL validation, configurable admin web apps, and installer tests.

  • The latest change removes the verified hosted launcher by its exact path, avoiding deletion of a same-named custom launcher.
  • That direct removal leaves the hosted web app’s icon behind when it is no longer used.

Reviews (3) · Last reviewed commit: "Remove only the verified hosted Tailscal..."

Comment thread bin/omarchy-install-service-tailscale Resolved
Comment thread bin/omarchy-install-service-tailscale Resolved
Comment thread bin/omarchy-install-service-tailscale Resolved
Comment thread bin/omarchy-install-service-tailscale Resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants