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 }{})