Aturan Linter - mengamankan param dalam penyebaran berlapis
Sumber daya penyebaran berlapis cakupan luar tidak boleh digunakan untuk parameter aman atau fungsi daftar*. Anda dapat mengekspos nilai aman dalam riwayat penyebaran.
Kode aturan Linter
Gunakan nilai berikut pada file konfigurasi Bicep untuk menyesuaikan pengaturan aturan:
secure-params-in-nested-deploy
Solusi
Atur properties.expressionEvaluationOptions.scope penyebaran ke inner
atau gunakan modul Bicep sebagai gantinya.
Contoh berikut gagal dalam pengujian ini karena parameter aman direferensikan dalam sumber daya penyebaran berlapis terluar.
@secure()
param secureValue string
resource nested 'Microsoft.Resources/deployments@2021-04-01' = {
name: 'nested'
properties: {
mode: 'Incremental'
template: {
'$schema': 'https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#'
contentVersion: '1.0.0.0'
variables: {}
resources: [
{
name: 'outerImplicit'
type: 'Microsoft.Network/networkSecurityGroups'
apiVersion: '2019-11-01'
location: '[resourceGroup().location]'
properties: {
securityRules: [
{
name: 'outerImplicit'
properties: {
description: format('{0}', secureValue)
protocol: 'Tcp'
}
}
]
}
}
]
}
}
}
Anda dapat memperbaikinya dengan mengatur properties.expressionEvaluationOptions.scope penyebaran ke 'dalam':
@secure()
param secureValue string
resource nested 'Microsoft.Resources/deployments@2021-04-01' = {
name: 'nested'
properties: {
mode: 'Incremental'
expressionEvaluationOptions: {
scope: 'Inner' // Set to inner scope
}
template: {
'$schema': 'https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#'
contentVersion: '1.0.0.0'
variables: {}
resources: [
{
name: 'outerImplicit'
type: 'Microsoft.Network/networkSecurityGroups'
apiVersion: '2019-11-01'
location: '[resourceGroup().location]'
properties: {
securityRules: [
{
name: 'outerImplicit'
properties: {
description: format('{0}', secureValue)
protocol: 'Tcp'
}
}
]
}
}
]
}
}
}
Langkah berikutnya
Untuk informasi selengkapnya tentang linter, lihat Menggunakan linter Bicep.