Bylaw

Gallery › SQL › Azure built-in policies

Azure SQL Database should have Microsoft Entra-only authentication enabled

Converted Policy Audit Deny Disabled Mode All Version 1.0.0

Require Azure SQL logical servers to use Microsoft Entra-only authentication. This policy doesn't block servers from being created with local authentication enabled. It does block local authentication from being enabled on resources after create. Consider using the 'Microsoft Entra-only authentication' initiative instead to require both. Learn more at: https://aka.ms/adonlycreate.

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

Azure Policy JSONSqlServer_ADOnlyEnabled_DisableADAuth_Deny.json · 62 lines
{
  "properties": {
    "displayName": "Azure SQL Database should have Microsoft Entra-only authentication enabled",
    "description": "Require Azure SQL logical servers to use Microsoft Entra-only authentication. This policy doesn't block servers from being created with local authentication enabled. It does block local authentication from being enabled on resources after create. Consider using the 'Microsoft Entra-only authentication' initiative instead to require both. Learn more at: https://aka.ms/adonlycreate.",
    "policyType": "BuiltIn",
    "mode": "All",
    "metadata": {
      "version": "1.0.0",
      "category": "SQL"
    },
    "version": "1.0.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.Sql/servers/azureADOnlyAuthentications"
          },
          {
            "value": "[resourcegroup().managedBy]",
            "notContains": "/providers/Microsoft.Synapse/"
          },
          {
            "anyOf": [
              {
                "field": "Microsoft.Sql/servers/azureADOnlyAuthentications/azureADOnlyAuthentication",
                "exists": false
              },
              {
                "field": "Microsoft.Sql/servers/azureADOnlyAuthentications/azureADOnlyAuthentication",
                "equals": false
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/b3a22bc9-66de-45fb-98fa-00f5df42f41a",
  "name": "b3a22bc9-66de-45fb-98fa-00f5df42f41a"
}
Bylawb3a22bc9-66de-45fb-98fa-00f5df42f41a.bylaw.ps1 · 36 lines
# Converted from SqlServer_ADOnlyEnabled_DisableADAuth_Deny.json by ConvertTo-Bylaw.
Policy 'b3a22bc9-66de-45fb-98fa-00f5df42f41a' {

    Properties @{
        DisplayName   = 'Azure SQL Database should have Microsoft Entra-only authentication enabled'
        Description   = 'Require Azure SQL logical servers to use Microsoft Entra-only authentication. This policy doesn''t block servers from being created with local authentication enabled. It does block local authentication from being enabled on resources after create. Consider using the ''Microsoft Entra-only authentication'' initiative instead to require both. Learn more at: https://aka.ms/adonlycreate.'
        Version       = '1.0.0'
        Category      = 'SQL'
        PolicyVersion = '1.0.0'
        Mode          = 'All'
    }

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

    Resource 'Microsoft.Sql/servers/azureADOnlyAuthentications' {

        When {
            Arm '[resourcegroup().managedBy]' | Must -Not -ContainText '/providers/Microsoft.Synapse/'
        }

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

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

    Effect (Param Effect)
}

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