fix: update auto-approved advertised routes when set after registration

This commit is contained in:
Johan Siebens
2025-04-28 10:52:14 +02:00
parent 644b99b70f
commit 814335d703
6 changed files with 188 additions and 2 deletions
+19
View File
@@ -1,6 +1,7 @@
package tsn
import (
"net/netip"
"slices"
"strings"
"tailscale.com/ipn/ipnstate"
@@ -60,6 +61,24 @@ func HasUser(email string) Condition {
}
}
func HasAllowedIP(route netip.Prefix) Condition {
return func(status *ipnstate.Status) bool {
if status.Self == nil || status.Self.AllowedIPs.Len() == 0 {
return false
}
return slices.Contains(status.Self.AllowedIPs.AsSlice(), route)
}
}
func IsMissingAllowedIP(route netip.Prefix) Condition {
return func(status *ipnstate.Status) bool {
if status.Self == nil || status.Self.AllowedIPs.Len() == 0 {
return true
}
return !slices.Contains(status.Self.AllowedIPs.AsSlice(), route)
}
}
func PeerCount(expected int) Condition {
return func(status *ipnstate.Status) bool {
return len(status.Peers()) == expected
+16 -2
View File
@@ -38,11 +38,25 @@ func (t *TailscaleNode) Hostname() string {
return t.hostname
}
func (t *TailscaleNode) Up(authkey string) error {
t.mustExecTailscaleCmd("up", "--login-server", t.loginServer, "--authkey", authkey)
func (t *TailscaleNode) Up(authkey string, flags ...UpFlag) error {
cmd := []string{"up", "--login-server", t.loginServer, "--authkey", authkey}
for _, f := range flags {
cmd = append(cmd, f...)
}
t.mustExecTailscaleCmd(cmd...)
return t.WaitFor(Connected())
}
func (t *TailscaleNode) Set(flags ...UpFlag) string {
cmd := []string{"set"}
for _, f := range flags {
cmd = append(cmd, f...)
}
return t.mustExecTailscaleCmd(cmd...)
}
func (t *TailscaleNode) LoginWithOidc(flags ...UpFlag) (int, error) {
check := func(stdout, stderr string) bool {
return strings.Contains(stderr, "To authenticate, visit:")
+6
View File
@@ -1,7 +1,13 @@
package tsn
import "strings"
type UpFlag = []string
func WithAdvertiseTags(tags string) UpFlag {
return []string{"--advertise-tags", tags}
}
func WithAdvertiseRoutes(routes []string) UpFlag {
return []string{"--advertise-routes", strings.Join(routes, ",")}
}