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

⭐️ Azure: Microsoft Microsoft Defender for Cloud - recommendations #4561

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
14 changes: 14 additions & 0 deletions providers/azure/resources/azure.lr
Original file line number Diff line number Diff line change
Expand Up @@ -1719,6 +1719,20 @@ private azure.subscription.cloudDefenderService @defaults("defenderForServers.en
defenderForContainers() dict
// List of configured security contacts
securityContacts() []azure.subscription.cloudDefenderService.securityContact
// List of recommendations
defenderRecommendations() []azure.subscription.cloudDefenderService.recommendation
}

// Microsoft Defender for Cloud recommendation
private azure.subscription.cloudDefenderService.recommendation @defaults("title affectedResource status properties") {
// Recommendation title
title string
// Affected resource
affectedResource string
// Recommendation status
status string
// Properties of the recommendation
properties dict
}

// Microsoft Defender for Cloud security contact
Expand Down
13 changes: 13 additions & 0 deletions providers/azure/resources/azure.lr.manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,8 @@ resources:
min_mondoo_version: 9.0.0
defenderForStorageAccounts:
min_mondoo_version: 9.0.0
defenderRecommendations:
min_mondoo_version: 9.0.0
monitoringAgentAutoProvision: {}
securityContacts: {}
subscriptionId: {}
Expand All @@ -397,6 +399,17 @@ resources:
refs:
- title: Microsoft Defender for Cloud Apps overview
url: https://learn.microsoft.com/en-us/defender-cloud-apps/what-is-defender-for-cloud-apps
azure.subscription.cloudDefenderService.recommendation:
fields:
affectedResource: {}
properties: {}
status: {}
title: {}
is_private: true
min_mondoo_version: 9.0.0
platform:
name:
- azure
azure.subscription.cloudDefenderService.securityContact:
fields:
alertNotifications: {}
Expand Down
53 changes: 53 additions & 0 deletions providers/azure/resources/cloud_defender.go
Original file line number Diff line number Diff line change
Expand Up @@ -657,3 +657,56 @@ type ServerVulnerabilityAssessmentsSettings struct {
type ServerVulnerabilityAssessmentsSettingsList struct {
Settings []ServerVulnerabilityAssessmentsSettings `json:"value"`
}

func (r *mqlAzureSubscriptionCloudDefenderServiceRecommendation) id() (string, error) {
return r.Title.Data, nil
}

func (a *mqlAzureSubscriptionCloudDefenderService) defenderRecommendations() ([]interface{}, error) {
conn := a.MqlRuntime.Connection.(*connection.AzureConnection)
ctx := context.Background()
token := conn.Token()
subId := a.SubscriptionId.Data

clientFactory, err := armsecurity.NewClientFactory(subId, token, nil)
if err != nil {
return nil, err
}

assessmentsClient := clientFactory.NewAssessmentsClient()
pager := assessmentsClient.NewListPager(fmt.Sprintf("subscriptions/%s", subId), &security.AssessmentsClientListOptions{})
res := []interface{}{}

for pager.More() {
page, err := pager.NextPage(ctx)
if err != nil {
return nil, err
}

for _, assessment := range page.Value {
if assessment.Properties == nil {
continue
}

properties, err := convert.JsonToDict(assessment.Properties)
if err != nil {
return nil, err
}

recommendationData := map[string]*llx.RawData{
"title": llx.StringData(*assessment.Properties.DisplayName),
"affectedResource": llx.StringData(*assessment.ID),
"properties": llx.DictData(properties),
"status": llx.StringData(string(*assessment.Properties.Status.Code)),
}

mqlRecommendation, err := CreateResource(a.MqlRuntime, "azure.subscription.cloudDefenderService.recommendation", recommendationData)
if err != nil {
return nil, err
}
res = append(res, mqlRecommendation)
}
}

return res, nil
}
Loading