リンター ルール - commandToExecute のシークレットに protectedSettings を使用する

このルールでは、カスタムのスクリプト リソースの設定プロパティでシークレットの露出の可能性が検索されます。

リンター ルールのコード

ルール設定をカスタマイズするには、Bicep 構成ファイルで次の値を使用します。

protect-commandtoexecute-secrets

解決策

カスタムのスクリプト リソースの場合、パスワードなどのシークレット データが含まれる場合は、settings プロパティ オブジェクトではなく protectedSettings プロパティ オブジェクトの下に値 commandToExecute を配置する必要があります。 たとえば、シークレット データは、セキュリティで保護されたパラメーター、listKeys などの list* 関数、またはカスタム スクリプトの引数で見つかる可能性があります。

settings オブジェクトではクリア テキストが使用されているため、シークレット データを使用しないでください。 詳細については、「Microsoft.Compute virtualMachines/extensions」、「Windows でのカスタムのスクリプト拡張機能」、および「Linux 仮想マシンで Azure カスタム スクリプト拡張機能 v2 を使用する」を参照してください。

次の例は、commandToExecutesettings の下に指定されていてセキュリティで保護されたパラメーターを使用しているため、不合格になります。

param vmName string
param location string
param fileUris string
param storageAccountName string

resource storageAccount 'Microsoft.Storage/storageAccounts@2022-09-01' existing = {
  name: storageAccountName
}

resource customScriptExtension 'Microsoft.HybridCompute/machines/extensions@2023-03-15-preview' = {
  name: '${vmName}/CustomScriptExtension'
  location: location
  properties: {
    publisher: 'Microsoft.Compute'
    type: 'CustomScriptExtension'
    autoUpgradeMinorVersion: true
    settings: {
      fileUris: split(fileUris, ' ')
      commandToExecute: 'mycommand ${storageAccount.listKeys().keys[0].value}'
    }
  }
}

これは、commandToExecute プロパティを protectedSettings オブジェクトに移動することで解決できます。

param vmName string
param location string
param fileUris string
param storageAccountName string

resource storageAccount 'Microsoft.Storage/storageAccounts@2022-09-01' existing = {
  name: storageAccountName
}

resource customScriptExtension 'Microsoft.HybridCompute/machines/extensions@2023-03-15-preview' = {
  name: '${vmName}/CustomScriptExtension'
  location: location
  properties: {
    publisher: 'Microsoft.Compute'
    type: 'CustomScriptExtension'
    autoUpgradeMinorVersion: true
    settings: {
      fileUris: split(fileUris, ' ')
    }
    protectedSettings: {
      commandToExecute: 'mycommand ${storageAccount.listKeys().keys[0].value}'
    }
  }
}

次のステップ

リンターの詳細については、「Bicep リンターの使用方法」を参照してください。