
Let op: de getSecret-methode werkt alleen als je ’m koppelt aan een module-parameter met de @secure-decorator.
deploy.bicep
param location string = resourceGroup().location
param tags object
param sqlServerName string
param keyVaultName string
param keyVaultResourceGroupName string
param subscriptionId string = subscription().subscriptionId
resource vaultResource ' Microsoft.KeyVault/vaults@2025-05-01' existing = {
name: keyVaultName
scope: resourceGroup(subscriptionId, keyVaultResourceGroupName)
}
module sqlModule 'modules/sql.bicep' = {
name: 'SqlDeploy'
params: {
location: location
tags: tags
sqlServerName: sqlServerName
administratorLogin: vaultResource.getSecret('sqlUser')
administratorLoginPassword: vaultResource.getSecret('sqlPassword')
}
}
modules/sql.bicep
@description('The resource location')
param location string
@description('The tags for the resources')
param tags object
@description('The name for the SQL Server')
param sqlServerName string
@secure()
@description('The SQL Administrator Login')
param administratorLogin string
@secure()
@description('The SQL Administrator password')
param administratorLoginPassword string
resource sqlServerResource 'Microsoft.Sql/servers/databases/extensions@2024-11-01-preview' = {
name: sqlServerName
location: location
tags: tags
properties: {
administratorLogin: administratorLogin
administratorLoginPassword: administratorLoginPassword
}
}
Op deze manier blijven secrets in Key Vault en komen ze niet in outputs of logs terecht.
4. Zwakke of standaard naamgevingsconventies
Een ander veelvoorkomend probleem is het gebruiken van voorspelbare namen van resources. Net zoals simpele wachtwoorden te makkelijk te raden zijn, geven namen zoals teststorage of productionvm te veel weg over je omgeving.
Voorbeeld:
resource storageaccount 'Microsoft.Storage/storageAccounts@2025-06-01' = {
name: 'prodstorage'
...
}
Beter: gebruik parameters met een willekeurige suffix of een unieke ID:
param storageName string = 'st${uniqueString(resourceGroup().id)}'
resource storageaccount 'Microsoft.Storage/storageAccounts@2025-06-01' = {
name: storageName
...
}
5. Parameters niet valideren
Te brede parameterinputs leveren snel fouten, typos of onveilige configuraties op.
Voorbeeld (te open):
param sku string
Beter: gebruik @allowed of andere validatie.
@allowed(['Standard_LRS', 'Standard_ZRS', 'Premium_LRS'])
param sku string = 'Standard_LRS'
6. Te brede role assignments
Rollen zoals Owner of Contributor toekennen terwijl dat niet nodig is, vergroot de kans op fouten of misbruik.
Voorbeeld:
resource roleAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
name: guid(resourceGroup().id, principalId, roleDefinitionId)
properties: {
principalId: principalId
roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', 'b24988ac-6180-42a0-ab88-20f7382dd24c') // Contributor
}
}
Beter: kies de kleinste rol die nodig is, zoals Storage Blob Data Reader voor alleen leesrechten.
7. Policies overslaan
Als je zonder Azure Policy of templatevalidatie deployt, mis je belangrijke controles. Daardoor glippen configuraties als open storage-accounts of publieke IP’s sneller door.
Voorbeeld: een storage account met allowBlobPublicAccess = true.
param allowBlobPublicAccess bool = true
Beter: dwing een policy af op subscription- of management group-niveau. Je kunt ook veilige defaults gebruiken:
param allowBlobPublicAccess bool = false