mirror of
https://github.com/tailscale/tailscale.git
synced 2025-08-11 13:18:53 +00:00
all: deprecate Node.Capabilities (more), remove PeerChange.Capabilities [capver 89]
First we had Capabilities []string. Then https://tailscale.com/blog/acl-grants (#4217) brought CapMap, a superset of Capabilities. Except we never really finished the transition inside the codebase to go all-in on CapMap. This does so. Notably, this coverts Capabilities on the wire early to CapMap internally so the code can only deal in CapMap, even against an old control server. In the process, this removes PeerChange.Capabilities support, which no known control plane sent anyway. They can and should use PeerChange.CapMap instead. Updates #11508 Updates #4217 Change-Id: I872074e226b873f9a578d9603897b831d50b25d9 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:

committed by
Brad Fitzpatrick

parent
4992aca6ec
commit
7b34154df2
@@ -823,15 +823,16 @@ func (b *LocalBackend) UpdateStatus(sb *ipnstate.StatusBuilder) {
|
||||
ss.UserID = b.netMap.User()
|
||||
if sn := b.netMap.SelfNode; sn.Valid() {
|
||||
peerStatusFromNode(ss, sn)
|
||||
if c := sn.Capabilities(); c.Len() > 0 {
|
||||
ss.Capabilities = c.AsSlice()
|
||||
}
|
||||
if cm := sn.CapMap(); cm.Len() > 0 {
|
||||
ss.Capabilities = make([]tailcfg.NodeCapability, 1, cm.Len()+1)
|
||||
ss.Capabilities[0] = "HTTPS://TAILSCALE.COM/s/DEPRECATED-NODE-CAPS#see-https://github.com/tailscale/tailscale/issues/11508"
|
||||
ss.CapMap = make(tailcfg.NodeCapMap, sn.CapMap().Len())
|
||||
cm.Range(func(k tailcfg.NodeCapability, v views.Slice[tailcfg.RawMessage]) bool {
|
||||
ss.CapMap[k] = v.AsSlice()
|
||||
ss.Capabilities = append(ss.Capabilities, k)
|
||||
return true
|
||||
})
|
||||
slices.Sort(ss.Capabilities[1:])
|
||||
}
|
||||
}
|
||||
for _, addr := range tailscaleIPs {
|
||||
|
@@ -522,7 +522,7 @@ func TestHandlePeerAPI(t *testing.T) {
|
||||
},
|
||||
}
|
||||
if tt.debugCap {
|
||||
selfNode.Capabilities = append(selfNode.Capabilities, tailcfg.CapabilityDebug)
|
||||
selfNode.CapMap = tailcfg.NodeCapMap{tailcfg.CapabilityDebug: nil}
|
||||
}
|
||||
var e peerAPITestEnv
|
||||
lb := &LocalBackend{
|
||||
|
@@ -684,8 +684,7 @@ func newTestBackend(t *testing.T) *LocalBackend {
|
||||
|
||||
b.netMap = &netmap.NetworkMap{
|
||||
SelfNode: (&tailcfg.Node{
|
||||
Name: "example.ts.net",
|
||||
Capabilities: []tailcfg.NodeCapability{tailcfg.NodeAttrsTailFSAccess},
|
||||
Name: "example.ts.net",
|
||||
}).View(),
|
||||
UserProfiles: map[tailcfg.UserID]tailcfg.UserProfile{
|
||||
tailcfg.UserID(1): {
|
||||
|
@@ -266,6 +266,10 @@ type PeerStatus struct {
|
||||
// "https://tailscale.com/cap/is-admin"
|
||||
// "https://tailscale.com/cap/file-sharing"
|
||||
// "funnel"
|
||||
//
|
||||
// Deprecated: use CapMap instead. See https://github.com/tailscale/tailscale/issues/11508
|
||||
// Every value is Capabilities is also a key in CapMap, even if it
|
||||
// has no values in that map.
|
||||
Capabilities []tailcfg.NodeCapability `json:",omitempty"`
|
||||
|
||||
// CapMap is a map of capabilities to their values.
|
||||
@@ -306,7 +310,7 @@ type PeerStatus struct {
|
||||
|
||||
// HasCap reports whether ps has the given capability.
|
||||
func (ps *PeerStatus) HasCap(cap tailcfg.NodeCapability) bool {
|
||||
return ps.CapMap.Contains(cap) || slices.Contains(ps.Capabilities, cap)
|
||||
return ps.CapMap.Contains(cap)
|
||||
}
|
||||
|
||||
// IsTagged reports whether ps is tagged.
|
||||
|
@@ -445,7 +445,7 @@ func CheckFunnelPort(wantedPort uint16, node *ipnstate.PeerStatus) error {
|
||||
break
|
||||
}
|
||||
if portsStr == "" {
|
||||
for _, attr := range node.Capabilities {
|
||||
for attr := range node.CapMap {
|
||||
attr := string(attr)
|
||||
if !strings.HasPrefix(attr, string(tailcfg.CapabilityFunnelPorts)) {
|
||||
continue
|
||||
|
Reference in New Issue
Block a user