Merge branch 'worktree-agent-ac54c8919e940163a'
# Conflicts: # scripts/setup-native.py
This commit is contained in:
@@ -42,6 +42,11 @@ type Config struct {
|
||||
// PublicURL is the HTTPS origin a TLS front (tailscale serve) exposes for
|
||||
// the same web proxy, for example https://box.tail1.ts.net:8443.
|
||||
PublicURL string
|
||||
// NoLAN means the proxy refuses LAN connections (the installer's loopback
|
||||
// + tailnet default). The advert then carries no LAN route: its address
|
||||
// records are the tailnet IPv4 addresses, TXT says lan=0, and tailnet
|
||||
// clients on the same LAN still find the machine through ts= and public=.
|
||||
NoLAN bool
|
||||
}
|
||||
|
||||
// Advert is the record set the server publishes.
|
||||
@@ -77,7 +82,18 @@ func Plan(cfg Config) (Advert, error) {
|
||||
if port <= 0 || port > 65535 {
|
||||
return Advert{}, fmt.Errorf("advertised port %d is out of range", port)
|
||||
}
|
||||
if len(cfg.IPs) == 0 {
|
||||
ips := cfg.IPs
|
||||
if cfg.NoLAN {
|
||||
ips = nil
|
||||
for _, ip := range cfg.TailscaleIPs {
|
||||
if IsTailscaleIP(ip) {
|
||||
ips = append(ips, ip.To4())
|
||||
}
|
||||
}
|
||||
if len(ips) == 0 {
|
||||
return Advert{}, fmt.Errorf("LAN connections are refused and there is no tailnet address: %w", ErrNotReachable)
|
||||
}
|
||||
} else if len(ips) == 0 {
|
||||
return Advert{}, fmt.Errorf("no LAN IPv4 address: %w", ErrNotReachable)
|
||||
}
|
||||
label := hostLabel(cfg.Hostname)
|
||||
@@ -96,6 +112,9 @@ func Plan(cfg Config) (Advert, error) {
|
||||
"tls=0",
|
||||
"auth=" + auth,
|
||||
}
|
||||
if cfg.NoLAN {
|
||||
txt = append(txt, "lan=0")
|
||||
}
|
||||
if ts := joinIPs(cfg.TailscaleIPs); ts != "" {
|
||||
txt = append(txt, "ts="+ts)
|
||||
}
|
||||
@@ -106,7 +125,7 @@ func Plan(cfg Config) (Advert, error) {
|
||||
Instance: "Pipelines-" + label,
|
||||
Host: label + ".local.",
|
||||
Port: port,
|
||||
IPs: cfg.IPs,
|
||||
IPs: ips,
|
||||
TXT: txt,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -157,3 +157,39 @@ func TestPlanAdvertisesTailnetAndPublicRoutes(t *testing.T) {
|
||||
t.Fatal("tailnet range check")
|
||||
}
|
||||
}
|
||||
|
||||
// With LAN connections refused the advert names no LAN route: the address
|
||||
// records are the tailnet IPs and TXT says lan=0, so tailnet clients on the
|
||||
// same LAN still find the machine on the proxy port that answers them.
|
||||
func TestPlanWithoutLANAdvertisesOnlyTailnetAndPublicRoutes(t *testing.T) {
|
||||
tailnetIPs := []net.IP{net.ParseIP("100.85.25.33"), net.ParseIP("fd7a:115c:a1e0::d501:199e")}
|
||||
advert, err := Plan(Config{ListenAddr: "127.0.0.1:8080", ProxyPort: 8083, Version: "v1", Hostname: "box", IPs: lan,
|
||||
TailscaleIPs: tailnetIPs, PublicURL: "https://box.tail1.ts.net:8443", NoLAN: true})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if advert.Port != 8083 || len(advert.IPs) != 1 || !advert.IPs[0].Equal(net.ParseIP("100.85.25.33")) {
|
||||
t.Fatalf("advert = %+v", advert)
|
||||
}
|
||||
for _, want := range []string{"lan=0", "ts=100.85.25.33", "public=https://box.tail1.ts.net:8443"} {
|
||||
if !slices.Contains(advert.TXT, want) {
|
||||
t.Fatalf("TXT %q lacks %s", advert.TXT, want)
|
||||
}
|
||||
}
|
||||
zone, err := advert.Zone()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
records := zone.Records(dns.Question{Name: advert.Host, Qtype: dns.TypeA, Qclass: dns.ClassINET})
|
||||
if len(records) != 1 || !records[0].(*dns.A).A.Equal(net.ParseIP("100.85.25.33")) {
|
||||
t.Fatalf("A records = %v", records)
|
||||
}
|
||||
if _, err := Plan(Config{ListenAddr: "127.0.0.1:8080", ProxyPort: 8083, Hostname: "box", IPs: lan, NoLAN: true,
|
||||
PublicURL: "https://box.tail1.ts.net:8443"}); !errors.Is(err, ErrNotReachable) {
|
||||
t.Fatalf("no tailnet address must not publish: %v", err)
|
||||
}
|
||||
withLAN, _ := Plan(Config{ListenAddr: "127.0.0.1:8080", ProxyPort: 8083, Hostname: "box", IPs: lan, TailscaleIPs: tailnetIPs})
|
||||
if slices.Contains(withLAN.TXT, "lan=0") || !withLAN.IPs[0].Equal(lan[0]) {
|
||||
t.Fatalf("LAN advert changed: %+v", withLAN)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,6 +121,10 @@ func discovered(entry *mdns.ServiceEntry) (FoundServer, bool) {
|
||||
}
|
||||
endpoint := (&url.URL{Scheme: scheme, Host: net.JoinHostPort(ip.String(), strconv.Itoa(entry.Port)), Path: path}).String()
|
||||
addresses := []FoundAddress{{Kind: "lan", Endpoint: endpoint}}
|
||||
if fields["lan"] == "0" {
|
||||
// The proxy refuses LAN connections; the address record is a tailnet IP.
|
||||
addresses = nil
|
||||
}
|
||||
for _, value := range strings.Split(fields["ts"], ",") {
|
||||
ts := net.ParseIP(strings.TrimSpace(value))
|
||||
if ts == nil || !IsTailscaleIP(ts) || len(addresses) > 5 {
|
||||
@@ -137,5 +141,8 @@ func discovered(entry *mdns.ServiceEntry) (FoundServer, bool) {
|
||||
}
|
||||
addresses = append(addresses, FoundAddress{Kind: "public", Endpoint: (&url.URL{Scheme: wsScheme, Host: u.Host, Path: path}).String()})
|
||||
}
|
||||
return FoundServer{Name: name, Endpoint: endpoint, Auth: auth, Version: fields["v"], Addresses: addresses}, true
|
||||
if len(addresses) == 0 {
|
||||
return FoundServer{}, false
|
||||
}
|
||||
return FoundServer{Name: name, Endpoint: addresses[0].Endpoint, Auth: auth, Version: fields["v"], Addresses: addresses}, true
|
||||
}
|
||||
|
||||
@@ -87,3 +87,21 @@ func TestBrowseListsEveryRouteToTheSameMachine(t *testing.T) {
|
||||
t.Fatalf("unsafe routes accepted: %+v", found.Addresses)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBrowseOmitsTheLANRouteWhenTheAdvertSaysLan0(t *testing.T) {
|
||||
item := service("100.85.25.33")
|
||||
item.InfoFields = append(item.InfoFields, "lan=0", "ts=100.85.25.33", "public=https://box.tail1.ts.net:8443")
|
||||
found, ok := discovered(item)
|
||||
want := []FoundAddress{
|
||||
{Kind: "tailscale", Endpoint: "ws://100.85.25.33:8083/connect"},
|
||||
{Kind: "public", Endpoint: "wss://box.tail1.ts.net:8443/connect"},
|
||||
}
|
||||
if !ok || !slices.Equal(found.Addresses, want) || found.Endpoint != want[0].Endpoint {
|
||||
t.Fatalf("found = %+v (%v)", found, ok)
|
||||
}
|
||||
bare := service("100.85.25.33")
|
||||
bare.InfoFields = append(bare.InfoFields, "lan=0")
|
||||
if _, ok := discovered(bare); ok {
|
||||
t.Fatal("an advert with no usable route was accepted")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user