Home › Studies › SC-500 › Storage, Databases & Networking › Database Security

Database Security

SQL firewall & network access · Entra authentication · TDE & customer-managed keys · masking & Always Encrypted · auditing · Defender for Databases

By the tools4free.dev team · Last reviewed November 13, 2026

Practice questions for this topic →

Network access and authentication

A new logical server denies all connections by default. Firewall rules apply to Azure SQL Database only; for SQL Managed Instance see its own networking configuration.

ControlScope and notes
Server-level IP firewall ruleAll databases on the server; stored in master; up to 256 per server. Portal, PowerShell, T-SQL (sp_set_firewall_rule) or CLI. Portal and PowerShell need subscription Owner or Contributor.
Database-level IP firewall ruleOne database; T-SQL only (sp_set_database_firewall_rule); only after the first server-level rule exists; needs at least CONTROL DATABASE; up to 256 per database. Microsoft recommends them whenever possible.
Allow Azure services and resources to access this serverOff by default in the portal. Adds a rule for 0.0.0.0 that lets any Azure resource connect, including other customers' subscriptions. Import Export Service needs it.
Virtual network firewall ruleAllows traffic from selected subnets (service endpoints).
Private LinkPrivate endpoint for the logical server in a specific virtual network.
Network security perimeterControls public network access to SQL Database; in preview at the time of writing, per Microsoft Learn. Not for SQL Managed Instance.

Authentication

Encryption and data protection

FeatureProtectsKey points
TDE (service-managed)Data at rest: database, backups and logsOn by default for new databases; must be enabled manually for older ones. Built-in server certificate, AES 256 (CBC). Can't encrypt master; tempdb is always encrypted.
TDE with customer-managed keySame, with your keyProtector in Key Vault or Managed HSM; set at server (or instance) level, optionally per database; DEK re-encrypted online when you switch.
Always EncryptedData in use in specific columns, even from DBAsDecrypted only for processing by client applications with access to the key; the key is never exposed to SQL Database or SQL Managed Instance.
Dynamic data maskingQuery results for non-privileged usersData in the database isn't changed. Server admin, Entra admin and db_owner see unmasked data.
Row-Level SecurityRows returned to a userBased on group membership or execution context.
LedgerTamper evidenceCryptographic proof of data integrity.

Customer-managed TDE requirements

Dynamic data masking

Auditing

Auditing writes database events to an Azure storage account, a Log Analytics workspace or Event Hubs. You can use any combination, and logs go to each.

SettingSQL DatabaseSQL Managed Instance
Policy levelsServer (all existing and new databases) or databaseServer audit plus server or database audit specifications
DestinationsStorage, Log Analytics, Event HubsAzure Storage (blob container, URL target)
Default retention0 = unlimited0 = unlimited
Storage authenticationManaged identity (recommended) or storage access keysSAS token credential (T-SQL)
Default action groupsBATCH_COMPLETED_GROUP, SUCCESSFUL_DATABASE_AUTHENTICATION_GROUP, FAILED_DATABASE_AUTHENTICATION_GROUPYou define audit specifications

SQL Managed Instance to blob (T-SQL)

  1. Create a private blob container in a storage account in the same region.
  2. Generate a SAS token (Blob service, start date yesterday) and remove the leading ?.
  3. CREATE CREDENTIAL named after the container URL, identity SHARED ACCESS SIGNATURE, secret = the token.
  4. CREATE SERVER AUDIT ... TO URL (PATH = '<container_url>', RETENTION_DAYS = n); retention default is 0.
  5. Create a server audit specification or database audit specification. Renew the SAS before it expires.

Defender for Databases

The Databases plan in Defender for Cloud bundles four plans, each priced separately. Switching Databases to On in Environment settings activates all four and protects all supported databases in the subscription; Select types lets you pick.

PlanCoversNotes
Defender for Azure SQL DatabasesSingle databases and elastic pools, managed instances, Synapse dedicated SQL pools (and SQL Server products)Vulnerability assessment and Advanced Threat Protection. Needs SQL security manager or a database or server admin role. Subscription level recommended; per-node pricing, one charge per server or instance.
Defender for SQL Servers on MachinesSQL Server on VMs and Azure Arc SQL Server instancesSubscription Owner to deploy; service account in sysadmin; outbound TCP 443 to *.<region>.arcdataservices.com. Moving to a new agent architecture.
Defender for Open-Source Relational DatabasesAzure Database for PostgreSQL and MySQL Flexible Server (all pricing tiers); Amazon RDSPaaS only; not Azure Arc-enabled machines.
Defender for Azure Cosmos DBCosmos DB accountsSubscription or single account (portal, PowerShell, CLI, ARM template, Policy).

CLI and PowerShell

TaskAzure CLIPowerShell
Create a server-level firewall ruleaz sql server firewall-rule create --resource-group myResourceGroup --server $servername -n ContosoIPRange --start-ip-address 192.168.1.0 --end-ip-address 192.168.1.255New-AzSqlServerFirewallRule -ResourceGroupName "myResourceGroup" -ServerName $servername -FirewallRuleName "ContosoIPRange" -StartIpAddress "192.168.1.0" -EndIpAddress "192.168.1.255"
Create a server-level firewall rule (T-SQL)-EXECUTE sp_set_firewall_rule @name = N'ContosoFirewallRule', @start_ip_address = '192.168.1.1', @end_ip_address = '192.168.1.10'
Enable SQL Database auditing with managed identityaz SQL server audit-policy update -g "sampleresourcegroup" -n "sampleauditingtestserver" --state Enabled --bsts Enabled --storage-endpoint https://<storageaccountname>.blob.core.windows.net --storage-key '""'Set-AzSqlServerAudit -ResourceGroupName "sampleresourcegroup" -ServerName "sampleauditingtestserver" -BlobStorageTargetState Enabled -StorageAccountResourceId "/subscriptions/<SubscriptionID>/resourcegroups/sampleresourcegroup/providers/Microsoft.Storage/storageAccounts/auditingteststorageacc" -UseIdentity True

Exam Tips

Tick each tip once you can answer it without looking.

“Add an IP rule for one database only, from the portal” → Not possible: database-level rules are T-SQL only. Trap: Server-level rules work in the portal but apply to every database on the server.

“Firewall check order for an internet client” → Database-level rules, then server-level rules. Trap: If neither matches the connection fails.

“Allow Azure services and resources to access this server” → Adds a 0.0.0.0 rule: any Azure resource, even other customers' subscriptions. Trap: It isn't limited to your subscription; prefer VNet rules or private endpoints.

“Firewall rules or network security perimeter for SQL Managed Instance” → Don't apply to Managed Instance. Trap: See the managed instance connectivity configuration instead.

“TDE on a new Azure SQL database” → On by default; older databases must be enabled manually. Trap: TDE can't encrypt master; tempdb is always encrypted.

“Control key rotation and revocation for TDE with no downtime” → Customer-managed TDE (BYOK) with the protector in Key Vault. Trap: Switching only re-encrypts the DEK, online.

“Server identity role for TDE protector (Key Vault RBAC)” → Key Vault Crypto Service Encryption User. Trap: Managed HSM uses Managed HSM Crypto User; access policy model needs get, wrapKey, unwrapKey.

“Key Vault for TDE must have” → Soft delete and purge protection on. Trap: Behind a firewall, allow trusted Microsoft services to bypass it unless private endpoints are used.

“Hide column data even from privileged DBAs” → Always Encrypted. Trap: Dynamic data masking leaves db_owner, server admin and Entra admin unmasked.

“Server auditing on plus database auditing on” → Database is audited twice in parallel. Trap: Database auditing doesn't override the server policy.

“Auditing to a storage account behind a firewall” → General-purpose v2 account. Trap: General-purpose v1 and Blob Storage accounts must be upgraded.

“Auditing to Log Analytics suddenly stops, no error” → Diagnostic setting SQLSecurityAuditEvents was deleted. Trap: Alert on deletion of diagnostic settings.

“Configure SQL auditing with CLI using managed identity” → Pre-assign Storage Blob Data Contributor to the server's managed identity. Trap: The portal does this automatically; scripts and templates don't.

“Failed Entra logins missing from audit log” → Look in the Entra admin center. Trap: With Entra authentication, failed login records don't appear in the SQL audit log; the Entra admin center logs them.

“Managed Instance audit credential rejected” → SAS token must not start with ?. Trap: Credential name is the container URL.

“Enable all database Defender plans at once” → Databases plan On for the subscription. Trap: Each plan is priced separately.

“Defender for SQL on machines deployment role” → Subscription Owner (includes Azure Policy). Trap: The service account must be sysadmin on each SQL instance.

Sources

Checked against Microsoft Learn on November 13, 2026.

← Storage SecurityNetwork Controls & VPN →