summaryrefslogtreecommitdiffhomepage
path: root/ipn/ipnserver
AgeCommit message (Collapse)AuthorFilesLines
2021-05-16all: adapt to opaque netaddr typesJosh Bleecher Snyder1-1/+1
This commit is a mishmash of automated edits using gofmt: gofmt -r 'netaddr.IPPort{IP: a, Port: b} -> netaddr.IPPortFrom(a, b)' -w . gofmt -r 'netaddr.IPPrefix{IP: a, Port: b} -> netaddr.IPPrefixFrom(a, b)' -w . gofmt -r 'a.IP.Is4 -> a.IP().Is4' -w . gofmt -r 'a.IP.As16 -> a.IP().As16' -w . gofmt -r 'a.IP.Is6 -> a.IP().Is6' -w . gofmt -r 'a.IP.As4 -> a.IP().As4' -w . gofmt -r 'a.IP.String -> a.IP().String' -w . And regexps: \w*(.*)\.Port = (.*) -> $1 = $1.WithPort($2) \w*(.*)\.IP = (.*) -> $1 = $1.WithIP($2) And lots of manual fixups. Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
2021-05-10ipn{,/ipnserver}: delay JSON marshaling of ipn.NotifiesBrad Fitzpatrick1-7/+40
If nobody is connected to the IPN bus, don't burn CPU & waste allocations (causing more GC) by encoding netmaps for nobody. This will notably help hello.ipn.dev. Updates tailscale/corp#1773 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-04-20cmd/tailscaled: don't block ipnserver startup behind engine init on WindowsBrad Fitzpatrick1-41/+1
With this change, the ipnserver's safesocket.Listen (the localhost tcp.Listen) happens right away, before any synchronous TUN/DNS/Engine/etc setup work, which might be slow, especially on early boot on Windows. Because the safesocket.Listen starts up early, that means localhost TCP dials (the safesocket.Connect from the GUI) complete successfully and thus the GUI avoids the MessageBox error. (I verified that pacifies it, even without a Listener.Accept; I'd feared that Windows localhost was maybe special and avoided the normal listener backlog). Once the GUI can then connect immediately without errors, the various timeouts then matter less, because the backend is no longer trying to race against the GUI's timeout. So keep retrying on errors for a minute, or 10 minutes if the system just booted in the past 10 minutes. This should fix the problem with Windows 10 desktops auto-logging in and starting the Tailscale frontend which was then showing a MessageBox error about failing to connect to tailscaled, which was slow coming up because the Windows networking stack wasn't up yet. Fingers crossed. Fixes #1313 (previously #1187, etc) Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-04-20ipn: don't Logout when Windows GUI disconnectsBrad Fitzpatrick1-6/+2
Logout used to be a no-op, so the ipnserver previously synthensized a Logout on disconnect. Now that Logout actually invalidates the node key that was forcing all GUI closes to log people out. Instead, add a method to LocalBackend to specifically mean "the Windows GUI closed, please forget all the state". Fixes tailscale/corp#1591 (ignoring the notification issues, tracked elsewhere) Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-04-19ipn, cmd/tailscale/cli: add pref to configure sudo-free operator userBrad Fitzpatrick1-3/+7
From discussion with @danderson. Fixes #1684 (in a different way) Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-04-07ipn, paths, cmd/tailscaled: remove LegacyConfigPath, relaynode migrationBrad Fitzpatrick1-14/+1
It is time. Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-03-31cmd/tailscale, ipn/localapi: add "tailscale bugreport" subcommandMaisem Ali1-5/+7
Adding a subcommand which prints and logs a log marker. This should help diagnose any issues that users face. Fixes #1466 Signed-off-by: Maisem Ali <maisem@tailscale.com>
2021-03-16Revert "cmd/tailscaled, ipn/{ipnlocal,ipnserver}: let netstack get access to ↵Brad Fitzpatrick1-8/+0
LocalBackend" This reverts commit 2bc518dcb248abb0a84f0ebf7a2d12203d106c66. @namansood didn't end up needing it in his 770aa71ffbfbb01f7c8bfc65ce5e0505c783efde.
2021-03-15cmd/tailscaled, ipn/{ipnlocal,ipnserver}: let netstack get access to ↵Brad Fitzpatrick1-0/+8
LocalBackend Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-03-05ipn/ipnserver: refactor permissions checks a bit, document more, fix WindowsBrad Fitzpatrick1-21/+46
Windows was only running the localapi on the debug port which was a stopgap at the time while doing peercreds work. Removed that, and wired it up correctly, with some more docs. More clean-up to do after 1.6, moving the localhost TCP auth code into the peercreds package. But that's too much for now, so the docs will have to suffice, even if it's at a bit of an awkward stage with the newly-renamed "NotWindows" field, which still isn't named well, but it's better than its old name of "Unknown" which hasn't been accurate since unix sock peercreds work anyway. Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-03-05ipn/ipnserver: set PermitWrite on localapi handlerBrad Fitzpatrick1-4/+5
The TODO was easy now with peerCreds and the isReadonlyConn func. Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-03-02ipn/ipnserver: grant client r/w access if peer uid matches tailscaledBrad Fitzpatrick1-0/+5
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-03-02safesocket, ipn/ipnserver: unify peercred info, fix bug on FreeBSD etcBrad Fitzpatrick1-0/+3
FreeBSD wasn't able to run "tailscale up" since the recent peercred refactoring. Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-03-01cmd/tailscaled, wgengine: remove --fake, replace with netstackBrad Fitzpatrick1-1/+1
And add a --socks5-server flag. And fix a race in SOCKS5 replies where the response header was written concurrently with the copy from the backend. Co-authored with Naman Sood. Updates #707 Updates #504 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-02-23ipn/ipnserver: fix Windows connection auth regressionBrad Fitzpatrick1-0/+5
Regression from code movement in d3efe8caf636aaa9a8e02b65877878954ea980b7 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-02-16ipn/ipnserver: on darwin, let users who are admins use CLI without sudoBrad Fitzpatrick1-4/+56
Tangentially related to #987, #177, #594, #925, #505 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-02-16safesocket, ipn/ipnserver: look up peer creds on DarwinBrad Fitzpatrick3-76/+14
And open up socket permissions like Linux, now that we know who connections are from. This uses the new inet.af/peercred that supports Linux and Darwin at the moment. Fixes #1347 Fixes #1348 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-02-15ipn/ipnserver, ipn/ipnlocal: move whois handler to new localapi packageBrad Fitzpatrick1-45/+22
2021-02-04ipn: split LocalBackend off into new ipn/ipnlocal packageBrad Fitzpatrick1-4/+5
And move a couple other types down into leafier packages. Now cmd/tailscale doesn't bring in netlink, magicsock, wgengine, etc. Fixes #1181 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-01-29ipn/ipnserver, cmd/hello: do whois over unix socket, not debug httpBrad Fitzpatrick1-6/+13
Start of a local HTTP API. Not a stable interface yet.
2021-01-28cmd/tailscaled: add whois/identd-ish debug handlerBrad Fitzpatrick1-0/+40
2021-01-25ipn/ipnserver: on Windows in unattended mode, wait for Engine foreverBrad Fitzpatrick1-28/+90
Updates #1187
2021-01-15ipn, ipnserver: only require sudo on Linux for mutable CLI actionsBrad Fitzpatrick3-4/+84
This partially reverts d6e9fb1df0fd6, which modified the permissions on the tailscaled Unix socket and thus required "sudo tailscale" even for "tailscale status". Instead, open the permissions back up (on Linux only) but have the server look at the peer creds and only permit read-only actions unless you're root. In the future we'll also have a group that can do mutable actions. On OpenBSD and FreeBSD, the permissions on the socket remain locked down to 0600 from d6e9fb1df0fd6. Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-01-11cmd/tailscaled, wgengine/netstack: add start of gvisor userspace netstack workBrad Fitzpatrick1-1/+1
Not usefully functional yet (mostly a proof of concept), but getting it submitted for some work @namansood is going to do atop this. Updates #707 Updates #634 Updates #48 Updates #835
2020-12-21all: annotate log verbosity levels on most egregiously spammy log printsBrad Fitzpatrick1-2/+4
Fixes #924 Fixes #282 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2020-12-15ipn/ipnserver: enable systemd-notify supportChristine Dodrill1-0/+2
Addresses #964 Still to be done: - Figure out the correct logging lines in util/systemd - Figure out if we need to slip the systemd.Status function anywhere else - Log util/systemd errors? (most of the errors are of the "you cannot do anything about this, but it might be a bad idea to crash the program if it errors" kind) Assistance in getting this over the finish line would help a lot. Signed-off-by: Christine Dodrill <me@christine.website> util/systemd: rename the nonlinux file to appease the magic Signed-off-by: Christine Dodrill <me@christine.website> util/systemd: fix package name Signed-off-by: Christine Dodrill <me@christine.website> util/systemd: fix review feedback from @mdlayher Signed-off-by: Christine Dodrill <me@christine.website> cmd/tailscale{,d}: update depaware manifests Signed-off-by: Christine Dodrill <me@christine.website> util/systemd: use sync.Once instead of func init Signed-off-by: Christine Dodrill <me@christine.website> control/controlclient: minor review feedback fixes Signed-off-by: Christine Dodrill <me@christine.website> {control,ipn,systemd}: fix review feedback Signed-off-by: Christine Dodrill <me@christine.website> review feedback fixes Signed-off-by: Christine Dodrill <me@christine.website> ipn: fix sprintf call Signed-off-by: Christine Dodrill <me@christine.website> ipn: make staticcheck less sad Signed-off-by: Christine Dodrill <me@christine.website> ipn: print IP address in connected status Signed-off-by: Christine Dodrill <me@christine.website> ipn: review feedback Signed-off-by: Christine Dodrill <me@christine.website> final fixups Signed-off-by: Christine Dodrill <me@christine.website>
2020-11-17ipn/ipnserver: add knob to disable babysitterBrad Fitzpatrick1-0/+4
2020-11-02ipn: only use Prefs, not computed stateKey, to determine server modeBrad Fitzpatrick1-1/+1
When the service was running without a client (e.g. after a reboot) and then the owner logs in and the GUI attaches, the computed state key changed to "" (driven by frontend prefs), and then it was falling out of server mode, despite the GUI-provided prefs still saying it wanted server mode. Also add some logging. And remove a scary "Access denied" from a user-visible error, making the two possible already-in-use error messages consistent with each other.
2020-11-02ipn, ipn/ipnserver: add IPN state for server in use, handle explicitlyBrad Fitzpatrick1-24/+113
On Windows, we were previously treating a server used by different users as a fatal error, which meant the second user (upon starting Tailscale, explicitly or via Start Up programs) got an invasive error message dialog. Instead, give it its own IPN state and change the Notify.ErrMessage to be details in that state. Then the Windows GUI can be less aggresive about that happening. Also, * wait to close the IPN connection until the server ownership state changes so the GUI doesn't need to repeatedly reconnect to discover changes. * fix a bug discovered during testing: on system reboot, the ipnserver's serverModeUser was getting cleared while the state transitioned from Unknown to Running. Instead, track 'inServerMode' explicitly and remove the old accessor method which was error prone. * fix a rare bug where the client could start up and set the server mode prefs in its Start call and we wouldn't persist that to the StateStore storage's prefs start key. (Previously it was only via a prefs toggle at runtime)
2020-11-02ipn/ipnserver: remove "Server mode" from a user-visible error messageBrad Fitzpatrick1-1/+1
That's an internal nickname.
2020-10-29ipn/ipnserver: move Windows local disk logging up to the parent processBrad Fitzpatrick1-0/+14
To capture panics, log.Printf writes to os.Stderr, etc. Fixes #726
2020-10-29ipn/ipnserver: work around os/user.LookupId failure on WindowsBrad Fitzpatrick1-3/+19
If we can't find the mapping from SID ("user ID") -> username, don't treat that as a fatal. Apparently that happens in the wild for Reasons. Ignore it for now. It's just a nice-to-have for error messages in the rare multi-user case. Updates #869 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2020-10-28version: use OSS repo's version when building.David Anderson1-1/+1
When building with redo, also include the git commit hash from the proprietary repo, so that we have a precise commit that identifies all build info (including Go toolchain version). Add a top-level build script demonstrating to downstream distros how to burn the right information into builds. Adjust `tailscale version` to print commit hashes when available. Fixes #841. Signed-off-by: David Anderson <danderson@tailscale.com>
2020-10-12ipn, ipnserver, cmd/tailscale: add "server mode" support on WindowsBrad Fitzpatrick1-12/+114
This partially (but not yet fully) migrates Windows to tailscaled's StateStore storage system. This adds a new bool Pref, ForceDaemon, defined as: // ForceDaemon specifies whether a platform that normally // operates in "client mode" (that is, requires an active user // logged in with the GUI app running) should keep running after the // GUI ends and/or the user logs out. // // The only current applicable platform is Windows. This // forced Windows to go into "server mode" where Tailscale is // running even with no users logged in. This might also be // used for macOS in the future. This setting has no effect // for Linux/etc, which always operate in daemon mode. Then, when ForceDaemon becomes true, we now write use the StateStore to track which user started it in server mode, and store their prefs under that key. The ipnserver validates the connections/identities and informs that LocalBackend which userid is currently in charge. The GUI can then enable/disable server mode at runtime, without using the CLI. But the "tailscale up" CLI was also fixed, so Windows users can use authkeys or ACL tags, etc. Updates #275
2020-10-09ipn/ipnserver: prevent use by multiple Windows users, add HTML status pageBrad Fitzpatrick1-54/+150
It was previously possible for two different Windows users to connect to the IPN server at once, but it didn't really work. They mostly stepped on each other's toes and caused chaos. Now only one can control it, but it can be active for everybody else. Necessary dependency step for Windows server/headless mode (#275) While here, finish wiring up the HTTP status page on Windows, now that all the dependent pieces are available.
2020-10-02all: use testing.T.TempDirJosh Bleecher Snyder1-7/+1
Bit of Friday cleanup. Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
2020-09-11ipn/ipnserver: make ipnserver also be an HTTP server for localhost clientsBrad Fitzpatrick1-1/+99
For now it just says hello to show auth works. More later.
2020-08-09backoff: update to Go style, document a bit, make 30s explicitBrad Fitzpatrick1-2/+2
Also, bit of behavior change: on non-nil err but expired context, don't reset the consecutive failure count. I don't think the old behavior was intentional. Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2020-07-29ipn/ipnserver: fix bug in earlier commit where conn can be strandedBrad Fitzpatrick1-5/+15
If a connection causes getEngine to transition from broken to fixed, that connection was getting lost.
2020-07-29ipn/ipnserver: staticcheck is not wrongBrad Fitzpatrick1-2/+3
shamecube.gif
2020-07-29ipn/ipnserver: make Engine argument a func that tries again for each connectionBrad Fitzpatrick2-11/+23
So a backend in server-an-error state (as used by Windows) can try to create a new Engine again each time somebody re-connects, relaunching the GUI app. (The proper fix is actually fixing Windows issues, but this makes things better in the short term) Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2020-07-15ipn/ipnserver: support simultaneous connectionsv0.100.0-107Brad Fitzpatrick1-68/+96
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2020-07-13cmd/tailscaled: graceful shutdown (#534)Dmytro Shynkevych1-0/+1
Signed-off-by: Dmytro Shynkevych <dmytro@tailscale.com>
2020-07-08ipn, ipn/ipnserver: add support for serving in error-message-only modeBrad Fitzpatrick1-5/+35
So Windows service failures can be propagated to the Windows UI client.
2020-07-02smallzstd: new package that constructs zstd small encoders/decoders.David Anderson1-5/+2
It's just a config wrapper that passes "use less memory at the expense of compression" parameters by default, so that we don't accidentally construct resource-hungry (de)compressors. Also includes a benchmark that measures the memory cost of the small variants vs. the stock variants. The savings are significant on both compressors (~8x less memory) and decompressors (~1.4x less, not including the savings from the significantly smaller window on the compression side - with those savings included it's more like ~140x smaller). BenchmarkSmallEncoder-8 56174 19354 ns/op 31 B/op 0 allocs/op BenchmarkSmallEncoderWithBuild-8 2900 382940 ns/op 1746547 B/op 36 allocs/op BenchmarkStockEncoder-8 48921 25761 ns/op 286 B/op 0 allocs/op BenchmarkStockEncoderWithBuild-8 426 2630241 ns/op 13843842 B/op 124 allocs/op BenchmarkSmallDecoder-8 123814 9344 ns/op 0 B/op 0 allocs/op BenchmarkSmallDecoderWithBuild-8 41547 27455 ns/op 27694 B/op 31 allocs/op BenchmarkStockDecoder-8 129832 9417 ns/op 1 B/op 0 allocs/op BenchmarkStockDecoderWithBuild-8 25561 51751 ns/op 39607 B/op 92 allocs/op Signed-off-by: David Anderson <danderson@tailscale.com>
2020-06-03ipn/ipnserver: revert decoder memory limit.David Anderson1-1/+0
The zstd library treats that limit as a hard cap on decompressed size, in the mode we're using it, rather than a window size. Signed-off-by: David Anderson <danderson@tailscale.com>
2020-05-20ipnserver and logpolicy: configure zstd with low-memory settings.Avery Pennarun1-1/+5
The compressed blobs we send back and forth are small and infrequent, which doesn't justify the 8MB * GOMAXPROCS memory that was being allocated. This was the overwhelming majority of memory use in tailscaled. On my system it goes from ~100M RSS to ~15M RSS (which is still suspiciously high, but we can worry about that more later). Signed-off-by: Avery Pennarun <apenwarr@tailscale.com>
2020-05-15wgengine: log node IDs when peers are added/removed (#381)Wendi Yu1-5/+1
Also stop logging data sent/received from nodes we're not connected to (ie all those `x`s being logged in the `peers: ` line) Signed-off-by: Wendi <wendi.yu@yahoo.ca>
2020-05-13Add tstest.PanicOnLog(), and fix various problems detected by this.Avery Pennarun1-2/+2
If a test calls log.Printf, 'go test' horrifyingly rearranges the output to no longer be in chronological order, which makes debugging virtually impossible. Let's stop that from happening by making log.Printf panic if called from any module, no matter how deep, during tests. This required us to change the default error handler in at least one http.Server, as well as plumbing a bunch of logf functions around, especially in magicsock and wgengine, but also in logtail and backoff. To add insult to injury, 'go test' also rearranges the output when a parent test has multiple sub-tests (all the sub-test's t.Logf is always printed after all the parent tests t.Logf), so we need to screw around with a special Logf that can point at the "current" t (current_t.Logf) in some places. Probably our entire way of using subtests is wrong, since 'go test' would probably like to run them all in parallel if you called t.Parallel(), but it definitely can't because the're all manipulating the shared state created by the parent test. They should probably all be separate toplevel tests instead, with common setup/teardown logic. But that's a job for another time. Signed-off-by: Avery Pennarun <apenwarr@tailscale.com>
2020-05-08Implement rate limiting on log messages (#356)Wendi Yu1-1/+5
Implement rate limiting on log messages Addresses issue #317, where logs can get spammed with the same message nonstop. Created a rate limiting closure on logging functions, which limits the number of messages being logged per second based on format string. To keep memory usage as constant as possible, the previous cache purging at periodic time intervals has been replaced by an LRU that discards the oldest string when the capacity of the cache is reached. Signed-off-by: Wendi Yu <wendi.yu@yahoo.ca>