Bylaw

Gallery › SQL › Azure built-in policies

MySQL servers should use customer-managed keys to encrypt data at rest

Converted Policy AuditIfNotExists Disabled Mode Indexed Version 1.0.4

Use customer-managed keys to manage the encryption at rest of your MySQL servers. By default, the data is encrypted at rest with service-managed keys, but customer-managed keys are commonly required to meet regulatory compliance standards. Customer-managed keys enable the data to be encrypted with an Azure Key Vault key created and owned by you. You have full control and responsibility for the key lifecycle, including rotation and management.

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

Azure Policy JSONMySQL_EnableByok_Audit.json · 60 lines
{
  "properties": {
    "displayName": "MySQL servers should use customer-managed keys to encrypt data at rest",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "Use customer-managed keys to manage the encryption at rest of your MySQL servers. By default, the data is encrypted at rest with service-managed keys, but customer-managed keys are commonly required to meet regulatory compliance standards. Customer-managed keys enable the data to be encrypted with an Azure Key Vault key created and owned by you. You have full control and responsibility for the key lifecycle, including rotation and management.",
    "metadata": {
      "version": "1.0.4",
      "category": "SQL"
    },
    "version": "1.0.4",
    "parameters": {
      "effect": {
        "type": "string",
        "defaultValue": "AuditIfNotExists",
        "allowedValues": [
          "AuditIfNotExists",
          "Disabled"
        ],
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        }
      }
    },
    "policyRule": {
      "if": {
        "field": "type",
        "equals": "Microsoft.DBforMySQL/servers"
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "type": "Microsoft.DBforMySQL/servers/keys",
          "existenceCondition": {
            "allOf": [
              {
                "field": "Microsoft.DBforMySQL/servers/keys/serverKeyType",
                "equals": "AzureKeyVault"
              },
              {
                "field": "Microsoft.DBforMySQL/servers/keys/uri",
                "notEquals": ""
              },
              {
                "field": "Microsoft.DBforMySQL/servers/keys/uri",
                "exists": "true"
              }
            ]
          }
        }
      }
    },
    "versions": [
      "1.0.4"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/83cef61d-dbd1-4b20-a4fc-5fbc7da10833",
  "name": "83cef61d-dbd1-4b20-a4fc-5fbc7da10833"
}
Bylaw83cef61d-dbd1-4b20-a4fc-5fbc7da10833.bylaw.ps1 · 30 lines
# Converted from MySQL_EnableByok_Audit.json by ConvertTo-Bylaw.
Policy '83cef61d-dbd1-4b20-a4fc-5fbc7da10833' {

    Properties @{
        DisplayName   = 'MySQL servers should use customer-managed keys to encrypt data at rest'
        Description   = 'Use customer-managed keys to manage the encryption at rest of your MySQL servers. By default, the data is encrypted at rest with service-managed keys, but customer-managed keys are commonly required to meet regulatory compliance standards. Customer-managed keys enable the data to be encrypted with an Azure Key Vault key created and owned by you. You have full control and responsibility for the key lifecycle, including rotation and management.'
        Version       = '1.0.4'
        Category      = 'SQL'
        PolicyVersion = '1.0.4'
        Mode          = 'Indexed'
    }

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

    Resource 'Microsoft.DBforMySQL/servers'

    AuditIfNotExists 'Microsoft.DBforMySQL/servers/keys' -Effect (Param Effect) {
        Require 'serverKeyType is AzureKeyVault, uri is not and uri exists' {
            Field serverKeyType | Must -Be 'AzureKeyVault'
            Field uri | Must -Not -Be '' -IfPresent
            Field uri | Must -Exist
        }
    }
}

Source: built-in-policies/policyDefinitions/SQL/MySQL_EnableByok_Audit.json in Azure/azure-policy, under the MIT licence.