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
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
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
}
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
}
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
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
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
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")
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
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
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")
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.
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.
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.
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.
Parameters
-
disabled_alerts
optional - set of string -
email_account_admins
optional - bool -
email_addresses
optional - set of string -
id
optional computed - string -
resource_group_name
required - string -
retention_days
optional - number -
server_name
required - string -
state
required - string -
storage_account_access_key
optional - string -
storage_endpoint
optional - string -
timeouts
single block
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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
"type": "Microsoft.Sql/servers/securityAlertPolicies",
"name": "Default",
"existenceCondition": {
"field": "Microsoft.Sql/securityAlertPolicies.state",
"equals": "Enabled"
},
"type": "Microsoft.Sql/servers/securityAlertPolicies",
"name": "Default",
"existenceCondition": {
"field": "Microsoft.Sql/securityAlertPolicies.state",
"equals": "Enabled"
},
"type": "Microsoft.Sql/servers/securityAlertPolicies",
"name": "Default",
"existenceCondition": {
"field": "Microsoft.Sql/securityAlertPolicies.state",
"equals": "Enabled"
},
"type": "Microsoft.Sql/servers/securityAlertPolicies",
"name": "Default",
"existenceCondition": {
"field": "Microsoft.Sql/securityAlertPolicies.state",
"equals": "Enabled"
},
"type": "Microsoft.Sql/servers/securityAlertPolicies",
"name": "Default",
"existenceCondition": {
"field": "Microsoft.Sql/securityAlertPolicies.state",
"equals": "Enabled"
},
"type": "Microsoft.Sql/servers/securityAlertPolicies",
"name": "Default",
"existenceCondition": {
"field": "Microsoft.Sql/securityAlertPolicies.state",
"equals": "Enabled"
},
"type": "Microsoft.Sql/servers/securityAlertPolicies",
"name": "Default",
"existenceCondition": {
"field": "Microsoft.Sql/securityAlertPolicies.state",
"equals": "Enabled"
},
"type": "Microsoft.Sql/servers/securityAlertPolicies",
"name": "Default",
"existenceCondition": {
"field": "Microsoft.Sql/securityAlertPolicies.state",
"equals": "Enabled"
},
"type": "Microsoft.Sql/servers/securityAlertPolicies",
"name": "Default",
"existenceCondition": {
"field": "Microsoft.Sql/securityAlertPolicies.state",
"equals": "Enabled"
},
"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.