From 4cd8636d63f07b9fcaf480f5d8f655b87b4157fe Mon Sep 17 00:00:00 2001 From: Kabir Sikand Date: Tue, 19 May 2026 22:38:42 +0000 Subject: [PATCH] tailcfg, ipn/ipnlocal: wire blueprint serves.apps + serves.services MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes the corp-side dangling wire fields (corp v2.1 ships ServeApps/ServeServices in BlueprintConfig but the OSS client never read them). Adds the missing OSS-side type field plus a reconciler that maps the resolved blueprint's app + service list onto local daemon state. tailcfg.BlueprintConfig gains ServeServices []string (companion to the existing ServeApps + ServeIPSets). Equal() updated; clone + view hand-edits follow the existing pattern (prior agent noted the corp pin makes go generate awkward, so the cloner/viewer files are hand-extended with regen sentinels updated). ipn/ipnlocal/local.go: two new reconcile functions, called from the tail of setNetMapLocked alongside the existing routes / prefs reconciles: - reconcileBlueprintAppConnectorLocked: flips Prefs.AppConnector.Advertise to match presence of any "app:" identifier in BlueprintConfig.ServeApps. Silence-equals-OFF consistent with the other blueprint prefs. Per-app routing rules (which domains/CIDRs each connector handles) remain owned by the existing app-connector machinery; the blueprint only toggles the node-level advertise bit. - reconcileBlueprintServicesLocked: surfaces the projected ServeServices list via the daemon log so operators can see what services the blueprint expects this node to advertise. Full reconcile into the daemon's services machinery is a follow-up — translating "svc:" identifiers into actual ServeConfig entries depends on the services backend exposing a reconcile API, which is out of scope for this commit. Operationally: after this commit, a blueprint that lists "serves.apps": ["app:github"] auto-enables the bound node as an app connector (no need for the operator to also run `tailscale set --advertise-connector` and have it rejected by the blueprint-lock); the per-app routing rules still come from the operator's app-connector configuration in the admin panel. Updates #cleanup Signed-off-by: Kabir Sikand --- ipn/ipnlocal/local.go | 68 ++++++++++++++++++++++++++++++++++++++++ tailcfg/tailcfg.go | 11 ++++++- tailcfg/tailcfg_clone.go | 14 +++++---- tailcfg/tailcfg_view.go | 21 +++++++++---- 4 files changed, 101 insertions(+), 13 deletions(-) diff --git a/ipn/ipnlocal/local.go b/ipn/ipnlocal/local.go index 52c43c171..a4b9049f5 100644 --- a/ipn/ipnlocal/local.go +++ b/ipn/ipnlocal/local.go @@ -6727,6 +6727,74 @@ func (b *LocalBackend) setNetMapLocked(nm *netmap.NetworkMap) { // does not stomp on user intent. b.reconcileBlueprintRoutesLocked(nm) b.reconcileBlueprintPrefsLocked(nm) + b.reconcileBlueprintAppConnectorLocked(nm) + b.reconcileBlueprintServicesLocked(nm) +} + +// reconcileBlueprintAppConnectorLocked syncs +// Prefs.AppConnector.Advertise with the BlueprintConfig.ServeApps +// carried by the netmap's SelfNode for a blueprint-bound node. +// Presence of any "app:" identifier in ServeApps flips the +// per-node app-connector advertisement on; an empty ServeApps +// list (silence-equals-OFF, consistent with the other blueprint +// reconciles) flips it back off. +// +// The per-app routing rules themselves (which domains/CIDRs each +// app connector handles) live in the existing app-connector +// machinery — the blueprint reconciler here only toggles the +// node-level Advertise bit. +// +// b.mu must be held. +func (b *LocalBackend) reconcileBlueprintAppConnectorLocked(nm *netmap.NetworkMap) { + if nm == nil || !nm.SelfNode.Valid() { + return + } + cfg := nm.SelfNode.BlueprintConfig() + if !cfg.Valid() { + return + } + want := cfg.ServeApps().Len() > 0 + cur := b.pm.CurrentPrefs() + if cur.AppConnector().Advertise == want { + return + } + newp := cur.AsStruct() + newp.AppConnector.Advertise = want + b.logf("blueprint %q: reconciled AppConnector.Advertise=%v from BlueprintConfig (%d serve-app(s))", + cur.BlueprintID(), want, cfg.ServeApps().Len()) + if err := b.pm.SetPrefs(newp.View(), b.pm.CurrentProfile().NetworkProfile()); err != nil { + b.logf("blueprint app-connector reconcile: persist prefs: %v", err) + return + } + if b.hostinfo == nil { + b.hostinfo = new(tailcfg.Hostinfo) + } + b.applyPrefsToHostinfoLocked(b.hostinfo, newp.View()) + b.goTracker.Go(b.doSetHostinfoFilterServices) +} + +// reconcileBlueprintServicesLocked surfaces the blueprint's +// ServeServices list for operator visibility. Full reconciliation +// into the daemon's services machinery is a follow-up — it requires +// translating "svc:" identifiers into actual ServeConfig +// entries, which depends on the services backend exposing a +// reconcile API. For now this just logs the projection so a bound +// node's expected services are observable via tailscaled logs. +// +// b.mu must be held. +func (b *LocalBackend) reconcileBlueprintServicesLocked(nm *netmap.NetworkMap) { + if nm == nil || !nm.SelfNode.Valid() { + return + } + cfg := nm.SelfNode.BlueprintConfig() + if !cfg.Valid() { + return + } + if cfg.ServeServices().Len() == 0 { + return + } + b.logf("blueprint %q: %d service(s) declared in ServeServices (full reconcile pending)", + b.pm.CurrentPrefs().BlueprintID(), cfg.ServeServices().Len()) } // reconcileBlueprintRoutesLocked syncs Prefs.AdvertiseRoutes with the diff --git a/tailcfg/tailcfg.go b/tailcfg/tailcfg.go index 3f95899c2..0c27eee6e 100644 --- a/tailcfg/tailcfg.go +++ b/tailcfg/tailcfg.go @@ -570,9 +570,17 @@ type BlueprintConfig struct { // ServeApps is the list of "app:" identifiers from the blueprint's // serves.apps field. Empty if the blueprint does not declare any - // apps. + // apps. When non-empty the bound daemon advertises itself as an + // app connector (Prefs.AppConnector.Advertise = true); silence + // forces the connector off. ServeApps []string `json:",omitempty"` + // ServeServices is the list of "svc:" identifiers from the + // blueprint's serves.services field. Empty if the blueprint does + // not declare any services. The daemon-side reconcile maps each + // entry to its corresponding Tailscale service advertisement. + ServeServices []string `json:",omitempty"` + // ServeIPSets is the list of "ipset:" identifiers from the // blueprint's serves.ipsets field. Empty if the blueprint does not // declare any ipset routes. Kept on the wire for operator @@ -619,6 +627,7 @@ func (c *BlueprintConfig) Equal(c2 *BlueprintConfig) bool { return slicesx.EqualSameNil(c.Tags, c2.Tags) && slicesx.EqualSameNil(c.ServeApps, c2.ServeApps) && slicesx.EqualSameNil(c.ServeIPSets, c2.ServeIPSets) && + slicesx.EqualSameNil(c.ServeServices, c2.ServeServices) && slicesx.EqualSameNil(c.Routes, c2.Routes) && slicesx.EqualSameNil(c.Attrs, c2.Attrs) && slicesx.EqualSameNil(c.Prefs, c2.Prefs) diff --git a/tailcfg/tailcfg_clone.go b/tailcfg/tailcfg_clone.go index 2c94188d1..47faba4de 100644 --- a/tailcfg/tailcfg_clone.go +++ b/tailcfg/tailcfg_clone.go @@ -703,6 +703,7 @@ func (src *BlueprintConfig) Clone() *BlueprintConfig { dst.Tags = append(src.Tags[:0:0], src.Tags...) dst.ServeApps = append(src.ServeApps[:0:0], src.ServeApps...) dst.ServeIPSets = append(src.ServeIPSets[:0:0], src.ServeIPSets...) + dst.ServeServices = append(src.ServeServices[:0:0], src.ServeServices...) dst.Routes = append(src.Routes[:0:0], src.Routes...) dst.Attrs = append(src.Attrs[:0:0], src.Attrs...) dst.Prefs = append(src.Prefs[:0:0], src.Prefs...) @@ -711,12 +712,13 @@ func (src *BlueprintConfig) Clone() *BlueprintConfig { // A compilation failure here means this code must be regenerated, with the command at the top of this file. var _BlueprintConfigCloneNeedsRegeneration = BlueprintConfig(struct { - Tags []string - ServeApps []string - ServeIPSets []string - Routes []netip.Prefix - Attrs []string - Prefs []string + Tags []string + ServeApps []string + ServeServices []string + ServeIPSets []string + Routes []netip.Prefix + Attrs []string + Prefs []string }{}) // Clone duplicates src into dst and reports whether it succeeded. diff --git a/tailcfg/tailcfg_view.go b/tailcfg/tailcfg_view.go index 29dec5a19..4ddc6311c 100644 --- a/tailcfg/tailcfg_view.go +++ b/tailcfg/tailcfg_view.go @@ -2808,6 +2808,14 @@ func (v BlueprintConfigView) ServeIPSets() views.Slice[string] { return views.SliceOf(v.ж.ServeIPSets) } +// ServeServices is the list of "svc:" identifiers from the +// blueprint's serves.services field. The daemon-side reconcile +// maps each entry to its corresponding Tailscale service +// advertisement. +func (v BlueprintConfigView) ServeServices() views.Slice[string] { + return views.SliceOf(v.ж.ServeServices) +} + // Routes is the concrete list of CIDR prefixes derived by the // control plane from ServeIPSets at projection time. The // blueprint-bound client uses these as the source of truth for @@ -2831,10 +2839,11 @@ func (v BlueprintConfigView) Equal(v2 BlueprintConfigView) bool { return v.ж.Eq // A compilation failure here means this code must be regenerated, with the command at the top of this file. var _BlueprintConfigViewNeedsRegeneration = BlueprintConfig(struct { - Tags []string - ServeApps []string - ServeIPSets []string - Routes []netip.Prefix - Attrs []string - Prefs []string + Tags []string + ServeApps []string + ServeServices []string + ServeIPSets []string + Routes []netip.Prefix + Attrs []string + Prefs []string }{})