diff --git a/lib/integrations/awsoidc/listdatabases_test.go b/lib/integrations/awsoidc/listdatabases_test.go index 72f72e6dfa534..568606fb0b7fe 100644 --- a/lib/integrations/awsoidc/listdatabases_test.go +++ b/lib/integrations/awsoidc/listdatabases_test.go @@ -188,13 +188,12 @@ func TestListDatabases(t *testing.T) { Name: "my-db", Description: "RDS instance in ", Labels: map[string]string{ - "account-id": "123456789012", - "endpoint-type": "instance", - "engine": "postgres", - "engine-version": "", - "region": "", - "teleport.dev/origin": "cloud", - "status": "available", + "account-id": "123456789012", + "endpoint-type": "instance", + "engine": "postgres", + "engine-version": "", + "region": "", + "status": "available", }, }, types.DatabaseSpecV3{ @@ -252,13 +251,12 @@ func TestListDatabases(t *testing.T) { Name: "my-db", Description: "RDS instance in ", Labels: map[string]string{ - "account-id": "123456789012", - "endpoint-type": "instance", - "engine": "postgres", - "engine-version": "", - "region": "", - "teleport.dev/origin": "cloud", - "status": "available", + "account-id": "123456789012", + "endpoint-type": "instance", + "engine": "postgres", + "engine-version": "", + "region": "", + "status": "available", }, }, types.DatabaseSpecV3{ @@ -303,13 +301,12 @@ func TestListDatabases(t *testing.T) { Name: "my-dbc", Description: "Aurora cluster in ", Labels: map[string]string{ - "account-id": "123456789012", - "endpoint-type": "primary", - "engine": "aurora-postgresql", - "engine-version": "", - "region": "", - "teleport.dev/origin": "cloud", - "status": "available", + "account-id": "123456789012", + "endpoint-type": "primary", + "engine": "aurora-postgresql", + "engine-version": "", + "region": "", + "status": "available", }, }, types.DatabaseSpecV3{ diff --git a/lib/services/database.go b/lib/services/database.go index 8b02948496898..fb5f66ef09577 100644 --- a/lib/services/database.go +++ b/lib/services/database.go @@ -1211,7 +1211,6 @@ func rdsEngineFamilyToProtocol(engineFamily string) (string, error) { // labelsFromAzureServer creates database labels for the provided Azure DB server. func labelsFromAzureServer(server *azure.DBServer) (map[string]string, error) { labels := azureTagsToLabels(server.Tags) - labels[types.OriginLabel] = types.OriginCloud labels[labelRegion] = server.Location labels[labelEngineVersion] = server.Properties.Version return withLabelsFromAzureResourceID(labels, server.ID) @@ -1232,7 +1231,6 @@ func withLabelsFromAzureResourceID(labels map[string]string, resourceID string) // labelsFromAzureRedis creates database labels from the provided Azure Redis instance. func labelsFromAzureRedis(server *armredis.ResourceInfo) (map[string]string, error) { labels := azureTagsToLabels(azure.ConvertTags(server.Tags)) - labels[types.OriginLabel] = types.OriginCloud labels[labelRegion] = azure.StringVal(server.Location) labels[labelEngineVersion] = azure.StringVal(server.Properties.RedisVersion) return withLabelsFromAzureResourceID(labels, azure.StringVal(server.ID)) @@ -1241,7 +1239,6 @@ func labelsFromAzureRedis(server *armredis.ResourceInfo) (map[string]string, err // labelsFromAzureRedisEnterprise creates database labels from the provided Azure Redis Enterprise server. func labelsFromAzureRedisEnterprise(cluster *armredisenterprise.Cluster, database *armredisenterprise.Database) (map[string]string, error) { labels := azureTagsToLabels(azure.ConvertTags(cluster.Tags)) - labels[types.OriginLabel] = types.OriginCloud labels[labelRegion] = azure.StringVal(cluster.Location) labels[labelEngineVersion] = azure.StringVal(cluster.Properties.RedisVersion) labels[labelEndpointType] = azure.StringVal(database.Properties.ClusteringPolicy) @@ -1252,7 +1249,6 @@ func labelsFromAzureRedisEnterprise(cluster *armredisenterprise.Cluster, databas // server. func labelsFromAzureSQLServer(server *armsql.Server) (map[string]string, error) { labels := azureTagsToLabels(azure.ConvertTags(server.Tags)) - labels[types.OriginLabel] = types.OriginCloud labels[labelRegion] = azure.StringVal(server.Location) labels[labelEngineVersion] = azure.StringVal(server.Properties.Version) return withLabelsFromAzureResourceID(labels, azure.StringVal(server.ID)) @@ -1262,7 +1258,6 @@ func labelsFromAzureSQLServer(server *armsql.Server) (map[string]string, error) // Azure Managed SQL server. func labelsFromAzureManagedSQLServer(server *armsql.ManagedInstance) (map[string]string, error) { labels := azureTagsToLabels(azure.ConvertTags(server.Tags)) - labels[types.OriginLabel] = types.OriginCloud labels[labelRegion] = azure.StringVal(server.Location) return withLabelsFromAzureResourceID(labels, azure.StringVal(server.ID)) } @@ -1270,7 +1265,6 @@ func labelsFromAzureManagedSQLServer(server *armsql.ManagedInstance) (map[string // labelsFromAzureMySQLFlexServer creates database labels for the provided Azure MySQL flex server. func labelsFromAzureMySQLFlexServer(server *armmysqlflexibleservers.Server) (map[string]string, error) { labels := azureTagsToLabels(azure.ConvertTags(server.Tags)) - labels[types.OriginLabel] = types.OriginCloud labels[labelRegion] = azure.StringVal(server.Location) labels[labelEngineVersion] = azure.StringVal(server.Properties.Version) @@ -1295,7 +1289,6 @@ func labelsFromAzureMySQLFlexServer(server *armmysqlflexibleservers.Server) (map // labelsFromAzurePostgresFlexServer creates database labels for the provided Azure postgres flex server. func labelsFromAzurePostgresFlexServer(server *armpostgresqlflexibleservers.Server) (map[string]string, error) { labels := azureTagsToLabels(azure.ConvertTags(server.Tags)) - labels[types.OriginLabel] = types.OriginCloud labels[labelRegion] = azure.StringVal(server.Location) labels[labelEngineVersion] = azure.StringVal(server.Properties.Version) return withLabelsFromAzureResourceID(labels, azure.StringVal(server.ID)) @@ -1366,7 +1359,6 @@ func labelsFromRedshiftServerlessVPCEndpoint(endpoint *redshiftserverless.Endpoi // labelsFromAWSMetadata returns labels from provided AWS metadata. func labelsFromAWSMetadata(meta *types.AWS) map[string]string { labels := make(map[string]string) - labels[types.OriginLabel] = types.OriginCloud if meta != nil { labels[labelAccountID] = meta.AccountID labels[labelRegion] = meta.Region diff --git a/lib/services/database_test.go b/lib/services/database_test.go index 66af57a0062fc..7eda7d565f4f1 100644 --- a/lib/services/database_test.go +++ b/lib/services/database_test.go @@ -327,7 +327,6 @@ func TestDatabaseFromAzureDBServer(t *testing.T) { Name: "testdb", Description: "Azure MySQL server in eastus", Labels: map[string]string{ - types.OriginLabel: types.OriginCloud, labelRegion: "eastus", labelEngine: "Microsoft.DBforMySQL/servers", labelEngineVersion: "5.7", @@ -375,7 +374,6 @@ func TestDatabaseFromAzureRedis(t *testing.T) { Name: name, Description: "Azure Redis server in eastus", Labels: map[string]string{ - types.OriginLabel: types.OriginCloud, labelRegion: region, labelEngine: "Microsoft.Cache/Redis", labelEngineVersion: "6.0", @@ -433,7 +431,6 @@ func TestDatabaseFromAzureRedisEnterprise(t *testing.T) { Name: name, Description: "Azure Redis Enterprise server in eastus", Labels: map[string]string{ - types.OriginLabel: types.OriginCloud, labelRegion: region, labelEngine: "Microsoft.Cache/redisEnterprise", labelEngineVersion: "6.0", @@ -483,7 +480,6 @@ func TestDatabaseFromRDSInstance(t *testing.T) { Name: "instance-1", Description: "RDS instance in us-west-1", Labels: map[string]string{ - types.OriginLabel: types.OriginCloud, labelAccountID: "123456789012", labelRegion: "us-west-1", labelEngine: RDSEnginePostgres, @@ -535,7 +531,6 @@ func TestDatabaseFromRDSV2Instance(t *testing.T) { Name: "instance-1", Description: "RDS instance in us-west-1", Labels: map[string]string{ - types.OriginLabel: types.OriginCloud, labelAccountID: "123456789012", labelRegion: "us-west-1", labelEngine: RDSEnginePostgres, @@ -603,7 +598,6 @@ func TestDatabaseFromRDSInstanceNameOverride(t *testing.T) { Name: "override-1", Description: "RDS instance in us-west-1", Labels: map[string]string{ - types.OriginLabel: types.OriginCloud, labelAccountID: "123456789012", labelRegion: "us-west-1", labelEngine: RDSEnginePostgres, @@ -669,7 +663,6 @@ func TestDatabaseFromRDSCluster(t *testing.T) { Name: "cluster-1", Description: "Aurora cluster in us-east-1", Labels: map[string]string{ - types.OriginLabel: types.OriginCloud, labelAccountID: "123456789012", labelRegion: "us-east-1", labelEngine: RDSEngineAuroraMySQL, @@ -693,7 +686,6 @@ func TestDatabaseFromRDSCluster(t *testing.T) { Name: "cluster-1-reader", Description: "Aurora cluster in us-east-1 (reader endpoint)", Labels: map[string]string{ - types.OriginLabel: types.OriginCloud, labelAccountID: "123456789012", labelRegion: "us-east-1", labelEngine: RDSEngineAuroraMySQL, @@ -714,7 +706,6 @@ func TestDatabaseFromRDSCluster(t *testing.T) { t.Run("custom endpoints", func(t *testing.T) { expectedLabels := map[string]string{ - types.OriginLabel: types.OriginCloud, labelAccountID: "123456789012", labelRegion: "us-east-1", labelEngine: RDSEngineAuroraMySQL, @@ -806,7 +797,6 @@ func TestDatabaseFromRDSV2Cluster(t *testing.T) { Name: "cluster-1", Description: "Aurora cluster in us-east-1", Labels: map[string]string{ - types.OriginLabel: types.OriginCloud, labelAccountID: "123456789012", labelRegion: "us-east-1", labelEngine: RDSEngineAuroraMySQL, @@ -880,7 +870,6 @@ func TestDatabaseFromRDSClusterNameOverride(t *testing.T) { Name: "mycluster-2", Description: "Aurora cluster in us-east-1", Labels: map[string]string{ - types.OriginLabel: types.OriginCloud, labelAccountID: "123456789012", labelRegion: "us-east-1", labelEngine: RDSEngineAuroraMySQL, @@ -905,7 +894,6 @@ func TestDatabaseFromRDSClusterNameOverride(t *testing.T) { Name: "mycluster-2-reader", Description: "Aurora cluster in us-east-1 (reader endpoint)", Labels: map[string]string{ - types.OriginLabel: types.OriginCloud, labelAccountID: "123456789012", labelRegion: "us-east-1", labelEngine: RDSEngineAuroraMySQL, @@ -927,7 +915,6 @@ func TestDatabaseFromRDSClusterNameOverride(t *testing.T) { t.Run("custom endpoints", func(t *testing.T) { expectedLabels := map[string]string{ - types.OriginLabel: types.OriginCloud, labelAccountID: "123456789012", labelRegion: "us-east-1", labelEngine: RDSEngineAuroraMySQL, @@ -1009,12 +996,11 @@ func TestDatabaseFromRDSProxy(t *testing.T) { Name: "testproxy", Description: "RDS Proxy in ca-central-1", Labels: map[string]string{ - "key": "val", - types.OriginLabel: types.OriginCloud, - labelAccountID: "123456789012", - labelRegion: "ca-central-1", - labelEngine: "MYSQL", - labelVPCID: "test-vpc-id", + "key": "val", + labelAccountID: "123456789012", + labelRegion: "ca-central-1", + labelEngine: "MYSQL", + labelVPCID: "test-vpc-id", }, }, types.DatabaseSpecV3{ Protocol: defaults.ProtocolMySQL, @@ -1041,7 +1027,6 @@ func TestDatabaseFromRDSProxy(t *testing.T) { Description: "RDS Proxy endpoint in ca-central-1", Labels: map[string]string{ "key": "val", - types.OriginLabel: types.OriginCloud, labelAccountID: "123456789012", labelRegion: "ca-central-1", labelEngine: "MYSQL", @@ -1232,7 +1217,6 @@ func TestDatabaseFromRedshiftCluster(t *testing.T) { Name: "mycluster", Description: "Redshift cluster in us-east-1", Labels: map[string]string{ - types.OriginLabel: types.OriginCloud, labelAccountID: "123456789012", labelRegion: "us-east-1", "key": "val", @@ -1284,7 +1268,6 @@ func TestDatabaseFromRedshiftCluster(t *testing.T) { Name: "mycluster-override-2", Description: "Redshift cluster in us-east-1", Labels: map[string]string{ - types.OriginLabel: types.OriginCloud, labelAccountID: "123456789012", labelRegion: "us-east-1", labelTeleportDBName: "mycluster-override-2", @@ -1362,7 +1345,6 @@ func TestDatabaseFromElastiCacheConfigurationEndpoint(t *testing.T) { Name: "my-cluster", Description: "ElastiCache cluster in us-east-1 (configuration endpoint)", Labels: map[string]string{ - types.OriginLabel: types.OriginCloud, labelAccountID: "123456789012", labelRegion: "us-east-1", labelEndpointType: "configuration", @@ -1435,7 +1417,6 @@ func TestDatabaseFromElastiCacheConfigurationEndpointNameOverride(t *testing.T) Name: "my-override-cluster-2", Description: "ElastiCache cluster in us-east-1 (configuration endpoint)", Labels: map[string]string{ - types.OriginLabel: types.OriginCloud, labelAccountID: "123456789012", labelRegion: "us-east-1", labelEndpointType: "configuration", @@ -1491,7 +1472,6 @@ func TestDatabaseFromElastiCacheNodeGroups(t *testing.T) { Name: "my-cluster", Description: "ElastiCache cluster in us-east-1 (primary endpoint)", Labels: map[string]string{ - types.OriginLabel: types.OriginCloud, labelAccountID: "123456789012", labelRegion: "us-east-1", labelEndpointType: "primary", @@ -1517,7 +1497,6 @@ func TestDatabaseFromElastiCacheNodeGroups(t *testing.T) { Name: "my-cluster-reader", Description: "ElastiCache cluster in us-east-1 (reader endpoint)", Labels: map[string]string{ - types.OriginLabel: types.OriginCloud, labelAccountID: "123456789012", labelRegion: "us-east-1", labelEndpointType: "reader", @@ -1575,7 +1554,6 @@ func TestDatabaseFromElastiCacheNodeGroupsNameOverride(t *testing.T) { Name: "my-override-cluster-2", Description: "ElastiCache cluster in us-east-1 (primary endpoint)", Labels: map[string]string{ - types.OriginLabel: types.OriginCloud, labelAccountID: "123456789012", labelRegion: "us-east-1", labelEndpointType: "primary", @@ -1602,7 +1580,6 @@ func TestDatabaseFromElastiCacheNodeGroupsNameOverride(t *testing.T) { Name: "my-override-cluster-2-reader", Description: "ElastiCache cluster in us-east-1 (reader endpoint)", Labels: map[string]string{ - types.OriginLabel: types.OriginCloud, labelAccountID: "123456789012", labelRegion: "us-east-1", labelEndpointType: "reader", @@ -1648,7 +1625,6 @@ func TestDatabaseFromMemoryDBCluster(t *testing.T) { Name: "my-cluster", Description: "MemoryDB cluster in us-east-1", Labels: map[string]string{ - types.OriginLabel: types.OriginCloud, labelAccountID: "123456789012", labelRegion: "us-east-1", labelEndpointType: "cluster", @@ -1682,7 +1658,6 @@ func TestDatabaseFromRedshiftServerlessWorkgroup(t *testing.T) { Name: "my-workgroup", Description: "Redshift Serverless workgroup in eu-west-2", Labels: map[string]string{ - types.OriginLabel: types.OriginCloud, labelAccountID: "123456789012", labelRegion: "eu-west-2", labelEndpointType: "workgroup", @@ -1717,7 +1692,6 @@ func TestDatabaseFromRedshiftServerlessVPCEndpoint(t *testing.T) { Name: "my-workgroup-my-endpoint", Description: "Redshift Serverless endpoint in eu-west-2", Labels: map[string]string{ - types.OriginLabel: types.OriginCloud, labelAccountID: "123456789012", labelRegion: "eu-west-2", labelEndpointType: "vpc-endpoint", @@ -1770,7 +1744,6 @@ func TestDatabaseFromMemoryDBClusterNameOverride(t *testing.T) { Name: "override-1", Description: "MemoryDB cluster in us-east-1", Labels: map[string]string{ - types.OriginLabel: types.OriginCloud, labelAccountID: "123456789012", labelRegion: "us-east-1", labelEndpointType: "cluster", @@ -2062,7 +2035,6 @@ func TestNewDatabaseFromAzureSQLServer(t *testing.T) { // Assert labels labels := db.GetMetadata().Labels - require.Equal(t, types.OriginCloud, labels[types.OriginLabel]) require.Equal(t, "westus", labels[labelRegion]) require.Equal(t, "12.0", labels[labelEngineVersion]) }, @@ -2118,7 +2090,6 @@ func TestNewDatabaseFromAzureManagedSQLServer(t *testing.T) { // Assert labels labels := db.GetMetadata().Labels - require.Equal(t, types.OriginCloud, labels[types.OriginLabel]) require.Equal(t, "westus", labels[labelRegion]) }, }, @@ -2205,7 +2176,6 @@ func TestDatabaseFromAzureMySQLFlexServer(t *testing.T) { } wantLabels := map[string]string{ - types.OriginLabel: types.OriginCloud, labelRegion: region, labelEngine: provider, labelEngineVersion: "8.0.21", @@ -2281,7 +2251,6 @@ func TestDatabaseFromAzurePostgresFlexServer(t *testing.T) { } wantLabels := map[string]string{ - types.OriginLabel: types.OriginCloud, labelRegion: region, labelEngine: provider, labelEngineVersion: "14", @@ -2378,7 +2347,6 @@ func TestMakeAzureDatabaseLoginUsername(t *testing.T) { Name: serverName, Description: "test azure db server", Labels: map[string]string{ - types.OriginLabel: types.OriginCloud, labelRegion: "eastus", labelEngine: tt.engine, labelEngineVersion: "1.2.3", diff --git a/lib/srv/db/watcher_test.go b/lib/srv/db/watcher_test.go index b377f4141d27a..92dee3f7787fa 100644 --- a/lib/srv/db/watcher_test.go +++ b/lib/srv/db/watcher_test.go @@ -228,9 +228,11 @@ func TestWatcherCloudFetchers(t *testing.T) { require.NoError(t, err) redshiftServerlessDatabase.SetStatusAWS(redshiftServerlessDatabase.GetAWS()) setDiscoveryGroupLabel(redshiftServerlessDatabase, "") + redshiftServerlessDatabase.SetOrigin(types.OriginCloud) // Test an Azure fetcher. azSQLServer, azSQLServerDatabase := makeAzureSQLServer(t, "discovery-azure", "group") setDiscoveryGroupLabel(azSQLServerDatabase, "") + azSQLServerDatabase.SetOrigin(types.OriginCloud) ctx := context.Background() testCtx := setupTestContext(ctx, t) diff --git a/lib/srv/discovery/common/watcher.go b/lib/srv/discovery/common/watcher.go index 5e225aa549d51..858431377d316 100644 --- a/lib/srv/discovery/common/watcher.go +++ b/lib/srv/discovery/common/watcher.go @@ -134,16 +134,22 @@ func (w *Watcher) fetchAndSend() { // never return the error otherwise it will impact other watchers. return nil } - if w.cfg.DiscoveryGroup != "" { - // Add the discovery group name to the static labels of each resource. - for _, r := range resources { - staticLabels := r.GetStaticLabels() - if staticLabels == nil { - staticLabels = make(map[string]string) - } + + for _, r := range resources { + staticLabels := r.GetStaticLabels() + if staticLabels == nil { + staticLabels = make(map[string]string) + } + + if w.cfg.DiscoveryGroup != "" { + // Add the discovery group name to the static labels of each resource. staticLabels[types.TeleportInternalDiscoveryGroupName] = w.cfg.DiscoveryGroup - r.SetStaticLabels(staticLabels) } + + // Set the origin to Cloud indicating that the resource was imported from a cloud provider. + staticLabels[types.OriginLabel] = types.OriginCloud + + r.SetStaticLabels(staticLabels) } fetchersLock.Lock()