Bylaw

Gallery › SQL › Azure built-in policies

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

Converted Policy Audit Deny Disabled Mode All Version 2.0.1

Implementing Transparent Data Encryption (TDE) with your own key provides increased transparency and control over the TDE Protector, increased security with an HSM-backed external service, and promotion of separation of duties. This recommendation applies to organizations with a related compliance requirement.

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

Azure Policy JSONSqlServer_EnsureServerTDEisEncryptedWithYourOwnKey_Deny.json · 82 lines
{
  "properties": {
    "displayName": "SQL servers should use customer-managed keys to encrypt data at rest",
    "description": "Implementing Transparent Data Encryption (TDE) with your own key provides increased transparency and control over the TDE Protector, increased security with an HSM-backed external service, and promotion of separation of duties. This recommendation applies to organizations with a related compliance requirement.",
    "policyType": "BuiltIn",
    "mode": "All",
    "metadata": {
      "version": "2.0.1",
      "category": "SQL"
    },
    "version": "2.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": {
        "anyOf": [
          {
            "allOf": [
              {
                "field": "type",
                "equals": "Microsoft.Sql/servers"
              },
              {
                "value": "[resourcegroup().managedBy]",
                "notContains": "/providers/Microsoft.Synapse/"
              },
              {
                "anyOf": [
                  {
                    "field": "Microsoft.Sql/servers/keyid",
                    "exists": false
                  },
                  {
                    "field": "Microsoft.Sql/servers/keyid",
                    "equals": ""
                  }
                ]
              }
            ]
          },
          {
            "allOf": [
              {
                "field": "type",
                "equals": "Microsoft.Sql/servers/encryptionProtector"
              },
              {
                "value": "[resourcegroup().managedBy]",
                "notContains": "/providers/Microsoft.Synapse/"
              },
              {
                "field": "Microsoft.Sql/servers/encryptionProtector/serverKeyType",
                "notequals": "AzureKeyVault"
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "2.0.1"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/0a370ff3-6cab-4e85-8995-295fd854c5b8",
  "name": "0a370ff3-6cab-4e85-8995-295fd854c5b8"
}
Bylaw0a370ff3-6cab-4e85-8995-295fd854c5b8.bylaw.ps1 · 40 lines
# Converted from SqlServer_EnsureServerTDEisEncryptedWithYourOwnKey_Deny.json by ConvertTo-Bylaw.
Policy '0a370ff3-6cab-4e85-8995-295fd854c5b8' {

    Properties @{
        DisplayName   = 'SQL servers should use customer-managed keys to encrypt data at rest'
        Description   = 'Implementing Transparent Data Encryption (TDE) with your own key provides increased transparency and control over the TDE Protector, increased security with an HSM-backed external service, and promotion of separation of duties. This recommendation applies to organizations with a related compliance requirement.'
        Version       = '2.0.1'
        Category      = 'SQL'
        PolicyVersion = '2.0.1'
        Mode          = 'All'
    }

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

    Resource * {

        Require 'type and keyid are as required' {
            AnyOf {
                Field type | Must -Not -Be 'Microsoft.Sql/servers' -IfPresent
                Arm '[resourcegroup().managedBy]' | Must -ContainText '/providers/Microsoft.Synapse/'
                Field 'Microsoft.Sql/servers/keyid' | Must -Not -Be ''
            }
        }

        Require 'type and serverKeyType are as required' {
            AnyOf {
                Field type | Must -Not -Be 'Microsoft.Sql/servers/encryptionProtector' -IfPresent
                Arm '[resourcegroup().managedBy]' | Must -ContainText '/providers/Microsoft.Synapse/'
                Field 'Microsoft.Sql/servers/encryptionProtector/serverKeyType' | Must -Be 'AzureKeyVault'
            }
        }
    }

    Effect (Param Effect)
}

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