From 732f32dad4c63a74ac8b2036aa5a83c7cb2db2b0 Mon Sep 17 00:00:00 2001 From: Kabir Sikand Date: Mon, 27 Jul 2026 19:48:16 +0000 Subject: [PATCH] tailcfg,ipn/ipnlocal: report authenticated funnel posture to control MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add Hostinfo.FunnelAuthEnabled so a node reports whether any of its funnel-enabled endpoints require visitors to authenticate with Login With Tailscale. Control (corp) reads this to show each funnel's posture (authenticated vs. public) in the admin console; it is the only node→control addition for authenticated Funnel, and it rides the existing Hostinfo channel next to IngressEnabled. The node computes it from the serve config (ServeConfig.HasFunnelAuth: any funnel-on web handler with Auth set, including foreground sessions) and sends it from maybeUpdateHostinfoFunnelLocked alongside IngressEnabled. Bump CurrentCapabilityVersion to 144 to mark that clients send this field. Updates tailscale/corp#38806 Change-Id: I86c5f04dd3beb71bef7cfe41fb6ef85728d364b6 Signed-off-by: Kabir Sikand --- ipn/ipnlocal/local_test.go | 22 ++++++++ ipn/ipnlocal/serve.go | 16 ++++++ ipn/ipnlocal/serve_disabled.go | 1 + ipn/serve.go | 34 ++++++++++++ ipn/serve_test.go | 60 ++++++++++++++++++++++ tailcfg/tailcfg.go | 10 +++- tailcfg/tailcfg_clone.go | 87 +++++++++++++++---------------- tailcfg/tailcfg_test.go | 1 + tailcfg/tailcfg_view.go | 94 ++++++++++++++++++---------------- 9 files changed, 238 insertions(+), 87 deletions(-) diff --git a/ipn/ipnlocal/local_test.go b/ipn/ipnlocal/local_test.go index d72d59c43..2fc59438a 100644 --- a/ipn/ipnlocal/local_test.go +++ b/ipn/ipnlocal/local_test.go @@ -7782,6 +7782,7 @@ func TestUpdateIngressAndServiceHashLocked(t *testing.T) { sc *ipn.ServeConfig wantIngress bool wantWireIngress bool + wantFunnelAuth bool wantControlUpdate bool }{ { @@ -7804,6 +7805,24 @@ func TestUpdateIngressAndServiceHashLocked(t *testing.T) { wantWireIngress: false, // implied by wantIngress wantControlUpdate: true, }, + { + name: "empty_hostinfo_funnel_auth_enabled", + hi: &tailcfg.Hostinfo{}, + sc: &ipn.ServeConfig{ + AllowFunnel: map[ipn.HostPort]bool{ + "tailnet.xyz:443": true, + }, + Web: map[ipn.HostPort]*ipn.WebServerConfig{ + "tailnet.xyz:443": {Handlers: map[string]*ipn.HTTPHandler{ + "/": {Proxy: "http://127.0.0.1:3000", Auth: &ipn.FunnelAuth{Provider: "tailscale"}}, + }}, + }, + }, + wantIngress: true, + wantWireIngress: false, // implied by wantIngress + wantFunnelAuth: true, + wantControlUpdate: true, + }, { name: "empty_hostinfo_service_configured", hi: &tailcfg.Hostinfo{}, @@ -7956,6 +7975,9 @@ func TestUpdateIngressAndServiceHashLocked(t *testing.T) { if tt.hi.WireIngress != tt.wantWireIngress { t.Errorf("WireIngress = %v, want %v", tt.hi.WireIngress, tt.wantWireIngress) } + if tt.hi.FunnelAuthEnabled != tt.wantFunnelAuth { + t.Errorf("FunnelAuthEnabled = %v, want %v", tt.hi.FunnelAuthEnabled, tt.wantFunnelAuth) + } b.mu.Lock() svcHash := vipServiceHash(b.logf, b.vipServicesFromPrefsLocked(prefs)) b.mu.Unlock() diff --git a/ipn/ipnlocal/serve.go b/ipn/ipnlocal/serve.go index a95f88b0e..dd5f91a29 100644 --- a/ipn/ipnlocal/serve.go +++ b/ipn/ipnlocal/serve.go @@ -1631,6 +1631,14 @@ func (b *LocalBackend) hasIngressEnabledLocked() bool { return b.serveConfig.Valid() && b.serveConfig.IsFunnelOn() } +// hasFunnelAuthEnabledLocked reports whether any funnel-enabled endpoint +// requires authentication. This bool is sent to control (in +// Hostinfo.FunnelAuthEnabled) so the admin console can show each funnel's +// posture (authenticated vs. public). +func (b *LocalBackend) hasFunnelAuthEnabledLocked() bool { + return b.serveConfig.Valid() && b.serveConfig.HasFunnelAuth() +} + // shouldWireInactiveIngressLocked reports whether the node is in a state where funnel is not actively enabled, but it // seems that it is intended to be used with funnel. func (b *LocalBackend) shouldWireInactiveIngressLocked() bool { @@ -1771,6 +1779,14 @@ func maybeUpdateHostinfoFunnelLocked(b *LocalBackend, hi *tailcfg.Hostinfo, pref hi.IngressEnabled = ie changed = true } + // The Hostinfo.FunnelAuthEnabled field tells control whether any funnel + // endpoint requires authentication, so the admin console can show the + // funnel's posture (authenticated vs. public). + if fa := b.hasFunnelAuthEnabledLocked(); hi.FunnelAuthEnabled != fa { + b.logf("Hostinfo.FunnelAuthEnabled changed to %v", fa) + hi.FunnelAuthEnabled = fa + changed = true + } // The Hostinfo.WireIngress field tells control whether the user intends // to use funnel with this node even though it is not currently enabled. // This is an optimization to control- Funnel requires creation of DNS diff --git a/ipn/ipnlocal/serve_disabled.go b/ipn/ipnlocal/serve_disabled.go index 7123ebe3b..f72b7b9da 100644 --- a/ipn/ipnlocal/serve_disabled.go +++ b/ipn/ipnlocal/serve_disabled.go @@ -27,6 +27,7 @@ func (b *LocalBackend) DeleteForegroundSession(sessionID string) error { type funnelFlow = struct{} func (*LocalBackend) hasIngressEnabledLocked() bool { return false } +func (*LocalBackend) hasFunnelAuthEnabledLocked() bool { return false } func (*LocalBackend) shouldWireInactiveIngressLocked() bool { return false } func (*LocalBackend) HasFunnelForHostPort(host string, port uint16) bool { return false diff --git a/ipn/serve.go b/ipn/serve.go index a996bb55b..9e1224d36 100644 --- a/ipn/serve.go +++ b/ipn/serve.go @@ -661,6 +661,40 @@ func (sc *ServeConfig) IsFunnelOn() bool { return false } +// HasFunnelAuth reports whether any funnel-enabled web handler on this node +// requires visitors to authenticate with Login With Tailscale (HTTPHandler.Auth +// is set). It is used to report the node's authenticated-Funnel posture to +// control (Hostinfo.FunnelAuthEnabled). +func (v ServeConfigView) HasFunnelAuth() bool { return v.ж.HasFunnelAuth() } + +// HasFunnelAuth reports whether any funnel-enabled web handler requires +// authentication. See [ServeConfigView.HasFunnelAuth]. +func (sc *ServeConfig) HasFunnelAuth() bool { + if sc == nil { + return false + } + for hp, on := range sc.AllowFunnel { + if !on { + continue + } + wsc, ok := sc.Web[hp] + if !ok { + continue + } + for _, h := range wsc.Handlers { + if h != nil && h.Auth != nil { + return true + } + } + } + for _, conf := range sc.Foreground { + if conf.HasFunnelAuth() { + return true + } + } + return false +} + // CheckFunnelAccess checks whether Funnel access is allowed for the given node // and port. // It checks: diff --git a/ipn/serve_test.go b/ipn/serve_test.go index f0f3a152f..47c495283 100644 --- a/ipn/serve_test.go +++ b/ipn/serve_test.go @@ -66,6 +66,66 @@ func TestFunnelAuthJSONRoundTrip(t *testing.T) { } } +func TestHasFunnelAuth(t *testing.T) { + authed := func() *HTTPHandler { + return &HTTPHandler{Proxy: "http://127.0.0.1:3000", Auth: &FunnelAuth{Provider: "tailscale"}} + } + tests := []struct { + name string + sc *ServeConfig + want bool + }{ + {name: "nil", sc: nil, want: false}, + {name: "empty", sc: &ServeConfig{}, want: false}, + { + name: "funnel on but no auth", + sc: &ServeConfig{ + AllowFunnel: map[HostPort]bool{"h:443": true}, + Web: map[HostPort]*WebServerConfig{"h:443": {Handlers: map[string]*HTTPHandler{"/": {Proxy: "http://127.0.0.1:3000"}}}}, + }, + want: false, + }, + { + name: "auth but funnel off", + sc: &ServeConfig{ + AllowFunnel: map[HostPort]bool{"h:443": false}, + Web: map[HostPort]*WebServerConfig{"h:443": {Handlers: map[string]*HTTPHandler{"/": authed()}}}, + }, + want: false, + }, + { + name: "auth and funnel on", + sc: &ServeConfig{ + AllowFunnel: map[HostPort]bool{"h:443": true}, + Web: map[HostPort]*WebServerConfig{"h:443": {Handlers: map[string]*HTTPHandler{"/": authed()}}}, + }, + want: true, + }, + { + name: "auth in foreground config", + sc: &ServeConfig{ + Foreground: map[string]*ServeConfig{ + "sess": { + AllowFunnel: map[HostPort]bool{"h:443": true}, + Web: map[HostPort]*WebServerConfig{"h:443": {Handlers: map[string]*HTTPHandler{"/": authed()}}}, + }, + }, + }, + want: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := tt.sc.HasFunnelAuth(); got != tt.want { + t.Errorf("HasFunnelAuth() = %v; want %v", got, tt.want) + } + if got := tt.sc.View().HasFunnelAuth(); got != tt.want { + t.Errorf("View().HasFunnelAuth() = %v; want %v", got, tt.want) + } + }) + } +} + func TestCheckFunnelAccess(t *testing.T) { caps := func(c ...tailcfg.NodeCapability) []tailcfg.NodeCapability { return c } const portAttr tailcfg.NodeCapability = "https://tailscale.com/cap/funnel-ports?ports=443,8080-8090,8443," diff --git a/tailcfg/tailcfg.go b/tailcfg/tailcfg.go index 5b38218c0..7ab881bca 100644 --- a/tailcfg/tailcfg.go +++ b/tailcfg/tailcfg.go @@ -190,7 +190,8 @@ type CapabilityVersion int // - 141: 2026-05-28: Client understands [NodeAttrNeverGSOEqualTail] // - 142: 2026-07-06: Client understands c2n /remoteapi/localapi/* proxy // - 143: 2026-07-22: Client correctly ignores conn25 node attributes when not enabled by environment variable -const CurrentCapabilityVersion CapabilityVersion = 143 +// - 144: 2026-07-27: Client sends Hostinfo.FunnelAuthEnabled to report authenticated Funnel posture (tailscale/corp#38806) +const CurrentCapabilityVersion CapabilityVersion = 144 // ID is an integer ID for a user, node, or login allocated by the // control plane. @@ -917,6 +918,13 @@ type Hostinfo struct { WireIngress bool `json:",omitzero"` IngressEnabled bool `json:",omitzero"` // if the node has any funnel endpoint enabled + // FunnelAuthEnabled reports whether the node has any Funnel endpoint that + // requires visitors to authenticate with Login With Tailscale + // (ipn.HTTPHandler.Auth). It is sent to control so the admin console can + // show each funnel's posture (authenticated vs. public). It is only + // meaningful when IngressEnabled is true. + FunnelAuthEnabled bool `json:",omitzero"` + // AllowsUpdate reports that the node has opted in to // admin-console-driven remote updates and that the running binary // includes client update support (the feature/clientupdate package, diff --git a/tailcfg/tailcfg_clone.go b/tailcfg/tailcfg_clone.go index e1d5551cd..03274521f 100644 --- a/tailcfg/tailcfg_clone.go +++ b/tailcfg/tailcfg_clone.go @@ -148,49 +148,50 @@ func (src *Hostinfo) Clone() *Hostinfo { // A compilation failure here means this code must be regenerated, with the command at the top of this file. var _HostinfoCloneNeedsRegeneration = Hostinfo(struct { - IPNVersion string - FrontendLogID string - BackendLogID string - OS string - OSVersion string - Container opt.Bool - Env string - Distro string - DistroVersion string - DistroCodeName string - App string - Desktop opt.Bool - Package string - DeviceModel string - PushDeviceToken string - Hostname string - ShieldsUp bool - ShareeNode bool - NoLogsNoSupport bool - RemoteConfig bool - WireIngress bool - IngressEnabled bool - AllowsUpdate bool - Machine string - GoArch string - GoArchVar string - GoVersion string - RoutableIPs []netip.Prefix - RequestTags []string - WoLMACs []string - Services []Service - NetInfo *NetInfo - SSH_HostKeys []string - Cloud string - Userspace opt.Bool - UserspaceRouter opt.Bool - AppConnector opt.Bool - ServicesHash string - PeerRelay bool - ExitNodeID StableNodeID - Location *Location - TPM *TPMInfo - StateEncrypted opt.Bool + IPNVersion string + FrontendLogID string + BackendLogID string + OS string + OSVersion string + Container opt.Bool + Env string + Distro string + DistroVersion string + DistroCodeName string + App string + Desktop opt.Bool + Package string + DeviceModel string + PushDeviceToken string + Hostname string + ShieldsUp bool + ShareeNode bool + NoLogsNoSupport bool + RemoteConfig bool + WireIngress bool + IngressEnabled bool + FunnelAuthEnabled bool + AllowsUpdate bool + Machine string + GoArch string + GoArchVar string + GoVersion string + RoutableIPs []netip.Prefix + RequestTags []string + WoLMACs []string + Services []Service + NetInfo *NetInfo + SSH_HostKeys []string + Cloud string + Userspace opt.Bool + UserspaceRouter opt.Bool + AppConnector opt.Bool + ServicesHash string + PeerRelay bool + ExitNodeID StableNodeID + Location *Location + TPM *TPMInfo + StateEncrypted opt.Bool }{}) // Clone makes a deep copy of NetInfo. diff --git a/tailcfg/tailcfg_test.go b/tailcfg/tailcfg_test.go index 5658f3111..7468ea575 100644 --- a/tailcfg/tailcfg_test.go +++ b/tailcfg/tailcfg_test.go @@ -54,6 +54,7 @@ func TestHostinfoEqual(t *testing.T) { "RemoteConfig", "WireIngress", "IngressEnabled", + "FunnelAuthEnabled", "AllowsUpdate", "Machine", "GoArch", diff --git a/tailcfg/tailcfg_view.go b/tailcfg/tailcfg_view.go index 008c6fcfa..68330885f 100644 --- a/tailcfg/tailcfg_view.go +++ b/tailcfg/tailcfg_view.go @@ -570,6 +570,13 @@ func (v HostinfoView) WireIngress() bool { return v.ж.WireIngress } // if the node has any funnel endpoint enabled func (v HostinfoView) IngressEnabled() bool { return v.ж.IngressEnabled } +// FunnelAuthEnabled reports whether the node has any Funnel endpoint that +// requires visitors to authenticate with Login With Tailscale +// (ipn.HTTPHandler.Auth). It is sent to control so the admin console can +// show each funnel's posture (authenticated vs. public). It is only +// meaningful when IngressEnabled is true. +func (v HostinfoView) FunnelAuthEnabled() bool { return v.ж.FunnelAuthEnabled } + // AllowsUpdate reports that the node has opted in to // admin-console-driven remote updates and that the running binary // includes client update support (the feature/clientupdate package, @@ -641,49 +648,50 @@ func (v HostinfoView) Equal(v2 HostinfoView) 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 _HostinfoViewNeedsRegeneration = Hostinfo(struct { - IPNVersion string - FrontendLogID string - BackendLogID string - OS string - OSVersion string - Container opt.Bool - Env string - Distro string - DistroVersion string - DistroCodeName string - App string - Desktop opt.Bool - Package string - DeviceModel string - PushDeviceToken string - Hostname string - ShieldsUp bool - ShareeNode bool - NoLogsNoSupport bool - RemoteConfig bool - WireIngress bool - IngressEnabled bool - AllowsUpdate bool - Machine string - GoArch string - GoArchVar string - GoVersion string - RoutableIPs []netip.Prefix - RequestTags []string - WoLMACs []string - Services []Service - NetInfo *NetInfo - SSH_HostKeys []string - Cloud string - Userspace opt.Bool - UserspaceRouter opt.Bool - AppConnector opt.Bool - ServicesHash string - PeerRelay bool - ExitNodeID StableNodeID - Location *Location - TPM *TPMInfo - StateEncrypted opt.Bool + IPNVersion string + FrontendLogID string + BackendLogID string + OS string + OSVersion string + Container opt.Bool + Env string + Distro string + DistroVersion string + DistroCodeName string + App string + Desktop opt.Bool + Package string + DeviceModel string + PushDeviceToken string + Hostname string + ShieldsUp bool + ShareeNode bool + NoLogsNoSupport bool + RemoteConfig bool + WireIngress bool + IngressEnabled bool + FunnelAuthEnabled bool + AllowsUpdate bool + Machine string + GoArch string + GoArchVar string + GoVersion string + RoutableIPs []netip.Prefix + RequestTags []string + WoLMACs []string + Services []Service + NetInfo *NetInfo + SSH_HostKeys []string + Cloud string + Userspace opt.Bool + UserspaceRouter opt.Bool + AppConnector opt.Bool + ServicesHash string + PeerRelay bool + ExitNodeID StableNodeID + Location *Location + TPM *TPMInfo + StateEncrypted opt.Bool }{}) // View returns a read-only view of NetInfo.