2023-01-27 21:37:20 +00:00
// Copyright (c) Tailscale Inc & AUTHORS
// SPDX-License-Identifier: BSD-3-Clause
2020-02-05 22:16:58 +00:00
2024-07-10 16:45:46 +01:00
// Package tailcfg contains types used by the Tailscale protocol with between
// the node and the coordination server.
2020-02-05 22:16:58 +00:00
package tailcfg
2023-08-20 04:14:32 +01:00
//go:generate go run tailscale.com/cmd/viewer --type=User,Node,Hostinfo,NetInfo,Login,DNSConfig,RegisterResponse,RegisterResponseAuth,RegisterRequest,DERPHomeParams,DERPRegion,DERPMap,DERPNode,SSHRule,SSHAction,SSHPrincipal,ControlDialPlan,Location,UserProfile --clonefunc
2020-07-27 18:40:34 +01:00
2020-02-05 22:16:58 +00:00
import (
2022-08-12 20:34:25 +01:00
"bytes"
2024-02-07 22:27:29 +00:00
"cmp"
2023-07-25 05:07:00 +01:00
"encoding/json"
2020-02-05 22:16:58 +00:00
"errors"
"fmt"
2023-10-04 03:12:37 +01:00
"maps"
all: convert more code to use net/netip directly
perl -i -npe 's,netaddr.IPPrefixFrom,netip.PrefixFrom,' $(git grep -l -F netaddr.)
perl -i -npe 's,netaddr.IPPortFrom,netip.AddrPortFrom,' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPrefix,netip.Prefix,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPort,netip.AddrPort,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IP\b,netip.Addr,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPv6Raw\b,netip.AddrFrom16,g' $(git grep -l -F netaddr. )
goimports -w .
Then delete some stuff from the net/netaddr shim package which is no
longer neeed.
Updates #5162
Change-Id: Ia7a86893fe21c7e3ee1ec823e8aba288d4566cd8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-07-26 05:14:09 +01:00
"net/netip"
2020-02-16 06:23:58 +00:00
"reflect"
2023-09-06 18:17:25 +01:00
"slices"
2020-02-05 22:16:58 +00:00
"strings"
"time"
2021-08-05 22:05:24 +01:00
"tailscale.com/types/dnstype"
2020-06-19 03:32:55 +01:00
"tailscale.com/types/key"
2020-02-25 22:05:17 +00:00
"tailscale.com/types/opt"
2020-05-03 21:58:39 +01:00
"tailscale.com/types/structs"
2022-08-12 20:34:25 +01:00
"tailscale.com/types/tkatype"
2021-01-25 22:41:39 +00:00
"tailscale.com/util/dnsname"
2023-09-30 23:28:14 +01:00
"tailscale.com/util/slicesx"
2020-02-05 22:16:58 +00:00
)
2022-03-06 17:32:52 +00:00
// CapabilityVersion represents the client's capability level. That
// is, it can be thought of as the client's simple version number: a
// single monotonically increasing integer, rather than the relatively
// complex x.y.z-xxxxx semver+hash(es). Whenever the client gains a
// capability or wants to negotiate a change in semantics with the
2023-01-19 20:40:58 +00:00
// server (control plane), peers (over PeerAPI), or frontend (over
// LocalAPI), bump this number and document what's new.
2022-03-06 17:32:52 +00:00
//
// Previously (prior to 2022-03-06), it was known as the "MapRequest
// version" or "mapVer" or "map cap" and that name and usage persists
// in places.
type CapabilityVersion int
// CurrentCapabilityVersion is the current capability version of the codebase.
2021-01-05 18:37:15 +00:00
//
// History of versions:
2022-08-02 17:33:46 +01:00
//
2022-09-08 05:46:54 +01:00
// - 3: implicit compression, keep-alives
// - 4: opt-in keep-alives via KeepAlive field, opt-in compression via Compress
// - 5: 2020-10-19, implies IncludeIPv6, delta Peers/UserProfiles, supports MagicDNS
// - 6: 2020-12-07: means MapResponse.PacketFilter nil means unchanged
// - 7: 2020-12-15: FilterRule.SrcIPs accepts CIDRs+ranges, doesn't warn about 0.0.0.0/::
// - 8: 2020-12-19: client can buggily receive IPv6 addresses and routes if beta enabled server-side
// - 9: 2020-12-30: client doesn't auto-add implicit search domains from peers; only DNSConfig.Domains
// - 10: 2021-01-17: client understands MapResponse.PeerSeenChange
// - 11: 2021-03-03: client understands IPv6, multiple default routes, and goroutine dumping
// - 12: 2021-03-04: client understands PingRequest
// - 13: 2021-03-19: client understands FilterRule.IPProto
// - 14: 2021-04-07: client understands DNSConfig.Routes and DNSConfig.Resolvers
// - 15: 2021-04-12: client treats nil MapResponse.DNSConfig as meaning unchanged
// - 16: 2021-04-15: client understands Node.Online, MapResponse.OnlineChange
// - 17: 2021-04-18: MapResponse.Domain empty means unchanged
// - 18: 2021-04-19: MapResponse.Node nil means unchanged (all fields now omitempty)
// - 19: 2021-04-21: MapResponse.Debug.SleepSeconds
// - 20: 2021-06-11: MapResponse.LastSeen used even less (https://github.com/tailscale/tailscale/issues/2107)
// - 21: 2021-06-15: added MapResponse.DNSConfig.CertDomains
// - 22: 2021-06-16: added MapResponse.DNSConfig.ExtraRecords
// - 23: 2021-08-25: DNSConfig.Routes values may be empty (for ExtraRecords support in 1.14.1+)
// - 24: 2021-09-18: MapResponse.Health from control to node; node shows in "tailscale status"
// - 25: 2021-11-01: MapResponse.Debug.Exit
// - 26: 2022-01-12: (nothing, just bumping for 1.20.0)
// - 27: 2022-02-18: start of SSHPolicy being respected
// - 28: 2022-03-09: client can communicate over Noise.
// - 29: 2022-03-21: MapResponse.PopBrowserURL
// - 30: 2022-03-22: client can request id tokens.
// - 31: 2022-04-15: PingRequest & PingResponse TSMP & disco support
// - 32: 2022-04-17: client knows FilterRule.CapMatch
// - 33: 2022-07-20: added MapResponse.PeersChangedPatch (DERPRegion + Endpoints)
// - 34: 2022-08-02: client understands CapabilityFileSharingTarget
// - 36: 2022-08-02: added PeersChangedPatch.{Key,DiscoKey,Online,LastSeen,KeyExpiry,Capabilities}
// - 37: 2022-08-09: added Debug.{SetForceBackgroundSTUN,SetRandomizeClientPort}; Debug are sticky
// - 38: 2022-08-11: added PingRequest.URLIsNoise
// - 39: 2022-08-15: clients can talk Noise over arbitrary HTTPS port
// - 40: 2022-08-22: added Node.KeySignature, PeersChangedPatch.KeySignature
// - 41: 2022-08-30: uses 100.100.100.100 for route-less ExtraRecords if global nameservers is set
2022-09-06 19:15:30 +01:00
// - 42: 2022-09-06: NextDNS DoH support; see https://github.com/tailscale/tailscale/pull/5556
2022-09-21 21:35:22 +01:00
// - 43: 2022-09-21: clients can return usernames for SSH
2022-09-23 18:06:55 +01:00
// - 44: 2022-09-22: MapResponse.ControlDialPlan
2022-09-26 18:52:41 +01:00
// - 45: 2022-09-26: c2n /debug/{goroutines,prefs,metrics}
2022-10-04 04:39:45 +01:00
// - 46: 2022-10-04: c2n /debug/component-logging
2022-10-13 18:43:00 +01:00
// - 47: 2022-10-11: Register{Request,Response}.NodeKeySignature
2022-11-02 20:13:26 +00:00
// - 48: 2022-11-02: Node.UnsignedPeerAPIOnly
2022-11-03 21:30:38 +00:00
// - 49: 2022-11-03: Client understands EarlyNoise
2022-11-14 03:31:25 +00:00
// - 50: 2022-11-14: Client understands CapabilityIngress
2022-11-30 18:34:59 +00:00
// - 51: 2022-11-30: Client understands CapabilityTailnetLockAlpha
2023-01-05 19:00:42 +00:00
// - 52: 2023-01-05: client can handle c2n POST /logtail/flush
2023-01-18 20:58:41 +00:00
// - 53: 2023-01-18: client respects explicit Node.Expired + auto-sets based on Node.KeyExpiry
2023-01-19 20:40:58 +00:00
// - 54: 2023-01-19: Node.Cap added, PeersChangedPatch.Cap, uses Node.Cap for ExitDNS before Hostinfo.Services fallback
2023-01-21 18:04:43 +00:00
// - 55: 2023-01-23: start of c2n GET+POST /update handler
2023-01-24 19:31:20 +00:00
// - 56: 2023-01-24: Client understands CapabilityDebugTSDNSResolution
2023-01-25 18:17:40 +00:00
// - 57: 2023-01-25: Client understands CapabilityBindToInterfaceByRoute
2023-03-10 18:26:07 +00:00
// - 58: 2023-03-10: Client retries lite map updates before restarting map poll.
2023-03-03 00:05:07 +00:00
// - 59: 2023-03-16: Client understands Peers[].SelfNodeV4MasqAddrForThisPeer
2023-04-06 01:28:28 +01:00
// - 60: 2023-04-06: Client understands IsWireGuardOnly
2023-04-20 05:33:33 +01:00
// - 61: 2023-04-18: Client understand SSHAction.SSHRecorderFailureAction
2023-05-05 22:06:23 +01:00
// - 62: 2023-05-05: Client can notify control over noise for SSHEventNotificationRequest recording failure events
2023-06-09 02:39:27 +01:00
// - 63: 2023-06-08: Client understands SSHAction.AllowRemotePortForwarding.
2023-07-07 16:39:35 +01:00
// - 64: 2023-07-11: Client understands s/CapabilityTailnetLockAlpha/CapabilityTailnetLock
2023-07-12 19:45:46 +01:00
// - 65: 2023-07-12: Client understands DERPMap.HomeParams + incremental DERPMap updates with params
2024-02-11 16:35:02 +00:00
// - 66: 2023-07-23: UserProfile.Groups added (available via WhoIs) (removed in 87)
2023-07-25 05:07:00 +01:00
// - 67: 2023-07-25: Client understands PeerCapMap
2023-08-10 03:56:43 +01:00
// - 68: 2023-08-09: Client has dedicated updateRoutine; MapRequest.Stream true means ignore Hostinfo+Endpoints
2023-08-17 04:03:57 +01:00
// - 69: 2023-08-16: removed Debug.LogHeap* + GoroutineDumpURL; added c2n /debug/logheap
2023-08-17 05:43:56 +01:00
// - 70: 2023-08-16: removed most Debug fields; added NodeAttrDisable*, NodeAttrDebug* instead
2023-08-17 20:29:51 +01:00
// - 71: 2023-08-17: added NodeAttrOneCGNATEnable, NodeAttrOneCGNATDisable
2023-08-23 21:42:15 +01:00
// - 72: 2023-08-23: TS-2023-006 UPnP issue fixed; UPnP can now be used again
2023-09-08 22:27:49 +01:00
// - 73: 2023-09-01: Non-Windows clients expect to receive ClientVersion
2023-09-18 16:52:22 +01:00
// - 74: 2023-09-18: Client understands NodeCapMap
2023-09-07 21:27:50 +01:00
// - 75: 2023-09-12: Client understands NodeAttrDNSForwarderDisableTCPRetries
2023-09-20 21:07:48 +01:00
// - 76: 2023-09-20: Client understands ExitNodeDNSResolvers for IsWireGuardOnly nodes
2023-10-03 19:55:06 +01:00
// - 77: 2023-10-03: Client understands Peers[].SelfNodeV6MasqAddrForThisPeer
2023-10-05 17:49:30 +01:00
// - 78: 2023-10-05: can handle c2n Wake-on-LAN sending
2023-10-17 19:04:44 +01:00
// - 79: 2023-10-05: Client understands UrgentSecurityUpdate in ClientVersion
2023-11-16 20:15:39 +00:00
// - 80: 2023-11-16: can handle c2n GET /tls-cert-status
2023-11-17 17:20:08 +00:00
// - 81: 2023-11-17: MapResponse.PacketFilters (incremental packet filter updates)
2023-12-05 17:23:00 +00:00
// - 82: 2023-12-01: Client understands NodeAttrLinuxMustUseIPTables, NodeAttrLinuxMustUseNfTables, c2n /netfilter-kind
2023-12-18 22:57:03 +00:00
// - 83: 2023-12-18: Client understands DefaultAutoUpdate
2024-01-04 17:29:04 +00:00
// - 84: 2024-01-04: Client understands SeamlessKeyRenewal
2024-01-05 12:06:12 +00:00
// - 85: 2024-01-05: Client understands MaxKeyDuration
2024-01-23 17:37:32 +00:00
// - 86: 2024-01-23: Client understands NodeAttrProbeUDPLifetime
2024-02-11 16:35:02 +00:00
// - 87: 2024-02-11: UserProfile.Groups removed (added in 66)
2024-03-07 19:17:40 +00:00
// - 88: 2024-03-05: Client understands NodeAttrSuggestExitNode
2024-03-23 23:23:59 +00:00
// - 89: 2024-03-23: Client no longer respects deleted PeerChange.Capabilities (use CapMap)
2024-04-04 21:07:58 +01:00
// - 90: 2024-04-03: Client understands PeerCapabilityTaildrive.
2024-04-23 22:11:04 +01:00
// - 91: 2024-04-24: Client understands PeerCapabilityTaildriveSharer.
2024-05-02 20:36:26 +01:00
// - 92: 2024-05-06: Client understands NodeAttrUserDialUseRoutes.
2024-05-06 23:22:17 +01:00
// - 93: 2024-05-06: added support for stateful firewalling.
2024-05-06 19:08:25 +01:00
// - 94: 2024-05-06: Client understands Node.IsJailed.
2024-05-06 23:38:24 +01:00
// - 95: 2024-05-06: Client uses NodeAttrUserDialUseRoutes to change DNS dialing behavior.
2024-05-29 18:51:50 +01:00
// - 96: 2024-05-29: Client understands NodeAttrSSHBehaviorV1
2024-06-10 23:48:01 +01:00
// - 97: 2024-06-06: Client understands NodeAttrDisableSplitDNSWhenNoCustomResolvers
2024-06-14 18:59:40 +01:00
// - 98: 2024-06-13: iOS/tvOS clients may provide serial number as part of posture information
2024-06-11 04:05:15 +01:00
// - 99: 2024-06-14: Client understands NodeAttrDisableLocalDNSOverrideViaNRPT
2024-11-11 16:51:58 +00:00
// - 100: 2024-06-18: Initial support for filtertype.Match.SrcCaps - actually usable in capver 109 (issue #12542)
2024-07-01 17:48:52 +01:00
// - 101: 2024-07-01: Client supports SSH agent forwarding when handling connections with /bin/su
2024-07-09 04:31:16 +01:00
// - 102: 2024-07-12: NodeAttrDisableMagicSockCryptoRouting support
2024-07-26 19:25:55 +01:00
// - 103: 2024-07-24: Client supports NodeAttrDisableCaptivePortalDetection
2024-08-03 16:57:31 +01:00
// - 104: 2024-08-03: SelfNodeV6MasqAddrForThisPeer now works
2024-08-05 23:09:34 +01:00
// - 105: 2024-08-05: Fixed SSH behavior on systems that use busybox (issue #12849)
2024-09-03 17:26:18 +01:00
// - 106: 2024-09-03: fix panic regression from cryptokey routing change (65fe0ba7b5)
2024-10-31 14:45:57 +00:00
// - 107: 2024-10-30: add App Connector to conffile (PR #13942)
2024-11-15 21:14:06 +00:00
// - 108: 2024-11-08: Client sends ServicesHash in Hostinfo, understands c2n GET /vip-services.
2024-11-11 16:51:58 +00:00
// - 109: 2024-11-18: Client supports filtertype.Match.SrcCaps (issue #12542)
const CurrentCapabilityVersion CapabilityVersion = 109
2021-01-05 18:37:15 +00:00
2021-01-21 02:34:50 +00:00
type StableID string
2020-02-05 22:16:58 +00:00
type ID int64
type UserID ID
2020-09-30 01:38:56 +01:00
func ( u UserID ) IsZero ( ) bool {
return u == 0
}
2020-02-05 22:16:58 +00:00
type LoginID ID
2020-10-01 01:55:12 +01:00
func ( u LoginID ) IsZero ( ) bool {
return u == 0
}
2020-02-05 22:16:58 +00:00
type NodeID ID
2020-09-30 01:38:56 +01:00
func ( u NodeID ) IsZero ( ) bool {
return u == 0
}
2021-01-21 02:34:50 +00:00
type StableNodeID StableID
func ( u StableNodeID ) IsZero ( ) bool {
return u == ""
}
2020-02-05 22:16:58 +00:00
// User is an IPN user.
//
// A user can have multiple logins associated with it (e.g. gmail and github oauth).
// (Note: none of our UIs support this yet.)
//
2022-09-25 19:29:55 +01:00
// Some properties are inherited from the logins and can be overridden, such as
2020-02-05 22:16:58 +00:00
// display name and profile picture.
//
// Other properties must be the same for all logins associated with a user.
// In particular: domain. If a user has a "tailscale.io" domain login, they cannot
// have a general gmail address login associated with the user.
type User struct {
ID UserID
LoginName string ` json:"-" ` // not stored, filled from Login // TODO REMOVE
DisplayName string // if non-empty overrides Login field
ProfilePicURL string // if non-empty overrides Login field
Logins [ ] LoginID
Created time . Time
2020-02-27 20:20:29 +00:00
}
2020-02-05 22:16:58 +00:00
type Login struct {
2020-05-03 21:58:39 +01:00
_ structs . Incomparable
2020-02-05 22:16:58 +00:00
ID LoginID
Provider string
LoginName string
DisplayName string
ProfilePicURL string
}
// A UserProfile is display-friendly data for a user.
// It includes the LoginName for display purposes but *not* the Provider.
// It also includes derived data from one of the user's logins.
type UserProfile struct {
ID UserID
2020-06-12 16:17:03 +01:00
LoginName string // "alice@smith.com"; for display purposes only (provider is not listed)
DisplayName string // "Alice Smith"
2020-02-05 22:16:58 +00:00
ProfilePicURL string
2021-04-01 22:44:40 +01:00
// Roles exists for legacy reasons, to keep old macOS clients
// happy. It JSON marshals as [].
Roles emptyStructJSONSlice
2023-07-23 22:48:03 +01:00
}
func ( p * UserProfile ) Equal ( p2 * UserProfile ) bool {
if p == nil && p2 == nil {
return true
}
if p == nil || p2 == nil {
return false
}
return p . ID == p2 . ID &&
p . LoginName == p2 . LoginName &&
p . DisplayName == p2 . DisplayName &&
2024-02-11 16:35:02 +00:00
p . ProfilePicURL == p2 . ProfilePicURL
2021-04-01 22:44:40 +01:00
}
type emptyStructJSONSlice struct { }
var emptyJSONSliceBytes = [ ] byte ( "[]" )
func ( emptyStructJSONSlice ) MarshalJSON ( ) ( [ ] byte , error ) {
return emptyJSONSliceBytes , nil
2020-02-05 22:16:58 +00:00
}
2021-04-01 22:44:40 +01:00
func ( emptyStructJSONSlice ) UnmarshalJSON ( [ ] byte ) error { return nil }
2023-09-18 17:40:14 +01:00
// RawMessage is a raw encoded JSON value. It implements Marshaler and
// Unmarshaler and can be used to delay JSON decoding or precompute a JSON
// encoding.
//
// It is like json.RawMessage but is a string instead of a []byte to better
// portray immutable data.
type RawMessage string
// MarshalJSON returns m as the JSON encoding of m.
func ( m RawMessage ) MarshalJSON ( ) ( [ ] byte , error ) {
if m == "" {
return [ ] byte ( "null" ) , nil
}
return [ ] byte ( m ) , nil
}
// UnmarshalJSON sets *m to a copy of data.
func ( m * RawMessage ) UnmarshalJSON ( data [ ] byte ) error {
if m == nil {
return errors . New ( "RawMessage: UnmarshalJSON on nil pointer" )
}
* m = RawMessage ( data )
return nil
}
2024-06-10 16:36:22 +01:00
// MarshalCapJSON returns a capability rule in RawMessage string format.
func MarshalCapJSON [ T any ] ( capRule T ) ( RawMessage , error ) {
bs , err := json . Marshal ( capRule )
if err != nil {
return "" , fmt . Errorf ( "error marshalling capability rule: %w" , err )
}
return RawMessage ( string ( bs ) ) , nil
}
2020-02-05 22:16:58 +00:00
type Node struct {
2021-01-21 02:34:50 +00:00
ID NodeID
StableID StableNodeID
2023-03-13 22:22:42 +00:00
// Name is the FQDN of the node.
// It is also the MagicDNS name for the node.
// It has a trailing dot.
// e.g. "host.tail-scale.ts.net."
Name string
2021-01-05 21:52:33 +00:00
2023-08-19 23:06:23 +01:00
// User is the user who created the node. If ACL tags are in use for the
// node then it doesn't reflect the ACL identity that the node is running
// as.
2021-01-05 21:52:33 +00:00
User UserID
// Sharer, if non-zero, is the user who shared this node, if different than User.
Sharer UserID ` json:",omitempty" `
2022-08-12 20:34:25 +01:00
Key key . NodePublic
2023-01-12 17:58:06 +00:00
KeyExpiry time . Time // the zero value if this node does not expire
2022-08-12 20:34:25 +01:00
KeySignature tkatype . MarshaledSignature ` json:",omitempty" `
Machine key . MachinePublic
DiscoKey key . DiscoPublic
2023-10-01 05:05:02 +01:00
Addresses [ ] netip . Prefix // IP addresses of this Node directly
AllowedIPs [ ] netip . Prefix // range of IP addresses to route to this node
Endpoints [ ] netip . AddrPort ` json:",omitempty" ` // IP+port (public via STUN, and local LANs)
2023-07-22 15:14:02 +01:00
// DERP is this node's home DERP region ID integer, but shoved into an
// IP:port string for legacy reasons. The IP address is always "127.3.3.40"
// (a loopback address (127) followed by the digits over the letters DERP on
// a QWERTY keyboard (3.3.40)). The "port number" is the home DERP region ID
// integer.
//
// TODO(bradfitz): simplify this legacy mess; add a new HomeDERPRegionID int
// field behind a new capver bump.
DERP string ` json:",omitempty" ` // DERP-in-IP:port ("127.3.3.40:N") endpoint
Hostinfo HostinfoView
Created time . Time
Cap CapabilityVersion ` json:",omitempty" ` // if non-zero, the node's capability version; old servers might not send
2021-04-16 00:03:59 +01:00
2021-10-20 22:26:31 +01:00
// Tags are the list of ACL tags applied to this node.
// Tags take the form of `tag:<value>` where value starts
// with a letter and only contains alphanumerics and dashes `-`.
// Some valid tag examples:
// `tag:prod`
// `tag:database`
// `tag:lab-1`
Tags [ ] string ` json:",omitempty" `
2021-07-27 16:01:29 +01:00
// PrimaryRoutes are the routes from AllowedIPs that this node
// is currently the primary subnet router for, as determined
// by the control plane. It does not include the self address
// values from Addresses that are in AllowedIPs.
all: convert more code to use net/netip directly
perl -i -npe 's,netaddr.IPPrefixFrom,netip.PrefixFrom,' $(git grep -l -F netaddr.)
perl -i -npe 's,netaddr.IPPortFrom,netip.AddrPortFrom,' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPrefix,netip.Prefix,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPort,netip.AddrPort,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IP\b,netip.Addr,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPv6Raw\b,netip.AddrFrom16,g' $(git grep -l -F netaddr. )
goimports -w .
Then delete some stuff from the net/netaddr shim package which is no
longer neeed.
Updates #5162
Change-Id: Ia7a86893fe21c7e3ee1ec823e8aba288d4566cd8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-07-26 05:14:09 +01:00
PrimaryRoutes [ ] netip . Prefix ` json:",omitempty" `
2021-07-27 16:01:29 +01:00
2021-04-16 00:03:59 +01:00
// LastSeen is when the node was last online. It is not
// updated when Online is true. It is nil if the current
// node doesn't have permission to know, or the node
// has never been online.
LastSeen * time . Time ` json:",omitempty" `
// Online is whether the node is currently connected to the
// coordination server. A value of nil means unknown, or the
// current node doesn't have permission to know.
Online * bool ` json:",omitempty" `
2020-02-05 22:16:58 +00:00
2020-11-25 18:27:01 +00:00
MachineAuthorized bool ` json:",omitempty" ` // TODO(crawshaw): replace with MachineStatus
2021-01-27 16:50:31 +00:00
2021-04-01 22:03:34 +01:00
// Capabilities are capabilities that the node has.
// They're free-form strings, but should be in the form of URLs/URIs
// such as:
// "https://tailscale.com/cap/is-admin"
2021-04-16 18:57:46 +01:00
// "https://tailscale.com/cap/file-sharing"
2023-09-18 16:52:22 +01:00
//
2024-03-23 23:23:59 +00:00
// Deprecated: use CapMap instead. See https://github.com/tailscale/tailscale/issues/11508
2023-09-06 18:17:25 +01:00
Capabilities [ ] NodeCapability ` json:",omitempty" `
2021-04-01 22:03:34 +01:00
2023-09-18 16:52:22 +01:00
// CapMap is a map of capabilities to their optional argument/data values.
//
// It is valid for a capability to not have any argument/data values; such
// capabilities can be tested for using the HasCap method. These type of
// capabilities are used to indicate that a node has a capability, but there
// is no additional data associated with it. These were previously
// represented by the Capabilities field, but can now be represented by
// CapMap with an empty value.
//
// See NodeCapability for more information on keys.
2024-04-16 15:51:40 +01:00
//
// Metadata about nodes can be transmitted in 3 ways:
// 1. MapResponse.Node.CapMap describes attributes that affect behavior for
// this node, such as which features have been enabled through the admin
// panel and any associated configuration details.
// 2. MapResponse.PacketFilter(s) describes access (both IP and application
// based) that should be granted to peers.
// 3. MapResponse.Peers[].CapMap describes attributes regarding a peer node,
// such as which features the peer supports or if that peer is preferred
// for a particular task vs other peers that could also be chosen.
2023-09-18 16:52:22 +01:00
CapMap NodeCapMap ` json:",omitempty" `
2022-11-02 20:13:26 +00:00
// UnsignedPeerAPIOnly means that this node is not signed nor subject to TKA
// restrictions. However, in exchange for that privilege, it does not get
// network access. It can only access this node's peerapi, which may not let
// it do anything. It is the tailscaled client's job to double-check the
// MapResponse's PacketFilter to verify that its AllowedIPs will not be
// accepted by the packet filter.
UnsignedPeerAPIOnly bool ` json:",omitempty" `
2021-01-27 16:50:31 +00:00
// The following three computed fields hold the various names that can
// be used for this node in UIs. They are populated from controlclient
// (not from control) by calling node.InitDisplayNames. These can be
// used directly or accessed via node.DisplayName or node.DisplayNames.
ComputedName string ` json:",omitempty" ` // MagicDNS base name (for normal non-shared-in nodes), FQDN (without trailing dot, for shared-in nodes), or Hostname (if no MagicDNS)
computedHostIfDifferent string // hostname, if different than ComputedName, otherwise empty
ComputedNameWithHost string ` json:",omitempty" ` // either "ComputedName" or "ComputedName (computedHostIfDifferent)", if computedHostIfDifferent is set
2022-09-22 20:49:24 +01:00
// DataPlaneAuditLogID is the per-node logtail ID used for data plane audit logging.
DataPlaneAuditLogID string ` json:",omitempty" `
2023-01-10 17:55:43 +00:00
// Expired is whether this node's key has expired. Control may send
// this; clients are only allowed to set this from false to true. On
// the client, this is calculated client-side based on a timestamp sent
// from control, to avoid clock skew issues.
Expired bool ` json:",omitempty" `
2023-03-03 00:05:07 +00:00
// SelfNodeV4MasqAddrForThisPeer is the IPv4 that this peer knows the current node as.
// It may be empty if the peer knows the current node by its native
// IPv4 address.
// This field is only populated in a MapResponse for peers and not
// for the current node.
//
// If set, it should be used to masquerade traffic originating from the
// current node to this peer. The masquerade address is only relevant
// for this peer and not for other peers.
//
// This only applies to traffic originating from the current node to the
// peer or any of its subnets. Traffic originating from subnet routes will
// not be masqueraded (e.g. in case of --snat-subnet-routes).
2023-04-13 18:12:31 +01:00
SelfNodeV4MasqAddrForThisPeer * netip . Addr ` json:",omitempty" `
2023-04-06 01:28:28 +01:00
2023-09-19 01:03:53 +01:00
// SelfNodeV6MasqAddrForThisPeer is the IPv6 that this peer knows the current node as.
// It may be empty if the peer knows the current node by its native
// IPv6 address.
// This field is only populated in a MapResponse for peers and not
// for the current node.
//
// If set, it should be used to masquerade traffic originating from the
// current node to this peer. The masquerade address is only relevant
// for this peer and not for other peers.
//
// This only applies to traffic originating from the current node to the
// peer or any of its subnets. Traffic originating from subnet routes will
// not be masqueraded (e.g. in case of --snat-subnet-routes).
SelfNodeV6MasqAddrForThisPeer * netip . Addr ` json:",omitempty" `
2023-04-06 01:28:28 +01:00
// IsWireGuardOnly indicates that this is a non-Tailscale WireGuard peer, it
// is not expected to speak Disco or DERP, and it must have Endpoints in
2023-09-14 17:58:36 +01:00
// order to be reachable.
2023-04-06 01:28:28 +01:00
IsWireGuardOnly bool ` json:",omitempty" `
2023-09-14 18:04:31 +01:00
2024-05-06 19:08:25 +01:00
// IsJailed indicates that this node is jailed and should not be allowed
// initiate connections, however outbound connections to it should still be
// allowed.
IsJailed bool ` json:",omitempty" `
2023-09-14 18:04:31 +01:00
// ExitNodeDNSResolvers is the list of DNS servers that should be used when this
// node is marked IsWireGuardOnly and being used as an exit node.
ExitNodeDNSResolvers [ ] * dnstype . Resolver ` json:",omitempty" `
2020-02-05 22:16:58 +00:00
}
2023-09-18 17:36:26 +01:00
// HasCap reports whether the node has the given capability.
2023-09-18 16:52:22 +01:00
// It is safe to call on an invalid NodeView.
2023-09-18 17:36:26 +01:00
func ( v NodeView ) HasCap ( cap NodeCapability ) bool {
return v . ж . HasCap ( cap )
}
// HasCap reports whether the node has the given capability.
2023-09-18 16:52:22 +01:00
// It is safe to call on a nil Node.
2023-09-18 17:36:26 +01:00
func ( v * Node ) HasCap ( cap NodeCapability ) bool {
2024-03-23 23:23:59 +00:00
return v != nil && v . CapMap . Contains ( cap )
2023-09-18 17:36:26 +01:00
}
2021-01-27 16:50:31 +00:00
// DisplayName returns the user-facing name for a node which should
// be shown in client UIs.
//
// Parameter forOwner specifies whether the name is requested by
// the owner of the node. When forOwner is false, the hostname is
// never included in the return value.
//
2022-09-25 19:29:55 +01:00
// Return value is either "Name" or "Name (Hostname)", where
2021-01-27 16:50:31 +00:00
// Name is the node's MagicDNS base name (for normal non-shared-in
// nodes), FQDN (without trailing dot, for shared-in nodes), or
// Hostname (if no MagicDNS). Hostname is only included in the
// return value if it varies from Name and forOwner is provided true.
//
// DisplayName is only valid if InitDisplayNames has been called.
func ( n * Node ) DisplayName ( forOwner bool ) string {
if forOwner {
return n . ComputedNameWithHost
2021-01-25 22:41:39 +00:00
}
2021-01-27 16:50:31 +00:00
return n . ComputedName
}
// DisplayName returns the decomposed user-facing name for a node.
//
// Parameter forOwner specifies whether the name is requested by
// the owner of the node. When forOwner is false, hostIfDifferent
// is always returned empty.
//
// Return value name is the node's primary name, populated with the
// node's MagicDNS base name (for normal non-shared-in nodes), FQDN
// (without trailing dot, for shared-in nodes), or Hostname (if no
// MagicDNS).
//
// Return value hostIfDifferent, when non-empty, is the node's
// hostname. hostIfDifferent is only populated when the hostname
// varies from name and forOwner is provided as true.
//
// DisplayNames is only valid if InitDisplayNames has been called.
func ( n * Node ) DisplayNames ( forOwner bool ) ( name , hostIfDifferent string ) {
if forOwner {
return n . ComputedName , n . computedHostIfDifferent
2021-01-25 22:41:39 +00:00
}
2021-01-27 16:50:31 +00:00
return n . ComputedName , ""
}
2023-03-13 06:52:17 +00:00
// IsTagged reports whether the node has any tags.
func ( n * Node ) IsTagged ( ) bool {
return len ( n . Tags ) > 0
}
2023-08-19 23:06:23 +01:00
// SharerOrUser Sharer if set, else User.
func ( n * Node ) SharerOrUser ( ) UserID {
2024-02-07 22:27:29 +00:00
return cmp . Or ( n . Sharer , n . User )
2023-08-19 23:06:23 +01:00
}
2023-08-18 15:57:44 +01:00
// IsTagged reports whether the node has any tags.
func ( n NodeView ) IsTagged ( ) bool { return n . ж . IsTagged ( ) }
// DisplayName wraps Node.DisplayName.
func ( n NodeView ) DisplayName ( forOwner bool ) string { return n . ж . DisplayName ( forOwner ) }
2023-08-19 23:06:23 +01:00
// SharerOrUser wraps Node.SharerOrUser.
func ( n NodeView ) SharerOrUser ( ) UserID { return n . ж . SharerOrUser ( ) }
2021-01-27 16:50:31 +00:00
// InitDisplayNames computes and populates n's display name
// fields: n.ComputedName, n.computedHostIfDifferent, and
// n.ComputedNameWithHost.
func ( n * Node ) InitDisplayNames ( networkMagicDNSSuffix string ) {
2021-02-18 22:15:38 +00:00
name := dnsname . TrimSuffix ( n . Name , networkMagicDNSSuffix )
2022-02-15 16:19:44 +00:00
var hostIfDifferent string
if n . Hostinfo . Valid ( ) {
hostIfDifferent = dnsname . SanitizeHostname ( n . Hostinfo . Hostname ( ) )
}
2021-01-27 16:50:31 +00:00
if strings . EqualFold ( name , hostIfDifferent ) {
hostIfDifferent = ""
}
if name == "" {
if hostIfDifferent != "" {
name = hostIfDifferent
hostIfDifferent = ""
} else {
name = n . Key . String ( )
}
}
var nameWithHost string
if hostIfDifferent != "" {
nameWithHost = fmt . Sprintf ( "%s (%s)" , name , hostIfDifferent )
} else {
nameWithHost = name
}
n . ComputedName = name
n . computedHostIfDifferent = hostIfDifferent
n . ComputedNameWithHost = nameWithHost
2021-01-25 22:41:39 +00:00
}
2020-02-05 22:16:58 +00:00
type MachineStatus int
const (
MachineUnknown = MachineStatus ( iota )
MachineUnauthorized // server has yet to approve
MachineAuthorized // server has approved
MachineInvalid // server has explicitly rejected this machine key
)
2023-09-02 02:15:19 +01:00
func ( m MachineStatus ) AppendText ( b [ ] byte ) ( [ ] byte , error ) {
return append ( b , m . String ( ) ... ) , nil
}
2020-02-05 22:16:58 +00:00
func ( m MachineStatus ) MarshalText ( ) ( [ ] byte , error ) {
return [ ] byte ( m . String ( ) ) , nil
}
func ( m * MachineStatus ) UnmarshalText ( b [ ] byte ) error {
switch string ( b ) {
case "machine-unknown" :
* m = MachineUnknown
case "machine-unauthorized" :
* m = MachineUnauthorized
case "machine-authorized" :
* m = MachineAuthorized
case "machine-invalid" :
* m = MachineInvalid
default :
var val int
if _ , err := fmt . Sscanf ( string ( b ) , "machine-unknown(%d)" , & val ) ; err != nil {
* m = MachineStatus ( val )
} else {
* m = MachineUnknown
}
}
return nil
}
func ( m MachineStatus ) String ( ) string {
switch m {
case MachineUnknown :
return "machine-unknown"
case MachineUnauthorized :
return "machine-unauthorized"
case MachineAuthorized :
return "machine-authorized"
case MachineInvalid :
return "machine-invalid"
default :
return fmt . Sprintf ( "machine-unknown(%d)" , int ( m ) )
}
}
2020-11-11 03:26:23 +00:00
func isNum ( b byte ) bool {
return b >= '0' && b <= '9'
}
func isAlpha ( b byte ) bool {
return ( b >= 'A' && b <= 'Z' ) || ( b >= 'a' && b <= 'z' )
}
2020-05-01 06:01:27 +01:00
2020-11-04 00:10:23 +00:00
// CheckTag validates tag for use as an ACL tag.
2020-05-01 06:01:27 +01:00
// For now we allow only ascii alphanumeric tags, and they need to start
// with a letter. No unicode shenanigans allowed, and we reserve punctuation
// marks other than '-' for a possible future URI scheme.
//
// Because we're ignoring unicode entirely, we can treat utf-8 as a series of
// bytes. Anything >= 128 is disqualified anyway.
//
// We might relax these rules later.
func CheckTag ( tag string ) error {
2024-05-31 22:01:05 +01:00
var ok bool
tag , ok = strings . CutPrefix ( tag , "tag:" )
if ! ok {
2020-05-01 06:01:27 +01:00
return errors . New ( "tags must start with 'tag:'" )
}
if tag == "" {
return errors . New ( "tag names must not be empty" )
}
2020-11-11 03:26:23 +00:00
if ! isAlpha ( tag [ 0 ] ) {
return errors . New ( "tag names must start with a letter, after 'tag:'" )
2020-10-28 14:59:57 +00:00
}
2020-11-11 03:26:23 +00:00
for _ , b := range [ ] byte ( tag ) {
if ! isNum ( b ) && ! isAlpha ( b ) && b != '-' {
2020-05-01 06:01:27 +01:00
return errors . New ( "tag names can only contain numbers, letters, or dashes" )
}
}
2020-11-11 03:26:23 +00:00
2020-05-01 06:01:27 +01:00
return nil
}
2024-10-17 00:08:06 +01:00
// CheckServiceName validates svc for use as a service name.
// We only allow valid DNS labels, since the expectation is that these will be
// used as parts of domain names.
func CheckServiceName ( svc string ) error {
var ok bool
svc , ok = strings . CutPrefix ( svc , "svc:" )
if ! ok {
return errors . New ( "services must start with 'svc:'" )
}
if svc == "" {
return errors . New ( "service names must not be empty" )
}
return dnsname . ValidLabel ( svc )
}
2020-11-04 00:10:23 +00:00
// CheckRequestTags checks that all of h.RequestTags are valid.
func ( h * Hostinfo ) CheckRequestTags ( ) error {
if h == nil {
return nil
}
for _ , tag := range h . RequestTags {
2020-11-04 00:19:20 +00:00
if err := CheckTag ( tag ) ; err != nil {
return fmt . Errorf ( "tag(%#v): %w" , tag , err )
2020-11-04 00:10:23 +00:00
}
}
return nil
}
2021-11-30 01:19:17 +00:00
// ServiceProto is a service type. It's usually
// TCP ("tcp") or UDP ("udp"), but it can also have
// meta service values as defined in Service.Proto.
2020-02-05 22:16:58 +00:00
type ServiceProto string
const (
2023-11-10 02:00:56 +00:00
TCP = ServiceProto ( "tcp" )
UDP = ServiceProto ( "udp" )
PeerAPI4 = ServiceProto ( "peerapi4" )
PeerAPI6 = ServiceProto ( "peerapi6" )
PeerAPIDNS = ServiceProto ( "peerapi-dns-proxy" )
2020-02-05 22:16:58 +00:00
)
2024-10-03 03:54:02 +01:00
// IsKnownServiceProto checks whether sp represents a known-valid value of
// ServiceProto.
func IsKnownServiceProto ( sp ServiceProto ) bool {
switch sp {
case TCP , UDP , PeerAPI4 , PeerAPI6 , PeerAPIDNS , ServiceProto ( "egg" ) :
return true
}
return false
}
2021-11-30 01:19:17 +00:00
// Service represents a service running on a node.
2020-02-05 22:16:58 +00:00
type Service struct {
2021-11-30 01:19:17 +00:00
_ structs . Incomparable
// Proto is the type of service. It's usually the constant TCP
// or UDP ("tcp" or "udp"), but it can also be one of the
// following meta service values:
//
// * "peerapi4": peerapi is available on IPv4; Port is the
// port number that the peerapi is running on the
// node's Tailscale IPv4 address.
// * "peerapi6": peerapi is available on IPv6; Port is the
// port number that the peerapi is running on the
// node's Tailscale IPv6 address.
2023-11-01 18:38:44 +00:00
// * "peerapi-dns-proxy": the local peerapi service supports
2021-11-30 01:19:17 +00:00
// being a DNS proxy (when the node is an exit
2024-05-28 23:22:24 +01:00
// node). For this service, the Port number must only be 1.
2021-11-30 01:19:17 +00:00
Proto ServiceProto
// Port is the port number.
//
2024-05-28 23:22:24 +01:00
// For Proto "peerapi-dns", it must be 1.
2021-11-30 01:19:17 +00:00
Port uint16
// Description is the textual description of the service,
// usually the process name that's running.
Description string ` json:",omitempty" `
2020-02-05 22:16:58 +00:00
// TODO(apenwarr): allow advertising services on subnet IPs?
// TODO(apenwarr): add "tags" here for each service?
}
2023-06-16 18:04:07 +01:00
// Location represents geographical location data about a
// Tailscale host. Location is optional and only set if
// explicitly declared by a node.
type Location struct {
2023-06-27 19:00:10 +01:00
Country string ` json:",omitempty" ` // User friendly country name, with proper capitalization ("Canada")
CountryCode string ` json:",omitempty" ` // ISO 3166-1 alpha-2 in upper case ("CA")
City string ` json:",omitempty" ` // User friendly city name, with proper capitalization ("Squamish")
// CityCode is a short code representing the city in upper case.
// CityCode is used to disambiguate a city from another location
// with the same city name. It uniquely identifies a particular
// geographical location, within the tailnet.
// IATA, ICAO or ISO 3166-2 codes are recommended ("YSE")
CityCode string ` json:",omitempty" `
2024-02-27 20:02:06 +00:00
// Latitude, Longitude are optional geographical coordinates of the node, in degrees.
// No particular accuracy level is promised; the coordinates may simply be the center of the city or country.
Latitude float64 ` json:",omitempty" `
Longitude float64 ` json:",omitempty" `
2023-06-27 19:00:10 +01:00
// Priority determines the order of use of an exit node when a
// location based preference matches more than one exit node,
// the node with the highest priority wins. Nodes of equal
// probability may be selected arbitrarily.
//
2023-06-16 18:04:07 +01:00
// A value of 0 means the exit node does not have a priority
// preference. A negative int is not allowed.
Priority int ` json:",omitempty" `
}
2020-02-25 18:04:20 +00:00
// Hostinfo contains a summary of a Tailscale host.
//
// Because it contains pointers (slices), this type should not be used
// as a value type.
2020-02-05 22:16:58 +00:00
type Hostinfo struct {
2022-09-11 18:57:18 +01:00
IPNVersion string ` json:",omitempty" ` // version of this code (in version.Long format)
FrontendLogID string ` json:",omitempty" ` // logtail ID of frontend instance
BackendLogID string ` json:",omitempty" ` // logtail ID of backend instance
OS string ` json:",omitempty" ` // operating system the client runs on (a version.OS value)
// OSVersion is the version of the OS, if available.
//
// For Android, it's like "10", "11", "12", etc. For iOS and macOS it's like
// "15.6.1" or "12.4.0". For Windows it's like "10.0.19044.1889". For
// FreeBSD it's like "12.3-STABLE".
//
// For Linux, prior to Tailscale 1.32, we jammed a bunch of fields into this
// string on Linux, like "Debian 10.4; kernel=xxx; container; env=kn" and so
// on. As of Tailscale 1.32, this is simply the kernel version on Linux, like
// "5.10.0-17-amd64".
OSVersion string ` json:",omitempty" `
2024-10-15 19:38:11 +01:00
Container opt . Bool ` json:",omitempty" ` // best-effort whether the client is running in a container
2022-09-11 18:57:18 +01:00
Env string ` json:",omitempty" ` // a hostinfo.EnvType in string form
Distro string ` json:",omitempty" ` // "debian", "ubuntu", "nixos", ...
DistroVersion string ` json:",omitempty" ` // "20.04", ...
DistroCodeName string ` json:",omitempty" ` // "jammy", "bullseye", ...
2023-02-27 17:58:54 +00:00
// App is used to disambiguate Tailscale clients that run using tsnet.
App string ` json:",omitempty" ` // "k8s-operator", "golinks", ...
2022-08-30 20:30:55 +01:00
Desktop opt . Bool ` json:",omitempty" ` // if a desktop was detected on Linux
Package string ` json:",omitempty" ` // Tailscale package to disambiguate ("choco", "appstore", etc; "" for unknown)
DeviceModel string ` json:",omitempty" ` // mobile phone model ("Pixel 3a", "iPhone12,3")
2023-01-29 22:04:40 +00:00
PushDeviceToken string ` json:",omitempty" ` // macOS/iOS APNs device token for notifications (and Android in the future)
2022-08-30 20:30:55 +01:00
Hostname string ` json:",omitempty" ` // name of the host the client runs on
ShieldsUp bool ` json:",omitempty" ` // indicates whether the host is blocking incoming connections
ShareeNode bool ` json:",omitempty" ` // indicates this node exists in netmap because it's owned by a shared-to user
2022-09-13 15:09:57 +01:00
NoLogsNoSupport bool ` json:",omitempty" ` // indicates that the user has opted out of sending logs and support
2022-11-16 04:30:53 +00:00
WireIngress bool ` json:",omitempty" ` // indicates that the node wants the option to receive ingress connections
2023-01-21 18:04:43 +00:00
AllowsUpdate bool ` json:",omitempty" ` // indicates that the node has opted-in to admin-console-drive remote updates
2023-01-22 18:16:15 +00:00
Machine string ` json:",omitempty" ` // the current host's machine type (uname -m)
GoArch string ` json:",omitempty" ` // GOARCH value (of the built binary)
GoArchVar string ` json:",omitempty" ` // GOARM, GOAMD64, etc (of the built binary)
2022-08-30 20:30:55 +01:00
GoVersion string ` json:",omitempty" ` // Go version binary was built with
RoutableIPs [ ] netip . Prefix ` json:",omitempty" ` // set of IP ranges this client can route
RequestTags [ ] string ` json:",omitempty" ` // set of ACL tags this node wants to claim
2023-10-05 17:49:30 +01:00
WoLMACs [ ] string ` json:",omitempty" ` // MAC address(es) to send Wake-on-LAN packets to wake this node (lowercase hex w/ colons)
2022-08-30 20:30:55 +01:00
Services [ ] Service ` json:",omitempty" ` // services advertised by this machine
NetInfo * NetInfo ` json:",omitempty" `
SSH_HostKeys [ ] string ` json:"sshHostKeys,omitempty" ` // if advertised
Cloud string ` json:",omitempty" `
Userspace opt . Bool ` json:",omitempty" ` // if the client is running in userspace (netstack) mode
UserspaceRouter opt . Bool ` json:",omitempty" ` // if the client's subnet router is running in userspace (netstack) mode
2023-11-10 02:00:56 +00:00
AppConnector opt . Bool ` json:",omitempty" ` // if the client is running the app-connector service
2024-11-15 21:14:06 +00:00
ServicesHash string ` json:",omitempty" ` // opaque hash of the most recent list of tailnet services, change in hash indicates config should be fetched via c2n
2020-02-05 22:16:58 +00:00
2023-06-16 18:04:07 +01:00
// Location represents geographical location data about a
// Tailscale host. Location is optional and only set if
// explicitly declared by a node.
Location * Location ` json:",omitempty" `
2020-02-05 22:16:58 +00:00
// NOTE: any new fields containing pointers in this type
2020-11-23 14:28:32 +00:00
// require changes to Hostinfo.Equal.
2020-02-05 22:16:58 +00:00
}
2024-11-15 21:14:06 +00:00
// VIPService represents a service created on a tailnet from the
// perspective of a node providing that service. These services
// have an virtual IP (VIP) address pair distinct from the node's IPs.
type VIPService struct {
// Name is the name of the service, of the form `svc:dns-label`.
// See CheckServiceName for a validation func.
// Name uniquely identifies a service on a particular tailnet,
// and so also corresponds uniquely to the pair of IP addresses
// belonging to the VIP service.
Name string
// Ports specify which ProtoPorts are made available by this node
// on the service's IPs.
Ports [ ] ProtoPortRange
// Active specifies whether new requests for the service should be
// sent to this node by control.
Active bool
}
2022-06-07 19:50:08 +01:00
// TailscaleSSHEnabled reports whether or not this node is acting as a
// Tailscale SSH server.
func ( hi * Hostinfo ) TailscaleSSHEnabled ( ) bool {
// Currently, we use `SSH_HostKeys` as a proxy for this. However, we may later
// include non-Tailscale host keys, and will add a separate flag to rely on.
return hi != nil && len ( hi . SSH_HostKeys ) > 0
}
2022-06-08 19:55:43 +01:00
func ( v HostinfoView ) TailscaleSSHEnabled ( ) bool { return v . ж . TailscaleSSHEnabled ( ) }
2022-11-20 18:22:54 +00:00
// TailscaleFunnelEnabled reports whether or not this node has explicitly
// enabled Funnel.
func ( hi * Hostinfo ) TailscaleFunnelEnabled ( ) bool {
return hi != nil && hi . WireIngress
}
func ( v HostinfoView ) TailscaleFunnelEnabled ( ) bool { return v . ж . TailscaleFunnelEnabled ( ) }
2020-02-25 22:05:17 +00:00
// NetInfo contains information about the host's network state.
type NetInfo struct {
// MappingVariesByDestIP says whether the host's NAT mappings
// vary based on the destination IP.
MappingVariesByDestIP opt . Bool
2020-02-28 22:14:02 +00:00
// HairPinning is their router does hairpinning.
// It reports true even if there's no NAT involved.
HairPinning opt . Bool
2022-07-19 00:56:10 +01:00
// WorkingIPv6 is whether the host has IPv6 internet connectivity.
2020-02-25 22:05:17 +00:00
WorkingIPv6 opt . Bool
2022-07-19 00:56:10 +01:00
// OSHasIPv6 is whether the OS supports IPv6 at all, regardless of
// whether IPv6 internet connectivity is available.
OSHasIPv6 opt . Bool
// WorkingUDP is whether the host has UDP internet connectivity.
2020-02-25 22:05:17 +00:00
WorkingUDP opt . Bool
2022-08-04 22:10:13 +01:00
// WorkingICMPv4 is whether ICMPv4 works.
// Empty means not checked.
WorkingICMPv4 opt . Bool
2021-03-09 23:09:10 +00:00
// HavePortMap is whether we have an existing portmap open
// (UPnP, PMP, or PCP).
HavePortMap bool ` json:",omitempty" `
2020-07-06 21:51:17 +01:00
// UPnP is whether UPnP appears present on the LAN.
// Empty means not checked.
UPnP opt . Bool
// PMP is whether NAT-PMP appears present on the LAN.
// Empty means not checked.
PMP opt . Bool
// PCP is whether PCP appears present on the LAN.
// Empty means not checked.
PCP opt . Bool
2023-07-22 15:14:02 +01:00
// PreferredDERP is this node's preferred (home) DERP region ID.
// This is where the node expects to be contacted to begin a
// peer-to-peer connection. The node might be be temporarily
// connected to multiple DERP servers (to speak to other nodes
// that are located elsewhere) but PreferredDERP is the region ID
// that the node subscribes to traffic at.
2020-03-04 06:21:56 +00:00
// Zero means disconnected or unknown.
PreferredDERP int
// LinkType is the current link type, if known.
2020-10-19 16:30:36 +01:00
LinkType string ` json:",omitempty" ` // "wired", "wifi", "mobile" (LTE, 4G, 3G, etc)
2020-03-04 06:21:56 +00:00
2020-02-25 22:05:17 +00:00
// DERPLatency is the fastest recent time to reach various
2020-05-17 17:51:38 +01:00
// DERP STUN servers, in seconds. The map key is the
// "regionID-v4" or "-v6"; it was previously the DERP server's
// STUN host:port.
2020-02-25 22:05:17 +00:00
//
// This should only be updated rarely, or when there's a
// material change, as any change here also gets uploaded to
// the control plane.
DERPLatency map [ string ] float64 ` json:",omitempty" `
2020-03-04 06:21:56 +00:00
2023-08-20 04:02:29 +01:00
// FirewallMode encodes both which firewall mode was selected and why.
// It is Linux-specific (at least as of 2023-08-19) and is meant to help
// debug iptables-vs-nftables issues. The string is of the form
// "{nft,ift}-REASON", like "nft-forced" or "ipt-default". Empty means
// either not Linux or a configuration in which the host firewall rules
// are not managed by tailscaled.
2023-08-15 22:52:04 +01:00
FirewallMode string ` json:",omitempty" `
2020-11-23 14:28:32 +00:00
// Update BasicallyEqual when adding fields.
2020-03-04 06:21:56 +00:00
}
2020-03-13 05:29:47 +00:00
func ( ni * NetInfo ) String ( ) string {
2020-03-23 02:34:09 +00:00
if ni == nil {
return "NetInfo(nil)"
}
2023-08-15 22:52:04 +01:00
return fmt . Sprintf ( "NetInfo{varies=%v hairpin=%v ipv6=%v ipv6os=%v udp=%v icmpv4=%v derp=#%v portmap=%v link=%q firewallmode=%q}" ,
2020-03-13 05:29:47 +00:00
ni . MappingVariesByDestIP , ni . HairPinning , ni . WorkingIPv6 ,
2022-10-21 20:13:49 +01:00
ni . OSHasIPv6 , ni . WorkingUDP , ni . WorkingICMPv4 ,
2023-08-15 22:52:04 +01:00
ni . PreferredDERP , ni . portMapSummary ( ) , ni . LinkType , ni . FirewallMode )
2020-07-06 21:51:17 +01:00
}
func ( ni * NetInfo ) portMapSummary ( ) string {
2021-03-09 23:09:10 +00:00
if ! ni . HavePortMap && ni . UPnP == "" && ni . PMP == "" && ni . PCP == "" {
2020-07-08 02:54:41 +01:00
return "?"
2020-07-06 21:51:17 +01:00
}
2021-03-09 23:09:10 +00:00
var prefix string
if ni . HavePortMap {
prefix = "active-"
}
return prefix + conciseOptBool ( ni . UPnP , "U" ) + conciseOptBool ( ni . PMP , "M" ) + conciseOptBool ( ni . PCP , "C" )
2020-07-06 21:51:17 +01:00
}
func conciseOptBool ( b opt . Bool , trueVal string ) string {
if b == "" {
return "_"
}
v , ok := b . Get ( )
if ! ok {
return "x"
}
if v {
return trueVal
}
return ""
2020-03-13 05:29:47 +00:00
}
2020-03-04 06:21:56 +00:00
// BasicallyEqual reports whether ni and ni2 are basically equal, ignoring
2020-05-17 17:51:38 +01:00
// changes in DERP ServerLatency & RegionLatency.
2020-03-04 06:21:56 +00:00
func ( ni * NetInfo ) BasicallyEqual ( ni2 * NetInfo ) bool {
if ( ni == nil ) != ( ni2 == nil ) {
return false
}
if ni == nil {
return true
}
return ni . MappingVariesByDestIP == ni2 . MappingVariesByDestIP &&
ni . HairPinning == ni2 . HairPinning &&
ni . WorkingIPv6 == ni2 . WorkingIPv6 &&
2022-07-19 00:56:10 +01:00
ni . OSHasIPv6 == ni2 . OSHasIPv6 &&
2020-03-04 06:21:56 +00:00
ni . WorkingUDP == ni2 . WorkingUDP &&
2022-08-04 22:10:13 +01:00
ni . WorkingICMPv4 == ni2 . WorkingICMPv4 &&
2021-03-09 23:09:10 +00:00
ni . HavePortMap == ni2 . HavePortMap &&
2020-07-06 21:51:17 +01:00
ni . UPnP == ni2 . UPnP &&
ni . PMP == ni2 . PMP &&
ni . PCP == ni2 . PCP &&
2020-03-04 06:21:56 +00:00
ni . PreferredDERP == ni2 . PreferredDERP &&
2023-08-15 22:52:04 +01:00
ni . LinkType == ni2 . LinkType &&
ni . FirewallMode == ni2 . FirewallMode
2020-02-25 22:05:17 +00:00
}
2020-02-18 03:33:01 +00:00
// Equal reports whether h and h2 are equal.
func ( h * Hostinfo ) Equal ( h2 * Hostinfo ) bool {
2020-07-23 18:41:54 +01:00
if h == nil && h2 == nil {
return true
}
if ( h == nil ) != ( h2 == nil ) {
return false
}
2020-02-18 03:33:01 +00:00
return reflect . DeepEqual ( h , h2 )
}
2021-12-22 23:04:44 +00:00
// HowUnequal returns a list of paths through Hostinfo where h and h2 differ.
// If they differ in nil-ness, the path is "nil", otherwise the path is like
// "ShieldsUp" or "NetInfo.nil" or "NetInfo.PCP".
func ( h * Hostinfo ) HowUnequal ( h2 * Hostinfo ) ( path [ ] string ) {
return appendStructPtrDiff ( nil , "" , reflect . ValueOf ( h ) , reflect . ValueOf ( h2 ) )
}
func appendStructPtrDiff ( base [ ] string , pfx string , p1 , p2 reflect . Value ) ( ret [ ] string ) {
ret = base
if p1 . IsNil ( ) && p2 . IsNil ( ) {
return base
}
mkPath := func ( b string ) string {
if pfx == "" {
return b
}
return pfx + "." + b
}
if p1 . IsNil ( ) || p2 . IsNil ( ) {
return append ( base , mkPath ( "nil" ) )
}
v1 , v2 := p1 . Elem ( ) , p2 . Elem ( )
t := v1 . Type ( )
for i , n := 0 , t . NumField ( ) ; i < n ; i ++ {
sf := t . Field ( i )
switch sf . Type . Kind ( ) {
case reflect . String :
if v1 . Field ( i ) . String ( ) != v2 . Field ( i ) . String ( ) {
ret = append ( ret , mkPath ( sf . Name ) )
}
continue
case reflect . Bool :
if v1 . Field ( i ) . Bool ( ) != v2 . Field ( i ) . Bool ( ) {
ret = append ( ret , mkPath ( sf . Name ) )
}
continue
case reflect . Int , reflect . Int8 , reflect . Int16 , reflect . Int32 , reflect . Int64 :
if v1 . Field ( i ) . Int ( ) != v2 . Field ( i ) . Int ( ) {
ret = append ( ret , mkPath ( sf . Name ) )
}
continue
case reflect . Uint , reflect . Uint8 , reflect . Uint16 , reflect . Uint32 , reflect . Uint64 , reflect . Uintptr :
if v1 . Field ( i ) . Uint ( ) != v2 . Field ( i ) . Uint ( ) {
ret = append ( ret , mkPath ( sf . Name ) )
}
continue
case reflect . Slice , reflect . Map :
if ! reflect . DeepEqual ( v1 . Field ( i ) . Interface ( ) , v2 . Field ( i ) . Interface ( ) ) {
ret = append ( ret , mkPath ( sf . Name ) )
}
continue
case reflect . Ptr :
if sf . Type . Elem ( ) . Kind ( ) == reflect . Struct {
ret = appendStructPtrDiff ( ret , sf . Name , v1 . Field ( i ) , v2 . Field ( i ) )
continue
}
}
panic ( fmt . Sprintf ( "unsupported type at %s: %s" , mkPath ( sf . Name ) , sf . Type . String ( ) ) )
}
return ret
}
2021-03-26 14:01:08 +00:00
// SignatureType specifies a scheme for signing RegisterRequest messages. It
// specifies the crypto algorithms to use, the contents of what is signed, and
// any other relevant details. Historically, requests were unsigned so the zero
// value is SignatureNone.
type SignatureType int
const (
// SignatureNone indicates that there is no signature, no Timestamp is
// required (but may be specified if desired), and both DeviceCert and
// Signature should be empty.
SignatureNone = SignatureType ( iota )
// SignatureUnknown represents an unknown signature scheme, which should
// be considered an error if seen.
SignatureUnknown
// SignatureV1 is computed as RSA-PSS-Sign(privateKeyForDeviceCert,
2021-09-17 18:17:57 +01:00
// SHA256(Timestamp || ServerIdentity || DeviceCert || ServerShortPubKey ||
// MachineShortPubKey)). The PSS salt length is equal to hash length
// (rsa.PSSSaltLengthEqualsHash). Device cert is required.
// Deprecated: uses old key serialization format.
SignatureV1
// SignatureV2 is computed as RSA-PSS-Sign(privateKeyForDeviceCert,
2021-03-26 14:01:08 +00:00
// SHA256(Timestamp || ServerIdentity || DeviceCert || ServerPubKey ||
// MachinePubKey)). The PSS salt length is equal to hash length
// (rsa.PSSSaltLengthEqualsHash). Device cert is required.
2021-09-17 18:17:57 +01:00
SignatureV2
2021-03-26 14:01:08 +00:00
)
2023-09-02 02:15:19 +01:00
func ( st SignatureType ) AppendText ( b [ ] byte ) ( [ ] byte , error ) {
return append ( b , st . String ( ) ... ) , nil
}
2021-03-26 14:01:08 +00:00
func ( st SignatureType ) MarshalText ( ) ( [ ] byte , error ) {
return [ ] byte ( st . String ( ) ) , nil
}
func ( st * SignatureType ) UnmarshalText ( b [ ] byte ) error {
switch string ( b ) {
case "signature-none" :
* st = SignatureNone
case "signature-v1" :
* st = SignatureV1
2021-09-17 18:17:57 +01:00
case "signature-v2" :
* st = SignatureV2
2021-03-26 14:01:08 +00:00
default :
var val int
if _ , err := fmt . Sscanf ( string ( b ) , "signature-unknown(%d)" , & val ) ; err != nil {
* st = SignatureType ( val )
} else {
* st = SignatureUnknown
}
}
return nil
}
func ( st SignatureType ) String ( ) string {
switch st {
case SignatureNone :
return "signature-none"
case SignatureUnknown :
return "signature-unknown"
case SignatureV1 :
return "signature-v1"
2021-09-17 18:17:57 +01:00
case SignatureV2 :
return "signature-v2"
2021-03-26 14:01:08 +00:00
default :
return fmt . Sprintf ( "signature-unknown(%d)" , int ( st ) )
}
}
2023-08-20 04:14:32 +01:00
// RegisterResponseAuth is the authentication information returned by the server
// in response to a RegisterRequest.
type RegisterResponseAuth struct {
_ structs . Incomparable
2024-04-20 18:04:04 +01:00
2024-04-21 18:17:51 +01:00
// At most one of Oauth2Token or AuthKey is set.
2024-04-20 18:04:04 +01:00
2024-05-17 22:54:41 +01:00
Oauth2Token * Oauth2Token ` json:",omitempty" ` // used by pre-1.66 Android only
2024-04-20 18:04:04 +01:00
AuthKey string ` json:",omitempty" `
2023-08-20 04:14:32 +01:00
}
2020-02-18 11:45:42 +00:00
// RegisterRequest is sent by a client to register the key for a node.
// It is encoded to JSON, encrypted with golang.org/x/crypto/nacl/box,
// using the local machine key, and sent to:
2022-08-02 17:33:46 +01:00
//
2020-02-18 11:45:42 +00:00
// https://login.tailscale.com/machine/<mkey hex>
2020-02-05 22:16:58 +00:00
type RegisterRequest struct {
2022-03-06 17:32:52 +00:00
_ structs . Incomparable
// Version is the client's capabilities when using the Noise
// transport.
//
// When using the original nacl crypto_box transport, the
// value must be 1.
Version CapabilityVersion
2021-11-02 03:55:52 +00:00
NodeKey key . NodePublic
OldNodeKey key . NodePublic
2022-08-01 23:46:41 +01:00
NLKey key . NLPublic
2024-04-20 18:04:04 +01:00
Auth * RegisterResponseAuth ` json:",omitempty" `
2021-04-09 06:26:27 +01:00
// Expiry optionally specifies the requested key expiry.
// The server policy may override.
// As a special case, if Expiry is in the past and NodeKey is
// the node's current key, the key is expired.
Expiry time . Time
Followup string // response waits until AuthURL is visited
2020-02-25 18:04:20 +00:00
Hostinfo * Hostinfo
2021-03-26 14:01:08 +00:00
2021-10-28 04:48:01 +01:00
// Ephemeral is whether the client is requesting that this
// node be considered ephemeral and be automatically deleted
// when it stops being active.
Ephemeral bool ` json:",omitempty" `
2022-10-13 18:43:00 +01:00
// NodeKeySignature is the node's own node-key signature, re-signed
// for its new node key using its network-lock key.
//
// This field is set when the client retries registration after learning
// its NodeKeySignature (which is in need of rotation).
NodeKeySignature tkatype . MarshaledSignature
2021-03-26 14:01:08 +00:00
// The following fields are not used for SignatureNone and are required for
// SignatureV1:
SignatureType SignatureType ` json:",omitempty" `
Timestamp * time . Time ` json:",omitempty" ` // creation time of request to prevent replay
DeviceCert [ ] byte ` json:",omitempty" ` // X.509 certificate for client device
Signature [ ] byte ` json:",omitempty" ` // as described by SignatureType
2023-10-13 19:13:41 +01:00
// Tailnet is an optional identifier specifying the name of the recommended or required
// network that the node should join. Its exact form should not be depended on; new
// forms are coming later. The identifier is generally a domain name (for an organization)
// or e-mail address (for a personal account on a shared e-mail provider). It is the same name
// used by the API, as described in /api.md#tailnet.
// If Tailnet begins with the prefix "required:" then the server should prevent logging in to a different
// network than the one specified. Otherwise, the server should recommend the specified network
// but still permit logging in to other networks.
// If empty, no recommendation is offered to the server and the login page should show all options.
Tailnet string ` json:",omitempty" `
2020-02-05 22:16:58 +00:00
}
2020-02-18 11:45:42 +00:00
// RegisterResponse is returned by the server in response to a RegisterRequest.
2020-02-05 22:16:58 +00:00
type RegisterResponse struct {
User User
Login Login
NodeKeyExpired bool // if true, the NodeKey needs to be replaced
MachineAuthorized bool // TODO(crawshaw): move to using MachineStatus
AuthURL string // if set, authorization pending
2021-10-26 18:19:35 +01:00
2022-10-13 18:43:00 +01:00
// If set, this is the current node-key signature that needs to be
// re-signed for the node's new node-key.
NodeKeySignature tkatype . MarshaledSignature
2022-09-25 19:29:55 +01:00
// Error indicates that authorization failed. If this is non-empty,
2021-10-26 18:19:35 +01:00
// other status fields should be ignored.
Error string
2020-02-05 22:16:58 +00:00
}
tailcfg: add Endpoint, EndpointType, MapRequest.EndpointType
Track endpoints internally with a new tailcfg.Endpoint type that
includes a typed netaddr.IPPort (instead of just a string) and
includes a type for how that endpoint was discovered (STUN, local,
etc).
Use []tailcfg.Endpoint instead of []string internally.
At the last second, send it to the control server as the existing
[]string for endpoints, but also include a new parallel
MapRequest.EndpointType []tailcfg.EndpointType, so the control server
can start filtering out less-important endpoint changes from
new-enough clients. Notably, STUN-discovered endpoints can be filtered
out from 1.6+ clients, as they can discover them amongst each other
via CallMeMaybe disco exchanges started over DERP. And STUN endpoints
change a lot, causing a lot of MapResposne updates. But portmapped
endpoints are worth keeping for now, as they they work right away
without requiring the firewall traversal extra RTT dance.
End result will be less control->client bandwidth. (despite negligible
increase in client->control bandwidth)
Updates tailscale/corp#1543
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-04-12 21:24:29 +01:00
// EndpointType distinguishes different sources of MapRequest.Endpoint values.
type EndpointType int
const (
EndpointUnknownType = EndpointType ( 0 )
EndpointLocal = EndpointType ( 1 )
EndpointSTUN = EndpointType ( 2 )
EndpointPortmapped = EndpointType ( 3 )
EndpointSTUN4LocalPort = EndpointType ( 4 ) // hard NAT: STUN'ed IPv4 address + local fixed port
2024-07-08 15:21:21 +01:00
EndpointExplicitConf = EndpointType ( 5 ) // explicitly configured (routing to be done by client)
tailcfg: add Endpoint, EndpointType, MapRequest.EndpointType
Track endpoints internally with a new tailcfg.Endpoint type that
includes a typed netaddr.IPPort (instead of just a string) and
includes a type for how that endpoint was discovered (STUN, local,
etc).
Use []tailcfg.Endpoint instead of []string internally.
At the last second, send it to the control server as the existing
[]string for endpoints, but also include a new parallel
MapRequest.EndpointType []tailcfg.EndpointType, so the control server
can start filtering out less-important endpoint changes from
new-enough clients. Notably, STUN-discovered endpoints can be filtered
out from 1.6+ clients, as they can discover them amongst each other
via CallMeMaybe disco exchanges started over DERP. And STUN endpoints
change a lot, causing a lot of MapResposne updates. But portmapped
endpoints are worth keeping for now, as they they work right away
without requiring the firewall traversal extra RTT dance.
End result will be less control->client bandwidth. (despite negligible
increase in client->control bandwidth)
Updates tailscale/corp#1543
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-04-12 21:24:29 +01:00
)
func ( et EndpointType ) String ( ) string {
switch et {
case EndpointUnknownType :
return "?"
case EndpointLocal :
return "local"
case EndpointSTUN :
return "stun"
case EndpointPortmapped :
return "portmap"
case EndpointSTUN4LocalPort :
return "stun4localport"
2024-07-08 15:21:21 +01:00
case EndpointExplicitConf :
return "explicitconf"
tailcfg: add Endpoint, EndpointType, MapRequest.EndpointType
Track endpoints internally with a new tailcfg.Endpoint type that
includes a typed netaddr.IPPort (instead of just a string) and
includes a type for how that endpoint was discovered (STUN, local,
etc).
Use []tailcfg.Endpoint instead of []string internally.
At the last second, send it to the control server as the existing
[]string for endpoints, but also include a new parallel
MapRequest.EndpointType []tailcfg.EndpointType, so the control server
can start filtering out less-important endpoint changes from
new-enough clients. Notably, STUN-discovered endpoints can be filtered
out from 1.6+ clients, as they can discover them amongst each other
via CallMeMaybe disco exchanges started over DERP. And STUN endpoints
change a lot, causing a lot of MapResposne updates. But portmapped
endpoints are worth keeping for now, as they they work right away
without requiring the firewall traversal extra RTT dance.
End result will be less control->client bandwidth. (despite negligible
increase in client->control bandwidth)
Updates tailscale/corp#1543
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-04-12 21:24:29 +01:00
}
return "other"
}
// Endpoint is an endpoint IPPort and an associated type.
// It doesn't currently go over the wire as is but is instead
2021-03-29 21:47:12 +01:00
// broken up into two parallel slices in MapRequest, for compatibility
tailcfg: add Endpoint, EndpointType, MapRequest.EndpointType
Track endpoints internally with a new tailcfg.Endpoint type that
includes a typed netaddr.IPPort (instead of just a string) and
includes a type for how that endpoint was discovered (STUN, local,
etc).
Use []tailcfg.Endpoint instead of []string internally.
At the last second, send it to the control server as the existing
[]string for endpoints, but also include a new parallel
MapRequest.EndpointType []tailcfg.EndpointType, so the control server
can start filtering out less-important endpoint changes from
new-enough clients. Notably, STUN-discovered endpoints can be filtered
out from 1.6+ clients, as they can discover them amongst each other
via CallMeMaybe disco exchanges started over DERP. And STUN endpoints
change a lot, causing a lot of MapResposne updates. But portmapped
endpoints are worth keeping for now, as they they work right away
without requiring the firewall traversal extra RTT dance.
End result will be less control->client bandwidth. (despite negligible
increase in client->control bandwidth)
Updates tailscale/corp#1543
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-04-12 21:24:29 +01:00
// reasons. But this type is used in the codebase.
type Endpoint struct {
all: convert more code to use net/netip directly
perl -i -npe 's,netaddr.IPPrefixFrom,netip.PrefixFrom,' $(git grep -l -F netaddr.)
perl -i -npe 's,netaddr.IPPortFrom,netip.AddrPortFrom,' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPrefix,netip.Prefix,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPort,netip.AddrPort,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IP\b,netip.Addr,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPv6Raw\b,netip.AddrFrom16,g' $(git grep -l -F netaddr. )
goimports -w .
Then delete some stuff from the net/netaddr shim package which is no
longer neeed.
Updates #5162
Change-Id: Ia7a86893fe21c7e3ee1ec823e8aba288d4566cd8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-07-26 05:14:09 +01:00
Addr netip . AddrPort
tailcfg: add Endpoint, EndpointType, MapRequest.EndpointType
Track endpoints internally with a new tailcfg.Endpoint type that
includes a typed netaddr.IPPort (instead of just a string) and
includes a type for how that endpoint was discovered (STUN, local,
etc).
Use []tailcfg.Endpoint instead of []string internally.
At the last second, send it to the control server as the existing
[]string for endpoints, but also include a new parallel
MapRequest.EndpointType []tailcfg.EndpointType, so the control server
can start filtering out less-important endpoint changes from
new-enough clients. Notably, STUN-discovered endpoints can be filtered
out from 1.6+ clients, as they can discover them amongst each other
via CallMeMaybe disco exchanges started over DERP. And STUN endpoints
change a lot, causing a lot of MapResposne updates. But portmapped
endpoints are worth keeping for now, as they they work right away
without requiring the firewall traversal extra RTT dance.
End result will be less control->client bandwidth. (despite negligible
increase in client->control bandwidth)
Updates tailscale/corp#1543
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-04-12 21:24:29 +01:00
Type EndpointType
}
2023-09-09 21:52:28 +01:00
// MapRequest is sent by a client to either update the control plane
// about its current state, or to start a long-poll of network map updates.
//
2020-02-18 11:45:42 +00:00
// The request includes a copy of the client's current set of WireGuard
// endpoints and general host information.
//
// The request is encoded to JSON, encrypted with golang.org/x/crypto/nacl/box,
// using the local machine key, and sent to:
2022-08-02 17:33:46 +01:00
//
2020-02-18 11:45:42 +00:00
// https://login.tailscale.com/machine/<mkey hex>/map
2020-02-05 22:16:58 +00:00
type MapRequest struct {
2020-10-19 23:32:22 +01:00
// Version is incremented whenever the client code changes enough that
// we want to signal to the control server that we're capable of something
// different.
//
2022-03-06 17:32:52 +00:00
// For current values and history, see the CapabilityVersion type's docs.
Version CapabilityVersion
2021-01-05 18:37:15 +00:00
2023-09-10 14:46:08 +01:00
Compress string // "zstd" or "" (no compression)
KeepAlive bool // whether server should send keep-alives back to us
NodeKey key . NodePublic
DiscoKey key . DiscoPublic
2023-08-10 03:56:43 +01:00
// Stream is whether the client wants to receive multiple MapResponses over
// the same HTTP connection.
//
// If false, the server will send a single MapResponse and then close the
// connection.
//
// If true and Version >= 68, the server should treat this as a read-only
// request and ignore any Hostinfo or other fields that might be set.
Stream bool
// Hostinfo is the client's current Hostinfo. Although it is always included
// in the request, the server may choose to ignore it when Stream is true
// and Version >= 68.
Hostinfo * Hostinfo
2020-07-03 21:55:33 +01:00
2022-07-28 05:21:02 +01:00
// MapSessionHandle, if non-empty, is a request to reattach to a previous
// map session after a previous map session was interrupted for whatever
// reason. Its value is an opaque string as returned by
// MapResponse.MapSessionHandle.
//
// When set, the client must also send MapSessionSeq to specify the last
// processed message in that prior session.
//
// The server may choose to ignore the request for any reason and start a
// new map session. This is only applicable when Stream is true.
MapSessionHandle string ` json:",omitempty" `
// MapSessionSeq is the sequence number in the map session identified by
// MapSesssionHandle that was most recently processed by the client.
// It is only applicable when MapSessionHandle is specified.
// If the server chooses to honor the MapSessionHandle request, only sequence
// numbers greater than this value will be returned.
MapSessionSeq int64 ` json:",omitempty" `
tailcfg: add Endpoint, EndpointType, MapRequest.EndpointType
Track endpoints internally with a new tailcfg.Endpoint type that
includes a typed netaddr.IPPort (instead of just a string) and
includes a type for how that endpoint was discovered (STUN, local,
etc).
Use []tailcfg.Endpoint instead of []string internally.
At the last second, send it to the control server as the existing
[]string for endpoints, but also include a new parallel
MapRequest.EndpointType []tailcfg.EndpointType, so the control server
can start filtering out less-important endpoint changes from
new-enough clients. Notably, STUN-discovered endpoints can be filtered
out from 1.6+ clients, as they can discover them amongst each other
via CallMeMaybe disco exchanges started over DERP. And STUN endpoints
change a lot, causing a lot of MapResposne updates. But portmapped
endpoints are worth keeping for now, as they they work right away
without requiring the firewall traversal extra RTT dance.
End result will be less control->client bandwidth. (despite negligible
increase in client->control bandwidth)
Updates tailscale/corp#1543
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-04-12 21:24:29 +01:00
// Endpoints are the client's magicsock UDP ip:port endpoints (IPv4 or IPv6).
2023-08-10 03:56:43 +01:00
// These can be ignored if Stream is true and Version >= 68.
2023-10-01 05:05:02 +01:00
Endpoints [ ] netip . AddrPort ` json:",omitempty" `
tailcfg: add Endpoint, EndpointType, MapRequest.EndpointType
Track endpoints internally with a new tailcfg.Endpoint type that
includes a typed netaddr.IPPort (instead of just a string) and
includes a type for how that endpoint was discovered (STUN, local,
etc).
Use []tailcfg.Endpoint instead of []string internally.
At the last second, send it to the control server as the existing
[]string for endpoints, but also include a new parallel
MapRequest.EndpointType []tailcfg.EndpointType, so the control server
can start filtering out less-important endpoint changes from
new-enough clients. Notably, STUN-discovered endpoints can be filtered
out from 1.6+ clients, as they can discover them amongst each other
via CallMeMaybe disco exchanges started over DERP. And STUN endpoints
change a lot, causing a lot of MapResposne updates. But portmapped
endpoints are worth keeping for now, as they they work right away
without requiring the firewall traversal extra RTT dance.
End result will be less control->client bandwidth. (despite negligible
increase in client->control bandwidth)
Updates tailscale/corp#1543
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-04-12 21:24:29 +01:00
// EndpointTypes are the types of the corresponding endpoints in Endpoints.
EndpointTypes [ ] EndpointType ` json:",omitempty" `
2022-10-27 21:40:31 +01:00
// TKAHead describes the hash of the latest AUM applied to the local
// tailnet key authority, if one is operating.
// It is encoded as tka.AUMHash.MarshalText.
TKAHead string ` json:",omitempty" `
2023-08-10 03:56:43 +01:00
// ReadOnly was set when client just wanted to fetch the MapResponse,
// without updating their Endpoints. The intended use was for clients to
// discover the DERP map at start-up before their first real endpoint
// update.
2020-09-17 19:28:09 +01:00
//
2023-08-10 03:56:43 +01:00
// Deprecated: always false as of Version 68.
2020-09-17 19:28:09 +01:00
ReadOnly bool ` json:",omitempty" `
2022-06-14 21:05:40 +01:00
// OmitPeers is whether the client is okay with the Peers list being omitted
// in the response.
//
// The behavior of OmitPeers being true varies based on Stream and ReadOnly:
2020-12-15 20:16:15 +00:00
//
// If OmitPeers is true, Stream is false, and ReadOnly is false,
// then the server will let clients update their endpoints without
// breaking existing long-polling (Stream == true) connections.
2022-06-14 21:05:40 +01:00
// In this case, the server can omit the entire response; the client
// only checks the HTTP response status code.
//
// If OmitPeers is true, Stream is false, but ReadOnly is true,
// then all the response fields are included. (This is what the client does
// when initially fetching the DERP map.)
2020-09-17 19:28:09 +01:00
OmitPeers bool ` json:",omitempty" `
2020-10-19 23:56:59 +01:00
// DebugFlags is a list of strings specifying debugging and
// development features to enable in handling this map
// request. The values are deliberately unspecified, as they get
// added and removed all the time during development, and offer no
// compatibility promise. To roll out semantic changes, bump
// Version instead.
2020-11-04 21:48:50 +00:00
//
// Current DebugFlags values are:
// * "warn-ip-forwarding-off": client is trying to be a subnet
// router but their IP forwarding is broken.
2021-02-18 16:58:13 +00:00
// * "warn-router-unhealthy": client's Router implementation is
// having problems.
2020-10-19 23:56:59 +01:00
DebugFlags [ ] string ` json:",omitempty" `
2020-02-05 22:16:58 +00:00
}
2020-04-30 06:49:17 +01:00
// PortRange represents a range of UDP or TCP port numbers.
type PortRange struct {
First uint16
Last uint16
}
2023-03-11 16:45:40 +00:00
// Contains reports whether port is in pr.
func ( pr PortRange ) Contains ( port uint16 ) bool {
return port >= pr . First && port <= pr . Last
}
2020-04-30 06:49:17 +01:00
var PortRangeAny = PortRange { 0 , 65535 }
2020-12-14 16:21:41 +00:00
// NetPortRange represents a range of ports that's allowed for one or more IPs.
2020-04-30 06:49:17 +01:00
type NetPortRange struct {
2020-05-03 21:58:39 +01:00
_ structs . Incomparable
2020-12-14 16:21:41 +00:00
IP string // IP, CIDR, Range, or "*" (same formats as FilterRule.SrcIPs)
2024-06-18 22:37:30 +01:00
Bits * int // deprecated; the 2020 way to turn IP into a CIDR. See FilterRule.SrcBits.
2020-04-30 06:49:17 +01:00
Ports PortRange
}
2022-03-18 18:48:40 +00:00
// CapGrant grants capabilities in a FilterRule.
type CapGrant struct {
2022-09-25 19:29:55 +01:00
// Dsts are the destination IP ranges that this capability
2022-03-18 18:48:40 +00:00
// grant matches.
all: convert more code to use net/netip directly
perl -i -npe 's,netaddr.IPPrefixFrom,netip.PrefixFrom,' $(git grep -l -F netaddr.)
perl -i -npe 's,netaddr.IPPortFrom,netip.AddrPortFrom,' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPrefix,netip.Prefix,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPort,netip.AddrPort,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IP\b,netip.Addr,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPv6Raw\b,netip.AddrFrom16,g' $(git grep -l -F netaddr. )
goimports -w .
Then delete some stuff from the net/netaddr shim package which is no
longer neeed.
Updates #5162
Change-Id: Ia7a86893fe21c7e3ee1ec823e8aba288d4566cd8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-07-26 05:14:09 +01:00
Dsts [ ] netip . Prefix
2022-03-18 18:48:40 +00:00
// Caps are the capabilities the source IP matched by
// FilterRule.SrcIPs are granted to the destination IP,
// matched by Dsts.
2023-07-25 05:07:00 +01:00
// Deprecated: use CapMap instead.
Caps [ ] PeerCapability ` json:",omitempty" `
// CapMap is a map of capabilities to their values.
// The key is the capability name, and the value is a list of
// values for that capability.
CapMap PeerCapMap ` json:",omitempty" `
}
2023-09-06 18:17:25 +01:00
// PeerCapability represents a capability granted to a peer by a FilterRule when
// the peer communicates with the node that has this rule. Its meaning is
// application-defined.
//
// It must be a URL like "https://tailscale.com/cap/file-send".
2023-07-25 05:07:00 +01:00
type PeerCapability string
const (
// PeerCapabilityFileSharingTarget grants the current node the ability to send
// files to the peer which has this capability.
PeerCapabilityFileSharingTarget PeerCapability = "https://tailscale.com/cap/file-sharing-target"
// PeerCapabilityFileSharingSend grants the ability to receive files from a
// node that's owned by a different user.
PeerCapabilityFileSharingSend PeerCapability = "https://tailscale.com/cap/file-send"
// PeerCapabilityDebugPeer grants the ability for a peer to read this node's
// goroutines, metrics, magicsock internal state, etc.
PeerCapabilityDebugPeer PeerCapability = "https://tailscale.com/cap/debug-peer"
// PeerCapabilityWakeOnLAN grants the ability to send a Wake-On-LAN packet.
PeerCapabilityWakeOnLAN PeerCapability = "https://tailscale.com/cap/wake-on-lan"
// PeerCapabilityIngress grants the ability for a peer to send ingress traffic.
PeerCapabilityIngress PeerCapability = "https://tailscale.com/cap/ingress"
2024-01-10 20:01:23 +00:00
// PeerCapabilityWebUI grants the ability for a peer to edit features from the
// device Web UI.
PeerCapabilityWebUI PeerCapability = "tailscale.com/cap/webui"
2024-04-23 22:11:04 +01:00
// PeerCapabilityTaildrive grants the ability for a peer to access Taildrive
// shares.
2024-04-04 21:07:58 +01:00
PeerCapabilityTaildrive PeerCapability = "tailscale.com/cap/drive"
2024-04-23 22:11:04 +01:00
// PeerCapabilityTaildriveSharer indicates that a peer has the ability to
// share folders with us.
PeerCapabilityTaildriveSharer PeerCapability = "tailscale.com/cap/drive-sharer"
2024-06-04 18:31:37 +01:00
// PeerCapabilityKubernetes grants a peer Kubernetes-specific
// capabilities, such as the ability to impersonate specific Tailscale
// user groups as Kubernetes user groups. This capability is read by
// peers that are Tailscale Kubernetes operator instances.
PeerCapabilityKubernetes PeerCapability = "tailscale.com/cap/kubernetes"
2024-11-15 21:14:06 +00:00
// PeerCapabilityServicesDestination grants a peer the ability to serve as
// a destination for a set of given VIP services, which is provided as the
// value of this key in NodeCapMap.
PeerCapabilityServicesDestination PeerCapability = "tailscale.com/cap/services-destination"
2023-07-25 05:07:00 +01:00
)
2023-09-18 16:52:22 +01:00
// NodeCapMap is a map of capabilities to their optional values. It is valid for
// a capability to have no values (nil slice); such capabilities can be tested
// for by using the Contains method.
//
// See [NodeCapability] for more information on keys.
type NodeCapMap map [ NodeCapability ] [ ] RawMessage
// Equal reports whether c and c2 are equal.
func ( c NodeCapMap ) Equal ( c2 NodeCapMap ) bool {
return maps . EqualFunc ( c , c2 , slices . Equal )
}
// UnmarshalNodeCapJSON unmarshals each JSON value in cm[cap] as T.
// If cap does not exist in cm, it returns (nil, nil).
// It returns an error if the values cannot be unmarshaled into the provided type.
func UnmarshalNodeCapJSON [ T any ] ( cm NodeCapMap , cap NodeCapability ) ( [ ] T , error ) {
vals , ok := cm [ cap ]
if ! ok {
return nil , nil
}
out := make ( [ ] T , 0 , len ( vals ) )
for _ , v := range vals {
var t T
if err := json . Unmarshal ( [ ] byte ( v ) , & t ) ; err != nil {
return nil , err
}
out = append ( out , t )
}
return out , nil
}
// Contains reports whether c has the capability cap. This is used to test for
// the existence of a capability, especially when the capability has no
// associated argument/data values.
func ( c NodeCapMap ) Contains ( cap NodeCapability ) bool {
_ , ok := c [ cap ]
return ok
}
2023-07-25 05:07:00 +01:00
// PeerCapMap is a map of capabilities to their optional values. It is valid for
// a capability to have no values (nil slice); such capabilities can be tested
// for by using the HasCapability method.
//
// The values are opaque to Tailscale, but are passed through from the ACLs to
// the application via the WhoIs API.
2023-09-18 17:40:14 +01:00
type PeerCapMap map [ PeerCapability ] [ ] RawMessage
2023-07-25 05:07:00 +01:00
2023-07-30 02:45:29 +01:00
// UnmarshalCapJSON unmarshals each JSON value in cm[cap] as T.
// If cap does not exist in cm, it returns (nil, nil).
// It returns an error if the values cannot be unmarshaled into the provided type.
func UnmarshalCapJSON [ T any ] ( cm PeerCapMap , cap PeerCapability ) ( [ ] T , error ) {
vals , ok := cm [ cap ]
if ! ok {
return nil , nil
}
out := make ( [ ] T , 0 , len ( vals ) )
for _ , v := range vals {
var t T
2023-09-18 17:40:14 +01:00
if err := json . Unmarshal ( [ ] byte ( v ) , & t ) ; err != nil {
2023-07-30 02:45:29 +01:00
return nil , err
}
out = append ( out , t )
}
return out , nil
}
2023-09-18 16:52:22 +01:00
// HasCapability reports whether c has the capability cap. This is used to test
// for the existence of a capability, especially when the capability has no
// associated argument/data values.
2023-07-25 05:07:00 +01:00
func ( c PeerCapMap ) HasCapability ( cap PeerCapability ) bool {
_ , ok := c [ cap ]
return ok
2022-03-18 18:48:40 +00:00
}
2020-04-30 06:49:17 +01:00
// FilterRule represents one rule in a packet filter.
2020-11-05 19:54:54 +00:00
//
// A rule is logically a set of source CIDRs to match (described by
2024-06-18 22:37:30 +01:00
// SrcIPs), and a set of destination targets that are then
2022-09-25 19:29:55 +01:00
// allowed if a source IP is matches of those CIDRs.
2020-04-30 06:49:17 +01:00
type FilterRule struct {
2020-11-05 19:54:54 +00:00
// SrcIPs are the source IPs/networks to match.
2020-12-14 16:21:41 +00:00
//
// It may take the following forms:
// * an IP address (IPv4 or IPv6)
// * the string "*" to match everything (both IPv4 & IPv6)
// * a CIDR (e.g. "192.168.0.0/16")
// * a range of two IPs, inclusive, separated by hyphen ("2eff::1-2eff::0800")
2024-06-18 21:44:12 +01:00
// * a string "cap:<capability>" with NodeCapMap cap name
2020-11-05 19:54:54 +00:00
SrcIPs [ ] string
2024-06-18 22:37:30 +01:00
// SrcBits is deprecated; it was the old way to specify a CIDR
2022-03-06 17:32:52 +00:00
// prior to CapabilityVersion 7. Its values correspond to the
2020-12-14 16:21:41 +00:00
// SrcIPs above.
2020-11-05 19:54:54 +00:00
//
2020-12-14 16:21:41 +00:00
// If an entry of SrcBits is present for the same index as a
// SrcIPs entry, it changes the SrcIP above to be a network
// with /n CIDR bits. If the slice is nil or insufficiently
// long, the default value (for an IPv4 address) for a
// position is 32, as if the SrcIPs above were a /32 mask. For
// a "*" SrcIPs value, the corresponding SrcBits value is
// ignored.
2024-06-18 22:37:30 +01:00
//
// This is still present in this file because the Tailscale control plane
// code still uses this type, for 118 clients that are still connected as of
// 2024-06-18, 3.5 years after the last release that used this type.
2021-01-05 18:54:01 +00:00
SrcBits [ ] int ` json:",omitempty" `
2020-11-05 19:54:54 +00:00
// DstPorts are the port ranges to allow once a source IP
2024-06-18 22:37:30 +01:00
// matches (is in the CIDR described by SrcIPs).
2022-03-18 18:48:40 +00:00
//
// CapGrant and DstPorts are mutually exclusive: at most one can be non-nil.
DstPorts [ ] NetPortRange ` json:",omitempty" `
2021-03-17 21:24:32 +00:00
// IPProto are the IP protocol numbers to match.
//
// As a special case, nil or empty means TCP, UDP, and ICMP.
//
// Numbers outside the uint8 range (below 0 or above 255) are
// reserved for Tailscale's use. Unknown ones are ignored.
//
// Depending on the IPProto values, DstPorts may or may not be
// used.
IPProto [ ] int ` json:",omitempty" `
2022-03-18 18:48:40 +00:00
// CapGrant, if non-empty, are the capabilities to
// conditionally grant to the source IP in SrcIPs.
//
// Think of DstPorts as "capabilities for networking" and
// CapGrant as arbitrary application-defined capabilities
// defined between the admin's ACLs and the application
// doing WhoIs lookups, looking up the remote IP address's
// application-level capabilities.
//
// CapGrant and DstPorts are mutually exclusive: at most one can be non-nil.
CapGrant [ ] CapGrant ` json:",omitempty" `
2020-04-30 06:49:17 +01:00
}
var FilterAllowAll = [ ] FilterRule {
2020-10-26 15:53:07 +00:00
{
2024-06-18 22:37:30 +01:00
SrcIPs : [ ] string { "*" } ,
2020-10-26 15:53:07 +00:00
DstPorts : [ ] NetPortRange { {
2020-04-30 06:49:17 +01:00
IP : "*" ,
Ports : PortRange { 0 , 65535 } ,
} } ,
} ,
}
2020-07-31 21:27:09 +01:00
// DNSConfig is the DNS configuration.
type DNSConfig struct {
2021-04-08 09:35:14 +01:00
// Resolvers are the DNS resolvers to use, in order of preference.
2022-05-03 22:41:58 +01:00
Resolvers [ ] * dnstype . Resolver ` json:",omitempty" `
2021-08-25 17:07:21 +01:00
2021-04-08 09:35:14 +01:00
// Routes maps DNS name suffixes to a set of DNS resolvers to
// use. It is used to implement "split DNS" and other advanced DNS
// routing overlays.
2021-08-25 17:07:21 +01:00
//
// Map keys are fully-qualified DNS name suffixes; they may
// optionally contain a trailing dot but no leading dot.
//
// If the value is an empty slice, that means the suffix should still
// be handled by Tailscale's built-in resolver (100.100.100.100), such
// as for the purpose of handling ExtraRecords.
2022-05-03 22:41:58 +01:00
Routes map [ string ] [ ] * dnstype . Resolver ` json:",omitempty" `
2021-08-25 17:07:21 +01:00
2021-04-20 05:30:39 +01:00
// FallbackResolvers is like Resolvers, but is only used if a
// split DNS configuration is requested in a configuration that
// doesn't work yet without explicit default resolvers.
2021-04-20 05:58:26 +01:00
// https://github.com/tailscale/tailscale/issues/1743
2022-05-03 22:41:58 +01:00
FallbackResolvers [ ] * dnstype . Resolver ` json:",omitempty" `
2020-08-24 22:27:21 +01:00
// Domains are the search domains to use.
2021-04-08 09:35:14 +01:00
// Search domains must be FQDNs, but *without* the trailing dot.
2020-08-24 22:27:21 +01:00
Domains [ ] string ` json:",omitempty" `
2021-04-08 09:35:14 +01:00
// Proxied turns on automatic resolution of hostnames for devices
// in the network map, aka MagicDNS.
// Despite the (legacy) name, does not necessarily cause request
// proxying to be enabled.
Proxied bool ` json:",omitempty" `
// The following fields are only set and used by
// MapRequest.Version >=9 and <14.
// Nameservers are the IP addresses of the nameservers to use.
all: convert more code to use net/netip directly
perl -i -npe 's,netaddr.IPPrefixFrom,netip.PrefixFrom,' $(git grep -l -F netaddr.)
perl -i -npe 's,netaddr.IPPortFrom,netip.AddrPortFrom,' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPrefix,netip.Prefix,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPort,netip.AddrPort,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IP\b,netip.Addr,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPv6Raw\b,netip.AddrFrom16,g' $(git grep -l -F netaddr. )
goimports -w .
Then delete some stuff from the net/netaddr shim package which is no
longer neeed.
Updates #5162
Change-Id: Ia7a86893fe21c7e3ee1ec823e8aba288d4566cd8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-07-26 05:14:09 +01:00
Nameservers [ ] netip . Addr ` json:",omitempty" `
2021-04-08 09:35:14 +01:00
2021-06-15 20:12:15 +01:00
// CertDomains are the set of DNS names for which the control
// plane server will assist with provisioning TLS
// certificates. See SetDNSRequest, which can be used to
// answer dns-01 ACME challenges for e.g. LetsEncrypt.
// These names are FQDNs without trailing periods, and without
// any "_acme-challenge." prefix.
CertDomains [ ] string ` json:",omitempty" `
2021-06-16 18:58:25 +01:00
// ExtraRecords contains extra DNS records to add to the
// MagicDNS config.
ExtraRecords [ ] DNSRecord ` json:",omitempty" `
2021-11-29 22:18:09 +00:00
2022-09-25 19:29:55 +01:00
// ExitNodeFilteredSuffixes are the DNS suffixes that the
2021-11-29 22:18:09 +00:00
// node, when being an exit node DNS proxy, should not answer.
//
// The entries do not contain trailing periods and are always
// all lowercase.
//
// If an entry starts with a period, it's a suffix match (but
// suffix ".a.b" doesn't match "a.b"; a prefix is required).
//
// If an entry does not start with a period, it's an exact
// match.
//
// Matches are case insensitive.
2023-07-09 03:33:23 +01:00
ExitNodeFilteredSet [ ] string ` json:",omitempty" `
2023-08-16 23:27:33 +01:00
// TempCorpIssue13969 is a temporary (2023-08-16) field for an internal hack day prototype.
// It contains a user inputed URL that should have a list of domains to be blocked.
// See https://github.com/tailscale/corp/issues/13969.
TempCorpIssue13969 string ` json:",omitempty" `
2021-06-16 18:58:25 +01:00
}
// DNSRecord is an extra DNS record to add to MagicDNS.
type DNSRecord struct {
// Name is the fully qualified domain name of
// the record to add. The trailing dot is optional.
Name string
// Type is the DNS record type.
// Empty means A or AAAA, depending on value.
// Other values are currently ignored.
Type string ` json:",omitempty" `
// Value is the IP address in string form.
// TODO(bradfitz): if we ever add support for record types
// with non-UTF8 binary data, add ValueBytes []byte that
// would take precedence.
Value string
2020-07-31 21:27:09 +01:00
}
2022-04-22 02:49:01 +01:00
// PingType is a string representing the kind of ping to perform.
type PingType string
const (
// PingDisco performs a ping, without involving IP at either end.
PingDisco PingType = "disco"
// PingTSMP performs a ping, using the IP layer, but avoiding the OS IP stack.
PingTSMP PingType = "TSMP"
// PingICMP performs a ping between two tailscale nodes using ICMP that is
// received by the target systems IP stack.
PingICMP PingType = "ICMP"
2022-05-28 05:34:36 +01:00
// PingPeerAPI performs a ping between two tailscale nodes using ICMP that is
// received by the target systems IP stack.
PingPeerAPI PingType = "peerapi"
2022-04-22 02:49:01 +01:00
)
2021-07-16 15:51:54 +01:00
// PingRequest with no IP and Types is a request to send an HTTP request to prove the
2021-03-05 04:54:44 +00:00
// long-polling client is still connected.
2022-04-15 17:00:27 +01:00
// PingRequest with Types and IP, will send a ping to the IP and send a POST
// request containing a PingResponse to the URL containing results.
2021-03-05 04:54:44 +00:00
type PingRequest struct {
2022-08-27 20:55:41 +01:00
// URL is the URL to reply to the PingRequest to.
2021-03-05 04:54:44 +00:00
// It will be a unique URL each time. No auth headers are necessary.
2021-06-15 20:28:34 +01:00
// If the client sees multiple PingRequests with the same URL,
// subsequent ones should be ignored.
2022-08-27 20:55:41 +01:00
//
// The HTTP method that the node should make back to URL depends on the other
// fields of the PingRequest. If Types is defined, then URL is the URL to
// send a POST request to. Otherwise, the node should just make a HEAD
// request to URL.
2021-03-05 04:54:44 +00:00
URL string
2022-08-10 22:52:02 +01:00
// URLIsNoise, if true, means that the client should hit URL over the Noise
// transport instead of TLS.
URLIsNoise bool ` json:",omitempty" `
2021-03-05 04:54:44 +00:00
// Log is whether to log about this ping in the success case.
// For failure cases, the client will log regardless.
Log bool ` json:",omitempty" `
2021-07-16 15:51:54 +01:00
2022-04-22 02:49:01 +01:00
// Types is the types of ping that are initiated. Can be any PingType, comma
// separated, e.g. "disco,TSMP"
2022-08-27 20:55:41 +01:00
//
// As a special case, if Types is "c2n", then this PingRequest is a
// client-to-node HTTP request. The HTTP request should be handled by this
// node's c2n handler and the HTTP response sent in a POST to URL. For c2n,
// the value of URLIsNoise is ignored and only the Noise transport (back to
// the control plane) will be used, as if URLIsNoise were true.
Types string ` json:",omitempty" `
// IP is the ping target, when needed by the PingType(s) given in Types.
all: convert more code to use net/netip directly
perl -i -npe 's,netaddr.IPPrefixFrom,netip.PrefixFrom,' $(git grep -l -F netaddr.)
perl -i -npe 's,netaddr.IPPortFrom,netip.AddrPortFrom,' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPrefix,netip.Prefix,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPort,netip.AddrPort,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IP\b,netip.Addr,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPv6Raw\b,netip.AddrFrom16,g' $(git grep -l -F netaddr. )
goimports -w .
Then delete some stuff from the net/netaddr shim package which is no
longer neeed.
Updates #5162
Change-Id: Ia7a86893fe21c7e3ee1ec823e8aba288d4566cd8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-07-26 05:14:09 +01:00
IP netip . Addr
2022-08-27 20:55:41 +01:00
// Payload is the ping payload.
//
// It is only used for c2n requests, in which case it's an HTTP/1.0 or
// HTTP/1.1-formatted HTTP request as parsable with http.ReadRequest.
Payload [ ] byte ` json:",omitempty" `
2021-03-05 04:54:44 +00:00
}
2022-04-15 17:00:27 +01:00
// PingResponse provides result information for a TSMP or Disco PingRequest.
// Typically populated from an ipnstate.PingResult used in `tailscale ping`.
type PingResponse struct {
2022-04-22 02:49:01 +01:00
Type PingType // ping type, such as TSMP or disco.
2022-04-15 17:00:27 +01:00
IP string ` json:",omitempty" ` // ping destination
NodeIP string ` json:",omitempty" ` // Tailscale IP of node handling IP (different for subnet routers)
NodeName string ` json:",omitempty" ` // DNS name base or (possibly not unique) hostname
// Err contains a short description of error conditions if the PingRequest
// could not be fulfilled for some reason.
// e.g. "100.1.2.3 is local Tailscale IP"
Err string ` json:",omitempty" `
// LatencySeconds reports measurement of the round-trip time of a message to
// the requested target, if it could be determined. If LatencySeconds is
// omitted, Err should contain information as to the cause.
LatencySeconds float64 ` json:",omitempty" `
// Endpoint is the ip:port if direct UDP was used.
// It is not currently set for TSMP pings.
Endpoint string ` json:",omitempty" `
// DERPRegionID is non-zero DERP region ID if DERP was used.
// It is not currently set for TSMP pings.
DERPRegionID int ` json:",omitempty" `
// DERPRegionCode is the three-letter region code
// corresponding to DERPRegionID.
// It is not currently set for TSMP pings.
DERPRegionCode string ` json:",omitempty" `
// PeerAPIPort is set by TSMP ping responses for peers that
// are running a peerapi server. This is the port they're
// running the server on.
PeerAPIPort uint16 ` json:",omitempty" `
// IsLocalIP is whether the ping request error is due to it being
// a ping to the local node.
IsLocalIP bool ` json:",omitempty" `
}
2023-09-09 21:52:28 +01:00
// MapResponse is the response to a MapRequest. It describes the state of the
// local node, the peer nodes, the DNS configuration, the packet filter, and
// more. A MapRequest, depending on its parameters, may result in the control
// plane coordination server sending 0, 1 or a stream of multiple MapResponse
// values.
//
// When the client sets MapRequest.Stream, the server sends a stream of
// MapResponses. That long-lived HTTP transaction is called a "map poll". In a
// map poll, the first MapResponse will be complete and subsequent MapResponses
// will be incremental updates with only changed information.
//
// The zero value for all fields means "unchanged". Unfortunately, several
// fields were defined before that convention was established, so they use a
// slice with omitempty, meaning this type can't be used to marshal JSON
// containing non-nil zero-length slices (meaning explicitly now empty). The
// control plane uses a separate type to marshal these fields. This type is
// primarily used for unmarshaling responses so the omitempty annotations are
// mostly useless, except that this type is also used for the integration test's
// fake control server. (It's not necessary to marshal a non-nil zero-length
// slice for the things we've needed to test in the integration tests as of
// 2023-09-09).
2020-02-05 22:16:58 +00:00
type MapResponse struct {
2022-07-28 05:21:02 +01:00
// MapSessionHandle optionally specifies a unique opaque handle for this
// stateful MapResponse session. Servers may choose not to send it, and it's
// only sent on the first MapResponse in a stream. The client can determine
// whether it's reattaching to a prior stream by seeing whether this value
// matches the requested MapRequest.MapSessionHandle.
MapSessionHandle string ` json:",omitempty" `
// Seq is a sequence number within a named map session (a response where the
// first message contains a MapSessionHandle). The Seq number may be omitted
// on responses that don't change the state of the stream, such as KeepAlive
// or certain types of PingRequests. This is the value to be sent in
// MapRequest.MapSessionSeq to resume after this message.
Seq int64 ` json:",omitempty" `
2021-03-05 04:54:44 +00:00
// KeepAlive, if set, represents an empty message just to keep
// the connection alive. When true, all other fields except
2022-03-21 21:10:25 +00:00
// PingRequest, ControlTime, and PopBrowserURL are ignored.
2021-03-05 04:54:44 +00:00
KeepAlive bool ` json:",omitempty" `
// PingRequest, if non-empty, is a request to the client to
// prove it's still there by sending an HTTP request to the
// provided URL. No auth headers are necessary.
// PingRequest may be sent on any MapResponse (ones with
// KeepAlive true or false).
PingRequest * PingRequest ` json:",omitempty" `
2020-02-05 22:16:58 +00:00
2022-03-21 21:10:25 +00:00
// PopBrowserURL, if non-empty, is a URL for the client to
// open to complete an action. The client should dup suppress
// identical URLs and only open it once for the same URL.
2022-07-19 17:20:49 +01:00
PopBrowserURL string ` json:",omitempty" `
2022-03-21 21:10:25 +00:00
2020-02-05 22:16:58 +00:00
// Networking
2021-04-19 18:56:48 +01:00
// Node describes the node making the map request.
// Starting with MapRequest.Version 18, nil means unchanged.
Node * Node ` json:",omitempty" `
// DERPMap describe the set of DERP servers available.
// A nil value means unchanged.
DERPMap * DERPMap ` json:",omitempty" `
2020-08-08 04:44:04 +01:00
// Peers, if non-empty, is the complete list of peers.
// It will be set in the first MapResponse for a long-polled request/response.
2020-12-03 20:16:10 +00:00
// Subsequent responses will be delta-encoded if MapRequest.Version >= 5 and server
// chooses, in which case Peers will be nil or zero length.
2020-08-08 04:44:04 +01:00
// If Peers is non-empty, PeersChanged and PeersRemoved should
// be ignored (and should be empty).
// Peers is always returned sorted by Node.ID.
Peers [ ] * Node ` json:",omitempty" `
// PeersChanged are the Nodes (identified by their ID) that
// have changed or been added since the past update on the
2020-12-03 20:16:10 +00:00
// HTTP response. It's not used by the server if MapRequest.Version < 5.
2020-08-08 04:44:04 +01:00
// PeersChanged is always returned sorted by Node.ID.
PeersChanged [ ] * Node ` json:",omitempty" `
// PeersRemoved are the NodeIDs that are no longer in the peer list.
PeersRemoved [ ] NodeID ` json:",omitempty" `
2020-07-31 21:27:09 +01:00
2022-07-20 21:31:20 +01:00
// PeersChangedPatch, if non-nil, means that node(s) have changed.
// This is a lighter version of the older PeersChanged support that
// only supports certain types of updates
//
// These are applied after Peers* above, but in practice the
// control server should only send these on their own, without
// the Peers* fields also set.
PeersChangedPatch [ ] * PeerChange ` json:",omitempty" `
2021-01-17 20:00:56 +00:00
// PeerSeenChange contains information on how to update peers' LastSeen
// times. If the value is false, the peer is gone. If the value is true,
// the LastSeen time is now. Absent means unchanged.
PeerSeenChange map [ NodeID ] bool ` json:",omitempty" `
2021-04-16 00:03:59 +01:00
// OnlineChange changes the value of a Peer Node.Online value.
OnlineChange map [ NodeID ] bool ` json:",omitempty" `
2021-01-05 18:37:15 +00:00
// DNSConfig contains the DNS settings for the client to use.
2021-04-12 20:12:13 +01:00
// A nil value means no change from an earlier non-nil value.
DNSConfig * DNSConfig ` json:",omitempty" `
2020-02-05 22:16:58 +00:00
2020-12-07 17:13:26 +00:00
// Domain is the name of the network that this node is
// in. It's either of the form "example.com" (for user
// foo@example.com, for multi-user networks) or
// "foo@gmail.com" (for siloed users on shared email
// providers). Its exact form should not be depended on; new
// forms are coming later.
2021-04-19 04:48:24 +01:00
// If empty, the value is unchanged.
Domain string ` json:",omitempty" `
2020-12-07 17:13:26 +00:00
2021-01-11 22:24:32 +00:00
// CollectServices reports whether this node's Tailnet has
// requested that info about services be included in HostInfo.
2021-01-12 15:54:34 +00:00
// If unset, the most recent non-empty MapResponse value in
// the HTTP response stream is used.
CollectServices opt . Bool ` json:",omitempty" `
2021-01-11 22:24:32 +00:00
2020-12-07 17:13:26 +00:00
// PacketFilter are the firewall rules.
//
// For MapRequest.Version >= 6, a nil value means the most
// previously streamed non-nil MapResponse.PacketFilter within
// the same HTTP response. A non-nil but empty list always means
// no PacketFilter (that is, to block everything).
2023-09-09 21:52:28 +01:00
//
// Note that this package's type, due its use of a slice and omitempty, is
// unable to marshal a zero-length non-nil slice. The control server needs
// to marshal this type using a separate type. See MapResponse docs.
2023-11-17 17:20:08 +00:00
//
// See PacketFilters for the newer way to send PacketFilter updates.
2021-04-19 18:56:48 +01:00
PacketFilter [ ] FilterRule ` json:",omitempty" `
2020-12-07 17:13:26 +00:00
2023-11-17 17:20:08 +00:00
// PacketFilters encodes incremental packet filter updates to the client
// without having to send the entire packet filter on any changes as
// required by the older PacketFilter (singular) field above. The map keys
// are server-assigned arbitrary strings. The map values are the new rules
// for that key, or nil to delete it. The client then concatenates all the
// rules together to generate the final packet filter. Because the
// FilterRules can only match or not match, the ordering of filter rules
// doesn't matter. (That said, the client generates the file merged packet
// filter rules by concananting all the packet filter rules sorted by the
// map key name. But it does so for stability and testability, not
// correctness. If something needs to rely on that property, something has
// gone wrong.)
//
// If the server sends a non-nil PacketFilter (above), that is equivalent to
// a named packet filter with the key "base". It is valid for the server to
// send both PacketFilter and PacketFilters in the same MapResponse or
// alternate between them within a session. The PacketFilter is applied
// first (if set) and then the PacketFilters.
//
// As a special case, the map key "*" with a value of nil means to clear all
// prior named packet filters (including any implicit "base") before
// processing the other map entries.
PacketFilters map [ string ] [ ] FilterRule ` json:",omitempty" `
2021-04-19 18:56:48 +01:00
// UserProfiles are the user profiles of nodes in the network.
// As as of 1.1.541 (mapver 5), this contains new or updated
// user profiles only.
UserProfiles [ ] UserProfile ` json:",omitempty" `
2020-04-08 06:24:06 +01:00
2023-09-09 21:52:28 +01:00
// Health, if non-nil, sets the health state of the node from the control
// plane's perspective. A nil value means no change from the previous
// MapResponse. A non-nil 0-length slice restores the health to good (no
// known problems). A non-zero length slice are the list of problems that
// the control place sees.
//
// Note that this package's type, due its use of a slice and omitempty, is
// unable to marshal a zero-length non-nil slice. The control server needs
// to marshal this type using a separate type. See MapResponse docs.
2021-09-18 20:59:55 +01:00
Health [ ] string ` json:",omitempty" `
2022-02-10 22:12:34 +00:00
// SSHPolicy, if non-nil, updates the SSH policy for how incoming
// SSH connections should be handled.
SSHPolicy * SSHPolicy ` json:",omitempty" `
2022-02-17 02:36:04 +00:00
// ControlTime, if non-zero, is the current timestamp according to the control server.
2022-02-18 18:14:14 +00:00
ControlTime * time . Time ` json:",omitempty" `
2022-02-17 02:36:04 +00:00
2022-08-29 22:02:12 +01:00
// TKAInfo describes the control plane's view of tailnet
// key authority (TKA) state.
//
// An initial nil TKAInfo indicates that the control plane
// believes TKA should not be enabled. An initial non-nil TKAInfo
// indicates the control plane believes TKA should be enabled.
// A nil TKAInfo in a mapresponse stream (i.e. a 'delta' mapresponse)
// indicates no change from the value sent earlier.
TKAInfo * TKAInfo ` json:",omitempty" `
2022-08-24 22:47:01 +01:00
2022-09-22 20:49:24 +01:00
// DomainDataPlaneAuditLogID, if non-empty, is the per-tailnet log ID to be
// used when writing data plane audit logs.
DomainDataPlaneAuditLogID string ` json:",omitempty" `
2020-04-08 06:24:06 +01:00
// Debug is normally nil, except for when the control server
// is setting debug settings on a node.
Debug * Debug ` json:",omitempty" `
2022-09-23 18:06:55 +01:00
// ControlDialPlan tells the client how to connect to the control
// server. An initial nil is equivalent to new(ControlDialPlan).
// A subsequent streamed nil means no change.
ControlDialPlan * ControlDialPlan ` json:",omitempty" `
2022-11-24 03:13:41 +00:00
// ClientVersion describes the latest client version that's available for
// download and whether the client is using it. A nil value means no change
// or nothing to report.
ClientVersion * ClientVersion ` json:",omitempty" `
2023-12-18 22:57:03 +00:00
// DefaultAutoUpdate is the default node auto-update setting for this
// tailnet. The node is free to opt-in or out locally regardless of this
// value. This value is only used on first MapResponse from control, the
// auto-update setting doesn't change if the tailnet admin flips the
// default after the node registered.
DefaultAutoUpdate opt . Bool ` json:",omitempty" `
2024-01-05 12:06:12 +00:00
// MaxKeyDuration describes the MaxKeyDuration setting for the tailnet.
// If zero, the value is unchanged.
MaxKeyDuration time . Duration ` json:",omitempty" `
2022-11-24 03:13:41 +00:00
}
// ClientVersion is information about the latest client version that's available
// for the client (and whether they're already running it).
//
// It does not include a URL to download the client, as that varies by platform.
type ClientVersion struct {
// RunningLatest is true if the client is running the latest build.
RunningLatest bool ` json:",omitempty" `
// LatestVersion is the latest version.Short ("1.34.2") version available
// for download for the client's platform and packaging type.
// It won't be populated if RunningLatest is true.
LatestVersion string ` json:",omitempty" `
2023-10-17 19:04:44 +01:00
// UrgentSecurityUpdate is set when the client is missing an important
// security update. That update may be in LatestVersion or earlier.
// UrgentSecurityUpdate should not be set if RunningLatest is false.
UrgentSecurityUpdate bool ` json:",omitempty" `
2022-11-24 03:13:41 +00:00
// Notify is whether the client should do an OS-specific notification about
// a new version being available. This should not be populated if
// RunningLatest is true. The client should not notify multiple times for
// the same LatestVersion value.
Notify bool ` json:",omitempty" `
// NotifyURL is a URL to open in the browser when the user clicks on the
// notification, when Notify is true.
NotifyURL string ` json:",omitempty" `
// NotifyText is the text to show in the notification, when Notify is true.
NotifyText string ` json:",omitempty" `
2022-09-23 18:06:55 +01:00
}
// ControlDialPlan is instructions from the control server to the client on how
// to connect to the control server; this is useful for maintaining connection
// if the client's network state changes after the initial connection, or due
// to the configuration that the control server pushes.
type ControlDialPlan struct {
// An empty list means the default: use DNS (unspecified which DNS).
Candidates [ ] ControlIPCandidate
}
// ControlIPCandidate represents a single candidate address to use when
// connecting to the control server.
type ControlIPCandidate struct {
// IP is the address to attempt connecting to.
IP netip . Addr
// DialStartSec is the number of seconds after the beginning of the
// connection process to wait before trying this candidate.
DialStartDelaySec float64 ` json:",omitempty" `
// DialTimeoutSec is the timeout for a connection to this candidate,
// starting after DialStartDelaySec.
DialTimeoutSec float64 ` json:",omitempty" `
// Priority is the relative priority of this candidate; candidates with
// a higher priority are preferred over candidates with a lower
// priority.
Priority int ` json:",omitempty" `
2020-04-08 06:24:06 +01:00
}
2023-08-18 01:29:15 +01:00
// Debug used to be a miscellaneous set of declarative debug config changes and
// imperative debug commands. They've since been mostly migrated to node
// attributes (MapResponse.Node.Capabilities) for the declarative things and c2n
// requests for the imperative things. Not much remains here. Don't add more.
2020-04-08 06:24:06 +01:00
type Debug struct {
2021-04-21 22:17:21 +01:00
// SleepSeconds requests that the client sleep for the
// provided number of seconds.
// The client can (and should) limit the value (such as 5
2023-08-17 20:29:51 +01:00
// minutes). This exists as a safety measure to slow down
// spinning clients, in case we introduce a bug in the
// state machine.
2021-04-21 22:17:21 +01:00
SleepSeconds float64 ` json:",omitempty" `
2021-06-22 19:53:41 +01:00
2022-04-18 21:43:03 +01:00
// DisableLogTail disables the logtail package. Once disabled it can't be
// re-enabled for the lifetime of the process.
2023-08-17 20:29:51 +01:00
//
// This is primarily used by Headscale.
2022-04-18 21:43:03 +01:00
DisableLogTail bool ` json:",omitempty" `
2021-11-01 18:50:46 +00:00
// Exit optionally specifies that the client should os.Exit
2023-08-17 20:29:51 +01:00
// with this code. This is a safety measure in case a client is crash
// looping or in an unsafe state and we need to remotely shut it down.
2021-11-01 18:50:46 +00:00
Exit * int ` json:",omitempty" `
2020-02-05 22:16:58 +00:00
}
2021-04-01 22:03:34 +01:00
func ( id ID ) String ( ) string { return fmt . Sprintf ( "id:%x" , int64 ( id ) ) }
func ( id UserID ) String ( ) string { return fmt . Sprintf ( "userid:%x" , int64 ( id ) ) }
func ( id LoginID ) String ( ) string { return fmt . Sprintf ( "loginid:%x" , int64 ( id ) ) }
func ( id NodeID ) String ( ) string { return fmt . Sprintf ( "nodeid:%x" , int64 ( id ) ) }
2020-02-05 22:16:58 +00:00
2020-02-16 06:23:58 +00:00
// Equal reports whether n and n2 are equal.
2020-02-05 22:16:58 +00:00
func ( n * Node ) Equal ( n2 * Node ) bool {
2020-02-16 06:23:58 +00:00
if n == nil && n2 == nil {
return true
2020-02-05 22:16:58 +00:00
}
2020-02-16 06:23:58 +00:00
return n != nil && n2 != nil &&
n . ID == n2 . ID &&
2021-01-21 02:34:50 +00:00
n . StableID == n2 . StableID &&
2020-02-16 06:23:58 +00:00
n . Name == n2 . Name &&
n . User == n2 . User &&
2021-01-05 21:52:33 +00:00
n . Sharer == n2 . Sharer &&
2022-11-02 20:13:26 +00:00
n . UnsignedPeerAPIOnly == n2 . UnsignedPeerAPIOnly &&
2020-02-16 06:23:58 +00:00
n . Key == n2 . Key &&
n . KeyExpiry . Equal ( n2 . KeyExpiry ) &&
2022-08-12 20:34:25 +01:00
bytes . Equal ( n . KeySignature , n2 . KeySignature ) &&
2020-02-16 06:23:58 +00:00
n . Machine == n2 . Machine &&
2020-06-19 03:32:55 +01:00
n . DiscoKey == n2 . DiscoKey &&
2023-04-13 18:12:31 +01:00
eqPtr ( n . Online , n2 . Online ) &&
2023-09-30 23:28:14 +01:00
slicesx . EqualSameNil ( n . Addresses , n2 . Addresses ) &&
slicesx . EqualSameNil ( n . AllowedIPs , n2 . AllowedIPs ) &&
slicesx . EqualSameNil ( n . PrimaryRoutes , n2 . PrimaryRoutes ) &&
slicesx . EqualSameNil ( n . Endpoints , n2 . Endpoints ) &&
2020-08-11 03:45:20 +01:00
n . DERP == n2 . DERP &&
2023-01-19 20:40:58 +00:00
n . Cap == n2 . Cap &&
2022-02-15 16:19:44 +00:00
n . Hostinfo . Equal ( n2 . Hostinfo ) &&
2020-02-16 06:23:58 +00:00
n . Created . Equal ( n2 . Created ) &&
2020-07-23 18:41:54 +01:00
eqTimePtr ( n . LastSeen , n2 . LastSeen ) &&
2021-01-27 16:50:31 +00:00
n . MachineAuthorized == n2 . MachineAuthorized &&
2023-09-06 18:17:25 +01:00
slices . Equal ( n . Capabilities , n2 . Capabilities ) &&
2023-09-18 16:52:22 +01:00
n . CapMap . Equal ( n2 . CapMap ) &&
2021-01-27 16:50:31 +00:00
n . ComputedName == n2 . ComputedName &&
n . computedHostIfDifferent == n2 . computedHostIfDifferent &&
2021-10-20 22:26:31 +01:00
n . ComputedNameWithHost == n2 . ComputedNameWithHost &&
2023-09-30 23:28:14 +01:00
slicesx . EqualSameNil ( n . Tags , n2 . Tags ) &&
2023-03-03 00:05:07 +00:00
n . Expired == n2 . Expired &&
2023-04-13 18:12:31 +01:00
eqPtr ( n . SelfNodeV4MasqAddrForThisPeer , n2 . SelfNodeV4MasqAddrForThisPeer ) &&
2023-09-19 01:03:53 +01:00
eqPtr ( n . SelfNodeV6MasqAddrForThisPeer , n2 . SelfNodeV6MasqAddrForThisPeer ) &&
2024-05-06 19:08:25 +01:00
n . IsWireGuardOnly == n2 . IsWireGuardOnly &&
n . IsJailed == n2 . IsJailed
2020-02-05 22:16:58 +00:00
}
2020-07-23 18:41:54 +01:00
2023-04-13 18:12:31 +01:00
func eqPtr [ T comparable ] ( a , b * T ) bool {
2021-04-16 00:03:59 +01:00
if a == b { // covers nil
return true
}
if a == nil || b == nil {
return false
}
return * a == * b
}
2020-07-23 18:41:54 +01:00
func eqTimePtr ( a , b * time . Time ) bool {
return ( ( a == nil ) == ( b == nil ) ) && ( a == nil || a . Equal ( * b ) )
}
2021-01-28 23:29:17 +00:00
2021-03-19 17:21:33 +00:00
// Oauth2Token is a copy of golang.org/x/oauth2.Token, to avoid the
// go.mod dependency on App Engine and grpc, which was causing problems.
// All we actually needed was this struct on the client side.
type Oauth2Token struct {
// AccessToken is the token that authorizes and authenticates
// the requests.
AccessToken string ` json:"access_token" `
// TokenType is the type of token.
// The Type method returns either this or "Bearer", the default.
TokenType string ` json:"token_type,omitempty" `
// RefreshToken is a token that's used by the application
// (as opposed to the user) to refresh the access token
// if it expires.
RefreshToken string ` json:"refresh_token,omitempty" `
// Expiry is the optional expiration time of the access token.
//
// If zero, TokenSource implementations will reuse the same
// token forever and RefreshToken or equivalent
// mechanisms for that TokenSource will not be used.
Expiry time . Time ` json:"expiry,omitempty" `
}
2021-04-16 18:57:46 +01:00
2023-09-06 18:17:25 +01:00
// NodeCapability represents a capability granted to the self node as listed in
// MapResponse.Node.Capabilities.
//
// It must be a URL like "https://tailscale.com/cap/file-sharing", or a
// well-known capability name like "funnel". The latter is only allowed for
// Tailscale-defined capabilities.
//
// Unlike PeerCapability, NodeCapability is not in context of a peer and is
// granted to the node itself.
//
// These are also referred to as "Node Attributes" in the ACL policy file.
type NodeCapability string
2022-04-17 16:45:49 +01:00
2023-09-06 18:17:25 +01:00
const (
CapabilityFileSharing NodeCapability = "https://tailscale.com/cap/file-sharing"
CapabilityAdmin NodeCapability = "https://tailscale.com/cap/is-admin"
CapabilitySSH NodeCapability = "https://tailscale.com/cap/ssh" // feature enabled/available
CapabilitySSHRuleIn NodeCapability = "https://tailscale.com/cap/ssh-rule-in" // some SSH rule reach this node
CapabilityDataPlaneAuditLogs NodeCapability = "https://tailscale.com/cap/data-plane-audit-logs" // feature enabled
CapabilityDebug NodeCapability = "https://tailscale.com/cap/debug" // exposes debug endpoints over the PeerAPI
2024-02-02 18:45:32 +00:00
CapabilityHTTPS NodeCapability = "https"
2022-04-17 16:45:49 +01:00
2023-01-25 18:17:40 +00:00
// CapabilityBindToInterfaceByRoute changes how Darwin nodes create
// sockets (in the net/netns package). See that package for more
// details on the behaviour of this capability.
2023-09-06 18:17:25 +01:00
CapabilityBindToInterfaceByRoute NodeCapability = "https://tailscale.com/cap/bind-to-interface-by-route"
2023-01-25 18:17:40 +00:00
2023-02-08 18:30:06 +00:00
// CapabilityDebugDisableAlternateDefaultRouteInterface changes how Darwin
// nodes get the default interface. There is an optional hook (used by the
// macOS and iOS clients) to override the default interface, this capability
// disables that and uses the default behavior (of parsing the routing
// table).
2023-09-06 18:17:25 +01:00
CapabilityDebugDisableAlternateDefaultRouteInterface NodeCapability = "https://tailscale.com/cap/debug-disable-alternate-default-route-interface"
2023-02-08 18:30:06 +00:00
// CapabilityDebugDisableBindConnToInterface disables the automatic binding
// of connections to the default network interface on Darwin nodes.
2023-09-06 18:17:25 +01:00
CapabilityDebugDisableBindConnToInterface NodeCapability = "https://tailscale.com/cap/debug-disable-bind-conn-to-interface"
2023-02-08 18:30:06 +00:00
2023-07-07 16:39:35 +01:00
// CapabilityTailnetLock indicates the node may initialize tailnet lock.
2023-09-06 18:17:25 +01:00
CapabilityTailnetLock NodeCapability = "https://tailscale.com/cap/tailnet-lock"
2022-11-30 18:34:59 +00:00
2022-11-25 03:40:48 +00:00
// Funnel warning capabilities used for reporting errors to the user.
2023-03-27 15:12:32 +01:00
// CapabilityWarnFunnelNoInvite indicates whether Funnel is enabled for the tailnet.
2023-08-09 15:06:58 +01:00
// This cap is no longer used 2023-08-09 onwards.
2023-09-06 18:17:25 +01:00
CapabilityWarnFunnelNoInvite NodeCapability = "https://tailscale.com/cap/warn-funnel-no-invite"
2022-11-25 03:40:48 +00:00
// CapabilityWarnFunnelNoHTTPS indicates HTTPS has not been enabled for the tailnet.
2023-08-09 15:06:58 +01:00
// This cap is no longer used 2023-08-09 onwards.
2023-09-06 18:17:25 +01:00
CapabilityWarnFunnelNoHTTPS NodeCapability = "https://tailscale.com/cap/warn-funnel-no-https"
2023-01-24 19:31:20 +00:00
// Debug logging capabilities
// CapabilityDebugTSDNSResolution enables verbose debug logging for DNS
// resolution for Tailscale-controlled domains (the control server, log
// server, DERP servers, etc.)
2023-09-06 18:17:25 +01:00
CapabilityDebugTSDNSResolution NodeCapability = "https://tailscale.com/cap/debug-ts-dns-resolution"
2023-03-11 16:45:40 +00:00
// CapabilityFunnelPorts specifies the ports that the Funnel is available on.
// The ports are specified as a comma-separated list of port numbers or port
// ranges (e.g. "80,443,8080-8090") in the ports query parameter.
// e.g. https://tailscale.com/cap/funnel-ports?ports=80,443,8080-8090
2023-09-06 18:17:25 +01:00
CapabilityFunnelPorts NodeCapability = "https://tailscale.com/cap/funnel-ports"
2021-06-02 04:04:37 +01:00
2024-03-22 21:18:04 +00:00
// NodeAttrOnlyTCP443 specifies that the client should not attempt to generate
// any outbound traffic that isn't TCP on port 443 (HTTPS). This is used for
// clients in restricted environments where only HTTPS traffic is allowed
// other types of traffic trips outbound firewall alarms. This thus implies
// all traffic is over DERP.
NodeAttrOnlyTCP443 NodeCapability = "only-tcp-443"
2022-11-17 21:09:43 +00:00
// NodeAttrFunnel grants the ability for a node to host ingress traffic.
2023-09-06 18:17:25 +01:00
NodeAttrFunnel NodeCapability = "funnel"
2023-01-25 21:42:04 +00:00
// NodeAttrSSHAggregator grants the ability for a node to collect SSH sessions.
2023-09-06 18:17:25 +01:00
NodeAttrSSHAggregator NodeCapability = "ssh-aggregator"
2023-08-17 05:43:56 +01:00
// NodeAttrDebugForceBackgroundSTUN forces a node to always do background
// STUN queries regardless of inactivity.
2023-09-06 18:17:25 +01:00
NodeAttrDebugForceBackgroundSTUN NodeCapability = "debug-always-stun"
2023-08-17 05:43:56 +01:00
// NodeAttrDebugDisableWGTrim disables the lazy WireGuard configuration,
// always giving WireGuard the full netmap, even for idle peers.
2023-09-06 18:17:25 +01:00
NodeAttrDebugDisableWGTrim NodeCapability = "debug-no-wg-trim"
2023-08-17 05:43:56 +01:00
// NodeAttrDisableSubnetsIfPAC controls whether subnet routers should be
// disabled if WPAD is present on the network.
2023-09-06 18:17:25 +01:00
NodeAttrDisableSubnetsIfPAC NodeCapability = "debug-disable-subnets-if-pac"
2023-08-17 05:43:56 +01:00
// NodeAttrDisableUPnP makes the client not perform a UPnP portmapping.
// By default, we want to enable it to see if it works on more clients.
//
// If UPnP catastrophically fails for people, this should be set kill
// new attempts at UPnP connections.
2023-09-06 18:17:25 +01:00
NodeAttrDisableUPnP NodeCapability = "debug-disable-upnp"
2023-08-17 05:43:56 +01:00
2023-09-02 03:28:00 +01:00
// NodeAttrDisableDeltaUpdates makes the client not process updates via the
// delta update mechanism and should instead treat all netmap changes as
// "full" ones as tailscaled did in 1.48.x and earlier.
2023-09-06 18:17:25 +01:00
NodeAttrDisableDeltaUpdates NodeCapability = "disable-delta-updates"
2023-09-02 03:28:00 +01:00
2023-08-17 05:43:56 +01:00
// NodeAttrRandomizeClientPort makes magicsock UDP bind to
// :0 to get a random local port, ignoring any configured
// fixed port.
2023-09-06 18:17:25 +01:00
NodeAttrRandomizeClientPort NodeCapability = "randomize-client-port"
2023-08-17 20:29:51 +01:00
2023-11-13 18:05:04 +00:00
// NodeAttrSilentDisco makes the client suppress disco heartbeats to its
// peers.
NodeAttrSilentDisco NodeCapability = "silent-disco"
2023-08-17 20:29:51 +01:00
// NodeAttrOneCGNATEnable makes the client prefer one big CGNAT /10 route
// rather than a /32 per peer. At most one of this or
// NodeAttrOneCGNATDisable may be set; if neither are, it's automatic.
2023-09-06 18:17:25 +01:00
NodeAttrOneCGNATEnable NodeCapability = "one-cgnat?v=true"
2023-08-17 20:29:51 +01:00
// NodeAttrOneCGNATDisable makes the client prefer a /32 route per peer
// rather than one big /10 CGNAT route. At most one of this or
// NodeAttrOneCGNATEnable may be set; if neither are, it's automatic.
2023-09-06 18:17:25 +01:00
NodeAttrOneCGNATDisable NodeCapability = "one-cgnat?v=false"
2023-09-21 10:31:48 +01:00
// NodeAttrPeerMTUEnable makes the client do path MTU discovery to its
// peers. If it isn't set, it defaults to the client default.
NodeAttrPeerMTUEnable NodeCapability = "peer-mtu-enable"
2023-09-07 21:27:50 +01:00
// NodeAttrDNSForwarderDisableTCPRetries disables retrying truncated
// DNS queries over TCP if the response is truncated.
NodeAttrDNSForwarderDisableTCPRetries NodeCapability = "dns-forwarder-disable-tcp-retries"
2023-12-04 17:08:56 +00:00
// NodeAttrLinuxMustUseIPTables forces Linux clients to use iptables for
// netfilter management.
// This cannot be set simultaneously with NodeAttrLinuxMustUseNfTables.
NodeAttrLinuxMustUseIPTables NodeCapability = "linux-netfilter?v=iptables"
// NodeAttrLinuxMustUseNfTables forces Linux clients to use nftables for
// netfilter management.
// This cannot be set simultaneously with NodeAttrLinuxMustUseIPTables.
NodeAttrLinuxMustUseNfTables NodeCapability = "linux-netfilter?v=nftables"
2024-01-04 17:29:04 +00:00
// NodeAttrSeamlessKeyRenewal makes clients enable beta functionality
// of renewing node keys without breaking connections.
NodeAttrSeamlessKeyRenewal NodeCapability = "seamless-key-renewal"
2024-01-23 17:37:32 +00:00
// NodeAttrProbeUDPLifetime makes the client probe UDP path lifetime at the
// tail end of an active direct connection in magicsock.
NodeAttrProbeUDPLifetime NodeCapability = "probe-udp-lifetime"
2024-02-02 18:45:32 +00:00
2024-04-04 21:07:58 +01:00
// NodeAttrsTaildriveShare enables sharing via Taildrive.
NodeAttrsTaildriveShare NodeCapability = "drive:share"
2024-02-09 22:23:42 +00:00
2024-04-04 21:07:58 +01:00
// NodeAttrsTaildriveAccess enables accessing shares via Taildrive.
NodeAttrsTaildriveAccess NodeCapability = "drive:access"
2024-03-05 15:54:41 +00:00
2024-03-07 19:17:40 +00:00
// NodeAttrSuggestExitNode is applied to each exit node which the control plane has determined
2024-03-05 15:54:41 +00:00
// is a recommended exit node.
2024-03-07 19:17:40 +00:00
NodeAttrSuggestExitNode NodeCapability = "suggest-exit-node"
2024-03-18 16:32:33 +00:00
// NodeAttrDisableWebClient disables using the web client.
NodeAttrDisableWebClient NodeCapability = "disable-web-client"
2024-04-12 21:31:27 +01:00
2024-04-18 21:07:08 +01:00
// NodeAttrLogExitFlows enables exit node destinations in network flow logs.
NodeAttrLogExitFlows NodeCapability = "log-exit-flows"
2024-04-25 20:05:39 +01:00
// NodeAttrAutoExitNode permits the automatic exit nodes feature.
NodeAttrAutoExitNode NodeCapability = "auto-exit-node"
2024-04-11 18:12:13 +01:00
// NodeAttrStoreAppCRoutes configures the node to store app connector routes persistently.
NodeAttrStoreAppCRoutes NodeCapability = "store-appc-routes"
2024-04-29 20:20:52 +01:00
// NodeAttrSuggestExitNodeUI allows the currently suggested exit node to appear in the client GUI.
NodeAttrSuggestExitNodeUI NodeCapability = "suggest-exit-node-ui"
2024-05-02 20:36:26 +01:00
// NodeAttrUserDialUseRoutes makes UserDial use either the peer dialer or the system dialer,
2024-05-03 00:33:13 +01:00
// depending on the destination address and the configured routes. When present, it also makes
// the DNS forwarder use UserDial instead of SystemDial when dialing resolvers.
2024-05-02 20:36:26 +01:00
NodeAttrUserDialUseRoutes NodeCapability = "user-dial-routes"
2024-05-29 18:51:50 +01:00
// NodeAttrSSHBehaviorV1 forces SSH to use the V1 behavior (no su, run SFTP in-process)
// Added 2024-05-29 in Tailscale version 1.68.
NodeAttrSSHBehaviorV1 NodeCapability = "ssh-behavior-v1"
2024-06-06 23:19:33 +01:00
2024-08-06 14:00:05 +01:00
// NodeAttrSSHBehaviorV2 forces SSH to use the V2 behavior (use su, run SFTP in child process).
// This overrides NodeAttrSSHBehaviorV1 if set.
// See forceV1Behavior in ssh/tailssh/incubator.go for distinction between
// V1 and V2 behavior.
// Added 2024-08-06 in Tailscale version 1.72.
NodeAttrSSHBehaviorV2 NodeCapability = "ssh-behavior-v2"
2024-06-06 23:19:33 +01:00
// NodeAttrDisableSplitDNSWhenNoCustomResolvers indicates that the node's
// DNS manager should not adopt a split DNS configuration even though the
// Config of the resolver only contains routes that do not specify custom
// resolver(s), hence all DNS queries can be safely sent to the upstream
// DNS resolver and the node's DNS forwarder doesn't need to handle all
// DNS traffic.
// This is for now (2024-06-06) an iOS-specific battery life optimization,
// and this node attribute allows us to disable the optimization remotely
// if needed.
NodeAttrDisableSplitDNSWhenNoCustomResolvers NodeCapability = "disable-split-dns-when-no-custom-resolvers"
2024-06-11 04:05:15 +01:00
// NodeAttrDisableLocalDNSOverrideViaNRPT indicates that the node's DNS manager should not
// create a default (catch-all) Windows NRPT rule when "Override local DNS" is enabled.
// Without this rule, Windows 8.1 and newer devices issue parallel DNS requests to DNS servers
// associated with all network adapters, even when "Override local DNS" is enabled and/or
// a Mullvad exit node is being used, resulting in DNS leaks.
// We began creating this rule on 2024-06-14, and this node attribute
// allows us to disable the new behavior remotely if needed.
NodeAttrDisableLocalDNSOverrideViaNRPT NodeCapability = "disable-local-dns-override-via-nrpt"
2024-07-09 04:31:16 +01:00
// NodeAttrDisableMagicSockCryptoRouting disables the use of the
// magicsock cryptorouting hook. See tailscale/corp#20732.
NodeAttrDisableMagicSockCryptoRouting NodeCapability = "disable-magicsock-crypto-routing"
2024-07-26 19:25:55 +01:00
// NodeAttrDisableCaptivePortalDetection instructs the client to not perform captive portal detection
// automatically when the network state changes.
NodeAttrDisableCaptivePortalDetection NodeCapability = "disable-captive-portal-detection"
2024-09-12 23:18:14 +01:00
// NodeAttrSSHEnvironmentVariables enables logic for handling environment variables sent
// via SendEnv in the SSH server and applying them to the SSH session.
NodeAttrSSHEnvironmentVariables NodeCapability = "ssh-env-vars"
2022-11-17 21:09:43 +00:00
)
2021-06-02 04:04:37 +01:00
// SetDNSRequest is a request to add a DNS record.
//
// This is used for ACME DNS-01 challenges (so people can use
// LetsEncrypt, etc).
//
// The request is encoded to JSON, encrypted with golang.org/x/crypto/nacl/box,
// using the local machine key, and sent to:
2022-08-02 17:33:46 +01:00
//
2021-06-02 04:04:37 +01:00
// https://login.tailscale.com/machine/<mkey hex>/set-dns
type SetDNSRequest struct {
2022-03-06 17:32:52 +00:00
// Version is the client's capabilities
// (CurrentCapabilityVersion) when using the Noise transport.
//
// When using the original nacl crypto_box transport, the
// value must be 1.
Version CapabilityVersion
2021-06-02 04:04:37 +01:00
// NodeKey is the client's current node key.
2021-11-02 03:55:52 +00:00
NodeKey key . NodePublic
2021-06-02 04:04:37 +01:00
// Name is the domain name for which to create a record.
2021-06-15 20:12:15 +01:00
// For ACME DNS-01 challenges, it should be one of the domains
// in MapResponse.DNSConfig.CertDomains with the prefix
// "_acme-challenge.".
2021-06-02 04:04:37 +01:00
Name string
// Type is the DNS record type. For ACME DNS-01 challenges, it
// should be "TXT".
Type string
// Value is the value to add.
Value string
}
2022-02-10 22:12:34 +00:00
2022-03-07 20:37:06 +00:00
// SetDNSResponse is the response to a SetDNSRequest.
type SetDNSResponse struct { }
2022-06-21 15:44:11 +01:00
// HealthChangeRequest is the JSON request body type used to report
// node health changes to https://<control>/machine/<mkey hex>/update-health.
type HealthChangeRequest struct {
Subsys string // a health.Subsystem value in string form
Error string // or empty if cleared
2024-03-20 13:41:56 +00:00
// NodeKey is the client's current node key.
// In clients <= 1.62.0 it was always the zero value.
NodeKey key . NodePublic
2022-06-21 15:44:11 +01:00
}
2022-02-10 22:12:34 +00:00
// SSHPolicy is the policy for how to handle incoming SSH connections
// over Tailscale.
type SSHPolicy struct {
2022-04-19 05:36:32 +01:00
// Rules are the rules to process for an incoming SSH connection. The first
// matching rule takes its action and stops processing further rules.
//
// When an incoming connection first starts, all rules are evaluated in
// "none" auth mode, where the client hasn't even been asked to send a
// public key. All SSHRule.Principals requiring a public key won't match. If
// a rule matches on the first pass and its Action is reject, the
// authentication fails with that action's rejection message, if any.
//
// If the first pass rule evaluation matches nothing without matching an
// Action with Reject set, the rules are considered to see whether public
// keys might still result in a match. If not, "none" auth is terminated
// before proceeding to public key mode. If so, the client is asked to try
// public key authentication and the rules are evaluated again for each of
// the client's present keys.
2022-02-10 22:12:34 +00:00
Rules [ ] * SSHRule ` json:"rules" `
}
// An SSH rule is a match predicate and associated action for an incoming SSH connection.
type SSHRule struct {
// RuleExpires, if non-nil, is when this rule expires.
//
// For example, a (principal,sshuser) tuple might be granted
// prompt-free SSH access for N minutes, so this rule would be
// before a expiration-free rule for the same principal that
// required an auth prompt. This permits the control plane to
// be out of the path for already-authorized SSH pairs.
//
// Once a rule matches, the lifetime of any accepting connection
// is subject to the SSHAction.SessionExpires time, if any.
RuleExpires * time . Time ` json:"ruleExpires,omitempty" `
// Principals matches an incoming connection. If the connection
// matches anything in this list and also matches SSHUsers,
// then Action is applied.
Principals [ ] * SSHPrincipal ` json:"principals" `
// SSHUsers are the SSH users that this rule matches. It is a
// map from either ssh-user|"*" => local-user. The map must
// contain a key for either ssh-user or, as a fallback, "*" to
// match anything. If it does, the map entry's value is the
// actual user that's logged in.
2022-02-18 22:10:26 +00:00
// If the map value is the empty string (for either the
// requested SSH user or "*"), the rule doesn't match.
2022-03-21 17:39:54 +00:00
// If the map value is "=", it means the ssh-user should map
// directly to the local-user.
2022-02-18 22:10:26 +00:00
// It may be nil if the Action is reject.
2022-02-10 22:12:34 +00:00
SSHUsers map [ string ] string ` json:"sshUsers" `
// Action is the outcome to task.
// A nil or invalid action means to deny.
Action * SSHAction ` json:"action" `
2024-09-23 03:15:26 +01:00
// AcceptEnv is a slice of environment variable names that are allowlisted
// for the SSH rule in the policy file.
//
// AcceptEnv values may contain * and ? wildcard characters which match against
// an arbitrary number of characters or a single character respectively.
AcceptEnv [ ] string ` json:"acceptEnv,omitempty" `
2022-02-10 22:12:34 +00:00
}
// SSHPrincipal is either a particular node or a user on any node.
type SSHPrincipal struct {
2022-04-01 20:57:12 +01:00
// Matching any one of the following four field causes a match.
// It must also match Certs, if non-empty.
2022-02-10 22:12:34 +00:00
Node StableNodeID ` json:"node,omitempty" `
NodeIP string ` json:"nodeIP,omitempty" `
UserLogin string ` json:"userLogin,omitempty" ` // email-ish: foo@example.com, bar@github
2022-04-01 20:57:12 +01:00
Any bool ` json:"any,omitempty" ` // if true, match any connection
2022-02-10 22:12:34 +00:00
// TODO(bradfitz): add StableUserID, once that exists
2022-04-01 20:57:12 +01:00
// PubKeys, if non-empty, means that this SSHPrincipal only
// matches if one of these public keys is presented by the user.
//
// As a special case, if len(PubKeys) == 1 and PubKeys[0] starts
// with "https://", then it's fetched (like https://github.com/username.keys).
2022-04-21 04:10:04 +01:00
// In that case, the following variable expansions are also supported
// in the URL:
// * $LOGINNAME_EMAIL ("foo@bar.com" or "foo@github")
// * $LOGINNAME_LOCALPART (the "foo" from either of the above)
2022-04-01 20:57:12 +01:00
PubKeys [ ] string ` json:"pubKeys,omitempty" `
2022-02-10 22:12:34 +00:00
}
// SSHAction is how to handle an incoming connection.
// At most one field should be non-zero.
type SSHAction struct {
// Message, if non-empty, is shown to the user before the
// action occurs.
Message string ` json:"message,omitempty" `
// Reject, if true, terminates the connection. This action
// has higher priority that Accept, if given.
// The reason this is exists is primarily so a response
// from HoldAndDelegate has a way to stop the poll.
Reject bool ` json:"reject,omitempty" `
// Accept, if true, accepts the connection immediately
// without further prompts.
Accept bool ` json:"accept,omitempty" `
2022-04-21 22:13:42 +01:00
// SessionDuration, if non-zero, is how long the session can stay open
2022-02-18 22:10:26 +00:00
// before being forcefully terminated.
2022-04-21 22:13:42 +01:00
SessionDuration time . Duration ` json:"sessionDuration,omitempty" `
2022-02-10 22:12:34 +00:00
2022-03-14 20:26:06 +00:00
// AllowAgentForwarding, if true, allows accepted connections to forward
// the ssh agent if requested.
AllowAgentForwarding bool ` json:"allowAgentForwarding,omitempty" `
2022-03-10 18:28:42 +00:00
// HoldAndDelegate, if non-empty, is a URL that serves an
// outcome verdict. The connection will be accepted and will
// block until the provided long-polling URL serves a new
// SSHAction JSON value. The URL must be fetched using the
// Noise transport (in package control/control{base,http}).
// If the long poll breaks before returning a complete HTTP
// response, it should be re-fetched as long as the SSH
// session is open.
2022-03-23 00:36:55 +00:00
//
// The following variables in the URL are expanded by tailscaled:
//
// * $SRC_NODE_IP (URL escaped)
// * $SRC_NODE_ID (Node.ID as int64 string)
// * $DST_NODE_IP (URL escaped)
// * $DST_NODE_ID (Node.ID as int64 string)
// * $SSH_USER (URL escaped, ssh user requested)
// * $LOCAL_USER (URL escaped, local user mapped)
2022-02-10 22:12:34 +00:00
HoldAndDelegate string ` json:"holdAndDelegate,omitempty" `
2022-03-14 20:23:17 +00:00
// AllowLocalPortForwarding, if true, allows accepted connections
// to use local port forwarding if requested.
AllowLocalPortForwarding bool ` json:"allowLocalPortForwarding,omitempty" `
2023-01-25 21:42:04 +00:00
2023-06-09 02:39:27 +01:00
// AllowRemotePortForwarding, if true, allows accepted connections
// to use remote port forwarding if requested.
AllowRemotePortForwarding bool ` json:"allowRemotePortForwarding,omitempty" `
2023-03-21 19:59:05 +00:00
// Recorders defines the destinations of the SSH session recorders.
// The recording will be uploaded to http://addr:port/record.
2023-04-20 05:10:55 +01:00
Recorders [ ] netip . AddrPort ` json:"recorders,omitempty" `
// OnRecorderFailure is the action to take if recording fails.
// If nil, the default action is to fail open.
OnRecordingFailure * SSHRecorderFailureAction ` json:"onRecordingFailure,omitempty" `
}
// SSHRecorderFailureAction is the action to take if recording fails.
type SSHRecorderFailureAction struct {
// RejectSessionWithMessage, if not empty, specifies that the session should
// be rejected if the recording fails to start.
// The message will be shown to the user before the session is rejected.
RejectSessionWithMessage string ` json:",omitempty" `
// TerminateSessionWithMessage, if not empty, specifies that the session
// should be terminated if the recording fails after it has started. The
// message will be shown to the user before the session is terminated.
TerminateSessionWithMessage string ` json:",omitempty" `
// NotifyURL, if non-empty, specifies a HTTP POST URL to notify when the
// recording fails. The payload is the JSON encoded
// SSHRecordingFailureNotifyRequest struct. The host field in the URL is
// ignored, and it will be sent to control over the Noise transport.
NotifyURL string ` json:",omitempty" `
}
2023-05-05 02:08:11 +01:00
// SSHEventNotifyRequest is the JSON payload sent to the NotifyURL
// for an SSH event.
type SSHEventNotifyRequest struct {
// EventType is the type of notify request being sent.
EventType SSHEventType
2023-05-05 19:03:15 +01:00
// ConnectionID uniquely identifies a connection made to the SSH server.
// It may be shared across multiple sessions over the same connection in
// case a single connection creates multiple sessions.
ConnectionID string
2023-04-20 05:10:55 +01:00
// CapVersion is the client's current CapabilityVersion.
CapVersion CapabilityVersion
// NodeKey is the client's current node key.
NodeKey key . NodePublic
// SrcNode is the ID of the node that initiated the SSH session.
SrcNode NodeID
// SSHUser is the user that was presented to the SSH server.
SSHUser string
// LocalUser is the user that was resolved from the SSHUser for the local machine.
LocalUser string
2023-05-05 02:08:11 +01:00
// RecordingAttempts is the list of recorders that were attempted, in order.
RecordingAttempts [ ] * SSHRecordingAttempt
2023-04-20 05:10:55 +01:00
}
2023-05-05 02:08:11 +01:00
// SSHEventType defines the event type linked to a SSH action or state.
type SSHEventType int
const (
2023-05-06 18:27:10 +01:00
UnspecifiedSSHEventType SSHEventType = 0
// SSHSessionRecordingRejected is the event that
// defines when a SSH session cannot be started
// because no recorder is available for session
// recording, and the SSHRecorderFailureAction
// RejectSessionWithMessage is not empty.
SSHSessionRecordingRejected SSHEventType = 1
// SSHSessionRecordingTerminated is the event that
// defines when session recording has failed
// during the session and the SSHRecorderFailureAction
// TerminateSessionWithMessage is not empty.
2023-05-05 02:08:11 +01:00
SSHSessionRecordingTerminated SSHEventType = 2
2023-05-06 18:27:10 +01:00
// SSHSessionRecordingFailed is the event that
// defines when session recording is unavailable and
// the SSHRecorderFailureAction RejectSessionWithMessage
// or TerminateSessionWithMessage is empty.
SSHSessionRecordingFailed SSHEventType = 3
2023-05-05 02:08:11 +01:00
)
2023-04-20 05:10:55 +01:00
// SSHRecordingAttempt is a single attempt to start a recording.
type SSHRecordingAttempt struct {
// Recorder is the address of the recorder that was attempted.
Recorder netip . AddrPort
// FailureMessage is the error message of the failed attempt.
FailureMessage string
2022-02-10 22:12:34 +00:00
}
2022-03-06 04:43:49 +00:00
2023-08-02 15:56:18 +01:00
// QueryFeatureRequest is a request sent to "/machine/feature/query"
// to get instructions on how to enable a feature, such as Funnel,
// for the node's tailnet.
//
// See QueryFeatureResponse for response structure.
type QueryFeatureRequest struct {
// Feature is the string identifier for a feature.
Feature string ` json:",omitempty" `
// NodeKey is the client's current node key.
NodeKey key . NodePublic ` json:",omitempty" `
}
// QueryFeatureResponse is the response to an QueryFeatureRequest.
2023-08-09 15:06:58 +01:00
// See cli.enableFeatureInteractive for usage.
2023-08-02 15:56:18 +01:00
type QueryFeatureResponse struct {
// Complete is true when the feature is already enabled.
Complete bool ` json:",omitempty" `
// Text holds lines to display in the CLI with information
// about the feature and how to enable it.
//
// Lines are separated by newline characters. The final
// newline may be omitted.
Text string ` json:",omitempty" `
// URL is the link for the user to visit to take action on
// enabling the feature.
//
// When empty, there is no action for this user to take.
URL string ` json:",omitempty" `
2023-08-09 15:06:58 +01:00
// ShouldWait specifies whether the CLI should block and
// wait for the user to enable the feature.
2023-08-02 15:56:18 +01:00
//
2023-08-09 15:06:58 +01:00
// If this is true, the enablement from the control server
// is expected to be a quick and uninterrupted process for
// the user, and blocking allows them to immediately start
// using the feature once enabled without rerunning the
// command (e.g. no need to re-run "funnel on").
//
// The CLI can watch the IPN notification bus for changes in
// required node capabilities to know when to continue.
ShouldWait bool ` json:",omitempty" `
2023-08-02 15:56:18 +01:00
}
2023-10-10 22:38:35 +01:00
// WebClientAuthResponse is the response to a web client authentication request
// sent to "/machine/webclient/action" or "/machine/webclient/wait".
// See client/web for usage.
type WebClientAuthResponse struct {
2023-10-19 19:46:25 +01:00
// ID is a unique identifier for the session auth request.
// It can be supplied to "/machine/webclient/wait" to pause until
// the session authentication has been completed.
ID string ` json:",omitempty" `
2023-10-10 22:38:35 +01:00
// URL is the link for the user to visit to authenticate the session.
//
// When empty, there is no action for the user to take.
URL string ` json:",omitempty" `
2023-10-19 19:46:25 +01:00
// Complete is true when the session authentication has been completed.
Complete bool ` json:",omitempty" `
2023-10-10 22:38:35 +01:00
}
2022-03-06 04:43:49 +00:00
// OverTLSPublicKeyResponse is the JSON response to /key?v=<n>
// over HTTPS (regular TLS) to the Tailscale control plane server,
// where the 'v' argument is the client's current capability version
// (previously known as the "MapRequest version").
//
// The "OverTLS" prefix is to loudly declare that this exchange
// doesn't happen over Noise and can be intercepted/MITM'ed by
2022-09-25 19:29:55 +01:00
// enterprise/corp proxies where the organization can put TLS roots
2022-03-06 04:43:49 +00:00
// on devices.
type OverTLSPublicKeyResponse struct {
// LegacyPublic specifies the control plane server's original
// NaCl crypto_box machine key.
// It will be zero for sufficiently new clients, based on their
// advertised "v" parameter (the CurrentMapRequestVersion).
// In that case, only the newer Noise-based transport may be used
// using the PublicKey field.
LegacyPublicKey key . MachinePublic ` json:"legacyPublicKey" `
// PublicKey specifies the server's public key for the
// Noise-based control plane protocol. (see packages
// control/controlbase and control/controlhttp)
PublicKey key . MachinePublic ` json:"publicKey" `
}
2022-03-23 04:49:27 +00:00
// TokenRequest is a request to get an OIDC ID token for an audience.
// The token can be presented to any resource provider which offers OIDC
// Federation.
//
// It is JSON-encoded and sent over Noise to "/machine/id-token".
type TokenRequest struct {
// CapVersion is the client's current CapabilityVersion.
CapVersion CapabilityVersion
// NodeKey is the client's current node key.
NodeKey key . NodePublic
// Audience the token is being requested for.
Audience string
}
// TokenResponse is the response to a TokenRequest.
type TokenResponse struct {
// IDToken is a JWT encoding the following standard claims:
//
// `sub` | the MagicDNS name of the node
// `aud` | Audience from the request
// `exp` | Token expiry
// `iat` | Token issuance time
// `iss` | Issuer
// `jti` | Random token identifier
// `nbf` | Not before time
//
// It also encodes the following Tailscale specific claims:
//
// `key` | the node public key
// `addresses` | the Tailscale IPs of the node
// `nid` | the node ID
// `node` | the name of the node
// `domain` | the domain of the node, it has the same format as MapResponse.Domain.
// `tags` | an array of <domain:tag> on the node (like alice.github:tag:foo or example.com:tag:foo)
// `user` | user emailish (like alice.github:alice@github or example.com:bob@example.com), if not tagged
// `uid` | user ID, if not tagged
IDToken string ` json:"id_token" `
}
2022-07-20 21:31:20 +01:00
// PeerChange is an update to a node.
type PeerChange struct {
// NodeID is the node ID being mutated. If the NodeID is not
// known in the current netmap, this update should be
// ignored. (But the server will try not to send such useless
// updates.)
NodeID NodeID
// DERPRegion, if non-zero, means that NodeID's home DERP
// region ID is now this number.
DERPRegion int ` json:",omitempty" `
2023-01-19 20:40:58 +00:00
// Cap, if non-zero, means that NodeID's capability version has changed.
Cap CapabilityVersion ` json:",omitempty" `
2023-09-18 16:52:22 +01:00
// CapMap, if non-nil, means that NodeID's capability map has changed.
CapMap NodeCapMap ` json:",omitempty" `
2023-01-19 20:40:58 +00:00
2022-07-20 21:31:20 +01:00
// Endpoints, if non-empty, means that NodeID's UDP Endpoints
// have changed to these.
2023-10-01 05:05:02 +01:00
Endpoints [ ] netip . AddrPort ` json:",omitempty" `
2022-08-03 04:42:13 +01:00
// Key, if non-nil, means that the NodeID's wireguard public key changed.
Key * key . NodePublic ` json:",omitempty" `
2022-08-12 20:34:25 +01:00
// KeySignature, if non-nil, means that the signature of the wireguard
// public key has changed.
KeySignature tkatype . MarshaledSignature ` json:",omitempty" `
2022-08-03 04:42:13 +01:00
// DiscoKey, if non-nil, means that the NodeID's discokey changed.
DiscoKey * key . DiscoPublic ` json:",omitempty" `
// Online, if non-nil, means that the NodeID's online status changed.
Online * bool ` json:",omitempty" `
// LastSeen, if non-nil, means that the NodeID's online status changed.
LastSeen * time . Time ` json:",omitempty" `
// KeyExpiry, if non-nil, changes the NodeID's key expiry.
KeyExpiry * time . Time ` json:",omitempty" `
2022-07-20 21:31:20 +01:00
}
// DerpMagicIP is a fake WireGuard endpoint IP address that means to
// use DERP. When used (in the Node.DERP field), the port number of
// the WireGuard endpoint is the DERP region ID number to use.
//
// Mnemonic: 3.3.40 are numbers above the keys D, E, R, P.
const DerpMagicIP = "127.3.3.40"
2022-10-30 15:42:54 +00:00
2023-07-26 20:06:03 +01:00
var DerpMagicIPAddr = netip . MustParseAddr ( DerpMagicIP )
2022-10-30 15:42:54 +00:00
// EarlyNoise is the early payload that's sent over Noise but before the HTTP/2
// handshake when connecting to the coordination server.
//
// This exists to let the server push some early info to client for that
// stateful HTTP/2+Noise connection without incurring an extra round trip. (This
// would've used HTTP/2 server push, had Go's client-side APIs been available)
type EarlyNoise struct {
// NodeKeyChallenge is a random per-connection public key to be used by
// the client to prove possession of a wireguard private key.
NodeKeyChallenge key . ChallengePublic ` json:"nodeKeyChallenge" `
}
2024-03-20 13:41:56 +00:00
// LBHeader is the HTTP request header used to provide a load balancer or
// internal reverse proxy with information about the request body without the
// reverse proxy needing to read the body to parse it out. Think of it akin to
// an HTTP Host header or SNI. The value may be absent (notably for old clients)
// but if present, it should match the request. A non-empty value that doesn't
// match the request body's.
//
// The possible values depend on the request path, but for /machine (Noise)
// requests, they'll usually be a node public key (in key.NodePublic.String
// format), matching the Request JSON body's NodeKey.
//
// Note that this is not a security or authentication header; it's strictly
// denormalized redundant data as an optimization.
//
// For some request types, the header may have multiple values. (e.g. OldNodeKey
// vs NodeKey)
const LBHeader = "Ts-Lb"