Bylaw

Gallery › Key Vault › Azure built-in policies

Azure Key Vault should use RBAC permission model

Converted Policy Audit Deny Disabled Mode Indexed Version 1.0.1

Enable RBAC permission model across Key Vaults. Learn more at: https://learn.microsoft.com/en-us/azure/key-vault/general/rbac-migration

ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.

Azure Policy JSONShould_Use_RBAC.json · 65 lines
{
  "properties": {
    "displayName": "Azure Key Vault should use RBAC permission model",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "Enable RBAC permission model across Key Vaults. Learn more at: https://learn.microsoft.com/en-us/azure/key-vault/general/rbac-migration",
    "metadata": {
      "version": "1.0.1",
      "category": "Key Vault"
    },
    "version": "1.0.1",
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        },
        "allowedValues": [
          "Audit",
          "Deny",
          "Disabled"
        ],
        "defaultValue": "Audit"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.KeyVault/vaults"
          },
          {
            "not": {
              "field": "Microsoft.KeyVault/vaults/createMode",
              "equals": "recover"
            }
          },
          {
            "anyOf": [
              {
                "field": "Microsoft.KeyVault/vaults/enableRbacAuthorization",
                "exists": "false"
              },
              {
                "field": "Microsoft.KeyVault/vaults/enableRbacAuthorization",
                "equals": "false"
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.0.1",
      "1.0.0-PREVIEW"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/12d4fa5e-1f9f-4c21-97a9-b99b3c6611b5",
  "name": "12d4fa5e-1f9f-4c21-97a9-b99b3c6611b5"
}
Bylaw12d4fa5e-1f9f-4c21-97a9-b99b3c6611b5.bylaw.ps1 · 36 lines
# Converted from Should_Use_RBAC.json by ConvertTo-Bylaw.
Policy '12d4fa5e-1f9f-4c21-97a9-b99b3c6611b5' {

    Properties @{
        DisplayName   = 'Azure Key Vault should use RBAC permission model'
        Description   = 'Enable RBAC permission model across Key Vaults. Learn more at: https://learn.microsoft.com/en-us/azure/key-vault/general/rbac-migration'
        Version       = '1.0.1'
        Category      = 'Key Vault'
        PolicyVersion = '1.0.1'
        Mode          = 'Indexed'
    }

    Parameter Effect @{
        AllowedValues = @('Audit', 'Deny', 'Disabled')
        Default       = 'Audit'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable the execution of the policy'
    }

    Resource 'Microsoft.KeyVault/vaults' {

        When {
            Field createMode | Must -Not -Be 'recover'
        }

        Require 'enableRbacAuthorization exists' {
            Field enableRbacAuthorization | Must -Exist
        }

        Require 'enableRbacAuthorization is not false' {
            Field enableRbacAuthorization | Must -Not -Be 'false' -IfPresent
        }
    }

    Effect (Param Effect)
}

Source: built-in-policies/policyDefinitions/Key Vault/Should_Use_RBAC.json in Azure/azure-policy, under the MIT licence.