Skip to content

Commit

Permalink
✨ Add direction to network security rules. Ensure destination port ra…
Browse files Browse the repository at this point in the history
…nges are always populated.

Signed-off-by: Preslav <preslav@mondoo.com>
  • Loading branch information
preslavgerchev committed Jan 22, 2024
1 parent 1da52db commit ff05bed
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
2 changes: 2 additions & 0 deletions providers/azure/resources/azure.lr
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,8 @@ private azure.subscription.networkService.securityrule @defaults("id name") {
properties dict
// Security rule destination port range
destinationPortRange []dict
// Security rule direction (outbound or inbound)
direction string
}

// Azure Network Watcher
Expand Down
12 changes: 12 additions & 0 deletions providers/azure/resources/azure.lr.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 11 additions & 6 deletions providers/azure/resources/azure.lr.manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ resources:
- azure
azure.subscription:
docs:
desc: |
Use the `azure.subscription` resource to assess the configuration of Azure subscriptions.
desc: "Use the `azure.subscription` resource to assess the configuration of
Azure subscriptions. \n"
fields:
advisor: {}
aks: {}
Expand Down Expand Up @@ -64,8 +64,8 @@ resources:
- azure
azure.subscription.advisorService:
docs:
desc: |
Use the `azure.subscription.advisorService` resource to retrieve scoring and recommendations from Microsoft Azure Advisor.
desc: "Use the `azure.subscription.advisorService` resource to retrieve scoring
and recommendations from Microsoft Azure Advisor. \n"
fields:
averageScore: {}
recommendations: {}
Expand All @@ -77,8 +77,12 @@ resources:
name:
- azure
snippets:
- query: "azure.subscription.advisorService {\n averageScore > 90\n}\n"
title: Check if the average score that the Azure Advisor service gives the subscription is greater than 90
- query: |
azure.subscription.advisorService {
averageScore > 90
}
title: Check if the average score that the Azure Advisor service gives the subscription
is greater than 90
azure.subscription.advisorService.recommendation:
fields:
category: {}
Expand Down Expand Up @@ -1429,6 +1433,7 @@ resources:
azure.subscription.networkService.securityrule:
fields:
destinationPortRange: {}
direction: {}
etag: {}
id: {}
name: {}
Expand Down
13 changes: 13 additions & 0 deletions providers/azure/resources/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -2050,11 +2050,24 @@ func azureSecurityRuleToMql(runtime *plugin.Runtime, secRule network.SecurityRul
}
}

if secRule.Properties != nil && secRule.Properties.DestinationPortRanges != nil {
for _, r := range secRule.Properties.DestinationPortRanges {
dPortRange := parseAzureSecurityRulePortRange(*r)
for i := range dPortRange {
destinationPortRange = append(destinationPortRange, map[string]interface{}{
"fromPort": dPortRange[i].FromPort,
"toPort": dPortRange[i].ToPort,
})
}
}
}

res, err := CreateResource(runtime, "azure.subscription.networkService.securityrule",
map[string]*llx.RawData{
"id": llx.StringData(convert.ToString(secRule.ID)),
"name": llx.StringData(convert.ToString(secRule.Name)),
"etag": llx.StringData(convert.ToString(secRule.Etag)),
"direction": llx.StringDataPtr((*string)(secRule.Properties.Direction)),
"properties": llx.DictData(properties),
"destinationPortRange": llx.ArrayData(destinationPortRange, types.String),
})
Expand Down

0 comments on commit ff05bed

Please sign in to comment.