-
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.
Signed-off-by: Nikita Pivkin <[email protected]>
- Loading branch information
Showing
17 changed files
with
1,081 additions
and
319 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# METADATA | ||
# title: Ensure that no sensitive credentials are exposed in VM custom_data | ||
# description: | | ||
# When creating Azure Virtual Machines, custom_data is used to pass start up information into the EC2 instance. This custom_dat must not contain access key credentials. | ||
# scope: package | ||
# schemas: | ||
# - input: schema["cloud"] | ||
# custom: | ||
# id: AVD-AZU-0037 | ||
# avd_id: AVD-AZU-0037 | ||
# provider: azure | ||
# service: compute | ||
# severity: MEDIUM | ||
# short_code: no-secrets-in-custom-data | ||
# recommended_action: Don't use sensitive credentials in the VM custom_data | ||
# input: | ||
# selector: | ||
# - type: cloud | ||
# subtypes: | ||
# - service: compute | ||
# provider: azure | ||
# terraform: | ||
# links: | ||
# - https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/virtual_machine#custom_data | ||
# good_examples: checks/cloud/azure/compute/no_secrets_in_custom_data.tf.go | ||
# bad_examples: checks/cloud/azure/compute/no_secrets_in_custom_data.tf.go | ||
package builtin.azure.compute.azure0037 | ||
|
||
import rego.v1 | ||
|
||
deny contains res if { | ||
vms := array.concat( | ||
object.get(input.azure.compute, "linuxvirtualmachines", []), | ||
object.get(input.azure.compute, "windowsvirtualmachines", []), | ||
) | ||
|
||
some vm in vms | ||
scan_result := squealer.scan_string(vm.virtualmachine.customdata.value) | ||
scan_result.transgressionFound | ||
res := result.new( | ||
"Virtual machine includes secret(s) in custom data.", | ||
vm.virtualmachine, | ||
) | ||
} |
71 changes: 0 additions & 71 deletions
71
checks/cloud/azure/compute/no_secrets_in_custom_data_test.go
This file was deleted.
Oops, something went wrong.
20 changes: 20 additions & 0 deletions
20
checks/cloud/azure/compute/no_secrets_in_custom_data_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,20 @@ | ||
package builtin.azure.compute.azure0037_test | ||
|
||
import rego.v1 | ||
|
||
import data.builtin.azure.compute.azure0037 as check | ||
import data.lib.test | ||
|
||
test_deny_secrets_in_custom_data if { | ||
inp := {"azure": {"compute": {"linuxvirtualmachines": [{"virtualmachine": {"customdata": {"value": `export DATABASE_PASSWORD=\"SomeSortOfPassword\"`}}}]}}} | ||
|
||
res := check.deny with input as inp | ||
count(res) == 1 | ||
} | ||
|
||
test_allow_no_secrets_in_custom_data if { | ||
inp := {"azure": {"compute": {"linuxvirtualmachines": [{"virtualmachine": {"customdata": {"value": `export GREETING="Hello there"`}}}]}}} | ||
|
||
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
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/database/no_public_firewall_access.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 database firewalls do not permit public access | ||
# description: | | ||
# Azure services can be allowed access through the firewall using a start and end IP address of 0.0.0.0. No other end ip address should be combined with a start of 0.0.0.0 | ||
# scope: package | ||
# schemas: | ||
# - input: schema["cloud"] | ||
# related_resources: | ||
# - https://docs.microsoft.com/en-us/rest/api/sql/2021-02-01-preview/firewall-rules/create-or-update | ||
# custom: | ||
# id: AVD-AZU-0029 | ||
# avd_id: AVD-AZU-0029 | ||
# provider: azure | ||
# service: database | ||
# severity: HIGH | ||
# short_code: no-public-firewall-access | ||
# recommended_action: Don't use wide ip ranges for the sql firewall | ||
# input: | ||
# selector: | ||
# - type: cloud | ||
# subtypes: | ||
# - service: database | ||
# provider: azure | ||
# terraform: | ||
# links: | ||
# - https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/sql_firewall_rule#end_ip_address | ||
# good_examples: checks/cloud/azure/database/no_public_firewall_access.tf.go | ||
# bad_examples: checks/cloud/azure/database/no_public_firewall_access.tf.go | ||
package builtin.azure.database.azure0029 | ||
|
||
import rego.v1 | ||
|
||
import data.lib.azure.database | ||
|
||
deny contains res if { | ||
some server in database.all_servers | ||
some rule in server.firewallrules | ||
not allowing_azure_services(rule) | ||
rule.startip.value != rule.endip.value | ||
is_public_rule(rule) | ||
res := result.new( | ||
"Firewall rule allows public internet access to a database server.", | ||
rule, | ||
) | ||
} | ||
|
||
is_public_rule(rule) if cidr.is_public(rule.startip.value) | ||
|
||
is_public_rule(rule) if cidr.is_public(rule.endip.value) | ||
|
||
allowing_azure_services(rule) if { | ||
rule.startip.value == "0.0.0.0" | ||
rule.endip.value == "0.0.0.0" | ||
} |
Oops, something went wrong.