Azure Database SQL Server Server Security Alert Policy

This page shows how to write Terraform and Azure Resource Manager for Database SQL Server Server Security Alert Policy and write them securely.

azurerm_mssql_server_security_alert_policy (Terraform)

The SQL Server Server Security Alert Policy in Database can be configured in Terraform with the resource name azurerm_mssql_server_security_alert_policy. The following sections describe 10 examples of how to use the resource and its parameters.

Example Usage from GitHub

security-alerts.tf#L1
resource "azurerm_mssql_server_security_alert_policy" "security-alert-policy" {
  resource_group_name        = data.azurerm_resource_group.rg.name
  server_name                = azurerm_mssql_server.db-server.name
  state                      = "Enabled"
  email_account_admins       = true
  email_addresses            = var.sql_server_security_alert_email_address
main.tf#L28
resource "azurerm_mssql_server_security_alert_policy" "alert_policy_good" {
  resource_group_name        = "group"
  server_name                = azurerm_sql_server.sql_server_good_1.name
  state                      = "Enabled"
  retention_days = 20
}
main.tf#L28
resource "azurerm_mssql_server_security_alert_policy" "alert_policy_good" {
  resource_group_name        = "group"
  server_name                = azurerm_sql_server.sql_server_good_1.name
  state                      = "Enabled"
  retention_days = 20
}
positive1.tf#L1
resource "azurerm_mssql_server_security_alert_policy" "positive1" {
  resource_group_name        = azurerm_resource_group.example.name
  server_name                = azurerm_sql_server.example.name
  state                      = "Enabled"
  storage_endpoint           = azurerm_storage_account.example.primary_blob_endpoint
  storage_account_access_key = azurerm_storage_account.example.primary_access_key
positive2.tf#L1
resource "azurerm_mssql_server_security_alert_policy" "positive2" {
  resource_group_name        = azurerm_resource_group.example.name
  server_name                = azurerm_sql_server.example.name
  state                      = "Enabled"
  storage_endpoint           = azurerm_storage_account.example.primary_blob_endpoint
  storage_account_access_key = azurerm_storage_account.example.primary_access_key
negative.tf#L1
resource "azurerm_mssql_server_security_alert_policy" "negative" {
  resource_group_name        = azurerm_resource_group.example.name
  server_name                = azurerm_sql_server.example.name
  state                      = "Enabled"
  storage_endpoint           = azurerm_storage_account.example.primary_blob_endpoint
  storage_account_access_key = azurerm_storage_account.example.primary_access_key
security_alert.tf#L15
resource "azurerm_mssql_server_security_alert_policy" "mssql" {
  count = try(var.settings.security_alert_policy, null) == null ? 0 : 1

  resource_group_name        = var.resource_group_name
  server_name                = azurerm_mssql_server.mssql.name
  state                      = try(var.settings.state, "Enabled")
main.tf#L7
resource "azurerm_mssql_server_security_alert_policy" "this" {
  disabled_alerts            = var.disabled_alerts
  email_account_admins       = var.email_account_admins
  email_addresses            = var.email_addresses
  resource_group_name        = var.resource_group_name
  retention_days             = var.retention_days
azurerm_mssql_server_security_alert_policy.example.tf#L1
resource "azurerm_mssql_server_security_alert_policy" "example" {
  resource_group_name        = var.resource_group.name
  server_name                = azurerm_sql_server.examplea.name
  state                      = "Enabled"
  storage_endpoint           = azurerm_storage_account.examplea.primary_blob_endpoint
  storage_account_access_key = azurerm_storage_account.examplea.primary_access_key
security_alert.tf#L15
resource "azurerm_mssql_server_security_alert_policy" "mssql" {
  count = try(var.settings.security_alert_policy, null) == null ? 0 : 1

  resource_group_name        = var.resource_group_name
  server_name                = azurerm_mssql_server.mssql.name
  state                      = try(var.settings.state, "Enabled")

Review your Terraform file for Azure best practices

Shisho Cloud, our free checker to make sure your Terraform configuration follows best practices, is available (beta).

Security Best Practices for azurerm_mssql_server_security_alert_policy

There are 3 settings in azurerm_mssql_server_security_alert_policy that should be taken care of for security reasons. The following section explain an overview and example code.

risk-label

Ensure to configure at least one email address for threat alerts

It is better to configure at least one email address for threat alerts. SQL Server is able to send alerts for threat detection via emails and it could support us to notice the incident on time.

risk-label

Ensure to enable all threat alerts

It is better to enable all threat alerts. SQL Server provides useful alerts including SQL Injection, vulnerabilities, access anomalies, and data exfiltration.

risk-label

Ensure to enable to send an alert email to owners

It is better to enable to send an alert email to owners to take quick actions by any critical incident on time.

Review your Azure Database settings

You can check if the azurerm_mssql_server_security_alert_policy setting in your .tf file is correct in 3 min with Shisho Cloud.

Parameters

Explanation in Terraform Registry

Manages a Security Alert Policy for a MSSQL Server. -> NOTE Security Alert Policy is currently only available for MS SQL databases.

Tips: Best Practices for The Other Azure Database Resources

In addition to the azurerm_mariadb_firewall_rule, Azure Database has the other resources that should be configured for security reasons. Please check some examples of those resources and precautions.

risk-label

azurerm_mariadb_firewall_rule

Ensure database firewalls do not permit public access

It is better to restrict IP address ranges that can access the database by firewall rules. If both start_ip_address and end_ip_address are set to 0.0.0.0, it blocks connections from the Internet and accepts connections from all Azure datacenter IP addresses.

risk-label

azurerm_mariadb_server

Ensure that access to Azure SQL Database is restricted

It is better to disable public access to the database to avoid unwilling communications with unknown services if not required.

risk-label

azurerm_mssql_database_extended_auditing_policy

Ensure to configure retention periods of database auditing to enough duration

It is better to configure retention periods of database auditing to enough duration. It would be better to set greater than at least 90 days.

risk-label

azurerm_mssql_server

Ensure to enable auditing on Azure SQL databases

It is better to enable auditing on Azure SQL databases. It helps you maintain regulatory compliance, monitor the activities indicating unexpected incidents or suspected security violations.

risk-label

azurerm_mysql_firewall_rule

Ensure database firewalls do not permit public access

It is better to restrict IP address ranges that can access the database by firewall rules. If both start_ip_address and end_ip_address are set to 0.0.0.0, it blocks connections from the Internet and accepts connections from all Azure datacenter IP addresses.

risk-label

azurerm_mysql_server

Ensure to disable public access to database

It is better to disable public access to the database to avoid unwilling communications with unknown services if not required.

risk-label

azurerm_postgresql_firewall_rule

Ensure database firewalls do not permit public access

It is better to restrict IP address ranges that can access the database by firewall rules. If both start_ip_address and end_ip_address are set to 0.0.0.0, it blocks connections from the Internet and accepts connections from all Azure datacenter IP addresses.

risk-label

azurerm_postgresql_server

Ensure to disable public access to database

It is better to disable public access to the database to avoid unwilling communications with unknown services if not required.

risk-label

azurerm_sql_firewall_rule

Ensure database firewalls do not permit public access

It is better to restrict IP address ranges that can access the database by firewall rules. If both start_ip_address and end_ip_address are set to 0.0.0.0, it blocks connections from the Internet and accepts connections from all Azure datacenter IP addresses.

risk-label

azurerm_sql_server

Ensure to enable auditing on Azure SQL databases

It is better to enable auditing on Azure SQL databases. It helps you maintain regulatory compliance, monitor the activities indicating unexpected incidents or suspected security violations.

Review your Azure Database settings

In addition to the above, there are other security points you should be aware of making sure that your .tf files are protected in Shisho Cloud.

Microsoft.Sql/servers/securityAlertPolicies (Azure Resource Manager)

The servers/securityAlertPolicies in Microsoft.Sql can be configured in Azure Resource Manager with the resource name Microsoft.Sql/servers/securityAlertPolicies. The following sections describe how to use the resource and its parameters.

Example Usage from GitHub

policy.json#L20
     "type": "Microsoft.Sql/servers/securityAlertPolicies",
     "name": "Default",
     "existenceCondition": {
      "field": "Microsoft.Sql/securityAlertPolicies.state",
      "equals": "Enabled"
     },
policy.json#L28
     "type": "Microsoft.Sql/servers/securityAlertPolicies",
     "name": "Default",
     "existenceCondition": {
      "field": "Microsoft.Sql/securityAlertPolicies.state",
      "equals": "Enabled"
     },
azurepolicy.rules.json#L9
         "type": "Microsoft.Sql/servers/securityAlertPolicies",
         "name": "Default",
         "existenceCondition": {
            "field": "Microsoft.Sql/securityAlertPolicies.state",
            "equals": "Enabled"
         },
sql-atp.json#L17
      "type": "Microsoft.Sql/servers/securityAlertPolicies",
      "name": "Default",
      "existenceCondition": {
        "field": "Microsoft.Sql/securityAlertPolicies.state",
        "equals": "Enabled"
      },
azurepolicy.rules.json#L9
         "type": "Microsoft.Sql/servers/securityAlertPolicies",
         "name": "Default",
         "existenceCondition": {
            "field": "Microsoft.Sql/securityAlertPolicies.state",
            "equals": "Enabled"
         },
azurepolicy.rules.json#L9
         "type": "Microsoft.Sql/servers/securityAlertPolicies",
         "name": "Default",
         "existenceCondition": {
            "field": "Microsoft.Sql/securityAlertPolicies.state",
            "equals": "Enabled"
         },
azurepolicy.json#L18
               "type": "Microsoft.Sql/servers/securityAlertPolicies",
               "name": "Default",
               "existenceCondition": {
                  "field": "Microsoft.Sql/securityAlertPolicies.state",
                  "equals": "Enabled"
               },
policy.json#L28
     "type": "Microsoft.Sql/servers/securityAlertPolicies",
     "name": "Default",
     "existenceCondition": {
      "field": "Microsoft.Sql/securityAlertPolicies.state",
      "equals": "Enabled"
     },
azurepolicy.json#L18
               "type": "Microsoft.Sql/servers/securityAlertPolicies",
               "name": "Default",
               "existenceCondition": {
                  "field": "Microsoft.Sql/securityAlertPolicies.state",
                  "equals": "Enabled"
               },
azurepolicy.json#L18
               "type": "Microsoft.Sql/servers/securityAlertPolicies",
               "name": "Default",
               "existenceCondition": {
                  "field": "Microsoft.Sql/securityAlertPolicies.state",
                  "equals": "Enabled"
               },

Frequently asked questions

What is Azure Database SQL Server Server Security Alert Policy?

Azure Database SQL Server Server Security Alert Policy is a resource for Database of Microsoft Azure. Settings can be wrote in Terraform.

Where can I find the example code for the Azure Database SQL Server Server Security Alert Policy?

For Terraform, the gayatri1030/azuresqlserver, SnidermanIndustries/checkov-fork and melscoop-test/check source code examples are useful. See the Terraform Example section for further details.

For Azure Resource Manager, the manoj-murali/ARMTemplates, Adam9911/vuminhchien and kprpg/Azure-Policies source code examples are useful. See the Azure Resource Manager Example section for further details.