Linter-regel – säkra params i kapslad distribution

Kapslade distributionsresurser med yttre omfång bör inte användas för säkra parametrar eller list*-funktioner. Du kan exponera de säkra värdena i distributionshistoriken.

Linter-regelkod

Använd följande värde i Bicep-konfigurationsfilen för att anpassa regelinställningar:

secure-params-in-nested-deploy

Lösning

Ange antingen distributionens properties.expressionEvaluationOptions.scope till inner eller använd en Bicep-modul i stället.

Följande exempel misslyckas med det här testet eftersom en säker parameter refereras till i en kapslad distributionsresurs med yttre omfång.

@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'
                }
              }
            ]
          }
        }
      ]
    }
  }
}

Du kan åtgärda det genom att ange distributionens properties.expressionEvaluationOptions.scope till "inner":

@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'
                }
              }
            ]
          }
        }
      ]
    }
  }
}

Nästa steg

Mer information om linter finns i Använda Bicep-linter.