Azure SQL Database Auditing

Azure SQL Database auditing tracks database events and writes them to an audit log in Azure storage, Azure Log Analytics, or Event Hubs. Auditing helps you maintain regulatory compliance, understand data activity, and gain insight into discrepancies and potential security threats.

Important: Auditing is enabled by default for new Azure SQL databases. For existing databases, you may need to enable it manually.

Key Features

How to Enable and Configure Auditing

Using the Azure Portal

The Azure portal provides an intuitive interface for configuring SQL Database auditing.

  1. Navigate to your Azure SQL database or server in the Azure portal.
  2. Under the Security section, select Auditing.
  3. Toggle the Auditing switch to On.
  4. Choose your desired Destination Type (Storage, Log Analytics, or Event Hubs).
  5. Configure the destination settings (e.g., storage account, Log Analytics workspace, or Event Hub namespace).
  6. Optionally, configure Storage Account Access Key or Diagnostic Settings.
  7. Specify audit log retention policies.
  8. Click Save.

Using Azure PowerShell

You can also manage auditing using Azure PowerShell cmdlets.


# Connect to your Azure account
Connect-AzAccount

# Set your subscription context
Set-AzContext -SubscriptionId "your-subscription-id"

# Enable auditing to Azure Storage
Set-AzSqlServerAudit -ResourceGroupName "YourResourceGroup" -ServerName "your-server-name" -AuditActionGroup "BATCH_ABORTED_GROUP", "APPLICATION_ROLE_CHANGE_PASSWORD_GROUP", "BACKUP_RESTORE_GROUP", "DATA_BASETRAIL_GROUP", "SCHEMA_CHANGE_GROUP", "SECURITY_GROUP", "SUCCESSFUL_LOGIN_GROUP", "UPDATED_SETTING_GROUP", "USER_ACCESS_CHANGE_GROUP", "INSERT_GROUP", "UPDATE_GROUP", "DELETE_GROUP", "SELECT_GROUP" -StorageEndpoint "https://yourstorageaccount.blob.core.windows.net" -RetentionInDays 30 -State Enabled

# Example of enabling auditing to Log Analytics
$logAnalytics = New-AzDiagnosticDetailSetting -Name "AuditToLogAnalytics" -Category "SQLInsights" -Metric $null -Log "AuditLogs" -ResourceId "/subscriptions/your-subscription-id/resourceGroups/YourResourceGroup/providers/Microsoft.OperationalInsights/workspaces/your-workspace-name"

Set-AzDiagnosticSetting -ResourceId "/subscriptions/your-subscription-id/resourceGroups/YourResourceGroup/providers/Microsoft.Sql/servers/your-server-name" -Settings $logAnalytics -Enabled
            

Audit Log Configuration Details

When configuring auditing, you can specify various settings:

Viewing and Analyzing Audit Logs

Once auditing is enabled, you can access and analyze the audit logs:

Example Kusto Query (Log Analytics)


AzureDiagnostics
| where ResourceProvider == "MICROSOFT.SQL" and Category == "AuditLogs"
| where OperationName == "SELECT" // Example: Filter for SELECT operations
| project TimeGenerated, DatabaseName, SchemaName, TableName, User, OperationName, ClientIP
| order by TimeGenerated desc
            

Best Practices