Review Azure SQL audit log retention

Keep logs long enough for investigations and audits.

Description

In an Azure SQL server audit policy for Blob Storage, retention_in_days sets how long to keep logs. A value of 0 sets no expiry under that policy.

Potential impact

If storage deletes records too early, investigators may lose the history of past data access or changes.

Remediation

Choose a period that covers your investigations and audits, including more than 90 days where required. Check whether a storage lifecycle rule expires the logs earlier and whether investigators can read records from the period they need.

Examples

Both server audit policies use the same Blob endpoint. The second increases retention from 20 to 95 days as an example. Use separately managed administrator credentials in production.

Before

hcl
resource "azurerm_mssql_server" "example" {
  name                         = "sqlserver"
  resource_group_name          = azurerm_resource_group.example.name
  location                     = azurerm_resource_group.example.location
  version                      = "12.0"
  administrator_login          = "mradministrator"
  administrator_login_password = "thisIsDog11"

}

resource "azurerm_mssql_server_extended_auditing_policy" "example" {
  server_id = azurerm_mssql_server.example.id
  blob_storage_endpoint                        = azurerm_storage_account.example.primary_blob_endpoint
  storage_account_access_key              = azurerm_storage_account.example.primary_access_key
  storage_account_access_key_is_secondary = false
  retention_in_days                       = 20
}

After

hcl
resource "azurerm_mssql_server" "example" {
  name                         = "sqlserver"
  resource_group_name          = azurerm_resource_group.example.name
  location                     = azurerm_resource_group.example.location
  version                      = "12.0"
  administrator_login          = "mradministrator"
  administrator_login_password = "thisIsDog11"

}

resource "azurerm_mssql_server_extended_auditing_policy" "example" {
  server_id = azurerm_mssql_server.example.id
  blob_storage_endpoint                        = azurerm_storage_account.example.primary_blob_endpoint
  storage_account_access_key              = azurerm_storage_account.example.primary_access_key
  storage_account_access_key_is_secondary = false
  retention_in_days                       = 95
}

References