diff --git a/lib/config/configuration.go b/lib/config/configuration.go index 5d4d300385dc5..262f6d620da2a 100644 --- a/lib/config/configuration.go +++ b/lib/config/configuration.go @@ -1375,14 +1375,15 @@ func applyDiscoveryConfig(fc *FileConfig, cfg *servicecfg.Config) error { Regions: matcher.Regions, ResourceTags: matcher.ResourceTags, } - - if matcher.InstallParams != nil { + if slices.Contains(matcher.Types, services.AzureMatcherVM) { m.Params = &types.InstallerParams{ - JoinMethod: matcher.InstallParams.JoinParams.Method, - JoinToken: matcher.InstallParams.JoinParams.TokenName, - ScriptName: matcher.InstallParams.ScriptName, PublicProxyAddr: getInstallerProxyAddr(matcher.InstallParams, fc), } + if matcher.InstallParams != nil { + m.Params.JoinMethod = matcher.InstallParams.JoinParams.Method + m.Params.JoinToken = matcher.InstallParams.JoinParams.TokenName + m.Params.ScriptName = matcher.InstallParams.ScriptName + } } cfg.Discovery.AzureMatchers = append(cfg.Discovery.AzureMatchers, m) } @@ -1396,13 +1397,15 @@ func applyDiscoveryConfig(fc *FileConfig, cfg *servicecfg.Config) error { ProjectIDs: matcher.ProjectIDs, ServiceAccounts: matcher.ServiceAccounts, } - if matcher.InstallParams != nil { + if slices.Contains(matcher.Types, services.GCPMatcherCompute) { m.Params = &types.InstallerParams{ - JoinMethod: matcher.InstallParams.JoinParams.Method, - JoinToken: matcher.InstallParams.JoinParams.TokenName, - ScriptName: matcher.InstallParams.ScriptName, PublicProxyAddr: getInstallerProxyAddr(matcher.InstallParams, fc), } + if matcher.InstallParams != nil { + m.Params.JoinMethod = matcher.InstallParams.JoinParams.Method + m.Params.JoinToken = matcher.InstallParams.JoinParams.TokenName + m.Params.ScriptName = matcher.InstallParams.ScriptName + } } cfg.Discovery.GCPMatchers = append(cfg.Discovery.GCPMatchers, m) } diff --git a/lib/config/configuration_test.go b/lib/config/configuration_test.go index c885a206d3607..55dcde0984641 100644 --- a/lib/config/configuration_test.go +++ b/lib/config/configuration_test.go @@ -3779,7 +3779,7 @@ func TestApplyDiscoveryConfig(t *testing.T) { discoveryConfig: Discovery{ AzureMatchers: []AzureMatcher{ { - Types: []string{"aks"}, + Types: []string{"aks", "vm"}, Subscriptions: []string{"abcd"}, }, }, @@ -3789,7 +3789,67 @@ func TestApplyDiscoveryConfig(t *testing.T) { AzureMatchers: []types.AzureMatcher{ { Subscriptions: []string{"abcd"}, - Types: []string{"aks"}, + Types: []string{"aks", "vm"}, + Params: &types.InstallerParams{ + PublicProxyAddr: "example.com", + }, + }, + }, + }, + }, + { + name: "gcp matchers", + discoveryConfig: Discovery{ + GCPMatchers: []GCPMatcher{ + { + Types: []string{"gce"}, + ProjectIDs: []string{"abcd"}, + InstallParams: &InstallParams{ + JoinParams: JoinParams{ + TokenName: "gcp-token", + Method: "gcp", + }, + ScriptName: "default-installer", + PublicProxyAddr: "proxy.example.com", + }, + }, + }, + }, + expectedDiscovery: servicecfg.DiscoveryConfig{ + Enabled: true, + GCPMatchers: []types.GCPMatcher{ + { + Types: []string{"gce"}, + ProjectIDs: []string{"abcd"}, + Params: &types.InstallerParams{ + JoinMethod: "gcp", + JoinToken: "gcp-token", + ScriptName: "default-installer", + PublicProxyAddr: "proxy.example.com", + }, + }, + }, + }, + }, + { + name: "gcp matchers no installer", + discoveryConfig: Discovery{ + GCPMatchers: []GCPMatcher{ + { + Types: []string{"gce"}, + ProjectIDs: []string{"abcd"}, + }, + }, + }, + expectedDiscovery: servicecfg.DiscoveryConfig{ + Enabled: true, + GCPMatchers: []types.GCPMatcher{ + { + Types: []string{"gce"}, + ProjectIDs: []string{"abcd"}, + Params: &types.InstallerParams{ + PublicProxyAddr: "example.com", + }, }, }, }, diff --git a/lib/config/fileconf_test.go b/lib/config/fileconf_test.go index 0d98e5fd662cb..43df76fdf4c78 100644 --- a/lib/config/fileconf_test.go +++ b/lib/config/fileconf_test.go @@ -947,6 +947,9 @@ func TestDiscoveryConfig(t *testing.T) { Labels: map[string]apiutils.Strings{ "discover_teleport": []string{"yes"}, }, + Tags: map[string]apiutils.Strings{ + "discover_teleport": []string{"yes"}, + }, ProjectIDs: []string{"p1", "p2"}, }, }, @@ -973,11 +976,14 @@ func TestDiscoveryConfig(t *testing.T) { expectedDiscoverySection: Discovery{ GCPMatchers: []GCPMatcher{ { - Types: []string{"gke"}, + Types: []string{"gce"}, Locations: []string{"eucentral1"}, Labels: map[string]apiutils.Strings{ "discover_teleport": []string{"yes"}, }, + Tags: map[string]apiutils.Strings{ + "discover_teleport": []string{"yes"}, + }, ProjectIDs: []string{"p1", "p2"}, ServiceAccounts: []string{"a@example.com", "b@example.com"}, InstallParams: &InstallParams{ @@ -1437,6 +1443,9 @@ func TestDiscoveryConfig(t *testing.T) { if expectedAzure := testCase.expectedDiscoverySection.AzureMatchers; expectedAzure != nil { require.Equal(t, expectedAzure, cfg.Discovery.AzureMatchers) } + if expectedGCP := testCase.expectedDiscoverySection.GCPMatchers; expectedGCP != nil { + require.Equal(t, expectedGCP, cfg.Discovery.GCPMatchers) + } }) } } diff --git a/lib/config/testdata_test.go b/lib/config/testdata_test.go index dd616a38be75b..ebe4c95f2e764 100644 --- a/lib/config/testdata_test.go +++ b/lib/config/testdata_test.go @@ -221,8 +221,10 @@ okta_service: // NoServicesConfigString is a configuration file with no services enabled // but with values for all services set. const NoServicesConfigString = ` +version: v3 teleport: nodename: node.example.com + proxy_server: "example.com" auth_service: enabled: no