Bylaw

Gallery › Synapse › Azure built-in policies

Configure Synapse workspaces to have auditing enabled to Log Analytics workspace

Converted Policy DeployIfNotExists Disabled Mode Indexed Version 1.0.0

To ensure the operations performed against your SQL assets are captured, Synapse workspaces should have auditing enabled. If auditing is not enabled, this policy will configure auditing events to flow to the specified Log Analytics workspace.

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

Azure Policy JSONWorkspaceSqlAuditingToLA_DINE.json · 114 lines
{
  "properties": {
    "displayName": "Configure Synapse workspaces to have auditing enabled to Log Analytics workspace",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "To ensure the operations performed against your SQL assets are captured, Synapse workspaces should have auditing enabled. If auditing is not enabled, this policy will configure auditing events to flow to the specified Log Analytics workspace.",
    "metadata": {
      "version": "1.0.0",
      "category": "Synapse"
    },
    "version": "1.0.0",
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        },
        "allowedValues": [
          "DeployIfNotExists",
          "Disabled"
        ],
        "defaultValue": "DeployIfNotExists"
      },
      "logAnalyticsWorkspaceId": {
        "type": "String",
        "metadata": {
          "displayName": "Log Analytics Workspace ID",
          "description": "Auditing will write database events to this Log Analytics Workspace. This should be in the following format '/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/{resourcegroup}/providers/Microsoft.OperationalInsights/workspaces/{logAnalyticsWorkspaceName}'",
          "strongType": "omsWorkspace",
          "assignPermissions": true
        }
      }
    },
    "policyRule": {
      "if": {
        "field": "type",
        "equals": "Microsoft.Synapse/workspaces"
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "type": "Microsoft.Synapse/workspaces/auditingSettings",
          "name": "Default",
          "existenceCondition": {
            "field": "Microsoft.Synapse/workspaces/auditingSettings/state",
            "equals": "Enabled"
          },
          "roleDefinitionIds": [
            "/providers/Microsoft.Authorization/roleDefinitions/92aaf0da-9dab-42b6-94a3-d43ce8d16293",
            "/providers/Microsoft.Authorization/roleDefinitions/8e3af657-a8ff-443c-a75c-2fe8c4bcb635"
          ],
          "deployment": {
            "properties": {
              "mode": "incremental",
              "template": {
                "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
                "contentVersion": "1.0.0.0",
                "parameters": {
                  "logAnalyticsWorkspaceId": {
                    "type": "string",
                    "minLength": 90
                  },
                  "synapseWorkspaceName": {
                    "type": "string",
                    "minLength": 3
                  }
                },
                "resources": [
                  {
                    "type": "Microsoft.Synapse/workspaces/providers/diagnosticSettings",
                    "apiVersion": "2021-05-01-preview",
                    "name": "[concat(parameters('synapseWorkspaceName'),'/microsoft.insights/SQLSecurityAuditEvents_3d229c42-c7e7-4c97-9a99-ec0d0d8b86c1')]",
                    "properties": {
                      "workspaceId": "[parameters('logAnalyticsWorkspaceId')]",
                      "logs": [
                        {
                          "category": "SQLSecurityAuditEvents",
                          "enabled": true
                        }
                      ]
                    }
                  },
                  {
                    "name": "[concat(parameters('synapseWorkspaceName'),'/default')]",
                    "type": "Microsoft.Synapse/workspaces/auditingSettings",
                    "apiVersion": "2019-06-01-preview",
                    "properties": {
                      "State": "Enabled",
                      "isAzureMonitorTargetEnabled": true
                    }
                  }
                ]
              },
              "parameters": {
                "synapseWorkspaceName": {
                  "value": "[field('name')]"
                },
                "logAnalyticsWorkspaceId": {
                  "value": "[parameters('logAnalyticsWorkspaceId')]"
                }
              }
            }
          }
        }
      }
    },
    "versions": [
      "1.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/32ba8d30-07c0-4136-ab18-9a11bf4a67b7",
  "name": "32ba8d30-07c0-4136-ab18-9a11bf4a67b7"
}
Bylaw32ba8d30-07c0-4136-ab18-9a11bf4a67b7.bylaw.ps1 · 37 lines
# Converted from WorkspaceSqlAuditingToLA_DINE.json by ConvertTo-Bylaw.
Policy '32ba8d30-07c0-4136-ab18-9a11bf4a67b7' {

    Properties @{
        DisplayName   = 'Configure Synapse workspaces to have auditing enabled to Log Analytics workspace'
        Description   = 'To ensure the operations performed against your SQL assets are captured, Synapse workspaces should have auditing enabled. If auditing is not enabled, this policy will configure auditing events to flow to the specified Log Analytics workspace.'
        Version       = '1.0.0'
        Category      = 'Synapse'
        PolicyVersion = '1.0.0'
        Mode          = 'Indexed'
    }

    Parameter Effect @{
        AllowedValues = @('DeployIfNotExists', 'Disabled')
        Default       = 'DeployIfNotExists'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable the execution of the policy'
    }
    Parameter LogAnalyticsWorkspaceId @{
        Type        = 'String'
        DisplayName = 'Log Analytics Workspace ID'
        Description = 'Auditing will write database events to this Log Analytics Workspace. This should be in the following format ''/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/{resourcegroup}/providers/Microsoft.OperationalInsights/workspaces/{logAnalyticsWorkspaceName}'''
        Metadata    = [ordered]@{ strongType = 'omsWorkspace'; assignPermissions = $true }
    }

    Resource 'Microsoft.Synapse/workspaces'

    DeployIfNotExists 'Microsoft.Synapse/workspaces/auditingSettings' -Role 'Log Analytics Contributor', 'Owner' -Name 'Default' -Effect (Param Effect) {
        Require 'state is Enabled' {
            Field state | Must -Be 'Enabled'
        }
        Deployment -TemplateFile './templates/32ba8d30-07c0-4136-ab18-9a11bf4a67b7.json' -Parameters ([ordered]@{
                synapseWorkspaceName    = (Arm '[field(''name'')]')
                logAnalyticsWorkspaceId = (Param LogAnalyticsWorkspaceId)
            })
    }
}

Its deployment templates are written beside it:

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