-
Notifications
You must be signed in to change notification settings - Fork 31
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 storage to Rego
Signed-off-by: Nikita Pivkin <[email protected]>
- Loading branch information
Showing
31 changed files
with
677 additions
and
504 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
47 changes: 47 additions & 0 deletions
47
checks/cloud/azure/storage/allow_microsoft_service_bypass.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,47 @@ | ||
# METADATA | ||
# title: Trusted Microsoft Services should have bypass access to Storage accounts | ||
# description: | | ||
# Some Microsoft services that interact with storage accounts operate from networks that can't be granted access through network rules. | ||
# To help this type of service work as intended, allow the set of trusted Microsoft services to bypass the network rules | ||
# scope: package | ||
# schemas: | ||
# - input: schema["cloud"] | ||
# related_resources: | ||
# - https://docs.microsoft.com/en-us/azure/storage/common/storage-network-security#trusted-microsoft-services | ||
# custom: | ||
# id: AVD-AZU-0010 | ||
# avd_id: AVD-AZU-0010 | ||
# provider: azure | ||
# service: storage | ||
# severity: HIGH | ||
# short_code: allow-microsoft-service-bypass | ||
# recommended_action: Allow Trusted Microsoft Services to bypass | ||
# input: | ||
# selector: | ||
# - type: cloud | ||
# subtypes: | ||
# - service: storage | ||
# provider: azure | ||
# terraform: | ||
# links: | ||
# - https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/storage_account#bypass | ||
# - https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/storage_account_network_rules#bypass | ||
# good_examples: checks/cloud/azure/storage/allow_microsoft_service_bypass.tf.go | ||
# bad_examples: checks/cloud/azure/storage/allow_microsoft_service_bypass.tf.go | ||
package builtin.azure.storage.azure0010 | ||
|
||
import rego.v1 | ||
|
||
deny contains res if { | ||
some rule in input.azure.storage.accounts[_].networkrules | ||
not has_bypass(rule) | ||
res := result.new( | ||
"Network rules do not allow bypass for Microsoft Services.", | ||
rule, | ||
) | ||
} | ||
|
||
has_bypass(rule) if { | ||
some bypass in rule.bypass | ||
bypass.value == "AzureServices" | ||
} |
77 changes: 0 additions & 77 deletions
77
checks/cloud/azure/storage/allow_microsoft_service_bypass_test.go
This file was deleted.
Oops, something went wrong.
21 changes: 21 additions & 0 deletions
21
checks/cloud/azure/storage/allow_microsoft_service_bypass_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,21 @@ | ||
package builtin.azure.storage.azure0010_test | ||
|
||
import rego.v1 | ||
|
||
import data.builtin.azure.storage.azure0010 as check | ||
import data.lib.test | ||
|
||
test_deny_rule_does_not_allow_bypass_access if { | ||
inp := {"azure": {"storage": {"accounts": [{ | ||
"name": "test", | ||
"networkrules": [{"bypass": []}], | ||
}]}}} | ||
|
||
test.assert_count(check.deny, 1) with input as inp | ||
} | ||
|
||
test_allow_rule_allow_bypass_access if { | ||
inp := {"azure": {"storage": {"accounts": [{"networkrules": [{"bypass": [{"value": "AzureServices"}]}]}]}}} | ||
|
||
test.assert_empty(check.deny) with input as inp | ||
} |
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,41 @@ | ||
# METADATA | ||
# title: The default action on Storage account network rules should be set to deny | ||
# description: | | ||
# The default_action for network rules should come into effect when no other rules are matched. | ||
# The default action should be set to Deny. | ||
# scope: package | ||
# schemas: | ||
# - input: schema["cloud"] | ||
# related_resources: | ||
# - https://docs.microsoft.com/en-us/azure/firewall/rule-processing | ||
# custom: | ||
# id: AVD-AZU-0012 | ||
# avd_id: AVD-AZU-0012 | ||
# provider: azure | ||
# service: storage | ||
# severity: CRITICAL | ||
# short_code: default-action-deny | ||
# recommended_action: Set network rules to deny | ||
# input: | ||
# selector: | ||
# - type: cloud | ||
# subtypes: | ||
# - service: storage | ||
# provider: azure | ||
# terraform: | ||
# links: | ||
# - https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/storage_account_network_rules#default_action | ||
# good_examples: checks/cloud/azure/storage/default_action_deny.tf.go | ||
# bad_examples: checks/cloud/azure/storage/default_action_deny.tf.go | ||
package builtin.azure.storage.azure0012 | ||
|
||
import rego.v1 | ||
|
||
deny contains res if { | ||
some rule in input.azure.storage.accounts[_].networkrules | ||
rule.allowbydefault.value | ||
res := result.new( | ||
"Network rules allow access by default.", | ||
rule.allowbydefault, | ||
) | ||
} |
This file was deleted.
Oops, something went wrong.
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,18 @@ | ||
package builtin.azure.storage.azure0012_test | ||
|
||
import rego.v1 | ||
|
||
import data.builtin.azure.storage.azure0012 as check | ||
import data.lib.test | ||
|
||
test_deny_rule_allow_acces_by_default if { | ||
inp := {"azure": {"storage": {"accounts": [{"networkrules": [{"allowbydefault": {"value": true}}]}]}}} | ||
|
||
test.assert_count(check.deny, 1) with input as inp | ||
} | ||
|
||
test_allow_rule_deny_acces_by_default if { | ||
inp := {"azure": {"storage": {"accounts": [{"networkrules": [{"allowbydefault": {"value": false}}]}]}}} | ||
|
||
test.assert_empty(check.deny) with input as inp | ||
} |
Oops, something went wrong.