Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/inventory/azurefetcher/fetcher_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (f *accountFetcher) fetch(ctx context.Context, resourceName string, functio
inventory.WithCloud(inventory.Cloud{
Provider: inventory.AzureCloudProvider,
AccountID: item.TenantId,
ServiceName: "Azure",
ServiceName: "Azure Entra",
}),
)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/inventory/azurefetcher/fetcher_account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestAccountFetcher_Fetch_Tenants(t *testing.T) {
inventory.WithCloud(inventory.Cloud{
Provider: inventory.AzureCloudProvider,
AccountID: "<tenant UUID>",
ServiceName: "Azure",
ServiceName: "Azure Entra",
}),
),
}
Expand Down Expand Up @@ -79,7 +79,7 @@ func TestAccountFetcher_Fetch_Subscriptions(t *testing.T) {
inventory.WithCloud(inventory.Cloud{
Provider: inventory.AzureCloudProvider,
AccountID: "<sub UUID>",
ServiceName: "Azure",
ServiceName: "Azure Entra",
}),
),
}
Expand Down
96 changes: 95 additions & 1 deletion internal/inventory/azurefetcher/fetcher_activedirectory.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,102 @@ func (f *activedirectoryFetcher) fetchServicePrincipals(ctx context.Context, ass
inventory.WithCloud(inventory.Cloud{
Provider: inventory.AzureCloudProvider,
AccountID: tenantId,
ServiceName: "Azure",
ServiceName: "Azure Entra",
}),
<<<<<<< HEAD
=======
inventory.WithTags(item.GetTags()),
)
}
}

func (f *activedirectoryFetcher) fetchDirectoryRoles(ctx context.Context, assetChan chan<- inventory.AssetEvent) {
f.logger.Info("Fetching Directory Roles")
defer f.logger.Info("Fetching Directory Roles - Finished")

items, err := f.provider.ListDirectoryRoles(ctx)
if err != nil {
f.logger.Errorf("Could not fetch Directory Roles: %v", err)
}

for _, item := range items {
assetChan <- inventory.NewAssetEvent(
inventory.AssetClassificationAzureRoleDefinition,
pointers.Deref(item.GetId()),
pickName(pointers.Deref(item.GetDisplayName()), pointers.Deref(item.GetId())),
inventory.WithRawAsset(
item.GetBackingStore().Enumerate(),
),
inventory.WithCloud(inventory.Cloud{
Provider: inventory.AzureCloudProvider,
AccountID: f.tenantID,
ServiceName: "Azure Entra",
}),
inventory.WithUser(inventory.User{
ID: pointers.Deref(item.GetId()),
Name: pointers.Deref(item.GetDisplayName()),
}),
)
}
}

func (f *activedirectoryFetcher) fetchGroups(ctx context.Context, assetChan chan<- inventory.AssetEvent) {
f.logger.Info("Fetching Groups")
defer f.logger.Info("Fetching Groups - Finished")

items, err := f.provider.ListGroups(ctx)
if err != nil {
f.logger.Errorf("Could not fetch Groups: %v", err)
}

for _, item := range items {
assetChan <- inventory.NewAssetEvent(
inventory.AssetClassificationAzureEntraGroup,
pointers.Deref(item.GetId()),
pickName(pointers.Deref(item.GetDisplayName()), pointers.Deref(item.GetId())),
inventory.WithRawAsset(
item.GetBackingStore().Enumerate(),
),
inventory.WithCloud(inventory.Cloud{
Provider: inventory.AzureCloudProvider,
AccountID: f.tenantID,
ServiceName: "Azure Entra",
}),
inventory.WithGroup(inventory.Group{
ID: pointers.Deref(item.GetId()),
Name: pointers.Deref(item.GetDisplayName()),
}),
)
}
}

func (f *activedirectoryFetcher) fetchUsers(ctx context.Context, assetChan chan<- inventory.AssetEvent) {
f.logger.Info("Fetching Users")
defer f.logger.Info("Fetching Users - Finished")

items, err := f.provider.ListUsers(ctx)
if err != nil {
f.logger.Errorf("Could not fetch Users: %v", err)
}

for _, item := range items {
assetChan <- inventory.NewAssetEvent(
inventory.AssetClassificationAzureEntraUser,
pointers.Deref(item.GetId()),
pickName(pointers.Deref(item.GetDisplayName()), pointers.Deref(item.GetId())),
inventory.WithRawAsset(
item.GetBackingStore().Enumerate(),
),
inventory.WithCloud(inventory.Cloud{
Provider: inventory.AzureCloudProvider,
AccountID: f.tenantID,
ServiceName: "Azure Entra",
}),
inventory.WithUser(inventory.User{
ID: pointers.Deref(item.GetId()),
Name: pointers.Deref(item.GetDisplayName()),
}),
>>>>>>> 7e3234f1 ([Asset Inventory][Azure] Fix Azure service names (cloud.service.name) (#3466))
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,57 @@ func TestActiveDirectoryFetcher_Fetch(t *testing.T) {
inventory.WithCloud(inventory.Cloud{
Provider: inventory.AzureCloudProvider,
AccountID: appOwnerOrganizationId.String(),
ServiceName: "Azure",
ServiceName: "Azure Entra",
}),
),
<<<<<<< HEAD
=======
inventory.NewAssetEvent(
inventory.AssetClassificationAzureRoleDefinition,
"id",
"dn",
inventory.WithRawAsset(values),
inventory.WithCloud(inventory.Cloud{
Provider: inventory.AzureCloudProvider,
AccountID: "id",
ServiceName: "Azure Entra",
}),
inventory.WithUser(inventory.User{
ID: "id",
Name: "dn",
}),
),
inventory.NewAssetEvent(
inventory.AssetClassificationAzureEntraGroup,
"id",
"dn",
inventory.WithRawAsset(values),
inventory.WithCloud(inventory.Cloud{
Provider: inventory.AzureCloudProvider,
AccountID: "id",
ServiceName: "Azure Entra",
}),
inventory.WithGroup(inventory.Group{
ID: "id",
Name: "dn",
}),
),
inventory.NewAssetEvent(
inventory.AssetClassificationAzureEntraUser,
"id",
"dn",
inventory.WithRawAsset(values),
inventory.WithCloud(inventory.Cloud{
Provider: inventory.AzureCloudProvider,
AccountID: "id",
ServiceName: "Azure Entra",
}),
inventory.WithUser(inventory.User{
ID: "id",
Name: "dn",
}),
),
>>>>>>> 7e3234f1 ([Asset Inventory][Azure] Fix Azure service names (cloud.service.name) (#3466))
}

// setup
Expand Down
34 changes: 20 additions & 14 deletions internal/inventory/azurefetcher/fetcher_resource_graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,29 +46,30 @@ func newResourceGraphFetcher(logger *clog.Logger, provider resourceGraphProvider
func (f *resourceGraphFetcher) Fetch(ctx context.Context, assetChan chan<- inventory.AssetEvent) {
resourcesToFetch := []struct {
name string
serviceName string
azureGroup string
azureType string
classification inventory.AssetClassification
}{
{"App Services", azurelib.AssetGroupResources, azurelib.WebsitesAssetType, inventory.AssetClassificationAzureAppService},
{"Container Registries", azurelib.AssetGroupResources, azurelib.ContainerRegistryAssetType, inventory.AssetClassificationAzureContainerRegistry},
{"Cosmos DB Accounts", azurelib.AssetGroupResources, azurelib.DocumentDBDatabaseAccountAssetType, inventory.AssetClassificationAzureCosmosDBAccount},
{"Cosmos DB SQL Databases", azurelib.AssetGroupResources, azurelib.CosmosDBForSQLDatabaseAssetType, inventory.AssetClassificationAzureCosmosDBSQLDatabase},
{"Disks", azurelib.AssetGroupResources, azurelib.DiskAssetType, inventory.AssetClassificationAzureDisk},
{"Elastic Pools", azurelib.AssetGroupResources, azurelib.ElasticPoolAssetType, inventory.AssetClassificationAzureElasticPool},
{"MySQL Flexible Servers", azurelib.AssetGroupResources, azurelib.FlexibleMySQLDBAssetType, inventory.AssetClassificationAzureSQLServer},
{"Resource Groups", azurelib.AssetGroupResourceContainers, azurelib.ResouceGroupAssetType, inventory.AssetClassificationAzureResourceGroup},
{"SQL Databases", azurelib.AssetGroupResources, azurelib.MySQLDatabaseAssetType, inventory.AssetClassificationAzureSQLDatabase},
{"Snapshots", azurelib.AssetGroupResources, azurelib.SnapshotAssetType, inventory.AssetClassificationAzureSnapshot},
{"Storage Accounts", azurelib.AssetGroupResources, azurelib.StorageAccountAssetType, inventory.AssetClassificationAzureStorageAccount},
{"Virtual Machines", azurelib.AssetGroupResources, azurelib.VirtualMachineAssetType, inventory.AssetClassificationAzureVirtualMachine},
{"App Services", "Azure App Services", azurelib.AssetGroupResources, azurelib.WebsitesAssetType, inventory.AssetClassificationAzureAppService},
{"Container Registries", "Azure Container Registries", azurelib.AssetGroupResources, azurelib.ContainerRegistryAssetType, inventory.AssetClassificationAzureContainerRegistry},
{"Cosmos DB Accounts", "Azure Cosmos DB", azurelib.AssetGroupResources, azurelib.DocumentDBDatabaseAccountAssetType, inventory.AssetClassificationAzureCosmosDBAccount},
{"Cosmos DB SQL Databases", "Azure Cosmos DB", azurelib.AssetGroupResources, azurelib.CosmosDBForSQLDatabaseAssetType, inventory.AssetClassificationAzureCosmosDBSQLDatabase},
{"Disks", "Azure Storage", azurelib.AssetGroupResources, azurelib.DiskAssetType, inventory.AssetClassificationAzureDisk},
{"Elastic Pools", "Azure SQL Elastic Pools", azurelib.AssetGroupResources, azurelib.ElasticPoolAssetType, inventory.AssetClassificationAzureElasticPool},
{"MySQL Flexible Servers", "Azure SQL Servers", azurelib.AssetGroupResources, azurelib.FlexibleMySQLDBServerAssetType, inventory.AssetClassificationAzureSQLServer},
{"Resource Groups", "Azure Management", azurelib.AssetGroupResourceContainers, azurelib.ResouceGroupAssetType, inventory.AssetClassificationAzureResourceGroup},
{"SQL Databases", "Azure SQL Databases", azurelib.AssetGroupResources, azurelib.MySQLDatabaseAssetType, inventory.AssetClassificationAzureSQLDatabase},
{"Snapshots", "Azure Storage", azurelib.AssetGroupResources, azurelib.SnapshotAssetType, inventory.AssetClassificationAzureSnapshot},
{"Storage Accounts", "Azure Storage", azurelib.AssetGroupResources, azurelib.StorageAccountAssetType, inventory.AssetClassificationAzureStorageAccount},
{"Virtual Machines", "Azure Virtual Machines", azurelib.AssetGroupResources, azurelib.VirtualMachineAssetType, inventory.AssetClassificationAzureVirtualMachine},
}
for _, r := range resourcesToFetch {
f.fetch(ctx, r.name, r.azureGroup, r.azureType, r.classification, assetChan)
f.fetch(ctx, r.name, r.serviceName, r.azureGroup, r.azureType, r.classification, assetChan)
}
}

func (f *resourceGraphFetcher) fetch(ctx context.Context, resourceName, resourceGroup, resourceType string, classification inventory.AssetClassification, assetChan chan<- inventory.AssetEvent) {
func (f *resourceGraphFetcher) fetch(ctx context.Context, resourceName, serviceName, resourceGroup, resourceType string, classification inventory.AssetClassification, assetChan chan<- inventory.AssetEvent) {
f.logger.Infof("Fetching %s", resourceName)
defer f.logger.Infof("Fetching %s - Finished", resourceName)

Expand All @@ -91,7 +92,12 @@ func (f *resourceGraphFetcher) fetch(ctx context.Context, resourceName, resource
inventory.WithCloud(inventory.Cloud{
Provider: inventory.AzureCloudProvider,
AccountID: item.TenantId,
<<<<<<< HEAD
ServiceName: "Azure",
=======
ProjectID: item.SubscriptionId,
ServiceName: serviceName,
>>>>>>> 7e3234f1 ([Asset Inventory][Azure] Fix Azure service names (cloud.service.name) (#3466))
}),
)
}
Expand Down
25 changes: 23 additions & 2 deletions internal/inventory/azurefetcher/fetcher_resource_graph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestResourceGraphFetcher_Fetch(t *testing.T) {
inventory.WithCloud(inventory.Cloud{
Provider: inventory.AzureCloudProvider,
AccountID: "<tenant id>",
ServiceName: "Azure",
ServiceName: "Azure App Services",
}),
),
inventory.NewAssetEvent(
Expand All @@ -62,9 +62,30 @@ func TestResourceGraphFetcher_Fetch(t *testing.T) {
inventory.WithCloud(inventory.Cloud{
Provider: inventory.AzureCloudProvider,
AccountID: "<tenant id>",
ServiceName: "Azure",
ServiceName: "Azure Storage",
}),
),
<<<<<<< HEAD
=======
inventory.NewAssetEvent(
inventory.AssetClassificationAzureVirtualMachine,
vm.Id,
vm.DisplayName,
inventory.WithRawAsset(vm),
inventory.WithCloud(inventory.Cloud{
Provider: inventory.AzureCloudProvider,
AccountID: "<tenant id>",
ServiceName: "Azure Virtual Machines",
MachineType: "xlarge",
InstanceID: "/vm",
}),
inventory.WithHost(inventory.Host{
ID: vm.Id,
Name: "localhost",
Type: "xlarge",
}),
),
>>>>>>> 7e3234f1 ([Asset Inventory][Azure] Fix Azure service names (cloud.service.name) (#3466))
}

// setup
Expand Down
6 changes: 6 additions & 0 deletions internal/inventory/azurefetcher/fetcher_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,14 @@ func (f *storageFetcher) fetch(ctx context.Context, storageAccounts []azurelib.A
inventory.WithRawAsset(item),
inventory.WithCloud(inventory.Cloud{
Provider: inventory.AzureCloudProvider,
<<<<<<< HEAD
AccountID: item.TenantId,
ServiceName: "Azure",
=======
AccountID: pickName(item.TenantId, f.tenantID),
ServiceName: "Azure Storage",
ProjectID: item.SubscriptionId,
>>>>>>> 7e3234f1 ([Asset Inventory][Azure] Fix Azure service names (cloud.service.name) (#3466))
}),
)
}
Expand Down
Loading
Loading