mirror of
https://github.com/tailscale/tailscale.git
synced 2026-11-27 03:56:25 -08:00
tailcfg: add Node.StableTailnetID and bump capver (#21314)
Add Node.StableTailnetID for control to send the current tailnet's stable ID on the self node. Expose it as CurrentTailnet.StableID in LocalAPI status and `tailscale status --json`, and display it in `tailscale whoami`. Bump CurrentCapabilityVersion to 148. Updates #14375 RELNOTE: Show the current tailnet's stable ID in status JSON and whoami. Change-Id: I0525ff735de8113c8d124045a94e00c19a5a02e2 Signed-off-by: Andrew Dunham <[email protected]>
This commit is contained in:
1 parent
8b3b8f122e
commit
158a2476c0
12 files changed
+212
-6
No files matched your search
@@ -99,8 +99,10 @@ func printWhoIs(who *apitype.WhoIsResponse, tailnet *ipnstate.TailnetStatus, asJ
|
||||
}
|
||||
}
|
||||
fmt.Fprintln(w, "Tailnet:")
|
||||
// TODO(will@): plumb through StableTailnetID so we can show that here as well
|
||||
fmt.Fprintf(w, " Name:\t%s\n", cmp.Or(displayName, tailnet.Name))
|
||||
if !tailnet.StableID.IsZero() {
|
||||
fmt.Fprintf(w, " ID:\t%s\n", tailnet.StableID)
|
||||
}
|
||||
fmt.Fprintf(w, " MagicDNS Suffix:\t%s\n", tailnet.MagicDNSSuffix)
|
||||
}
|
||||
w.Flush()
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
// Copyright (c) Tailscale Inc & contributors
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
package cli
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"tailscale.com/client/tailscale/apitype"
|
||||
"tailscale.com/ipn/ipnstate"
|
||||
"tailscale.com/tailcfg"
|
||||
"tailscale.com/tstest"
|
||||
)
|
||||
|
||||
func TestPrintWhoIsTailnet(t *testing.T) {
|
||||
who := &apitype.WhoIsResponse{
|
||||
Node: &tailcfg.Node{Name: "node.example.ts.net.", StableID: "node-abcd"},
|
||||
UserProfile: &tailcfg.UserProfile{ID: 1, LoginName: "[email protected]"},
|
||||
}
|
||||
for _, tt := range []struct {
|
||||
name string
|
||||
tailnet *ipnstate.TailnetStatus
|
||||
wantTailnet string
|
||||
}{
|
||||
{
|
||||
name: "with_id",
|
||||
tailnet: &ipnstate.TailnetStatus{
|
||||
Name: "example.com", StableID: "tailnet-abcd", MagicDNSSuffix: "example.ts.net",
|
||||
},
|
||||
wantTailnet: "Name: example.com ID: tailnet-abcd MagicDNS Suffix: example.ts.net",
|
||||
},
|
||||
{
|
||||
name: "without_id",
|
||||
tailnet: &ipnstate.TailnetStatus{
|
||||
Name: "example.com", MagicDNSSuffix: "example.ts.net",
|
||||
},
|
||||
wantTailnet: "Name: example.com MagicDNS Suffix: example.ts.net",
|
||||
},
|
||||
{name: "peer"},
|
||||
} {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
var out strings.Builder
|
||||
tstest.Replace[io.Writer](t, &Stdout, &out)
|
||||
if err := printWhoIs(who, tt.tailnet, false); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// Get everything after the section header
|
||||
_, tailnetOutput, hasTailnet := strings.Cut(out.String(), "Tailnet:\n")
|
||||
if want := tt.tailnet != nil; hasTailnet != want {
|
||||
t.Fatalf("Tailnet section present = %v; want %v", hasTailnet, want)
|
||||
}
|
||||
// Ignore tabwriter's spacing when comparing the contents.
|
||||
gotTailnet := strings.Join(strings.Fields(tailnetOutput), " ")
|
||||
if gotTailnet != tt.wantTailnet {
|
||||
t.Errorf("tailnet output = %q; want %q", gotTailnet, tt.wantTailnet)
|
||||
}
|
||||
|
||||
out.Reset()
|
||||
if err := printWhoIs(who, tt.tailnet, true); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var got whoisAndTailnet
|
||||
if err := json.Unmarshal([]byte(out.String()), &got); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !reflect.DeepEqual(got.CurrentTailnet, tt.tailnet) {
|
||||
t.Errorf("JSON CurrentTailnet = %+v; want %+v", got.CurrentTailnet, tt.tailnet)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -775,8 +775,8 @@ func peerChangeDiff(was tailcfg.NodeView, n *tailcfg.Node, onFalse func(string))
|
||||
case "computedHostIfDifferent", "ComputedName", "ComputedNameWithHost":
|
||||
// Caller's responsibility to have populated these.
|
||||
continue
|
||||
case "DataPlaneAuditLogID":
|
||||
// Not sent for peers.
|
||||
case "DataPlaneAuditLogID", "StableTailnetID":
|
||||
// Not sent for peers.
|
||||
case "Capabilities":
|
||||
// Deprecated; see https://github.com/tailscale/tailscale/issues/11508
|
||||
// And it was never sent by any known control server.
|
||||
|
||||
@@ -1499,6 +1499,7 @@ func (b *LocalBackend) updateStatusLocked(sb *ipnstate.StatusBuilder) {
|
||||
s.CurrentTailnet.MagicDNSSuffix = nm.MagicDNSSuffix()
|
||||
s.CurrentTailnet.MagicDNSEnabled = nm.DNS.Proxied
|
||||
s.CurrentTailnet.Name = nm.Domain
|
||||
s.CurrentTailnet.StableID = nm.StableTailnetID()
|
||||
if prefs := b.pm.CurrentPrefs(); prefs.Valid() {
|
||||
if !prefs.RouteAll() && nm.AnyPeersAdvertiseRoutes() {
|
||||
s.Health = append(s.Health, healthmsg.WarnAcceptRoutesOff)
|
||||
|
||||
@@ -1936,6 +1936,48 @@ func TestStatusPeerCapabilities(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestStatusStableTailnetID(t *testing.T) {
|
||||
b := newTestLocalBackend(t)
|
||||
for _, tt := range []struct {
|
||||
name string
|
||||
stableID tailcfg.StableTailnetID
|
||||
}{
|
||||
{name: "populated", stableID: "tailnet-abcd"},
|
||||
{name: "missing"},
|
||||
} {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
b.setNetMapLocked(&netmap.NetworkMap{
|
||||
Domain: "example.com",
|
||||
SelfNode: (&tailcfg.Node{
|
||||
MachineAuthorized: true,
|
||||
Addresses: ipps("100.101.101.101"),
|
||||
StableTailnetID: tt.stableID,
|
||||
}).View(),
|
||||
})
|
||||
|
||||
// The ID is returned with or without peers.
|
||||
t.Run("with_peers", func(t *testing.T) {
|
||||
st := b.Status()
|
||||
if st.CurrentTailnet == nil {
|
||||
t.Fatalf("CurrentTailnet is nil")
|
||||
}
|
||||
if got := st.CurrentTailnet.StableID; got != tt.stableID {
|
||||
t.Errorf("CurrentTailnet.StableID = %q; want %q", got, tt.stableID)
|
||||
}
|
||||
})
|
||||
t.Run("without_peers", func(t *testing.T) {
|
||||
st := b.StatusWithoutPeers()
|
||||
if st.CurrentTailnet == nil {
|
||||
t.Fatalf("CurrentTailnet is nil")
|
||||
}
|
||||
if got := st.CurrentTailnet.StableID; got != tt.stableID {
|
||||
t.Errorf("CurrentTailnet.StableID = %q; want %q", got, tt.stableID)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestStatusWithoutPeersSelfUserProfile verifies that the self user's
|
||||
// UserProfile is reported in Status.User even when peers are omitted, so that
|
||||
// callers like `tailscale status --peers=false` can resolve the self node's
|
||||
|
||||
@@ -173,6 +173,10 @@ type TailnetStatus struct {
|
||||
// Name is the name of the network that's currently in use.
|
||||
Name string
|
||||
|
||||
// StableID is the stable, unique identifier of the tailnet, as used to
|
||||
// identify the tailnet in the Tailscale API.
|
||||
StableID tailcfg.StableTailnetID
|
||||
|
||||
// MagicDNSSuffix is the network's MagicDNS suffix for nodes
|
||||
// in the network such as "userfoo.tailscale.net".
|
||||
// There are no surrounding dots.
|
||||
|
||||
+21
-2
@@ -196,7 +196,8 @@ type CapabilityVersion int
|
||||
// - 145: 2026-08-04: Client understands [NodeAttrScopeQuad100OnMacOS]
|
||||
// - 146: 2026-09-02: Client understands [NodeAttrConnReject]; can handle C2N /debug/rejects.
|
||||
// - 147: 2026-09-09: Client handles 429/503 responses with retry-after headers to /machine/ endpoints
|
||||
const CurrentCapabilityVersion CapabilityVersion = 147
|
||||
// - 148: 2026-09-15: Client understands [Node.StableTailnetID]
|
||||
const CurrentCapabilityVersion CapabilityVersion = 148
|
||||
|
||||
// ID is an integer ID for a user, node, or login allocated by the
|
||||
// control plane.
|
||||
@@ -261,6 +262,16 @@ func (u StableNodeID) IsZero() bool {
|
||||
return u == ""
|
||||
}
|
||||
|
||||
// StableTailnetID is the stable and opaque identifier of the tailnet this node
|
||||
// is a member of, as used to identify the tailnet in the Tailscale API. These
|
||||
// IDs are guaranteed to be unique across all tailnets for a single control
|
||||
// server instance, but may or may not be unique across different servers.
|
||||
type StableTailnetID string
|
||||
|
||||
func (id StableTailnetID) IsZero() bool {
|
||||
return id == ""
|
||||
}
|
||||
|
||||
// User is a Tailscale user.
|
||||
//
|
||||
// A user can have multiple logins associated with it (e.g. gmail and github oauth).
|
||||
@@ -543,6 +554,13 @@ type Node struct {
|
||||
// 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"`
|
||||
|
||||
// StableTailnetID is the identifier of the tailnet this node is a
|
||||
// member of.
|
||||
//
|
||||
// Control only populates this for the self node in a MapResponse
|
||||
// (MapResponse.Node); it is empty for peers.
|
||||
StableTailnetID StableTailnetID `json:",omitzero"`
|
||||
}
|
||||
|
||||
// HasCap reports whether the node has the given capability.
|
||||
@@ -2415,7 +2433,8 @@ func (n *Node) Equal(n2 *Node) bool {
|
||||
eqPtr(n.SelfNodeV4MasqAddrForThisPeer, n2.SelfNodeV4MasqAddrForThisPeer) &&
|
||||
eqPtr(n.SelfNodeV6MasqAddrForThisPeer, n2.SelfNodeV6MasqAddrForThisPeer) &&
|
||||
n.IsWireGuardOnly == n2.IsWireGuardOnly &&
|
||||
n.IsJailed == n2.IsJailed
|
||||
n.IsJailed == n2.IsJailed &&
|
||||
n.StableTailnetID == n2.StableTailnetID
|
||||
}
|
||||
|
||||
func eqPtr[T comparable](a, b *T) bool {
|
||||
|
||||
@@ -122,6 +122,7 @@ var _NodeCloneNeedsRegeneration = Node(struct {
|
||||
IsWireGuardOnly bool
|
||||
IsJailed bool
|
||||
ExitNodeDNSResolvers []*dnstype.Resolver
|
||||
StableTailnetID StableTailnetID
|
||||
}{})
|
||||
|
||||
// Clone makes a deep copy of Hostinfo.
|
||||
|
||||
@@ -350,6 +350,7 @@ func TestNodeEqual(t *testing.T) {
|
||||
"ComputedName", "computedHostIfDifferent", "ComputedNameWithHost",
|
||||
"DataPlaneAuditLogID", "Expired", "SelfNodeV4MasqAddrForThisPeer",
|
||||
"SelfNodeV6MasqAddrForThisPeer", "IsWireGuardOnly", "IsJailed", "ExitNodeDNSResolvers",
|
||||
"StableTailnetID",
|
||||
}
|
||||
if have := fieldsOf(reflect.TypeFor[Node]()); !reflect.DeepEqual(have, nodeHandles) {
|
||||
t.Errorf("Node.Equal check might be out of sync\nfields: %q\nhandled: %q\n",
|
||||
@@ -404,6 +405,21 @@ func TestNodeEqual(t *testing.T) {
|
||||
&Node{StableID: "node-abcd"},
|
||||
true,
|
||||
},
|
||||
{
|
||||
&Node{StableTailnetID: "tailnet-abcd"},
|
||||
&Node{},
|
||||
false,
|
||||
},
|
||||
{
|
||||
&Node{StableTailnetID: "tailnet-abcd"},
|
||||
&Node{StableTailnetID: "tailnet-efgh"},
|
||||
false,
|
||||
},
|
||||
{
|
||||
&Node{StableTailnetID: "tailnet-abcd"},
|
||||
&Node{StableTailnetID: "tailnet-abcd"},
|
||||
true,
|
||||
},
|
||||
{
|
||||
&Node{User: 0},
|
||||
&Node{User: 1},
|
||||
|
||||
@@ -376,7 +376,14 @@ func (v NodeView) IsJailed() bool { return v.ж.IsJailed }
|
||||
func (v NodeView) ExitNodeDNSResolvers() views.SliceView[*dnstype.Resolver, dnstype.ResolverView] {
|
||||
return views.SliceOfViews[*dnstype.Resolver, dnstype.ResolverView](v.ж.ExitNodeDNSResolvers)
|
||||
}
|
||||
func (v NodeView) Equal(v2 NodeView) bool { return v.ж.Equal(v2.ж) }
|
||||
|
||||
// StableTailnetID is the identifier of the tailnet this node is a
|
||||
// member of.
|
||||
//
|
||||
// Control only populates this for the self node in a MapResponse
|
||||
// (MapResponse.Node); it is empty for peers.
|
||||
func (v NodeView) StableTailnetID() StableTailnetID { return v.ж.StableTailnetID }
|
||||
func (v NodeView) Equal(v2 NodeView) bool { return v.ж.Equal(v2.ж) }
|
||||
|
||||
// A compilation failure here means this code must be regenerated, with the command at the top of this file.
|
||||
var _NodeViewNeedsRegeneration = Node(struct {
|
||||
@@ -416,6 +423,7 @@ var _NodeViewNeedsRegeneration = Node(struct {
|
||||
IsWireGuardOnly bool
|
||||
IsJailed bool
|
||||
ExitNodeDNSResolvers []*dnstype.Resolver
|
||||
StableTailnetID StableTailnetID
|
||||
}{})
|
||||
|
||||
// View returns a read-only view of Hostinfo.
|
||||
|
||||
@@ -297,6 +297,16 @@ func (nm *NetworkMap) DomainName() string {
|
||||
return nm.Domain
|
||||
}
|
||||
|
||||
// StableTailnetID returns the stable ID of the tailnet the current node is a
|
||||
// member of, as sent by control on the self node. It returns the empty string
|
||||
// if nm is nil or nm.SelfNode is invalid.
|
||||
func (nm *NetworkMap) StableTailnetID() tailcfg.StableTailnetID {
|
||||
if nm == nil || !nm.SelfNode.Valid() {
|
||||
return ""
|
||||
}
|
||||
return nm.SelfNode.StableTailnetID()
|
||||
}
|
||||
|
||||
// TailnetDisplayName returns the admin-editable name contained in
|
||||
// NodeAttrTailnetDisplayName. If the capability is not present it
|
||||
// returns an empty string.
|
||||
|
||||
@@ -52,6 +52,34 @@ func eps(s ...string) []netip.AddrPort {
|
||||
return eps
|
||||
}
|
||||
|
||||
func TestStableTailnetID(t *testing.T) {
|
||||
for _, tt := range []struct {
|
||||
name string
|
||||
nm *NetworkMap
|
||||
want tailcfg.StableTailnetID
|
||||
}{
|
||||
{name: "nil_map"},
|
||||
{name: "invalid_self_node", nm: &NetworkMap{}},
|
||||
{
|
||||
name: "missing_id",
|
||||
nm: &NetworkMap{SelfNode: (&tailcfg.Node{}).View()},
|
||||
},
|
||||
{
|
||||
name: "populated",
|
||||
nm: &NetworkMap{
|
||||
SelfNode: (&tailcfg.Node{StableTailnetID: "tailnet-abcd"}).View(),
|
||||
},
|
||||
want: "tailnet-abcd",
|
||||
},
|
||||
} {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := tt.nm.StableTailnetID(); got != tt.want {
|
||||
t.Errorf("StableTailnetID() = %q; want %q", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestNetworkMapConcise(t *testing.T) {
|
||||
for _, tt := range []struct {
|
||||
name string
|
||||
|
||||
Reference in new issue
Block a user