Skip to content

feat: sign in with a pre-authorized auth key - #172

Merged
dantraynor merged 2 commits into
mainfrom
feat/auth-key-login
Nov 14, 2026
Merged

dantraynor merged 2 commits into
mainfrom
feat/auth-key-login

Conversation

@dantraynor

Copy link
Copy Markdown
Owner

Closes #154

What

Adds a "Use an auth key" option to the login view. Pasting a pre-authorized (optionally tagged) key registers the current browser profile without a browser login page. This covers the case in #154: machines where users can't install the Tailscale app and shouldn't need their own Tailscale account.

Today the only way to do this is setting TS_AUTHKEY in the user environment, which applies to every browser profile and every tsnet program for that user. This scopes the key to one profile.

How

  • Helper (host/authkey_login.go): new login-auth-key command. Only accepted while the profile is in NeedsLogin. It calls Start with the key, then StartLoginInteractive, the same sequence tsnet uses for TS_AUTHKEY on first start. A watcher on the IPN bus reports a rejection or a 30s timeout. On rejection, the control client is reset so the key is dropped and not retried.
  • Capability: the helper advertises supportsAuthKeyLogin in procRunning. Older helpers don't, so the option stays hidden until users update.
  • Extension: background handler forwards the trimmed key. Popup form uses a password field, keeps a pasted key across status re-renders, and clears it on submit. Works with protected browsing on, since the helper reaches the coordination server directly.

Key handling

  • Never written to extension storage, prefs, or logs. The native-host send path logs only the command name.
  • Helper error messages bound for the extension redact the key, including the parts of a tailnet-lock wrapped key.
  • Format check is deliberately loose (printable ASCII, no whitespace, at most 512 bytes) so Headscale pre-auth keys work too.

Testing

  • Go integration test against testcontrol with RequireAuthKey: a wrong key returns a redacted rejection and leaves the profile logged out, then the right key reaches Running with no auth URL and WantRunning=true. Passed 8 repeated runs under -race.
  • Unit tests for validation, redaction, and the not-initialized path; background tests for forwarding, capability gating, state gating, empty keys, and error copy; popup tests for the form.
  • go test -race ./..., pnpm typecheck, pnpm test, and pnpm build all pass.

Not yet tried against real Tailscale or Headscale, and the form hasn't been checked in a real browser.

Add a "Use an auth key" option to the login view. The extension sends
the key to the helper with a new login-auth-key command. The helper
hands it to the backend for the current profile only and registers
without a browser login URL, the same way tsnet uses TS_AUTHKEY on
first start, but scoped to one browser profile instead of the user's
whole environment.

The key is never written to storage, prefs, or logs. If the
coordination server rejects it, the helper reports the rejection with
the key redacted and resets the control client so the key is not
retried. Older helpers do not advertise supportsAuthKeyLogin, so the
option stays hidden until the helper is updated.

Closes #154
sendMessage logged the whole message when the background port was
disconnected. With auth key sign-in that would print the key to the
popup console, and send-file messages would dump file data. Log the
message type only. Flagged by CodeQL on #172.
@dantraynor
dantraynor merged commit 4c1ef88 into main Nov 14, 2026
19 checks passed
@dantraynor
dantraynor deleted the feat/auth-key-login branch November 14, 2026 03:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: sign in with a pre-authorized (tagged) auth key

1 participant