From af3ac37bc0642bbadb82011e89cf6d985c9cd3ca Mon Sep 17 00:00:00 2001 From: Przemko Robakowski Date: Mon, 14 Oct 2024 23:20:25 +0200 Subject: [PATCH] Add resource matchers to Windows desktop service config (#46985) * Add DynamicWindowsDesktop to proto * Add resource matchers to Windows desktop service config * move rpc to separate server * e * remove dynamic windows from paginated resource * Update api/proto/teleport/legacy/types/types.proto Co-authored-by: rosstimothy <39066650+rosstimothy@users.noreply.github.com> * gci --------- Co-authored-by: rosstimothy <39066650+rosstimothy@users.noreply.github.com> --- lib/config/configuration.go | 6 ++++++ lib/config/fileconf.go | 2 ++ lib/service/desktop.go | 1 + lib/service/servicecfg/windows.go | 3 +++ lib/srv/desktop/windows_server.go | 2 ++ 5 files changed, 14 insertions(+) diff --git a/lib/config/configuration.go b/lib/config/configuration.go index 6d32dce7243ea..0f23047f64f74 100644 --- a/lib/config/configuration.go +++ b/lib/config/configuration.go @@ -2246,6 +2246,12 @@ func applyWindowsDesktopConfig(fc *FileConfig, cfg *servicecfg.Config) error { } cfg.WindowsDesktop.HostLabels = servicecfg.NewHostLabelRules(hlrs...) + for _, matcher := range fc.WindowsDesktop.ResourceMatchers { + cfg.WindowsDesktop.ResourceMatchers = append(cfg.WindowsDesktop.ResourceMatchers, services.ResourceMatcher{ + Labels: matcher.Labels, + }) + } + if fc.WindowsDesktop.Labels != nil { cfg.WindowsDesktop.Labels = maps.Clone(fc.WindowsDesktop.Labels) } diff --git a/lib/config/fileconf.go b/lib/config/fileconf.go index 987711d807f0b..34ea2a60f2607 100644 --- a/lib/config/fileconf.go +++ b/lib/config/fileconf.go @@ -2399,6 +2399,8 @@ type WindowsDesktopService struct { // A host can match multiple rules and will get a union of all // the matched labels. HostLabels []WindowsHostLabelRule `yaml:"host_labels,omitempty"` + // ResourceMatchers match dynamic Windows desktop resources. + ResourceMatchers []ResourceMatcher `yaml:"resources,omitempty"` } // Check checks whether the WindowsDesktopService is valid or not diff --git a/lib/service/desktop.go b/lib/service/desktop.go index 5ebc52af55a8c..adc3f19de92d0 100644 --- a/lib/service/desktop.go +++ b/lib/service/desktop.go @@ -236,6 +236,7 @@ func (process *TeleportProcess) initWindowsDesktopServiceRegistered(logger *slog DiscoveryLDAPAttributeLabels: cfg.WindowsDesktop.Discovery.LabelAttributes, Hostname: cfg.Hostname, ConnectedProxyGetter: proxyGetter, + ResourceMatchers: cfg.WindowsDesktop.ResourceMatchers, }) if err != nil { return trace.Wrap(err) diff --git a/lib/service/servicecfg/windows.go b/lib/service/servicecfg/windows.go index d5250c71f7b26..988dc16b3e466 100644 --- a/lib/service/servicecfg/windows.go +++ b/lib/service/servicecfg/windows.go @@ -24,6 +24,7 @@ import ( "regexp" "github.com/gravitational/teleport/lib/limiter" + "github.com/gravitational/teleport/lib/services" "github.com/gravitational/teleport/lib/utils" ) @@ -65,6 +66,8 @@ type WindowsDesktopConfig struct { // HostLabels specifies rules that are used to apply labels to Windows hosts. HostLabels HostLabelRules Labels map[string]string + // ResourceMatchers match dynamic Windows desktop resources. + ResourceMatchers []services.ResourceMatcher } // WindowsHost is configuration for single Windows desktop host diff --git a/lib/srv/desktop/windows_server.go b/lib/srv/desktop/windows_server.go index 40c19a2ada1aa..c158d6c1ce0d9 100644 --- a/lib/srv/desktop/windows_server.go +++ b/lib/srv/desktop/windows_server.go @@ -210,6 +210,8 @@ type WindowsServiceConfig struct { // ConnectedProxyGetter gets the proxies teleport is connected to. ConnectedProxyGetter *reversetunnel.ConnectedProxyGetter Labels map[string]string + // ResourceMatchers match dynamic Windows desktop resources. + ResourceMatchers []services.ResourceMatcher } // HeartbeatConfig contains the configuration for service heartbeats.