2020-02-05 22:16:58 +00:00
|
|
|
// Copyright (c) 2020 Tailscale Inc & AUTHORS All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package ipn
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
ipn, ipnserver, cmd/tailscale: add "server mode" support on Windows
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-12 21:28:21 +00:00
|
|
|
"runtime"
|
|
|
|
"strings"
|
2020-02-05 22:16:58 +00:00
|
|
|
|
2020-02-18 03:33:01 +00:00
|
|
|
"github.com/tailscale/wireguard-go/wgcfg"
|
2020-02-05 22:16:58 +00:00
|
|
|
"tailscale.com/atomicfile"
|
|
|
|
"tailscale.com/control/controlclient"
|
2020-05-15 02:07:06 +00:00
|
|
|
"tailscale.com/wgengine/router"
|
2020-02-05 22:16:58 +00:00
|
|
|
)
|
|
|
|
|
2020-02-17 23:45:30 +00:00
|
|
|
// Prefs are the user modifiable settings of the Tailscale node agent.
|
2020-02-05 22:16:58 +00:00
|
|
|
type Prefs struct {
|
2020-02-19 05:03:22 +00:00
|
|
|
// ControlURL is the URL of the control server to use.
|
|
|
|
ControlURL string
|
ipn, ipnserver, cmd/tailscale: add "server mode" support on Windows
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-12 21:28:21 +00:00
|
|
|
|
2020-02-17 23:45:30 +00:00
|
|
|
// RouteAll specifies whether to accept subnet and default routes
|
|
|
|
// advertised by other nodes on the Tailscale network.
|
|
|
|
RouteAll bool
|
ipn, ipnserver, cmd/tailscale: add "server mode" support on Windows
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-12 21:28:21 +00:00
|
|
|
|
2020-02-17 23:45:30 +00:00
|
|
|
// AllowSingleHosts specifies whether to install routes for each
|
|
|
|
// node IP on the tailscale network, in addition to a route for
|
|
|
|
// the whole network.
|
ipn, ipnserver, cmd/tailscale: add "server mode" support on Windows
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-12 21:28:21 +00:00
|
|
|
// This corresponds to the "tailscale up --host-routes" value,
|
|
|
|
// which defaults to true.
|
2020-02-17 23:45:30 +00:00
|
|
|
//
|
|
|
|
// TODO(danderson): why do we have this? It dumps a lot of stuff
|
|
|
|
// into the routing table, and a single network route _should_ be
|
|
|
|
// all that we need. But when I turn this off in my tailscaled,
|
|
|
|
// packets stop flowing. What's up with that?
|
2020-02-05 22:16:58 +00:00
|
|
|
AllowSingleHosts bool
|
ipn, ipnserver, cmd/tailscale: add "server mode" support on Windows
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-12 21:28:21 +00:00
|
|
|
|
2020-02-17 23:45:30 +00:00
|
|
|
// CorpDNS specifies whether to install the Tailscale network's
|
|
|
|
// DNS configuration, if it exists.
|
|
|
|
CorpDNS bool
|
ipn, ipnserver, cmd/tailscale: add "server mode" support on Windows
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-12 21:28:21 +00:00
|
|
|
|
2020-02-17 23:45:30 +00:00
|
|
|
// WantRunning indicates whether networking should be active on
|
|
|
|
// this node.
|
|
|
|
WantRunning bool
|
ipn, ipnserver, cmd/tailscale: add "server mode" support on Windows
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-12 21:28:21 +00:00
|
|
|
|
2020-04-29 06:37:35 +00:00
|
|
|
// ShieldsUp indicates whether to block all incoming connections,
|
|
|
|
// regardless of the control-provided packet filter. If false, we
|
|
|
|
// use the packet filter as provided. If true, we block incoming
|
|
|
|
// connections.
|
|
|
|
ShieldsUp bool
|
ipn, ipnserver, cmd/tailscale: add "server mode" support on Windows
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-12 21:28:21 +00:00
|
|
|
|
2020-05-01 05:01:27 +00:00
|
|
|
// AdvertiseTags specifies groups that this node wants to join, for
|
|
|
|
// purposes of ACL enforcement. These can be referenced from the ACL
|
|
|
|
// security policy. Note that advertising a tag doesn't guarantee that
|
|
|
|
// the control server will allow you to take on the rights for that
|
|
|
|
// tag.
|
|
|
|
AdvertiseTags []string
|
ipn, ipnserver, cmd/tailscale: add "server mode" support on Windows
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-12 21:28:21 +00:00
|
|
|
|
2020-06-02 16:12:05 +00:00
|
|
|
// Hostname is the hostname to use for identifying the node. If
|
|
|
|
// not set, os.Hostname is used.
|
|
|
|
Hostname string
|
ipn, ipnserver, cmd/tailscale: add "server mode" support on Windows
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-12 21:28:21 +00:00
|
|
|
|
2020-07-24 21:05:04 +00:00
|
|
|
// OSVersion overrides tailcfg.Hostinfo's OSVersion.
|
|
|
|
OSVersion string
|
ipn, ipnserver, cmd/tailscale: add "server mode" support on Windows
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-12 21:28:21 +00:00
|
|
|
|
2020-07-24 21:05:04 +00:00
|
|
|
// DeviceModel overrides tailcfg.Hostinfo's DeviceModel.
|
|
|
|
DeviceModel string
|
2020-02-17 23:45:30 +00:00
|
|
|
|
|
|
|
// NotepadURLs is a debugging setting that opens OAuth URLs in
|
|
|
|
// notepad.exe on Windows, rather than loading them in a browser.
|
|
|
|
//
|
2020-04-29 06:37:35 +00:00
|
|
|
// apenwarr 2020-04-29: Unfortunately this is still needed sometimes.
|
|
|
|
// Windows' default browser setting is sometimes screwy and this helps
|
2020-05-01 05:01:27 +00:00
|
|
|
// users narrow it down a bit.
|
2020-02-17 23:45:30 +00:00
|
|
|
NotepadURLs bool
|
2020-02-05 22:16:58 +00:00
|
|
|
|
ipn, ipnserver, cmd/tailscale: add "server mode" support on Windows
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-12 21:28:21 +00:00
|
|
|
// 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.
|
|
|
|
ForceDaemon bool `json:"ForceDaemon,omitempty"`
|
|
|
|
|
2020-05-13 22:35:22 +00:00
|
|
|
// The following block of options only have an effect on Linux.
|
|
|
|
|
|
|
|
// AdvertiseRoutes specifies CIDR prefixes to advertise into the
|
|
|
|
// Tailscale network as reachable through the current
|
|
|
|
// node.
|
|
|
|
AdvertiseRoutes []wgcfg.CIDR
|
ipn, ipnserver, cmd/tailscale: add "server mode" support on Windows
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-12 21:28:21 +00:00
|
|
|
|
2020-05-13 22:35:22 +00:00
|
|
|
// NoSNAT specifies whether to source NAT traffic going to
|
|
|
|
// destinations in AdvertiseRoutes. The default is to apply source
|
|
|
|
// NAT, which makes the traffic appear to come from the router
|
|
|
|
// machine rather than the peer's Tailscale IP.
|
|
|
|
//
|
|
|
|
// Disabling SNAT requires additional manual configuration in your
|
|
|
|
// network to route Tailscale traffic back to the subnet relay
|
|
|
|
// machine.
|
|
|
|
//
|
|
|
|
// Linux-only.
|
|
|
|
NoSNAT bool
|
ipn, ipnserver, cmd/tailscale: add "server mode" support on Windows
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-12 21:28:21 +00:00
|
|
|
|
2020-05-15 02:07:06 +00:00
|
|
|
// NetfilterMode specifies how much to manage netfilter rules for
|
|
|
|
// Tailscale, if at all.
|
|
|
|
NetfilterMode router.NetfilterMode
|
2020-05-13 22:35:22 +00:00
|
|
|
|
2020-02-05 22:16:58 +00:00
|
|
|
// The Persist field is named 'Config' in the file for backward
|
|
|
|
// compatibility with earlier versions.
|
|
|
|
// TODO(apenwarr): We should move this out of here, it's not a pref.
|
|
|
|
// We can maybe do that once we're sure which module should persist
|
|
|
|
// it (backend or frontend?)
|
|
|
|
Persist *controlclient.Persist `json:"Config"`
|
|
|
|
}
|
|
|
|
|
2020-02-03 18:35:52 +00:00
|
|
|
// IsEmpty reports whether p is nil or pointing to a Prefs zero value.
|
2020-02-17 23:01:23 +00:00
|
|
|
func (p *Prefs) IsEmpty() bool { return p == nil || p.Equals(&Prefs{}) }
|
2020-02-03 18:35:52 +00:00
|
|
|
|
ipn, ipnserver, cmd/tailscale: add "server mode" support on Windows
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-12 21:28:21 +00:00
|
|
|
func (p *Prefs) Pretty() string { return p.pretty(runtime.GOOS) }
|
|
|
|
func (p *Prefs) pretty(goos string) string {
|
|
|
|
var sb strings.Builder
|
|
|
|
sb.WriteString("Prefs{")
|
|
|
|
fmt.Fprintf(&sb, "ra=%v ", p.RouteAll)
|
|
|
|
if !p.AllowSingleHosts {
|
|
|
|
sb.WriteString("mesh=false ")
|
|
|
|
}
|
|
|
|
fmt.Fprintf(&sb, "dns=%v want=%v ", p.CorpDNS, p.WantRunning)
|
|
|
|
if p.ForceDaemon {
|
|
|
|
sb.WriteString("server=true ")
|
|
|
|
}
|
|
|
|
if p.NotepadURLs {
|
|
|
|
sb.WriteString("notepad=true ")
|
|
|
|
}
|
|
|
|
if p.ShieldsUp {
|
|
|
|
sb.WriteString("shields=true ")
|
|
|
|
}
|
|
|
|
if len(p.AdvertiseRoutes) > 0 || goos == "linux" {
|
|
|
|
fmt.Fprintf(&sb, "routes=%v ", p.AdvertiseRoutes)
|
|
|
|
}
|
|
|
|
if len(p.AdvertiseRoutes) > 0 || p.NoSNAT {
|
|
|
|
fmt.Fprintf(&sb, "snat=%v ", !p.NoSNAT)
|
|
|
|
}
|
|
|
|
if goos == "linux" {
|
|
|
|
fmt.Fprintf(&sb, "nf=%v ", p.NetfilterMode)
|
|
|
|
}
|
2020-02-17 23:01:23 +00:00
|
|
|
if p.Persist != nil {
|
ipn, ipnserver, cmd/tailscale: add "server mode" support on Windows
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-12 21:28:21 +00:00
|
|
|
sb.WriteString(p.Persist.Pretty())
|
2020-02-05 22:16:58 +00:00
|
|
|
} else {
|
ipn, ipnserver, cmd/tailscale: add "server mode" support on Windows
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-12 21:28:21 +00:00
|
|
|
sb.WriteString("Persist=nil")
|
2020-02-05 22:16:58 +00:00
|
|
|
}
|
ipn, ipnserver, cmd/tailscale: add "server mode" support on Windows
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-12 21:28:21 +00:00
|
|
|
sb.WriteString("}")
|
|
|
|
return sb.String()
|
2020-02-05 22:16:58 +00:00
|
|
|
}
|
|
|
|
|
2020-02-17 23:01:23 +00:00
|
|
|
func (p *Prefs) ToBytes() []byte {
|
|
|
|
data, err := json.MarshalIndent(p, "", "\t")
|
2020-02-05 22:16:58 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Prefs marshal: %v\n", err)
|
|
|
|
}
|
|
|
|
return data
|
|
|
|
}
|
|
|
|
|
2020-02-17 23:01:23 +00:00
|
|
|
func (p *Prefs) Equals(p2 *Prefs) bool {
|
|
|
|
if p == nil && p2 == nil {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
if p == nil || p2 == nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return p != nil && p2 != nil &&
|
2020-02-19 05:03:22 +00:00
|
|
|
p.ControlURL == p2.ControlURL &&
|
2020-02-17 23:01:23 +00:00
|
|
|
p.RouteAll == p2.RouteAll &&
|
|
|
|
p.AllowSingleHosts == p2.AllowSingleHosts &&
|
|
|
|
p.CorpDNS == p2.CorpDNS &&
|
|
|
|
p.WantRunning == p2.WantRunning &&
|
|
|
|
p.NotepadURLs == p2.NotepadURLs &&
|
2020-04-29 06:37:35 +00:00
|
|
|
p.ShieldsUp == p2.ShieldsUp &&
|
2020-05-11 20:16:52 +00:00
|
|
|
p.NoSNAT == p2.NoSNAT &&
|
2020-05-15 02:07:06 +00:00
|
|
|
p.NetfilterMode == p2.NetfilterMode &&
|
2020-06-02 16:12:05 +00:00
|
|
|
p.Hostname == p2.Hostname &&
|
2020-07-24 21:05:04 +00:00
|
|
|
p.OSVersion == p2.OSVersion &&
|
|
|
|
p.DeviceModel == p2.DeviceModel &&
|
ipn, ipnserver, cmd/tailscale: add "server mode" support on Windows
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-12 21:28:21 +00:00
|
|
|
p.ForceDaemon == p2.ForceDaemon &&
|
2020-02-17 23:01:23 +00:00
|
|
|
compareIPNets(p.AdvertiseRoutes, p2.AdvertiseRoutes) &&
|
2020-05-01 05:01:27 +00:00
|
|
|
compareStrings(p.AdvertiseTags, p2.AdvertiseTags) &&
|
2020-02-17 23:01:23 +00:00
|
|
|
p.Persist.Equals(p2.Persist)
|
|
|
|
}
|
|
|
|
|
2020-02-18 03:33:01 +00:00
|
|
|
func compareIPNets(a, b []wgcfg.CIDR) bool {
|
2020-02-17 23:01:23 +00:00
|
|
|
if len(a) != len(b) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
for i := range a {
|
2020-03-17 03:27:00 +00:00
|
|
|
if !a[i].IP.Equal(b[i].IP) || a[i].Mask != b[i].Mask {
|
2020-02-17 23:01:23 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
2020-02-05 22:16:58 +00:00
|
|
|
}
|
|
|
|
|
2020-05-01 05:01:27 +00:00
|
|
|
func compareStrings(a, b []string) bool {
|
|
|
|
if len(a) != len(b) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
for i := range a {
|
|
|
|
if a[i] != b[i] {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2020-02-20 19:07:00 +00:00
|
|
|
func NewPrefs() *Prefs {
|
|
|
|
return &Prefs{
|
|
|
|
// Provide default values for options which might be missing
|
|
|
|
// from the json data for any reason. The json can still
|
|
|
|
// override them to false.
|
2020-02-19 05:03:22 +00:00
|
|
|
ControlURL: "https://login.tailscale.com",
|
2020-02-05 22:16:58 +00:00
|
|
|
RouteAll: true,
|
|
|
|
AllowSingleHosts: true,
|
|
|
|
CorpDNS: true,
|
|
|
|
WantRunning: true,
|
2020-05-15 02:07:06 +00:00
|
|
|
NetfilterMode: router.NetfilterOn,
|
2020-02-05 22:16:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-20 19:07:00 +00:00
|
|
|
// PrefsFromBytes deserializes Prefs from a JSON blob. If
|
|
|
|
// enforceDefaults is true, Prefs.RouteAll and Prefs.AllowSingleHosts
|
|
|
|
// are forced on.
|
|
|
|
func PrefsFromBytes(b []byte, enforceDefaults bool) (*Prefs, error) {
|
2020-02-17 23:01:23 +00:00
|
|
|
p := NewPrefs()
|
2020-02-05 22:16:58 +00:00
|
|
|
if len(b) == 0 {
|
2020-02-17 23:01:23 +00:00
|
|
|
return p, nil
|
2020-02-05 22:16:58 +00:00
|
|
|
}
|
|
|
|
persist := &controlclient.Persist{}
|
|
|
|
err := json.Unmarshal(b, persist)
|
|
|
|
if err == nil && (persist.Provider != "" || persist.LoginName != "") {
|
|
|
|
// old-style relaynode config; import it
|
2020-02-17 23:01:23 +00:00
|
|
|
p.Persist = persist
|
2020-02-05 22:16:58 +00:00
|
|
|
} else {
|
2020-02-17 23:01:23 +00:00
|
|
|
err = json.Unmarshal(b, &p)
|
2020-02-05 22:16:58 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Printf("Prefs parse: %v: %v\n", err, b)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if enforceDefaults {
|
2020-02-17 23:01:23 +00:00
|
|
|
p.RouteAll = true
|
|
|
|
p.AllowSingleHosts = true
|
2020-02-05 22:16:58 +00:00
|
|
|
}
|
2020-02-17 23:01:23 +00:00
|
|
|
return p, err
|
2020-02-05 22:16:58 +00:00
|
|
|
}
|
|
|
|
|
2020-02-27 20:20:29 +00:00
|
|
|
// Clone returns a deep copy of p.
|
|
|
|
func (p *Prefs) Clone() *Prefs {
|
|
|
|
// TODO: write a faster/non-Fatal-y Clone implementation?
|
2020-02-17 23:01:23 +00:00
|
|
|
p2, err := PrefsFromBytes(p.ToBytes(), false)
|
2020-02-05 22:16:58 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Prefs was uncopyable: %v\n", err)
|
|
|
|
}
|
2020-02-20 19:07:00 +00:00
|
|
|
return p2
|
2020-02-05 22:16:58 +00:00
|
|
|
}
|
|
|
|
|
2020-07-22 17:31:28 +00:00
|
|
|
// LoadPrefs loads a legacy relaynode config file into Prefs
|
|
|
|
// with sensible migration defaults set.
|
|
|
|
func LoadPrefs(filename string) (*Prefs, error) {
|
2020-02-05 22:16:58 +00:00
|
|
|
data, err := ioutil.ReadFile(filename)
|
|
|
|
if err != nil {
|
2020-09-17 14:59:55 +00:00
|
|
|
return nil, fmt.Errorf("LoadPrefs open: %w", err) // err includes path
|
2020-02-05 22:16:58 +00:00
|
|
|
}
|
2020-02-20 19:07:00 +00:00
|
|
|
p, err := PrefsFromBytes(data, false)
|
2020-02-05 22:16:58 +00:00
|
|
|
if err != nil {
|
2020-09-17 14:59:55 +00:00
|
|
|
return nil, fmt.Errorf("LoadPrefs(%q) decode: %w", filename, err)
|
2020-02-05 22:16:58 +00:00
|
|
|
}
|
2020-02-20 19:07:00 +00:00
|
|
|
return p, nil
|
2020-02-05 22:16:58 +00:00
|
|
|
}
|
|
|
|
|
2020-02-17 23:01:23 +00:00
|
|
|
func SavePrefs(filename string, p *Prefs) {
|
|
|
|
log.Printf("Saving prefs %v %v\n", filename, p.Pretty())
|
|
|
|
data := p.ToBytes()
|
2020-02-05 22:16:58 +00:00
|
|
|
os.MkdirAll(filepath.Dir(filename), 0700)
|
|
|
|
if err := atomicfile.WriteFile(filename, data, 0666); err != nil {
|
|
|
|
log.Printf("SavePrefs: %v\n", err)
|
|
|
|
}
|
|
|
|
}
|