-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(checks): migrate Azure monitor, network, synapse, securityce…
…nter to Rego Signed-off-by: Nikita Pivkin <[email protected]>
- Loading branch information
Showing
41 changed files
with
813 additions
and
669 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
checks/cloud/azure/monitor/activity_log_retention_set.rego
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# METADATA | ||
# title: Ensure the activity retention log is set to at least a year | ||
# description: | | ||
# The average time to detect a breach is up to 210 days, to ensure that all the information required for an effective investigation is available, the retention period should allow for delayed starts to investigating. | ||
# scope: package | ||
# schemas: | ||
# - input: schema["cloud"] | ||
# related_resources: | ||
# - https://docs.microsoft.com/en-us/azure/azure-monitor/essentials/platform-logs-overview | ||
# custom: | ||
# id: AVD-AZU-0031 | ||
# avd_id: AVD-AZU-0031 | ||
# provider: azure | ||
# service: monitor | ||
# severity: MEDIUM | ||
# short_code: activity-log-retention-set | ||
# recommended_action: Set a retention period that will allow for delayed investigation | ||
# input: | ||
# selector: | ||
# - type: cloud | ||
# subtypes: | ||
# - service: monitor | ||
# provider: azure | ||
# terraform: | ||
# links: | ||
# - https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/monitor_log_profile#retention_policy | ||
# good_examples: checks/cloud/azure/monitor/activity_log_retention_set.tf.go | ||
# bad_examples: checks/cloud/azure/monitor/activity_log_retention_set.tf.go | ||
package builtin.azure.monitor.azure0031 | ||
|
||
import rego.v1 | ||
|
||
deny contains res if { | ||
some profile in input.azure.monitor.logprofiles | ||
isManaged(profile) | ||
not profile.retentionpolicy.enabled.value | ||
res := result.new( | ||
"Profile does not enable the log retention policy.", | ||
object.get(profile, ["retentionpolicy", "enabled"], profile), | ||
) | ||
} | ||
|
||
deny contains res if { | ||
some profile in input.azure.monitor.logprofiles | ||
isManaged(profile) | ||
profile.retentionpolicy.enabled.value | ||
not is_recommended_retention_policy(profile) | ||
res := result.new( | ||
"Profile has a log retention policy of less than 1 year.", | ||
object.get(profile, ["retentionpolicy", "days"], profile), | ||
) | ||
} | ||
|
||
is_recommended_retention_policy(profile) := profile.retentionpolicy.days.value >= 365 |
89 changes: 0 additions & 89 deletions
89
checks/cloud/azure/monitor/activity_log_retention_set_test.go
This file was deleted.
Oops, something went wrong.
33 changes: 33 additions & 0 deletions
33
checks/cloud/azure/monitor/activity_log_retention_set_test.rego
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package builtin.azure.monitor.azure0031_test | ||
|
||
import rego.v1 | ||
|
||
import data.builtin.azure.monitor.azure0031 as check | ||
import data.lib.test | ||
|
||
test_deny_retention_policy_disabled if { | ||
inp := {"azure": {"monitor": {"logprofiles": [{"retentionpolicy": {"enabled": {"value": false}}}]}}} | ||
|
||
res := check.deny with input as inp | ||
count(res) == 1 | ||
} | ||
|
||
test_deny_retention_policy_enabled_but_days_lt_365 if { | ||
inp := {"azure": {"monitor": {"logprofiles": [{"retentionpolicy": { | ||
"enabled": {"value": true}, | ||
"days": {"value": 30}, | ||
}}]}}} | ||
|
||
res := check.deny with input as inp | ||
count(res) == 1 | ||
} | ||
|
||
test_allow_retention_policy_enabled_and_days_gt_365 if { | ||
inp := {"azure": {"monitor": {"logprofiles": [{"retentionpolicy": { | ||
"enabled": {"value": true}, | ||
"days": {"value": 365}, | ||
}}]}}} | ||
|
||
res := check.deny with input as inp | ||
count(res) == 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# METADATA | ||
# title: Ensure log profile captures all activities | ||
# description: | | ||
# Log profiles should capture all categories to ensure that all events are logged | ||
# scope: package | ||
# schemas: | ||
# - input: schema["cloud"] | ||
# related_resources: | ||
# - https://docs.microsoft.com/en-us/azure/azure-monitor/essentials/activity-log | ||
# - https://docs.microsoft.com/en-us/cli/azure/monitor/log-profiles?view=azure-cli-latest#az_monitor_log_profiles_create-required-parameters | ||
# custom: | ||
# id: AVD-AZU-0033 | ||
# avd_id: AVD-AZU-0033 | ||
# provider: azure | ||
# service: monitor | ||
# severity: MEDIUM | ||
# short_code: capture-all-activities | ||
# recommended_action: Configure log profile to capture all activities | ||
# input: | ||
# selector: | ||
# - type: cloud | ||
# subtypes: | ||
# - service: monitor | ||
# provider: azure | ||
# terraform: | ||
# links: | ||
# - https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/monitor_log_profile#categories | ||
# good_examples: checks/cloud/azure/monitor/capture_all_activities.tf.go | ||
# bad_examples: checks/cloud/azure/monitor/capture_all_activities.tf.go | ||
package builtin.azure.monitor.azure0033 | ||
|
||
import rego.v1 | ||
|
||
required_categories := {"Action", "Write", "Delete"} | ||
|
||
deny contains res if { | ||
some profile in input.azure.monitor.logprofiles | ||
isManaged(profile) | ||
missing := missing_required_categories(profile) | ||
count(missing) > 0 | ||
res := result.new( | ||
sprintf("Log profile does not require categories: %v", [missing]), | ||
profile, | ||
) | ||
} | ||
|
||
missing_required_categories(profile) := missing if { | ||
categories := { | ||
val | | ||
some category in profile.categories | ||
val := category.value | ||
} | ||
|
||
missing := required_categories - categories | ||
} else := {} |
Oops, something went wrong.