From f28ac40a606adbd70fd19896fc12a0eecf11f1ad Mon Sep 17 00:00:00 2001 From: Gavin Frazar Date: Wed, 17 Aug 2022 14:39:49 -0700 Subject: [PATCH 01/13] Add Azure auto-discovery configuration fields --- lib/config/fileconf.go | 16 ++++++++++++++++ lib/service/cfg.go | 2 ++ lib/services/matchers.go | 18 ++++++++++++++++++ lib/srv/db/server.go | 2 ++ 4 files changed, 38 insertions(+) diff --git a/lib/config/fileconf.go b/lib/config/fileconf.go index d18c77c192737..dfdb80f137029 100644 --- a/lib/config/fileconf.go +++ b/lib/config/fileconf.go @@ -1166,6 +1166,8 @@ type Databases struct { ResourceMatchers []ResourceMatcher `yaml:"resources,omitempty"` // AWSMatchers match AWS hosted databases. AWSMatchers []AWSMatcher `yaml:"aws,omitempty"` + // AzureMatchers match Azure hosted databases. + AzureMatchers []AzureMatcher `yaml:"azure,omitempty"` } // ResourceMatcher matches cluster resources. @@ -1188,6 +1190,20 @@ type AWSMatcher struct { SSMDocument string `yaml:"ssm_command_document"` } +// AzureMatcher matches Azure databases. +type AzureMatcher struct { + // Subscriptions are Azure subscriptions to query for resources + Subscriptions []string `yaml:"subscriptions,omitempty"` + // ResourceGroups are Azure resource groups to query for resources. + ResourceGroups []string `yaml:"resource_groups,omitempty"` + // Types are azure database types to match: "mysql", "postgres" + Types []string `yaml:"types,omitempty"` + // Regions are Azure locations to match for databases. + Regions []string `yaml:"regions,omitempty"` + // Tags are Azure tags to match. + Tags map[string]apiutils.Strings `yaml:"tags,omitempty"` +} + // Database represents a single database proxied by the service. type Database struct { // Name is the name for the database proxy service. diff --git a/lib/service/cfg.go b/lib/service/cfg.go index 075adbb539c61..d3acc4bc0551b 100644 --- a/lib/service/cfg.go +++ b/lib/service/cfg.go @@ -699,6 +699,8 @@ type DatabasesConfig struct { ResourceMatchers []services.ResourceMatcher // AWSMatchers match AWS hosted databases. AWSMatchers []services.AWSMatcher + // AzureMatchers match Azure hosted databases. + AzureMatchers []services.AzureMatcher // Limiter limits the connection and request rates. Limiter limiter.Config } diff --git a/lib/services/matchers.go b/lib/services/matchers.go index 7e7dc443dfef1..ae1effb2a47cd 100644 --- a/lib/services/matchers.go +++ b/lib/services/matchers.go @@ -42,6 +42,20 @@ type AWSMatcher struct { SSMDocument string } +// AzureMatcher matches Azure databases. +type AzureMatcher struct { + // Subscriptions are Azure subscriptions to query for resources + Subscriptions []string + // ResourceGroups are Azure resource groups to query for resources. + ResourceGroups []string + // Types are Azure database types to match, "rds" or "redshift". + Types []string + // Regions are Azure regions to query for databases. + Regions []string + // Tags are Azure tags to match. + Tags types.Labels +} + // MatchResourceLabels returns true if any of the provided selectors matches the provided database. func MatchResourceLabels(matchers []ResourceMatcher, resource types.ResourceWithLabels) bool { for _, matcher := range matchers { @@ -246,4 +260,8 @@ const ( AWSMatcherMemoryDB = "memorydb" // AWSMatcherEC2 is the AWS matcher type for EC2 instances. AWSMatcherEC2 = "ec2" + // AzureMatcherMySQL is the Azure matcher type for Azure MySQL databases. + AzureMatcherMySQL = "mysql" + // AzureMatcherPostgres is the Azure matcher type for Azure Postgres databases. + AzureMatcherPostgres = "postgres" ) diff --git a/lib/srv/db/server.go b/lib/srv/db/server.go index 3d11f21e45099..59f6432da228f 100644 --- a/lib/srv/db/server.go +++ b/lib/srv/db/server.go @@ -88,6 +88,8 @@ type Config struct { ResourceMatchers []services.ResourceMatcher // AWSMatchers is a list of AWS databases matchers. AWSMatchers []services.AWSMatcher + // AzureMatchers is a list of Azure databases matchers. + AzureMatchers []services.AzureMatcher // Databases is a list of proxied databases from static configuration. Databases types.Databases // CloudLabels is a service that imports labels from a cloud provider. The labels are shared From ccf04e77c91d9ca9f0f060715588a6554f90944e Mon Sep 17 00:00:00 2001 From: Gavin Frazar Date: Wed, 17 Aug 2022 14:41:03 -0700 Subject: [PATCH 02/13] Init databases if azure matchers are in config --- lib/service/db.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/service/db.go b/lib/service/db.go index b008e9be251a5..08b966af28a14 100644 --- a/lib/service/db.go +++ b/lib/service/db.go @@ -34,7 +34,8 @@ func (process *TeleportProcess) shouldInitDatabases() bool { databasesCfg := len(process.Config.Databases.Databases) > 0 resourceMatchersCfg := len(process.Config.Databases.ResourceMatchers) > 0 awsMatchersCfg := len(process.Config.Databases.AWSMatchers) > 0 - anyCfg := databasesCfg || resourceMatchersCfg || awsMatchersCfg + azureMatchersCfg := len(process.Config.Databases.AzureMatchers) > 0 + anyCfg := databasesCfg || resourceMatchersCfg || awsMatchersCfg || azureMatchersCfg return process.Config.Databases.Enabled && anyCfg } From eb631a893ea8e7552352187cdab57009d8a62d6a Mon Sep 17 00:00:00 2001 From: Gavin Frazar Date: Wed, 17 Aug 2022 14:40:36 -0700 Subject: [PATCH 03/13] Use AzureMatchers in db service --- lib/service/db.go | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/service/db.go b/lib/service/db.go index 08b966af28a14..dc99118e91180 100644 --- a/lib/service/db.go +++ b/lib/service/db.go @@ -216,6 +216,7 @@ func (process *TeleportProcess) initDatabaseService() (retErr error) { CloudLabels: process.cloudLabels, ResourceMatchers: process.Config.Databases.ResourceMatchers, AWSMatchers: process.Config.Databases.AWSMatchers, + AzureMatchers: process.Config.Databases.AzureMatchers, OnHeartbeat: process.onHeartbeat(teleport.ComponentDatabase), LockWatcher: lockWatcher, ConnectedProxyGetter: proxyGetter, From 053a2f91c2c6cc597bd39ebba5e9bc043069b66f Mon Sep 17 00:00:00 2001 From: Gavin Frazar Date: Wed, 17 Aug 2022 14:41:39 -0700 Subject: [PATCH 04/13] Use all azure subscriptions/resource groups if omitted in matcher --- lib/config/configuration.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/config/configuration.go b/lib/config/configuration.go index 318fff76796e6..38a407326950b 100644 --- a/lib/config/configuration.go +++ b/lib/config/configuration.go @@ -1135,6 +1135,22 @@ func applyDatabasesConfig(fc *FileConfig, cfg *service.Config) error { Tags: matcher.Tags, }) } + for _, matcher := range fc.Databases.AzureMatchers { + if len(matcher.Subscriptions) == 0 || apiutils.SliceContainsStr(matcher.Subscriptions, types.Wildcard) { + matcher.Subscriptions = []string{types.Wildcard} + } + if len(matcher.ResourceGroups) == 0 || apiutils.SliceContainsStr(matcher.ResourceGroups, types.Wildcard) { + matcher.ResourceGroups = []string{types.Wildcard} + } + cfg.Databases.AzureMatchers = append(cfg.Databases.AzureMatchers, + services.AzureMatcher{ + Subscriptions: matcher.Subscriptions, + ResourceGroups: matcher.ResourceGroups, + Types: matcher.Types, + Regions: matcher.Regions, + Tags: matcher.Tags, + }) + } for _, database := range fc.Databases.Databases { staticLabels := make(map[string]string) if database.StaticLabels != nil { From 38e1df74c3c50daafc7d74cb2ac94b3205e24632 Mon Sep 17 00:00:00 2001 From: Gavin Frazar Date: Wed, 17 Aug 2022 14:44:42 -0700 Subject: [PATCH 05/13] Add azure config tests --- lib/config/configuration_test.go | 88 +++++++++++++++++++++++++++++++- lib/config/testdata_test.go | 17 ++++++ 2 files changed, 104 insertions(+), 1 deletion(-) diff --git a/lib/config/configuration_test.go b/lib/config/configuration_test.go index 4feb74b3b1e63..8ddd116ba1f76 100644 --- a/lib/config/configuration_test.go +++ b/lib/config/configuration_test.go @@ -290,7 +290,7 @@ func TestConfigReading(t *testing.T) { require.True(t, conf.SSH.Enabled()) require.False(t, conf.Kube.Enabled()) - // static config + // good config conf, err = ReadFromFile(testConfigs.configFile) require.NoError(t, err) require.Empty(t, cmp.Diff(conf, &FileConfig{ @@ -419,6 +419,35 @@ func TestConfigReading(t *testing.T) { }, }, }, + AzureMatchers: []AzureMatcher{ + { + Subscriptions: []string{"sub1", "sub2"}, + ResourceGroups: []string{"rg1", "rg2"}, + Types: []string{"mysql"}, + Regions: []string{"eastus", "westus"}, + Tags: map[string]apiutils.Strings{ + "a": {"b"}, + }, + }, + { + Subscriptions: []string{"sub3", "sub4"}, + ResourceGroups: []string{"rg3", "rg4"}, + Types: []string{"postgres"}, + Regions: []string{"centralus"}, + Tags: map[string]apiutils.Strings{ + "c": {"d"}, + }, + }, + { + Subscriptions: nil, + ResourceGroups: nil, + Types: []string{"mysql", "postgres"}, + Regions: []string{"centralus"}, + Tags: map[string]apiutils.Strings{ + "e": {"f"}, + }, + }, + }, }, Metrics: Metrics{ Service: Service{ @@ -765,6 +794,30 @@ SREzU8onbBsjMg9QDiSf5oJLKvd/Ren+zGY7 require.Equal(t, 1, *cfg.Auth.KeyStore.SlotNumber) require.Equal(t, "example_pin", cfg.Auth.KeyStore.Pin) require.ElementsMatch(t, []string{"ca-pin-from-string", "ca-pin-from-file1", "ca-pin-from-file2"}, cfg.CAPins) + + require.True(t, cfg.Databases.Enabled) + require.Empty(t, cmp.Diff(cfg.Databases.AzureMatchers, + []services.AzureMatcher{ + { + Subscriptions: []string{"sub1", "sub2"}, + ResourceGroups: []string{"group1", "group2"}, + Types: []string{"postgres", "mysql"}, + Regions: []string{"eastus", "centralus"}, + Tags: map[string]apiutils.Strings{ + "a": {"b"}, + }, + }, + { + Subscriptions: []string{"*"}, + ResourceGroups: []string{"*"}, + Types: []string{"postgres", "mysql"}, + Regions: []string{"westus"}, + Tags: map[string]apiutils.Strings{ + "c": {"d"}, + }, + }, + }, + cmp.AllowUnexported(Service{}))) } // TestApplyConfigNoneEnabled makes sure that if a section is not enabled, @@ -1335,6 +1388,33 @@ func makeConfigFixture() string { Tags: map[string]apiutils.Strings{"c": {"d"}}, }, } + conf.Databases.AzureMatchers = []AzureMatcher{ + { + Subscriptions: []string{"sub1", "sub2"}, + ResourceGroups: []string{"rg1", "rg2"}, + Types: []string{"mysql"}, + Regions: []string{"eastus", "westus"}, + Tags: map[string]apiutils.Strings{ + "a": {"b"}, + }, + }, + { + Subscriptions: []string{"sub3", "sub4"}, + ResourceGroups: []string{"rg3", "rg4"}, + Types: []string{"postgres"}, + Regions: []string{"centralus"}, + Tags: map[string]apiutils.Strings{ + "c": {"d"}, + }, + }, + { + Types: []string{"mysql", "postgres"}, + Regions: []string{"centralus"}, + Tags: map[string]apiutils.Strings{ + "e": {"f"}, + }, + }, + } // Metrics service. conf.Metrics.EnabledFlag = "yes" @@ -1993,6 +2073,12 @@ db_service: regions: ["us-east-1", "us-west-1"] tags: '*': '*' + azure: + - subscriptions: ["foo", "bar"] + types: ["mysql", "postgres"] + regions: ["eastus", "westus"] + tags: + '*': '*' databases: - name: foo protocol: postgres diff --git a/lib/config/testdata_test.go b/lib/config/testdata_test.go index dd01991a2d386..c4e22e8466532 100644 --- a/lib/config/testdata_test.go +++ b/lib/config/testdata_test.go @@ -164,6 +164,23 @@ proxy_service: mysql_public_addr: mysql.example:3306 mongo_listen_addr: webhost:27017 mongo_public_addr: mongo.example:27017 + +db_service: + enabled: yes + resources: + - labels: + "*": "*" + azure: + - subscriptions: ["sub1", "sub2"] + resource_groups: ["group1", "group2"] + types: ["postgres", "mysql"] + regions: ["eastus", "centralus"] + tags: + "a": "b" + - types: ["postgres", "mysql"] + regions: ["westus"] + tags: + "c": "d" ` // NoServicesConfigString is a configuration file with no services enabled From 16035a2e652cb62e7dfb6e3dcfea9f5a42ef8c4a Mon Sep 17 00:00:00 2001 From: Gavin Frazar Date: Thu, 18 Aug 2022 09:45:59 -0700 Subject: [PATCH 06/13] Update lib/services/matchers.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Krzysztof Skrzętnicki --- lib/services/matchers.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/services/matchers.go b/lib/services/matchers.go index ae1effb2a47cd..ed8d25ab2a2cd 100644 --- a/lib/services/matchers.go +++ b/lib/services/matchers.go @@ -48,7 +48,7 @@ type AzureMatcher struct { Subscriptions []string // ResourceGroups are Azure resource groups to query for resources. ResourceGroups []string - // Types are Azure database types to match, "rds" or "redshift". + // Types are Azure resource types to match, for example "mysql" or "postgres". Types []string // Regions are Azure regions to query for databases. Regions []string From e350127cabf041e0f1e3684924a552584103fa19 Mon Sep 17 00:00:00 2001 From: Gavin Frazar Date: Thu, 18 Aug 2022 09:47:02 -0700 Subject: [PATCH 07/13] Update lib/config/fileconf.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Marek Smoliński --- lib/config/fileconf.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/config/fileconf.go b/lib/config/fileconf.go index dfdb80f137029..fdf0114652ea6 100644 --- a/lib/config/fileconf.go +++ b/lib/config/fileconf.go @@ -1196,7 +1196,7 @@ type AzureMatcher struct { Subscriptions []string `yaml:"subscriptions,omitempty"` // ResourceGroups are Azure resource groups to query for resources. ResourceGroups []string `yaml:"resource_groups,omitempty"` - // Types are azure database types to match: "mysql", "postgres" + // Types are Azure database types to match: "mysql", "postgres" Types []string `yaml:"types,omitempty"` // Regions are Azure locations to match for databases. Regions []string `yaml:"regions,omitempty"` From bdf621af16675e79ef297f2c3d3ccf5cb2ea2c88 Mon Sep 17 00:00:00 2001 From: Gavin Frazar Date: Thu, 18 Aug 2022 10:00:14 -0700 Subject: [PATCH 08/13] Update lib/config/fileconf.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Marek Smoliński --- lib/config/fileconf.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/config/fileconf.go b/lib/config/fileconf.go index fdf0114652ea6..6609f46d2f50b 100644 --- a/lib/config/fileconf.go +++ b/lib/config/fileconf.go @@ -1192,7 +1192,7 @@ type AWSMatcher struct { // AzureMatcher matches Azure databases. type AzureMatcher struct { - // Subscriptions are Azure subscriptions to query for resources + // Subscriptions are Azure subscriptions to query for resources. Subscriptions []string `yaml:"subscriptions,omitempty"` // ResourceGroups are Azure resource groups to query for resources. ResourceGroups []string `yaml:"resource_groups,omitempty"` From 09d1e0562d93950b36417b18a5aed6c2e9acb45c Mon Sep 17 00:00:00 2001 From: Gavin Frazar Date: Thu, 18 Aug 2022 10:00:24 -0700 Subject: [PATCH 09/13] Update lib/services/matchers.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Marek Smoliński --- lib/services/matchers.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/services/matchers.go b/lib/services/matchers.go index ed8d25ab2a2cd..1858038cb83ad 100644 --- a/lib/services/matchers.go +++ b/lib/services/matchers.go @@ -44,7 +44,7 @@ type AWSMatcher struct { // AzureMatcher matches Azure databases. type AzureMatcher struct { - // Subscriptions are Azure subscriptions to query for resources + // Subscriptions are Azure subscriptions to query for resources. Subscriptions []string // ResourceGroups are Azure resource groups to query for resources. ResourceGroups []string From 263864f1193b8dc2a60ded03c3dc1d9038a7c58a Mon Sep 17 00:00:00 2001 From: Gavin Frazar Date: Thu, 18 Aug 2022 10:29:02 -0700 Subject: [PATCH 10/13] Remove superfluous cmp option for diffing azure matcher --- lib/config/configuration_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/config/configuration_test.go b/lib/config/configuration_test.go index 8ddd116ba1f76..822155491cbbc 100644 --- a/lib/config/configuration_test.go +++ b/lib/config/configuration_test.go @@ -816,8 +816,7 @@ SREzU8onbBsjMg9QDiSf5oJLKvd/Ren+zGY7 "c": {"d"}, }, }, - }, - cmp.AllowUnexported(Service{}))) + })) } // TestApplyConfigNoneEnabled makes sure that if a section is not enabled, From d3b940d8374b9932d160054fa7ad7c14a6a93a2b Mon Sep 17 00:00:00 2001 From: Gavin Frazar Date: Thu, 18 Aug 2022 11:10:27 -0700 Subject: [PATCH 11/13] Rename AzureMatchers Tags to ResourceTags --- lib/config/configuration.go | 2 +- lib/config/configuration_test.go | 16 ++++++++-------- lib/config/fileconf.go | 4 ++-- lib/services/matchers.go | 4 ++-- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/config/configuration.go b/lib/config/configuration.go index 38a407326950b..9b9cca1422566 100644 --- a/lib/config/configuration.go +++ b/lib/config/configuration.go @@ -1148,7 +1148,7 @@ func applyDatabasesConfig(fc *FileConfig, cfg *service.Config) error { ResourceGroups: matcher.ResourceGroups, Types: matcher.Types, Regions: matcher.Regions, - Tags: matcher.Tags, + ResourceTags: matcher.ResourceTags, }) } for _, database := range fc.Databases.Databases { diff --git a/lib/config/configuration_test.go b/lib/config/configuration_test.go index 822155491cbbc..9337359cd45e0 100644 --- a/lib/config/configuration_test.go +++ b/lib/config/configuration_test.go @@ -425,7 +425,7 @@ func TestConfigReading(t *testing.T) { ResourceGroups: []string{"rg1", "rg2"}, Types: []string{"mysql"}, Regions: []string{"eastus", "westus"}, - Tags: map[string]apiutils.Strings{ + ResourceTags: map[string]apiutils.Strings{ "a": {"b"}, }, }, @@ -434,7 +434,7 @@ func TestConfigReading(t *testing.T) { ResourceGroups: []string{"rg3", "rg4"}, Types: []string{"postgres"}, Regions: []string{"centralus"}, - Tags: map[string]apiutils.Strings{ + ResourceTags: map[string]apiutils.Strings{ "c": {"d"}, }, }, @@ -443,7 +443,7 @@ func TestConfigReading(t *testing.T) { ResourceGroups: nil, Types: []string{"mysql", "postgres"}, Regions: []string{"centralus"}, - Tags: map[string]apiutils.Strings{ + ResourceTags: map[string]apiutils.Strings{ "e": {"f"}, }, }, @@ -803,7 +803,7 @@ SREzU8onbBsjMg9QDiSf5oJLKvd/Ren+zGY7 ResourceGroups: []string{"group1", "group2"}, Types: []string{"postgres", "mysql"}, Regions: []string{"eastus", "centralus"}, - Tags: map[string]apiutils.Strings{ + ResourceTags: map[string]apiutils.Strings{ "a": {"b"}, }, }, @@ -812,7 +812,7 @@ SREzU8onbBsjMg9QDiSf5oJLKvd/Ren+zGY7 ResourceGroups: []string{"*"}, Types: []string{"postgres", "mysql"}, Regions: []string{"westus"}, - Tags: map[string]apiutils.Strings{ + ResourceTags: map[string]apiutils.Strings{ "c": {"d"}, }, }, @@ -1393,7 +1393,7 @@ func makeConfigFixture() string { ResourceGroups: []string{"rg1", "rg2"}, Types: []string{"mysql"}, Regions: []string{"eastus", "westus"}, - Tags: map[string]apiutils.Strings{ + ResourceTags: map[string]apiutils.Strings{ "a": {"b"}, }, }, @@ -1402,14 +1402,14 @@ func makeConfigFixture() string { ResourceGroups: []string{"rg3", "rg4"}, Types: []string{"postgres"}, Regions: []string{"centralus"}, - Tags: map[string]apiutils.Strings{ + ResourceTags: map[string]apiutils.Strings{ "c": {"d"}, }, }, { Types: []string{"mysql", "postgres"}, Regions: []string{"centralus"}, - Tags: map[string]apiutils.Strings{ + ResourceTags: map[string]apiutils.Strings{ "e": {"f"}, }, }, diff --git a/lib/config/fileconf.go b/lib/config/fileconf.go index 6609f46d2f50b..a9379b194acf7 100644 --- a/lib/config/fileconf.go +++ b/lib/config/fileconf.go @@ -1200,8 +1200,8 @@ type AzureMatcher struct { Types []string `yaml:"types,omitempty"` // Regions are Azure locations to match for databases. Regions []string `yaml:"regions,omitempty"` - // Tags are Azure tags to match. - Tags map[string]apiutils.Strings `yaml:"tags,omitempty"` + // ResourceTags are Azure tags on resources to match. + ResourceTags map[string]apiutils.Strings `yaml:"tags,omitempty"` } // Database represents a single database proxied by the service. diff --git a/lib/services/matchers.go b/lib/services/matchers.go index 1858038cb83ad..3e11f13252f63 100644 --- a/lib/services/matchers.go +++ b/lib/services/matchers.go @@ -52,8 +52,8 @@ type AzureMatcher struct { Types []string // Regions are Azure regions to query for databases. Regions []string - // Tags are Azure tags to match. - Tags types.Labels + // ResourceTags are Azure tags to match. + ResourceTags types.Labels } // MatchResourceLabels returns true if any of the provided selectors matches the provided database. From 8d879bc29540cb534d1cd22119703197e8ffd337 Mon Sep 17 00:00:00 2001 From: Gavin Frazar Date: Thu, 18 Aug 2022 11:20:36 -0700 Subject: [PATCH 12/13] Deduplicate subscription/resource groups and add tests --- lib/config/configuration.go | 2 ++ lib/config/configuration_test.go | 13 +++++++++++-- lib/config/testdata_test.go | 10 ++++++++-- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/lib/config/configuration.go b/lib/config/configuration.go index 9b9cca1422566..8661dfbe86ac6 100644 --- a/lib/config/configuration.go +++ b/lib/config/configuration.go @@ -1136,6 +1136,8 @@ func applyDatabasesConfig(fc *FileConfig, cfg *service.Config) error { }) } for _, matcher := range fc.Databases.AzureMatchers { + matcher.Subscriptions = apiutils.Deduplicate(matcher.Subscriptions) + matcher.ResourceGroups = apiutils.Deduplicate(matcher.ResourceGroups) if len(matcher.Subscriptions) == 0 || apiutils.SliceContainsStr(matcher.Subscriptions, types.Wildcard) { matcher.Subscriptions = []string{types.Wildcard} } diff --git a/lib/config/configuration_test.go b/lib/config/configuration_test.go index 9337359cd45e0..9e9bef73aa46b 100644 --- a/lib/config/configuration_test.go +++ b/lib/config/configuration_test.go @@ -799,8 +799,8 @@ SREzU8onbBsjMg9QDiSf5oJLKvd/Ren+zGY7 require.Empty(t, cmp.Diff(cfg.Databases.AzureMatchers, []services.AzureMatcher{ { - Subscriptions: []string{"sub1", "sub2"}, - ResourceGroups: []string{"group1", "group2"}, + Subscriptions: []string{"sub1", "sub2"}, // deduplicated subscriptions + ResourceGroups: []string{"group1", "group2"}, // deduplicated resource groups Types: []string{"postgres", "mysql"}, Regions: []string{"eastus", "centralus"}, ResourceTags: map[string]apiutils.Strings{ @@ -816,6 +816,15 @@ SREzU8onbBsjMg9QDiSf5oJLKvd/Ren+zGY7 "c": {"d"}, }, }, + { + Subscriptions: []string{"*"}, // wildcard equivalence + ResourceGroups: []string{"*"}, // wildcard equivalence + Types: []string{"postgres", "mysql"}, + Regions: []string{"westus"}, + ResourceTags: map[string]apiutils.Strings{ + "e": {"f"}, + }, + }, })) } diff --git a/lib/config/testdata_test.go b/lib/config/testdata_test.go index c4e22e8466532..6701022711210 100644 --- a/lib/config/testdata_test.go +++ b/lib/config/testdata_test.go @@ -171,8 +171,8 @@ db_service: - labels: "*": "*" azure: - - subscriptions: ["sub1", "sub2"] - resource_groups: ["group1", "group2"] + - subscriptions: ["sub1", "sub2", "sub1", "sub2"] + resource_groups: ["group1", "group2", "group2", "group1"] types: ["postgres", "mysql"] regions: ["eastus", "centralus"] tags: @@ -181,6 +181,12 @@ db_service: regions: ["westus"] tags: "c": "d" + - subscriptions: ["sub1", "*", "sub1", "sub2"] + resource_groups: ["group1", "*", "group2", "group1"] + types: ["postgres", "mysql"] + regions: ["westus"] + tags: + "e": "f" ` // NoServicesConfigString is a configuration file with no services enabled From 88230e9ad881dbbad50d35e06267819ffb181744 Mon Sep 17 00:00:00 2001 From: Gavin Frazar Date: Fri, 19 Aug 2022 11:26:34 -0700 Subject: [PATCH 13/13] Remove azure matcher config fixup --- lib/config/configuration.go | 8 -------- lib/config/configuration_test.go | 17 ++++------------- lib/config/testdata_test.go | 10 ++-------- 3 files changed, 6 insertions(+), 29 deletions(-) diff --git a/lib/config/configuration.go b/lib/config/configuration.go index 8661dfbe86ac6..bab2f9a5c93a3 100644 --- a/lib/config/configuration.go +++ b/lib/config/configuration.go @@ -1136,14 +1136,6 @@ func applyDatabasesConfig(fc *FileConfig, cfg *service.Config) error { }) } for _, matcher := range fc.Databases.AzureMatchers { - matcher.Subscriptions = apiutils.Deduplicate(matcher.Subscriptions) - matcher.ResourceGroups = apiutils.Deduplicate(matcher.ResourceGroups) - if len(matcher.Subscriptions) == 0 || apiutils.SliceContainsStr(matcher.Subscriptions, types.Wildcard) { - matcher.Subscriptions = []string{types.Wildcard} - } - if len(matcher.ResourceGroups) == 0 || apiutils.SliceContainsStr(matcher.ResourceGroups, types.Wildcard) { - matcher.ResourceGroups = []string{types.Wildcard} - } cfg.Databases.AzureMatchers = append(cfg.Databases.AzureMatchers, services.AzureMatcher{ Subscriptions: matcher.Subscriptions, diff --git a/lib/config/configuration_test.go b/lib/config/configuration_test.go index 9e9bef73aa46b..259c8f678b5be 100644 --- a/lib/config/configuration_test.go +++ b/lib/config/configuration_test.go @@ -799,8 +799,8 @@ SREzU8onbBsjMg9QDiSf5oJLKvd/Ren+zGY7 require.Empty(t, cmp.Diff(cfg.Databases.AzureMatchers, []services.AzureMatcher{ { - Subscriptions: []string{"sub1", "sub2"}, // deduplicated subscriptions - ResourceGroups: []string{"group1", "group2"}, // deduplicated resource groups + Subscriptions: []string{"sub1", "sub2"}, + ResourceGroups: []string{"group1", "group2"}, Types: []string{"postgres", "mysql"}, Regions: []string{"eastus", "centralus"}, ResourceTags: map[string]apiutils.Strings{ @@ -808,23 +808,14 @@ SREzU8onbBsjMg9QDiSf5oJLKvd/Ren+zGY7 }, }, { - Subscriptions: []string{"*"}, - ResourceGroups: []string{"*"}, + Subscriptions: nil, + ResourceGroups: nil, Types: []string{"postgres", "mysql"}, Regions: []string{"westus"}, ResourceTags: map[string]apiutils.Strings{ "c": {"d"}, }, }, - { - Subscriptions: []string{"*"}, // wildcard equivalence - ResourceGroups: []string{"*"}, // wildcard equivalence - Types: []string{"postgres", "mysql"}, - Regions: []string{"westus"}, - ResourceTags: map[string]apiutils.Strings{ - "e": {"f"}, - }, - }, })) } diff --git a/lib/config/testdata_test.go b/lib/config/testdata_test.go index 6701022711210..c4e22e8466532 100644 --- a/lib/config/testdata_test.go +++ b/lib/config/testdata_test.go @@ -171,8 +171,8 @@ db_service: - labels: "*": "*" azure: - - subscriptions: ["sub1", "sub2", "sub1", "sub2"] - resource_groups: ["group1", "group2", "group2", "group1"] + - subscriptions: ["sub1", "sub2"] + resource_groups: ["group1", "group2"] types: ["postgres", "mysql"] regions: ["eastus", "centralus"] tags: @@ -181,12 +181,6 @@ db_service: regions: ["westus"] tags: "c": "d" - - subscriptions: ["sub1", "*", "sub1", "sub2"] - resource_groups: ["group1", "*", "group2", "group1"] - types: ["postgres", "mysql"] - regions: ["westus"] - tags: - "e": "f" ` // NoServicesConfigString is a configuration file with no services enabled