Hi community,
we’re currently heavily investing in writing Sentinel policies for our platform.
During this development, we discovered a specific/strange behaviour, which impedes sufficient checks in certain cases.
Context:
We have dedicated subscriptions and resource groups for different environments (dev, stage, prod). We’d like to write a Sentinel policy that verifies added VNet integrations (e.g. for the Key Vault or MSSQL Server resources) against the requirement of restrict/prevent cross-environment communication. For example: only allow DEV resources to communicate with DEV, not PROD.
Such VNet integrations can be added by referencing the related Terraform resource or by directly using the ID string.
Example for the Key Vault:
resource "azurerm_key_vault" "example" {
[...]
network_acls {
virtual_network_subnet_ids = [
azurerm_resource_group.example.id, # TF Reference
"/subscriptions/<SUB-ID>/resourceGroups/<RG-NAME>/providers/Microsoft.Network/virtualNetworks/<VNET-NAME>/subnets/<SUBNET-NAME>" # ID String
]
}
}
Problem:
What we found is that as soon as a single Terraform reference appears in the list of subnet IDs, the static strings are neither part of the tfconfig
nor the tfplan
data/mocks, as the whole block is replaced with/part of the after_unknown
block only.
tfconfig -> resources
:
"network_acls": [
{
[...]
"virtual_network_subnet_ids": {
"references": [
"azurerm_subnet.example",
],
},
},
],
tfplan -> resource_changes
:
"after_unknown": {
[...]
"network_acls": [
{
"virtual_network_subnet_ids": true,
},
],
This prevents us from any (known) way to check this requirement via Sentinel.
Is there any way to view/access also the static strings, when a reference is used in combination?
Many thanks in advance.