Documentation ¶
Overview ¶
Package controlclient implements the client for the Tailscale control plane.
It handles authentication, port picking, and collects the local network configuration.
Index ¶
- Constants
- Variables
- func DERPRouteFlag() opt.Bool
- func NewHostinfo() *tailcfg.Hostinfo
- func TrimWGConfig() opt.Bool
- type Client
- func (c *Client) AuthCantContinue() bool
- func (c *Client) Direct() *Direct
- func (c *Client) Expiry() *time.Time
- func (c *Client) Login(t *oauth2.Token, flags LoginFlags)
- func (c *Client) Logout()
- func (c *Client) SetHostinfo(hi *tailcfg.Hostinfo)
- func (c *Client) SetNetInfo(ni *tailcfg.NetInfo)
- func (c *Client) SetPaused(paused bool)
- func (c *Client) SetStatusFunc(fn func(Status))
- func (c *Client) Shutdown()
- func (c *Client) Start()
- func (c *Client) TestOnlyNodePublicKey() wgkey.Key
- func (c *Client) TestOnlySetAuthKey(authkey string)
- func (c *Client) TestOnlyTimeNow() time.Time
- func (c *Client) UpdateEndpoints(localPort uint16, endpoints []string)
- type Decompressor
- type Direct
- func (c *Direct) GetPersist() Persist
- func (c *Direct) PollNetMap(ctx context.Context, maxPolls int, cb func(*NetworkMap)) error
- func (c *Direct) SendLiteMapUpdate(ctx context.Context) error
- func (c *Direct) SetEndpoints(localPort uint16, endpoints []string) (changed bool)
- func (c *Direct) SetHostinfo(hi *tailcfg.Hostinfo) bool
- func (c *Direct) SetNetInfo(ni *tailcfg.NetInfo) bool
- func (c *Direct) TryLogin(ctx context.Context, t *oauth2.Token, flags LoginFlags) (url string, err error)
- func (c *Direct) TryLogout(ctx context.Context) error
- func (c *Direct) WaitLoginURL(ctx context.Context, url string) (newUrl string, err error)
- type LoginFlags
- type LoginGoal
- type NetworkMap
- func (nm *NetworkMap) Concise() string
- func (b *NetworkMap) ConciseDiffFrom(a *NetworkMap) string
- func (nm *NetworkMap) JSON() string
- func (nm *NetworkMap) MagicDNSSuffix() string
- func (nm *NetworkMap) String() string
- func (nm *NetworkMap) WGCfg(logf logger.Logf, flags WGConfigFlags) (*wgcfg.Config, error)
- type Options
- type Persist
- type State
- type Status
- type WGConfigFlags
Constants ¶
const ( StateNew = State(iota) StateNotAuthenticated StateAuthenticating StateURLVisitRequired StateAuthenticated StateSynchronized // connected and received map update )
const ( LoginDefault = LoginFlags(0) LoginInteractive = LoginFlags(1 << iota) // force user login and key refresh )
const EndpointDiscoSuffix = ".disco.tailscale:12345"
EndpointDiscoSuffix is appended to the hex representation of a peer's discovery key and is then the sole wireguard endpoint for peers with a non-zero discovery key. This form is then recognize by magicsock's CreateEndpoint.
Variables ¶
var Debug = initDebug()
Debug contains temporary internal-only debug knobs. They're unexported to not draw attention to them.
Functions ¶
func DERPRouteFlag ¶ added in v1.2.0
DERPRouteFlag reports the last reported value from control for whether DERP route optimization (Issue 150) should be enabled.
func NewHostinfo ¶
func TrimWGConfig ¶ added in v1.2.0
TrimWGConfig reports the last reported value from control for whether we should do lazy wireguard configuration.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client connects to a tailcontrol server for a node.
func NewNoStart ¶
NewNoStart creates a new Client, but without calling Start on it.
func (*Client) AuthCantContinue ¶
func (*Client) Direct ¶ added in v0.98.1
Direct returns the underlying direct client object. Used in tests only.
func (*Client) Expiry ¶ added in v0.98.1
Expiry returns the credential expiration time, or the zero time if the expiration time isn't known. Used in tests only.
func (*Client) SetHostinfo ¶
func (*Client) SetNetInfo ¶
func (*Client) SetPaused ¶ added in v1.2.0
SetPaused controls whether HTTP activity should be paused.
The client can be paused and unpaused repeatedly, unlike Start and Shutdown, which can only be used once.
func (*Client) SetStatusFunc ¶
func (*Client) Start ¶
func (c *Client) Start()
Start starts the client's goroutines.
It should only be called for clients created by NewNoStart.
func (*Client) TestOnlyNodePublicKey ¶ added in v0.98.1
NodePublicKey returns the node public key currently in use. This is used exclusively in tests.
func (*Client) TestOnlySetAuthKey ¶ added in v0.98.1
func (*Client) TestOnlyTimeNow ¶ added in v0.98.1
func (*Client) UpdateEndpoints ¶
type Decompressor ¶
type Direct ¶
type Direct struct {
// contains filtered or unexported fields
}
Direct is the client that connects to a tailcontrol server for a node.
func (*Direct) GetPersist ¶
func (*Direct) PollNetMap ¶
PollNetMap makes a /map request to download the network map, calling cb with each new netmap.
maxPolls is how many network maps to download; common values are 1 or -1 (to keep a long-poll query open to the server).
func (*Direct) SendLiteMapUpdate ¶ added in v1.4.0
SendLiteMapUpdate makes a /map request to update the server of our latest state, but does not fetch anything. It returns an error if the server did not return a successful 200 OK response.
func (*Direct) SetEndpoints ¶
SetEndpoints updates the list of locally advertised endpoints. It won't be replicated to the server until a *fresh* call to PollNetMap(). You don't need to restart PollNetMap if we return changed==false.
func (*Direct) SetHostinfo ¶
SetHostinfo clones the provided Hostinfo and remembers it for the next update. It reports whether the Hostinfo has changed.
func (*Direct) SetNetInfo ¶
SetNetInfo clones the provided NetInfo and remembers it for the next update. It reports whether the NetInfo has changed.
type LoginFlags ¶
type LoginFlags int
type NetworkMap ¶
type NetworkMap struct { SelfNode *tailcfg.Node NodeKey tailcfg.NodeKey PrivateKey wgkey.Private Expiry time.Time // Name is the DNS name assigned to this node. Name string Addresses []netaddr.IPPrefix LocalPort uint16 // used for debugging MachineStatus tailcfg.MachineStatus MachineKey tailcfg.MachineKey Peers []*tailcfg.Node // sorted by Node.ID DNS tailcfg.DNSConfig Hostinfo tailcfg.Hostinfo PacketFilter []filter.Match // CollectServices reports whether this node's Tailnet has // requested that info about services be included in HostInfo. // If set, Hostinfo.ShieldsUp blocks services collection; that // takes precedence over this field. CollectServices bool // DERPMap is the last DERP server map received. It's reused // between updates and should not be modified. DERPMap *tailcfg.DERPMap // Debug knobs from control server for debug or feature gating. Debug *tailcfg.Debug User tailcfg.UserID Domain string // TODO(crawshaw): reduce UserProfiles to []tailcfg.UserProfile? // There are lots of ways to slice this data, leave it up to users. UserProfiles map[tailcfg.UserID]tailcfg.UserProfile }
func (*NetworkMap) Concise ¶
func (nm *NetworkMap) Concise() string
func (*NetworkMap) ConciseDiffFrom ¶
func (b *NetworkMap) ConciseDiffFrom(a *NetworkMap) string
func (*NetworkMap) JSON ¶
func (nm *NetworkMap) JSON() string
func (*NetworkMap) MagicDNSSuffix ¶ added in v1.4.0
func (nm *NetworkMap) MagicDNSSuffix() string
MagicDNSSuffix returns the domain's MagicDNS suffix (even if MagicDNS isn't necessarily in use).
It will neither start nor end with a period.
func (*NetworkMap) String ¶
func (nm *NetworkMap) String() string
func (*NetworkMap) WGCfg ¶
func (nm *NetworkMap) WGCfg(logf logger.Logf, flags WGConfigFlags) (*wgcfg.Config, error)
WGCfg returns the NetworkMaps's Wireguard configuration.
type Options ¶
type Options struct { Persist Persist // initial persistent data MachinePrivateKey wgkey.Private // the machine key to use ServerURL string // URL of the tailcontrol server AuthKey string // optional node auth key for auto registration TimeNow func() time.Time // time.Now implementation used by Client Hostinfo *tailcfg.Hostinfo // non-nil passes ownership, nil means to use default using os.Hostname, etc DiscoPublicKey tailcfg.DiscoKey NewDecompressor func() (Decompressor, error) KeepAlive bool Logf logger.Logf HTTPTestClient *http.Client // optional HTTP client to use (for tests only) DebugFlags []string // debug settings to send to control // understands Node.Sharer. If false, the Sharer is mapped to the User. KeepSharerAndUserSplit bool }
type Persist ¶
type Persist struct { // LegacyFrontendPrivateMachineKey is here temporarily // (starting 2020-09-28) during migration of Windows users' // machine keys from frontend storage to the backend. On the // first LocalBackend.Start call, the backend will initialize // the real (backend-owned) machine key from the frontend's // provided value (if non-zero), picking a new random one if // needed. This field should be considered read-only from GUI // frontends. The real value should not be written back in // this field, lest the frontend persist it to disk. LegacyFrontendPrivateMachineKey wgkey.Private `json:"PrivateMachineKey"` PrivateNodeKey wgkey.Private OldPrivateNodeKey wgkey.Private // needed to request key rotation Provider string LoginName string // contains filtered or unexported fields }
type State ¶ added in v0.98.1
type State int
State is the high-level state of the client. It is used only in unit tests for proper sequencing, don't depend on it anywhere else. TODO(apenwarr): eliminate 'state', as it's now obsolete.
func (State) MarshalText ¶ added in v0.98.1
type Status ¶
type Status struct { LoginFinished *empty.Message Err string URL string Persist *Persist // locally persisted configuration NetMap *NetworkMap // server-pushed configuration Hostinfo *tailcfg.Hostinfo // current Hostinfo data State State // contains filtered or unexported fields }
type WGConfigFlags ¶ added in v1.0.0
type WGConfigFlags int
WGConfigFlags is a bitmask of flags to control the behavior of the wireguard configuration generation done by NetMap.WGCfg.
const ( AllowSingleHosts WGConfigFlags = 1 << iota AllowSubnetRoutes AllowDefaultRoute )