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 feae8db6e3371..f197480043dbf 100644 --- a/lib/services/database.go +++ b/lib/services/database.go @@ -1234,7 +1234,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) @@ -1255,7 +1254,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)) @@ -1264,7 +1262,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) @@ -1275,7 +1272,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)) @@ -1285,7 +1281,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)) } @@ -1293,7 +1288,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) @@ -1318,7 +1312,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)) @@ -1389,7 +1382,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 56cb0a2f306de..0a5a007d2fa7f 100644 --- a/lib/services/database_test.go +++ b/lib/services/database_test.go @@ -363,7 +363,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", @@ -411,7 +410,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", @@ -469,7 +467,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", @@ -519,7 +516,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, @@ -571,7 +567,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, @@ -639,7 +634,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, @@ -705,7 +699,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, @@ -729,7 +722,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, @@ -750,7 +742,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, @@ -842,7 +833,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, @@ -916,7 +906,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, @@ -941,7 +930,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, @@ -963,7 +951,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, @@ -1045,12 +1032,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, @@ -1077,7 +1063,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", @@ -1268,7 +1253,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", @@ -1320,7 +1304,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", @@ -1398,7 +1381,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", @@ -1471,7 +1453,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", @@ -1527,7 +1508,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", @@ -1553,7 +1533,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", @@ -1611,7 +1590,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", @@ -1638,7 +1616,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", @@ -1684,7 +1661,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", @@ -1718,7 +1694,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", @@ -1753,7 +1728,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", @@ -1806,7 +1780,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", @@ -2098,7 +2071,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]) }, @@ -2154,7 +2126,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]) }, }, @@ -2241,7 +2212,6 @@ func TestDatabaseFromAzureMySQLFlexServer(t *testing.T) { } wantLabels := map[string]string{ - types.OriginLabel: types.OriginCloud, labelRegion: region, labelEngine: provider, labelEngineVersion: "8.0.21", @@ -2317,7 +2287,6 @@ func TestDatabaseFromAzurePostgresFlexServer(t *testing.T) { } wantLabels := map[string]string{ - types.OriginLabel: types.OriginCloud, labelRegion: region, labelEngine: provider, labelEngineVersion: "14", @@ -2414,7 +2383,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() diff --git a/lib/srv/discovery/discovery_test.go b/lib/srv/discovery/discovery_test.go index fb6e50f76e2a5..5b422f31b9d26 100644 --- a/lib/srv/discovery/discovery_test.go +++ b/lib/srv/discovery/discovery_test.go @@ -1232,6 +1232,7 @@ func makeRDSInstance(t *testing.T, name, region string, discoveryGroup string) ( } database, err := services.NewDatabaseFromRDSInstance(instance) require.NoError(t, err) + database.SetOrigin(types.OriginCloud) staticLabels := database.GetStaticLabels() staticLabels[types.TeleportInternalDiscoveryGroupName] = discoveryGroup database.SetStaticLabels(staticLabels)