You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
Go to file
Alex Chan b7fe1cea9f cmd/tailscale/cli: only print authURLs and device approval URLs once
This patch fixes several issues related to printing login and device
approval URLs, especially when `tailscale up` is interrupted:

1.  Only print a login URL that will cause `tailscale up` to complete.
    Don't print expired URLs or URLs from previous login attempts.

2.  Print the device approval URL if you run `tailscale up` after
    previously completing a login, but before approving the device.

3.  Use the correct control URL for device approval if you run a bare
    `tailscale up` after previously completing a login, but before
    approving the device.

4.  Don't print the device approval URL more than once (or at least,
    not consecutively).

Updates tailscale/corp#31476
Updates #17361

## How these fixes work

This patch went through a lot of trial and error, and there may still
be bugs! These notes capture the different scenarios and considerations
as we wrote it, which are also captured by integration tests.

1.  We were getting stale login URLs from the initial IPN state
    notification.

    When the IPN watcher was moved to before Start() in c011369, we
    mistakenly continued to request the initial state. This is only
    necessary if you start watching after you call Start(), because
    you may have missed some notifications.

    By getting the initial state before calling Start(), we'd get
    a stale login URL. If you clicked that URL, you could complete
    the login in the control server (if it wasn't expired), but your
    instance of `tailscale up` would hang, because it's listening for
    login updates from a different login URL.

    In this patch, we no longer request the initial state, and so we
    don't print a stale URL.

2.  Once you skip the initial state from IPN, the following sequence:

    *   Run `tailscale up`
    *   Log into a tailnet with device approval
    *   ^C after the device approval URL is printed, but without approving
    *   Run `tailscale up` again

    means that nothing would ever be printed.

    `tailscale up` would send tailscaled the pref `WantRunning: true`,
    but that was already the case so nothing changes. You never get any
    IPN notifications, and in particular you never get a state change to
    `NeedsMachineAuth`. This means we'd never print the device approval URL.

    In this patch, we add a hard-coded rule that if you're doing a simple up
    (which won't trigger any other IPN notifications) and you start in the
    `NeedsMachineAuth` state, we print the device approval message without
    waiting for an IPN notification.

3.  Consider the following sequence:

    *   Run `tailscale up --login-server=<custom server>`
    *   Log into a tailnet with device approval
    *   ^C after the device approval URL is printed, but without approving
    *   Run `tailscale up` again

    We'd print the device approval URL for the default control server,
    rather than the real control server, because we were using the `prefs`
    from the CLI arguments (which are all the defaults) rather than the
    `curPrefs` (which contain the custom login server).

    In this patch, we use the `prefs` if the user has specified any settings
    (and other code will ensure this is a complete set of settings) or
    `curPrefs` if it's a simple `tailscale up`.

4.  Consider the following sequence: you've logged in, but not completed
    device approval, and you run `down` and `up` in quick succession.

    *   `up`: sees state=NeedsMachineAuth
    *   `up`: sends `{wantRunning: true}`, prints out the device approval URL
    *   `down`: changes state to Stopped
    *   `up`: changes state to Starting
    *   tailscaled: changes state to NeedsMachineAuth
    *   `up`: gets an IPN notification with the state change, and prints
        a second device approval URL

    Either URL works, but this is annoying for the user.

    In this patch, we track whether the last printed URL was the device
    approval URL, and if so, we skip printing it a second time.

Signed-off-by: Alex Chan <alexc@tailscale.com>
2 months ago
.bencher bencher: add config to suppress failures on benchmark regressions. 4 years ago
.github tstest/integration/vms,.github/workflows: bump Ubuntu and NixOS for VM tests + cleanup (#16098) 2 months ago
appc appc,ipn/ipnlocal: receive AppConnector updates via the event bus (#17411) 2 months ago
atomicfile ipn/store: automatically migrate between plaintext and encrypted state (#16318) 5 months ago
chirp scripts/check_license_headers.sh: delete, rewrite as a Go test 6 months ago
client ipn/localapi: dead code eliminate unreachable/useless LocalAPI handlers when disabled 2 months ago
clientupdate feature, net/tshttpproxy: pull out support for using proxies as a feature 2 months ago
cmd cmd/tailscale/cli: only print authURLs and device approval URLs once 2 months ago
control control/controlclient: add missing comment (#17498) 2 months ago
derp derp/derphttp: de-flake DERP HTTP clients tests with memnet and synctest 2 months ago
disco disco: add missing message types to MessageSummary (#17081) 3 months ago
docs docs/windows/policy: add ADMX policy definition for AllowTailscaledRestart 2 months ago
doctor all: remove non-applicable "linux" deps on Android 7 months ago
drive drive: don't use regexp package in leaf types package 2 months ago
envknob all: use buildfeature constants in a few more places 2 months ago
feature feature/linkspeed: move cosmetic tstun netlink code out to modular feature 2 months ago
gokrazy gokrazy/natlab: update gokrazy, wire up natlab tests to GitHub CI 9 months ago
health health: make it omittable 2 months ago
hostinfo hostinfo, ipnlocal: add optional os-specific callback for querying the hostname (#15647) 8 months ago
internal control/ts2021: rename from internal/noiseconn in prep for controlclient split 2 months ago
ipn ipn/ipnlocal: use eventbus.SubscribeFunc in expiryManager 2 months ago
jsondb all: update copyright and license headers 3 years ago
k8s-operator k8s-operator/sessionrecording: gives the connection to the recorder from the hijacker a dedicated context (#17403) 2 months ago
kube all: use Go 1.20's errors.Join instead of our multierr package 2 months ago
licenses licenses: update license notices 2 months ago
log net/netmon: remove usage of direct callbacks from netmon (#17292) 2 months ago
logpolicy net/netmon: remove usage of direct callbacks from netmon (#17292) 2 months ago
logtail net/netmon: remove usage of direct callbacks from netmon (#17292) 2 months ago
maths maths: add exponentially weighted moving average type 9 months ago
metrics metrics,syncs: add ShardedInt support to metrics.LabelMap 12 months ago
net feature/linkspeed: move cosmetic tstun netlink code out to modular feature 2 months ago
omit cmd/tailscaled, ipn/conffile: support ec2 user-data config file 2 years ago
packages/deb go.mod: upgrade nfpm to v2 (#8786) 2 years ago
paths all: detect JetKVM and specialize a handful of things for it 5 months ago
portlist portlist: add Plan 9 support 8 months ago
posture util/syspolicy/policyclient: add policyclient.Client interface, start plumbing 3 months ago
prober all: use Go 1.20's errors.Join instead of our multierr package 2 months ago
proxymap ipnlocal,proxymap,wgengine/netstack: add optional WhoIs/proxymap debug 1 year ago
release all: use Go 1.20's errors.Join instead of our multierr package 2 months ago
safesocket feature/featuretags, all: add build features, use existing ones in more places 2 months ago
safeweb safeweb: Set Cross-Origin-Opener-Policy for browser requests (#15936) 7 months ago
scripts scripts/installer.sh: add Siemens Industrial OS (#17185) 3 months ago
sessionrecording cmd/tsrecorder: adds sending api level logging to tsrecorder (#16960) 2 months ago
ssh/tailssh util/backoff: rename logtail/backoff package to util/backoff 2 months ago
syncs syncs: add Semaphore.Len (#16981) 3 months ago
tailcfg util/checkchange: stop using deephash everywhere 2 months ago
tempfork feature/c2n: move answerC2N code + deps out of control/controlclient 2 months ago
tka tka: use ts_omit_tailnetlock in another spot, for ed25519consensus 2 months ago
tool tool/gocross: ensure child process error codes are propagated on non-Unix 3 months ago
tsconsensus cmd/natc,tsconsensus: add cluster config admin 4 months ago
tsconst tsconst, util/linuxfw, wgengine/router: move Linux fw consts to tsconst 2 months ago
tsd cmd/tailscaled: start implementing ts_omit_netstack 2 months ago
tsnet go.toolchain.rev: bump Go to 1.25.2 2 months ago
tstest cmd/tailscale/cli: only print authURLs and device approval URLs once 2 months ago
tstime tstime: add GoDuration which JSON serializes with time.Duration.String (#15726) 8 months ago
tsweb scripts/check_license_headers.sh: delete, rewrite as a Go test 6 months ago
types types/lazy: document difference from sync.OnceValue 2 months ago
util util/eventbus: add a function-based subscriber type (#17432) 2 months ago
version cmd/tailscale/cli: add "configure jetkvm" subcommand 5 months ago
wf wf/firewall: allow link-local multicast for permitted local routes when the killswitch is on on Windows 1 year ago
wgengine wgengine/magicsock: start peer relay path discovery sooner (#17485) 2 months ago
words words: add some more (#17177) 3 months ago
.gitattributes .: add .gitattributes entry to use Go hunk-header driver 4 years ago
.gitignore cmd/k8s-operator: Add NOTES.txt to Helm chart (#16364) 5 months ago
.golangci.yml .github: Bump golangci/golangci-lint-action from 6.5.0 to 7.0.0 (#15476) 8 months ago
ALPINE.txt docker: bump alpine v3.19 -> 3.22 (#17155) 3 months ago
AUTHORS Move Linux client & common packages into a public repo. 6 years ago
CODEOWNERS CODEOWNERS: add the start of an owners file 2 years ago
CODE_OF_CONDUCT.md CODE_OF_CONDUCT.md: fix duplicate entry (#16814) 3 months ago
Dockerfile docker: bump alpine v3.19 -> 3.22 (#17155) 3 months ago
Dockerfile.base docker: bump alpine v3.19 -> 3.22 (#17155) 3 months ago
LICENSE all: update tools that manage copyright headers 3 years ago
Makefile Makefile, cmd/*/depaware.txt: split out vendor packages explicitly 2 months ago
PATENTS Move Linux client & common packages into a public repo. 6 years ago
README.md README: update the version of Go in the README 2 months ago
SECURITY.md Add a SECURITY.md for vulnerability reports. 6 years ago
VERSION.txt VERSION.txt: this is v1.89.0 (#17099) 3 months ago
api.md {api.md,publicapi}: remove old API docs (#13468) 1 year ago
assert_ts_toolchain_match.go tailscaleroot: panic if tailscale_go build tag but Go toolchain mismatch 1 year ago
build_dist.sh build_dist.sh: keep --extra-small making a usable build, add --min 2 months ago
build_docker.sh build_docker.sh: support including extra files (#17405) 2 months ago
flake.lock .github/Makefile/flake: update nix flake support (#16636) 4 months ago
flake.nix cmd/tsrecorder: adds sending api level logging to tsrecorder (#16960) 2 months ago
go.mod go.toolchain.rev: bump Go to 1.25.2 2 months ago
go.mod.sri cmd/tsrecorder: adds sending api level logging to tsrecorder (#16960) 2 months ago
go.sum cmd/tsrecorder: adds sending api level logging to tsrecorder (#16960) 2 months ago
go.toolchain.branch go.toolchain.branch: bump to go1.25 (#16954) 3 months ago
go.toolchain.rev go.toolchain.rev: bump Go to 1.25.2 2 months ago
gomod_test.go go.mod: add test that replace directives aren't added in oss 2 years ago
header.txt cmd/k8s-operator: operator can create subnetrouter (#9505) 2 years ago
license_test.go wgengine/router{,/osrouter}: split OS router implementations into subpackage 2 months ago
pkgdoc_test.go all: skip looking for package comments in .git/ repository (#15384) 9 months ago
pull-toolchain.sh pull-toolchain.sh: don't run update-flake.sh 3 years ago
shell.nix cmd/tsrecorder: adds sending api level logging to tsrecorder (#16960) 2 months ago
staticcheck.conf all: cleanup unused code, part 2 (#10670) 2 years ago
update-flake.sh Code Improvements (#11311) 2 years ago
version-embed.go Fix various linting, vet & static check issues 11 months ago
version_tailscale_test.go tailscaleroot: panic if tailscale_go build tag but Go toolchain mismatch 1 year ago
version_test.go .github/workflows: test that ./go/tool version matches go mod version 6 months ago

README.md

Tailscale

https://tailscale.com

Private WireGuard® networks made easy

Overview

This repository contains the majority of Tailscale's open source code. Notably, it includes the tailscaled daemon and the tailscale CLI tool. The tailscaled daemon runs on Linux, Windows, macOS, and to varying degrees on FreeBSD and OpenBSD. The Tailscale iOS and Android apps use this repo's code, but this repo doesn't contain the mobile GUI code.

Other Tailscale repos of note:

For background on which parts of Tailscale are open source and why, see https://tailscale.com/opensource/.

Using

We serve packages for a variety of distros and platforms at https://pkgs.tailscale.com.

Other clients

The macOS, iOS, and Windows clients use the code in this repository but additionally include small GUI wrappers. The GUI wrappers on non-open source platforms are themselves not open source.

Building

We always require the latest Go release, currently Go 1.25. (While we build releases with our Go fork, its use is not required.)

go install tailscale.com/cmd/tailscale{,d}

If you're packaging Tailscale for distribution, use build_dist.sh instead, to burn commit IDs and version info into the binaries:

./build_dist.sh tailscale.com/cmd/tailscale
./build_dist.sh tailscale.com/cmd/tailscaled

If your distro has conventions that preclude the use of build_dist.sh, please do the equivalent of what it does in your distro's way, so that bug reports contain useful version information.

Bugs

Please file any issues about this code or the hosted service on the issue tracker.

Contributing

PRs welcome! But please file bugs. Commit messages should reference bugs.

We require Developer Certificate of Origin Signed-off-by lines in commits.

See commit-messages.md (or skim git log) for our commit message style.

About Us

Tailscale is primarily developed by the people at https://github.com/orgs/tailscale/people. For other contributors, see:

WireGuard is a registered trademark of Jason A. Donenfeld.