Bylaw

Gallery › PostgreSQL › Azure built-in policies

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

Converted Policy Audit Deny Disabled Mode Indexed Version 1.1.0

Use customer-managed keys to manage the encryption at rest of your PostgreSQL flexible 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 JSONFlexibleServers_EnableCMK_AINE.json · 63 lines
{
  "properties": {
    "displayName": "PostgreSQL flexible 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 PostgreSQL flexible 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.1.0",
      "category": "PostgreSQL"
    },
    "version": "1.1.0",
    "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.DBforPostgreSQL/flexibleServers"
          },
          {
            "anyOf": [
              {
                "field": "Microsoft.DBforPostgreSQL/flexibleServers/dataEncryption.type",
                "notEquals": "AzureKeyVault"
              },
              {
                "field": "Microsoft.DBforPostgreSQL/flexibleServers/dataEncryption.primaryKeyURI",
                "exists": false
              },
              {
                "field": "Microsoft.DBforPostgreSQL/flexibleServers/dataEncryption.primaryKeyURI",
                "equals": ""
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.1.0",
      "1.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/12c74c95-0efd-48da-b8d9-2a7d68470c92",
  "name": "12c74c95-0efd-48da-b8d9-2a7d68470c92"
}
Bylaw12c74c95-0efd-48da-b8d9-2a7d68470c92.bylaw.ps1 · 36 lines
# Converted from FlexibleServers_EnableCMK_AINE.json by ConvertTo-Bylaw.
Policy '12c74c95-0efd-48da-b8d9-2a7d68470c92' {

    Properties @{
        DisplayName   = 'PostgreSQL flexible servers should use customer-managed keys to encrypt data at rest'
        Description   = 'Use customer-managed keys to manage the encryption at rest of your PostgreSQL flexible 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.1.0'
        Category      = 'PostgreSQL'
        PolicyVersion = '1.1.0'
        Mode          = 'Indexed'
    }

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

    Resource 'Microsoft.DBforPostgreSQL/flexibleServers' {

        Require 'dataEncryption.type is AzureKeyVault' {
            Field dataEncryption.type | Must -Be 'AzureKeyVault'
        }

        Require 'dataEncryption.primaryKeyURI exists' {
            Field dataEncryption.primaryKeyURI | Must -Exist
        }

        Require 'dataEncryption.primaryKeyURI is not' {
            Field dataEncryption.primaryKeyURI | Must -Not -Be '' -IfPresent
        }
    }

    Effect (Param Effect)
}

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