08 / 13Data
Azure SQL Database security hardening
Harden Azure SQL Database: Entra-only authentication, firewall without Azure-wide rules, private endpoints, TLS, TDE with customer-managed keys, auditing and Defender.
- Service
- SQL Database
- Category
- Data
- Baseline
- 11 controls
- Updated
On this page
Azure SQL Database is a managed SQL Server engine that sits behind a logical server with a public DNS name (<server>.database.windows.net). Its weak points are not in the engine but in the defaults around it: a SQL admin login with a password that ends up in connection strings, a firewall rule called "Allow Azure services and resources to access this server" that actually admits traffic from any Azure subscription of any customer, a public endpoint open to address ranges nobody remembers adding, and auditing that was never turned on. Brute force and password spraying against public SQL endpoints are routine enough that Microsoft Defender for SQL ships dedicated alerts for them, and SQL injection through the application remains the classic path to the data (MITRE ATT&CK T1190). This page maps each control to the Microsoft cloud security benchmark (MCSB) and the Azure SQL Database security baseline, and to the database services section of the CIS Microsoft Azure Foundations Benchmark.
Baseline controls
Plain CIS numbers refer to the CIS Microsoft Azure Foundations Benchmark v7.0.0; numbers marked Database refer to the CIS Microsoft Azure Database Services Benchmark v2.0.1.
| Control | Why | How to check | ID |
|---|---|---|---|
| Microsoft Entra-only authentication | Removes SQL logins and their passwords from the attack surface | az sql server ad-only-auth get | MCSB IM-1 / CIS Azure Database 2.0.1 9.9 |
| Microsoft Entra admin is a group | Admin access tied to identity lifecycle, MFA and PIM | az sql server ad-admin list | MCSB IM-1 / CIS Database 9.5 |
| No Azure-wide or all-IP firewall rules | 0.0.0.0 admits every Azure tenant, 0.0.0.0 to 255.255.255.255 admits the internet | az sql server firewall-rule list | MCSB NS-2 / CIS Database 9.3 |
| Public network access off, private endpoints | Database reachable only from your networks | publicNetworkAccess is Disabled | MCSB NS-2 / CIS Database 9.2 |
| Minimum TLS version 1.2 | Rejects legacy protocol clients explicitly | minimalTlsVersion is 1.2 or 1.3 | MCSB DP-3 / CIS Database 9.8 |
| TDE with a customer-managed key | Key lifecycle and revocation under your control | az sql server tde-key show returns AzureKeyVault | MCSB DP-5 / CIS Database 9.4 |
| Server auditing to Log Analytics | Evidence of logins, queries and permission changes | az sql server audit-policy show | MCSB LT-3 / CIS Database 9.1, 9.7 |
| Microsoft Defender for SQL | Alerts on injection, brute force, anomalous access | Defender plan SqlServers is Standard | MCSB LT-1 / CIS 8.1.7.3 |
| Vulnerability assessment, express configuration | Finds misconfigurations and excessive permissions | Defender for Cloud recommendations | MCSB PV-5 |
| Ledger and Always Encrypted for sensitive data | Tamper evidence, and data hidden from DBAs and the engine | sys.database_ledger_digest_locations, column metadata | - |
| Outbound networking restricted | Blocks exfiltration to arbitrary storage or endpoints | restrictOutboundNetworkAccess is Enabled | - |
Microsoft Entra-only authentication
Every logical server is created with a SQL authentication admin (login and password). Unless you disable it, that account and any other SQL logins can be brute-forced, sprayed and leaked in connection strings. Microsoft Entra-only authentication turns SQL authentication off for the server and all its databases: SQL logins, including the server admin, can no longer connect.
Create new servers Entra-only from the start:
az sql server create \
--name sql-app1-prod-weu --resource-group rg-app1 --location westeurope \
--enable-ad-only-auth \
--external-admin-principal-type Group \
--external-admin-name sg-sql-app1-admins \
--external-admin-sid <group-object-id> \
--minimal-tls-version 1.2 \
--enable-public-network false
For an existing server, make sure the Entra admin is set and every application uses Entra tokens, then switch:
az sql server ad-only-auth enable -g rg-app1 -n sql-app1-prod-weu
az sql server ad-only-auth get -g rg-app1 -n sql-app1-prod-weu
Portal: SQL server > Settings > Microsoft Entra ID > Support only Microsoft Entra authentication for this server.
Applications use managed identities
Create a contained database user for each application's managed identity and grant only the database roles it needs:
CREATE USER [app1-prod-identity] FROM EXTERNAL PROVIDER;
ALTER ROLE db_datareader ADD MEMBER [app1-prod-identity];
ALTER ROLE db_datawriter ADD MEMBER [app1-prod-identity];
The connection string then contains no secret (Authentication=Active Directory Default or Active Directory Managed Identity, depending on the driver). To resolve users with FROM EXTERNAL PROVIDER, the server's identity needs read access to Microsoft Graph (the Directory Readers role or the User.Read.All, GroupMember.Read.All and Application.Read.All application permissions).
Anyone with SQL Security Manager or Contributor on the server can turn Entra-only authentication back off. Watch for that in the activity log (see Logging and detection).
Enforce: Azure SQL Database should have Microsoft Entra-only authentication enabled with Deny blocks both new servers without it and attempts to disable it. Azure SQL logical servers should have Microsoft Entra-only authentication enabled during creation is the softer variant that only checks creation. The rollout method is on the Azure Policy page.
az policy assignment create \
--name deny-sql-local-auth \
--display-name "Azure SQL Database should have Microsoft Entra-only authentication enabled" \
--policy b3a22bc9-66de-45fb-98fa-00f5df42f41a \
--scope /providers/Microsoft.Management/managementGroups/mg-landing-zones \
--params '{"effect":{"value":"Deny"}}'
Microsoft Entra admin
The Microsoft Entra admin of the server is sysadmin-equivalent on every database. Set it to a security group, not to an individual user, so that membership follows joiners and leavers, and manage that membership with PIM for Groups so nobody holds it permanently.
az sql server ad-admin create -g rg-app1 --server sql-app1-prod-weu \
--display-name sg-sql-app1-admins --object-id <group-object-id>
az sql server ad-admin list -g rg-app1 --server sql-app1-prod-weu -o table
Use a role-assignable group (isAssignableToRole) so that only Privileged Role Administrators and group owners can change its membership. Group design and PIM are covered on the Entra ID page.
Enforce: An Azure Active Directory administrator should be provisioned for SQL servers (the built-in still carries the old name) in AuditIfNotExists.
Server firewall rules
When public network access is enabled, the server firewall decides which source IP addresses can reach the gateway. Two rules deserve special attention:
AllowAllWindowsAzureIps(start and end0.0.0.0), created by the portal checkbox Allow Azure services and resources to access this server. It does not mean "my subscription": it admits connections from any Azure IP address, including virtual machines and functions in other customers' subscriptions. Authentication is then the only barrier.- All-IP rules (
0.0.0.0to255.255.255.255), often added "temporarily" to debug a connection and never removed.
List and remove them:
az sql server firewall-rule list -g rg-app1 --server sql-app1-prod-weu -o table
az sql server firewall-rule delete -g rg-app1 --server sql-app1-prod-weu \
--name AllowAllWindowsAzureIps
Check every server you can read:
for id in $(az sql server list --query "[].id" -o tsv); do
az sql server firewall-rule list --ids "$id" \
--query "[?startIpAddress=='0.0.0.0'].{server:'$id', rule:name, start:startIpAddress, end:endIpAddress}" -o tsv
done
Database-level firewall rules live inside each database and are not visible in the portal or ARM. Check them with T-SQL (SELECT * FROM sys.database_firewall_rules;) and remove unexpected ones with EXECUTE sp_delete_database_firewall_rule N'<name>';.
If Azure services need access, use a private endpoint, or virtual network rules for the specific subnets (az sql server vnet-rule create), not the Azure-wide rule.
Enforce: no built-in policy denies these two rules, so use a custom Deny definition on the firewall rule child resource:
{
"mode": "All",
"policyRule": {
"if": {
"allOf": [
{ "field": "type", "equals": "Microsoft.Sql/servers/firewallRules" },
{ "field": "Microsoft.Sql/servers/firewallRules/startIpAddress", "equals": "0.0.0.0" }
]
},
"then": { "effect": "deny" }
}
}
This blocks both the Azure-wide rule and any rule starting at 0.0.0.0, including the all-IP range.
Public network access and private endpoints
The strongest posture is no public endpoint at all: set public network access to disabled and connect through a private endpoint in your VNet. When public access is disabled, firewall rules cannot be created or changed, and public connections fail with error 47073.
SQL_ID=$(az sql server show -g rg-app1 -n sql-app1-prod-weu --query id -o tsv)
az network private-endpoint create \
--name pe-sql-app1-prod --resource-group rg-app1 \
--vnet-name vnet-app1 --subnet snet-private-endpoints \
--private-connection-resource-id "$SQL_ID" \
--group-id sqlServer --connection-name sql-app1-prod
az sql server update -g rg-app1 -n sql-app1-prod-weu --set publicNetworkAccess="Disabled"
Link the privatelink.database.windows.net private DNS zone to the VNets that resolve it; the central DNS pattern is on the Virtual Network page. Clients keep using the normal <server>.database.windows.net name, which resolves to the private IP inside your network.
Portal: SQL server > Security > Networking > Public access and Private access.
Enforce: Public network access on Azure SQL Database should be disabled (Deny), and Private endpoint connections on Azure SQL Database should be enabled to audit the endpoint side. Configure Azure SQL Server to disable public network access (Modify) remediates existing servers.
Minimum TLS version
TLS 1.0 and 1.1 are retired for Azure SQL Database, and the service accepts TLS 1.2 or later. The server property still defaults to "no minimum", which compliance scanners flag and which leaves the decision implicit. Set it explicitly:
az sql server update -g rg-app1 -n sql-app1-prod-weu --minimal-tls-version 1.2
az sql server show -g rg-app1 -n sql-app1-prod-weu --query minimalTlsVersion
Use 1.3 once every client driver supports it. Once you set a minimum, you cannot go back to "no minimum".
Enforce: Azure SQL Database should be running TLS version 1.2 or newer.
Transparent data encryption with customer-managed keys
Transparent data encryption (TDE) is on by default for every new database and encrypts data files, logs and backups at rest with a service-managed key. Verify that no database had it disabled:
az sql db tde show -g rg-app1 --server sql-app1-prod-weu --database appdb --query state
When your policy requires control over the key (revocation, rotation, separation of duties), use a customer-managed TDE protector stored in Key Vault:
# Server identity that can reach the key
az sql server update -g rg-app1 -n sql-app1-prod-weu \
--identity-type UserAssigned \
--user-assigned-identity-id "$UAMI_ID" \
--pid "$UAMI_ID"
# Grant "Key Vault Crypto Service Encryption User" to the identity on the key, then:
KID=$(az keyvault key show --vault-name kv-app1-prod-weu -n tde-protector --query key.kid -o tsv)
az sql server key create -g rg-app1 --server sql-app1-prod-weu --kid "$KID"
az sql server tde-key set -g rg-app1 --server sql-app1-prod-weu \
--server-key-type AzureKeyVault --kid "$KID" --auto-rotation-enabled true
The key must be RSA (2048 or 3072 bits) in a vault with soft delete and purge protection. If the server loses access to the key for long enough, databases become inaccessible; if the key is purged, the data is gone. Key Vault settings, rotation and logging are on the Key Vault page.
Enforce: SQL servers should use customer-managed keys to encrypt data at rest (Audit) where CMK is required, and Transparent Data Encryption on SQL databases should be enabled everywhere.
Auditing
SQL auditing records database events (logins, queries, permission changes) and writes them to Log Analytics, a storage account or Event Hubs. Enable it at the server level so it covers every current and future database:
az sql server audit-policy update -g rg-app1 -n sql-app1-prod-weu \
--state Enabled \
--lats Enabled --lawri "$LAW_ID"
The default action groups (BATCH_COMPLETED_GROUP, SUCCESSFUL_DATABASE_AUTHENTICATION_GROUP, FAILED_DATABASE_AUTHENTICATION_GROUP) cover queries and logins. Add DATABASE_PERMISSION_CHANGE_GROUP, DATABASE_PRINCIPAL_CHANGE_GROUP and DATABASE_ROLE_MEMBER_CHANGE_GROUP if you prune batch events for volume. Also audit Microsoft support engineers' operations on the server:
az sql server ms-support audit-policy update -g rg-app1 -n sql-app1-prod-weu \
--state Enabled --lats Enabled --lawri "$LAW_ID"
If you write to a storage account, use the server's managed identity rather than a storage key, and keep at least 90 days of retention.
Portal: SQL server > Security > Auditing.
Enforce: Configure SQL servers to have auditing enabled to Log Analytics workspace (DeployIfNotExists) at the management group, and Auditing on SQL server should be enabled to audit. Workspace design and retention are on the Azure Monitor page.
Microsoft Defender for SQL and vulnerability assessment
Microsoft Defender for Azure SQL adds two things: Advanced Threat Protection, which alerts on SQL injection, brute force, logins from suspicious IPs or unusual locations and unusual data export; and vulnerability assessment, which scans each database for misconfigurations, excessive permissions and unprotected sensitive data.
Enable the plan at subscription level. When you do, Defender for Cloud turns on Advanced Threat Protection and vulnerability assessment in the express configuration for every Azure SQL database in the subscription. Express configuration needs no storage account and is the recommended mode.
az security pricing create -n SqlServers --tier Standard
# Per server, if you enable it outside the plan
az sql server advanced-threat-protection-setting update \
-g rg-app1 -n sql-app1-prod-weu --state Enabled
Servers that still use the classic vulnerability assessment configuration (results in a storage account) can be switched to express in SQL server > Security > Microsoft Defender for Cloud; baselines and scan history are not migrated. To enable express configuration at scale through the API:
az rest --method put \
--url "https://management.azure.com${SQL_ID}/sqlVulnerabilityAssessments/default?api-version=2025-01-01" \
--body '{"properties":{"state":"Enabled"}}'
Review findings in Defender for Cloud under the recommendation SQL databases should have vulnerability findings resolved, and set a baseline for accepted results so new deviations stand out. Plan management is on the Defender for Cloud page.
Enforce: Configure Azure Defender to be enabled on SQL servers (DeployIfNotExists), plus Azure Defender for SQL should be enabled for unprotected Azure SQL servers and Vulnerability assessment should be enabled on your SQL servers to audit.
Ledger and Always Encrypted
Two engine features address threats the controls above cannot: an insider with high privileges.
- Ledger makes tables tamper-evident. Each transaction is hashed into a blockchain-like structure, and database digests can be stored in immutable storage or Azure Confidential Ledger, so a later modification by a DBA or an attacker is detectable through verification. Create a ledger database (
az sql db create ... --ledger-on, all tables become ledger tables) or individual ledger tables (WITH (SYSTEM_VERSIONING = ON, LEDGER = ON)), then turn on automatic digest upload withaz sql db ledger-digest-uploads enable --endpoint <confidential-ledger-or-blob-endpoint>. Use it for audit trails, financial records and anything you may need to prove untouched. - Always Encrypted encrypts selected columns on the client side. The column master key stays in Key Vault and the database engine only sees ciphertext, so administrators, backups and a compromised server cannot read the values. Secure enclaves extend it to support pattern matching and range queries on encrypted columns. Use it for national identifiers, card data and similar fields, with the column master key in a vault with purge protection.
Both have functional trade-offs (ledger tables are append-only for history, Always Encrypted limits query operations), so apply them to specific tables and columns rather than to everything.
Outbound networking restriction
By default the server can initiate outbound connections, which features such as auditing to storage, BULK INSERT, external tables and sp_invoke_external_rest_endpoint use. An attacker with enough database rights can use the same paths to push data to a storage account they control. Restrict outbound traffic to an explicit list of FQDNs:
az sql server update -g rg-app1 -n sql-app1-prod-weu --restrict-outbound-network-access true
az sql server outbound-firewall-rule create -g rg-app1 --server sql-app1-prod-weu \
--outbound-rule-fqdn stauditsqlweu01.blob.core.windows.net
az sql server outbound-firewall-rule list -g rg-app1 --server sql-app1-prod-weu -o table
Add every destination your features need (audit storage account, ledger digest endpoint, external data sources) before turning the restriction on, then test.
Portal: SQL server > Security > Networking > Connectivity > Outbound networking.
Logging and detection
Send server auditing to Log Analytics (see Auditing) and enable diagnostic settings on each database for the SQLSecurityAuditEvents, DevOpsOperationsAudit and Errors categories, at scale with Enable logging by category group for SQL databases (microsoft.sql/servers/databases) to Log Analytics. The organization-wide setup is on the Azure Monitor page.
Failed logins by source, a sign of brute force or password spraying:
AzureDiagnostics
| where Category == "SQLSecurityAuditEvents"
| where action_name_s == "DATABASE AUTHENTICATION FAILED"
| summarize Failures = count(), Principals = dcount(server_principal_name_s)
by client_ip_s, server_instance_name_s, bin(TimeGenerated, 1h)
| where Failures > 20
Permission and principal changes inside databases:
AzureDiagnostics
| where Category == "SQLSecurityAuditEvents"
| where statement_s has_any ("ALTER ROLE", "GRANT", "CREATE USER", "CREATE LOGIN", "ALTER LOGIN")
| project TimeGenerated, server_instance_name_s, database_name_s, server_principal_name_s,
client_ip_s, application_name_s, statement_s
Control plane changes that weaken the baseline (firewall rules, Entra-only authentication, admin, auditing, server properties) come from the activity log:
AzureActivity
| where ActivityStatusValue == "Success"
| where OperationNameValue has "MICROSOFT.SQL/SERVERS/"
| where OperationNameValue has_any ("FIREWALLRULES/WRITE", "AZUREADONLYAUTHENTICATIONS",
"ADMINISTRATORS/WRITE", "AUDITINGSETTINGS/WRITE", "OUTBOUNDFIREWALLRULES")
or OperationNameValue =~ "MICROSOFT.SQL/SERVERS/WRITE"
| project TimeGenerated, Caller, CallerIpAddress, OperationNameValue, _ResourceId
Defender for SQL alerts (potential SQL injection, potential brute force, login from a suspicious IP, unusual export location) appear in Defender for Cloud; route them to Microsoft Sentinel or your ticketing system.
Common mistakes
- Ticking Allow Azure services and resources to access this server to make an App Service connect, which opens the server to every Azure customer's resources.
- Leaving SQL authentication on "for emergencies", with the server admin password in a wiki or a pipeline variable, so it becomes the easiest credential to steal.
- Setting an individual user as Microsoft Entra admin; when that person leaves, nobody can administer the databases, or the account stays active with
sysadminrights. - Adding a private endpoint but leaving public network access enabled with old firewall rules, so the public path stays open.
- Using a customer-managed TDE key in a vault without purge protection, or revoking the server identity's key access during a cleanup, which takes every database offline.
- Enabling auditing per database instead of at server level, so newly created databases are not audited.
- Granting
db_ownerto application identities instead of the narrow roles they need, which turns any SQL injection into full database control.
References
- Security best practices for Azure SQL Database (Microsoft Learn)
- Azure security baseline for Azure SQL (Microsoft cloud security benchmark)
- Microsoft Entra-only authentication with Azure SQL (Microsoft Learn)
- Azure SQL Database and Azure Synapse IP firewall rules (Microsoft Learn)
- Connectivity settings for Azure SQL Database (Microsoft Learn)
- Azure SQL transparent data encryption with customer-managed key (Microsoft Learn)
- Auditing for Azure SQL Database and Azure Synapse Analytics (Microsoft Learn)
- Enable SQL vulnerability assessment express configuration (Microsoft Learn)
- Outbound firewall rules for Azure SQL Database (Microsoft Learn)
- Ledger overview (Microsoft Learn)
- MITRE ATT&CK T1190: Exploit Public-Facing Application (MITRE)
- CIS Microsoft Azure Foundations Benchmark (CIS)
Filed under sql-database, data-protection, identity, network
Written by
Florian Amette, Cloud Security Engineer & EditorSecurity engineer writing practical hardening pages for Microsoft Azure tenants and subscriptions, aligned with the CIS Microsoft Azure Foundations Benchmark.