Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Do not use parent connection for azure provider. #4284

Merged
merged 1 commit into from
Jun 21, 2024
Merged
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
14 changes: 8 additions & 6 deletions providers/azure/resources/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ func Discover(runtime *plugin.Runtime, rootConf *inventory.Config) (*inventory.I
subsWithConfigs := make([]subWithConfig, len(subs))
for i := range subs {
sub := subs[i]
subsWithConfigs[i] = subWithConfig{sub: sub, conf: getSubConfig(conn.Conf, conn.ID(), sub)}
subsWithConfigs[i] = subWithConfig{sub: sub, conf: getSubConfig(conn.Conf, sub)}
}

if stringx.ContainsAnyOf(targets, DiscoverySubscriptions, DiscoveryAll, DiscoveryAuto) {
// we've already discovered those, simply add them as assets
for _, s := range subsWithConfigs {
assets = append(assets, subToAsset(s.sub, s.conf, conn.ID()))
assets = append(assets, subToAsset(s))
}
}
matchingTargets := []string{DiscoveryAll}
Expand Down Expand Up @@ -728,8 +728,10 @@ func discoverSubscriptions(conn *connection.AzureConnection, filter connection.S
return subs, nil
}

func subToAsset(sub subscriptions.Subscription, conf *inventory.Config, parentConnId uint32) *inventory.Asset {
copyConf := conf.Clone(inventory.WithoutDiscovery(), inventory.WithParentConnectionId(parentConnId))
func subToAsset(subWithConfig subWithConfig) *inventory.Asset {
sub := subWithConfig.sub
conf := subWithConfig.conf
copyConf := conf.Clone(inventory.WithoutDiscovery())
platformId := "//platformid.api.mondoo.app/runtime/azure/subscriptions/" + *sub.SubscriptionID
tenantId := "unknown"
if sub.TenantID != nil {
Expand All @@ -752,8 +754,8 @@ func subToAsset(sub subscriptions.Subscription, conf *inventory.Config, parentCo

// creates a config with filled in subscription and tenant id, this config can be used by the subscription asset
// or any assets that are discovered within that subscription
func getSubConfig(rootConf *inventory.Config, parentId uint32, sub subscriptions.Subscription) *inventory.Config {
cfg := rootConf.Clone(inventory.WithoutDiscovery(), inventory.WithParentConnectionId(parentId))
func getSubConfig(rootConf *inventory.Config, sub subscriptions.Subscription) *inventory.Config {
cfg := rootConf.Clone(inventory.WithoutDiscovery())
if cfg.Options == nil {
cfg.Options = map[string]string{}
}
Expand Down
Loading