mirror of
https://github.com/tailscale/tailscale.git
synced 2025-08-11 21:27:31 +00:00
tailcfg,all: add/plumb Node.IsJailed
This adds a new bool that can be sent down from control to do jailing on the client side. Previously this would only be done from control by modifying the packet filter we sent down to clients. This would result in a lot of additional work/CPU on control, we could instead just do this on the client. This has always been a TODO which we keep putting off, might as well do it now. Updates tailscale/corp#19623 Signed-off-by: Maisem Ali <maisem@tailscale.com>
This commit is contained in:
@@ -134,7 +134,8 @@ type CapabilityVersion int
|
||||
// - 91: 2024-04-24: Client understands PeerCapabilityTaildriveSharer.
|
||||
// - 92: 2024-05-06: Client understands NodeAttrUserDialUseRoutes.
|
||||
// - 93: 2024-05-06: added support for stateful firewalling.
|
||||
const CurrentCapabilityVersion CapabilityVersion = 93
|
||||
// - 94: 2024-05-06: Client understands Node.IsJailed.
|
||||
const CurrentCapabilityVersion CapabilityVersion = 94
|
||||
|
||||
type StableID string
|
||||
|
||||
@@ -416,6 +417,11 @@ type Node struct {
|
||||
// order to be reachable.
|
||||
IsWireGuardOnly bool `json:",omitempty"`
|
||||
|
||||
// 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"`
|
||||
|
||||
// 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"`
|
||||
@@ -2046,7 +2052,8 @@ func (n *Node) Equal(n2 *Node) bool {
|
||||
n.Expired == n2.Expired &&
|
||||
eqPtr(n.SelfNodeV4MasqAddrForThisPeer, n2.SelfNodeV4MasqAddrForThisPeer) &&
|
||||
eqPtr(n.SelfNodeV6MasqAddrForThisPeer, n2.SelfNodeV6MasqAddrForThisPeer) &&
|
||||
n.IsWireGuardOnly == n2.IsWireGuardOnly
|
||||
n.IsWireGuardOnly == n2.IsWireGuardOnly &&
|
||||
n.IsJailed == n2.IsJailed
|
||||
}
|
||||
|
||||
func eqPtr[T comparable](a, b *T) bool {
|
||||
|
@@ -118,6 +118,7 @@ var _NodeCloneNeedsRegeneration = Node(struct {
|
||||
SelfNodeV4MasqAddrForThisPeer *netip.Addr
|
||||
SelfNodeV6MasqAddrForThisPeer *netip.Addr
|
||||
IsWireGuardOnly bool
|
||||
IsJailed bool
|
||||
ExitNodeDNSResolvers []*dnstype.Resolver
|
||||
}{})
|
||||
|
||||
|
@@ -363,7 +363,7 @@ func TestNodeEqual(t *testing.T) {
|
||||
"UnsignedPeerAPIOnly",
|
||||
"ComputedName", "computedHostIfDifferent", "ComputedNameWithHost",
|
||||
"DataPlaneAuditLogID", "Expired", "SelfNodeV4MasqAddrForThisPeer",
|
||||
"SelfNodeV6MasqAddrForThisPeer", "IsWireGuardOnly", "ExitNodeDNSResolvers",
|
||||
"SelfNodeV6MasqAddrForThisPeer", "IsWireGuardOnly", "IsJailed", "ExitNodeDNSResolvers",
|
||||
}
|
||||
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",
|
||||
@@ -607,6 +607,16 @@ func TestNodeEqual(t *testing.T) {
|
||||
},
|
||||
false,
|
||||
},
|
||||
{
|
||||
&Node{IsJailed: true},
|
||||
&Node{IsJailed: true},
|
||||
true,
|
||||
},
|
||||
{
|
||||
&Node{IsJailed: false},
|
||||
&Node{IsJailed: true},
|
||||
false,
|
||||
},
|
||||
}
|
||||
for i, tt := range tests {
|
||||
got := tt.a.Equal(tt.b)
|
||||
|
@@ -195,6 +195,7 @@ func (v NodeView) SelfNodeV6MasqAddrForThisPeer() *netip.Addr {
|
||||
}
|
||||
|
||||
func (v NodeView) IsWireGuardOnly() bool { return v.ж.IsWireGuardOnly }
|
||||
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)
|
||||
}
|
||||
@@ -235,6 +236,7 @@ var _NodeViewNeedsRegeneration = Node(struct {
|
||||
SelfNodeV4MasqAddrForThisPeer *netip.Addr
|
||||
SelfNodeV6MasqAddrForThisPeer *netip.Addr
|
||||
IsWireGuardOnly bool
|
||||
IsJailed bool
|
||||
ExitNodeDNSResolvers []*dnstype.Resolver
|
||||
}{})
|
||||
|
||||
|
Reference in New Issue
Block a user