Most Azure database compromises do not need an exploit: they start with a SQL login password, a Cosmos DB account key or a firewall rule that lets the whole of Azure in. Azure SQL Database, Azure SQL Managed Instance and Azure Cosmos DB all give you strong identity controls, but every one of them also ships with a shared secret path (SQL authentication, account keys) and a public endpoint that stay open until someone closes them. This guide covers how authentication and authorisation work in both services, which roles can change security settings, how applications and integrations should connect, what to log, and the hardening baseline we would expect in production. It is for cloud security engineers, DBAs and platform teams. For the general database identity model across engines, see the Database Credential and Access Security Guide; this page goes into the Azure specifics.
This is an independent guide from NHI Mgmt Group, based on Microsoft's public documentation as of November 2026. It is not sponsored or reviewed by Microsoft. Product features change, so confirm settings against Microsoft's current documentation.
Key takeaways
- Turn off the shared secrets. Microsoft Entra-only authentication disables SQL authentication, including the server admin login, and
disableLocalAuthdisables Cosmos DB account keys. Nothing else reduces risk as much. - "Allow Azure services" is not your tenant. The 0.0.0.0 firewall rule on Azure SQL and the "Accept connections from within public Azure datacenters" option on Cosmos DB admit traffic from other customers' subscriptions too.
- Control plane and data plane are separate. Azure RBAC on the resource does not equal access to the data, and data access through keys bypasses Azure RBAC entirely. Govern both.
- Applications should use managed identities. Managed identities remove connection-string passwords and keys from code, configuration and pipelines. See the Azure Managed Identities Security Guide.
- Logs only help if they are switched on and protected. Azure SQL auditing and Cosmos DB
ControlPlaneRequestsdiagnostics are not complete by default, and audit storage needs the same least privilege as the database.
How identity and access work in Azure SQL and Cosmos DB
Both services have two layers. The control plane is Azure Resource Manager: creating servers and accounts, changing firewall rules, reading keys, setting the Entra admin. It is governed by Azure RBAC and logged in the Azure Activity log. The data plane is the database endpoint itself: running queries, reading and writing items. Each service authenticates the data plane differently.
Azure SQL Database and SQL Managed Instance
- SQL authentication: contained database users or server logins with passwords, including the server administrator created at provisioning. These local secrets bypass Entra MFA, Conditional Access and account disablement.
- Microsoft Entra authentication: users, groups, service principals and managed identities are mapped to database users (
CREATE USER ... FROM EXTERNAL PROVIDER). A Microsoft Entra admin must be set on the server or instance; it is the Entra equivalent of the server admin. - Microsoft Entra-only authentication: a server or instance setting that disables SQL authentication completely, including connections from the SQL server administrator, logins and users. Microsoft documents that the Entra admin must be set before you enable it, and that it can be enforced at creation with Azure Policy. The portal may still show a system-generated server administrator name after it is enabled; that account cannot sign in.
- Authorisation inside the database: standard database roles and permissions (
db_datareader,db_owner, granular GRANTs). Microsoft notes that db_owner permissions cannot be restricted, so a db_owner can change settings such as TDE and can read all user data.
Azure Cosmos DB
- Account keys: each account has primary and secondary keys that grant full read, write and delete access to all data in the account, plus a read-only pair. Keys are long-lived and not tied to an identity, so key-based requests cannot be attributed.
- Resource tokens: scoped tokens issued by your own backend from permission resources, used by older client-side patterns. They still depend on the backend holding a key.
- Native data plane RBAC (Microsoft Entra): role definitions and assignments inside the account. For the NoSQL API the built-in roles are Cosmos DB Built-in Data Reader and Cosmos DB Built-in Data Contributor (role ID
00000000-0000-0000-0000-000000000002). Assignments are scoped to the account (/), a database (/dbs/<database>) or a container (/dbs/<database>/colls/<container>). Microsoft states that data plane RBAC cannot be managed in the Azure portal: use the CLI (az cosmosdb sql role assignment create), PowerShell or Bicep. - Disabling keys: set
disableLocalAuthtotrueon the account (portal: Key-based authentication set to Disable at creation). After that, key-based connections fail and only Entra identities with data plane roles can read or write data.
| Question | Azure SQL | Cosmos DB (NoSQL API) |
|---|---|---|
| Shared secret path | SQL logins and contained users with passwords, server admin | Primary and secondary keys, read-only keys, connection strings |
| Setting that removes it | Microsoft Entra-only authentication (az sql server ad-only-auth enable) | disableLocalAuth: true |
| Identity-based data access | Entra users, groups, service principals, managed identities mapped to database users | Data plane role assignments to Entra principals |
| Where data permissions live | Inside the database (T-SQL roles and GRANTs) | Inside the account (Cosmos role definitions and assignments, not Azure IAM) |
| Control plane log | Azure Activity log | Azure Activity log plus ControlPlaneRequests diagnostic category |
| Data plane log | Azure SQL auditing | Diagnostic settings resource logs |
Admin roles and privileged access
The privileged surface is wider than the Owner role. Anyone who can read keys, change the firewall or change the Entra admin can reach the data, so treat these as privileged roles and put them behind Privileged Identity Management (PIM) or an equivalent just-in-time process. See the Azure RBAC and Service Principals Guide.
| Role or permission | What it can do | Why it matters |
|---|---|---|
| Owner, Contributor on the subscription or resource group | Change any server or account setting, read Cosmos keys | Indirect data access through key retrieval or firewall change |
| SQL Server Contributor, SQL Managed Instance Contributor | Manage servers and instances | Microsoft documents that these roles cannot enable or disable Entra-only authentication, which is useful for separation of duties |
| SQL Security Manager | Manage security policies, including Microsoft.Sql/servers/azureADOnlyAuthentications/* | Can switch SQL authentication back on: restrict and alert |
| Microsoft Entra admin of a SQL server | Full administrative rights in every database on the server | Assign a group, not an individual; keep membership small and reviewed |
| db_owner | Everything in the database, including reading all data | Cannot be restricted; use Always Encrypted with role separation for data DBAs must not see |
Cosmos DB Operator (230815da-be43-4aae-9cb4-875f7bd000aa) | Manage accounts, but its notActions exclude listKeys, listConnectionStrings, readonlyKeys and regenerateKey | The right role for platform operators who should not touch data |
Any role with Microsoft.DocumentDB/databaseAccounts/listKeys/action | Retrieve the primary key | Equivalent to full data access while keys are enabled |
Cosmos data plane role assignment at scope / | Data access across every database and container | Scope assignments to the container where possible |
- Separate data owner and security owner: Microsoft recommends Transparent Data Encryption (TDE) with customer-managed keys in Azure Key Vault so that the key holder can revoke access independently of the database administrator. See the Azure Key Vault Security Guide.
- Break-glass: with Entra-only authentication there is no SQL password fallback. Keep a documented emergency path through a dedicated Entra emergency access account or group that can be made Entra admin, and test it.
Integrations, API tokens and service accounts
Applications, ETL jobs, reporting tools and AI agents are where database credentials end up in plain text. The target: no workload holds a database password or account key.
- Managed identities first: Microsoft's Azure SQL security playbook recommends system-assigned or user-assigned managed identities for applications in App Service, Functions, AKS and VMs. For Cosmos DB, grant the managed identity a data plane role at the narrowest scope. See the Azure Managed Identities Security Guide.
- Service principals for workloads outside Azure: prefer certificate or workload identity federation over client secrets. See the Azure Entra Client Secrets Security Guide.
- Legacy SQL authentication: where an application cannot use Entra, keep the login per application, store the password in Key Vault, rotate it, grant only the schema permissions it needs, and track it as an exception with an owner and end date.
- Cosmos keys during migration: if keys are still in use, rotate them on a schedule using the documented pattern: move clients to the secondary key, regenerate the primary, move back, then regenerate the secondary. Never ship a key in browser or mobile code.
- Block key-based schema changes: set
disableKeyBasedMetadataWriteAccesstotrueso key holders cannot create or change databases and containers through the data endpoint. Changes then go through Azure Resource Manager, the CLI or templates, under Azure RBAC. - Inventory every connection: use the SQL audit log and Cosmos logs to see which principals connect, and record each one as a non-human identity with an owner. See the Non-Human Identity (NHI) Guide.
The provider's platform can also leak keys. In August 2021 Wiz disclosed ChaosDB, a flaw in the Cosmos DB Jupyter Notebook feature that exposed customers' primary keys; Microsoft disabled the feature and told affected customers to regenerate keys. Accounts with keys disabled would have exposed nothing useful.
Logging and detection
What to collect
| Source | How to enable | What it shows |
|---|---|---|
| Azure Activity log | Subscription diagnostic setting to Log Analytics or SIEM | Firewall changes, key listing and regeneration, Entra admin changes, Entra-only toggles, public network access changes |
| Azure SQL auditing | Server-level auditing to Log Analytics, Event Hubs or a storage account | Default action groups BATCH_COMPLETED_GROUP, SUCCESSFUL_DATABASE_AUTHENTICATION_GROUP and FAILED_DATABASE_AUTHENTICATION_GROUP: queries, procedures, successful and failed logins |
| Microsoft Defender for SQL | Defender for Cloud plan per subscription | Advanced Threat Protection alerts (for example SQL injection and anomalous access) and Vulnerability Assessment findings |
Cosmos DB ControlPlaneRequests | Diagnostic setting on the account | Operations such as "Account keys updated" and "Account network settings updated"; join with AzureActivity on the activity ID to find the caller |
| Cosmos DB data plane resource logs | Diagnostic setting on the account | Request-level activity, including 403 responses from the IP firewall |
| Microsoft Defender for Azure Cosmos DB | Defender for Cloud plan | Threat alerts for unusual access to accounts |
Detections worth writing
- Secret path reopened: Entra-only authentication disabled,
disableLocalAuthset to false, or public network access set back to enabled. - Key retrieval:
listKeysorlistConnectionStringson a Cosmos account by anyone other than the expected deployment identity, and any key regeneration outside a change window. - Firewall widening: a 0.0.0.0 rule, a rule wider than a /24 from the internet, or a new rule added outside infrastructure as code.
- Failed login bursts: repeated
FAILED_DATABASE_AUTHENTICATION_GROUPevents from one source, suggesting password spraying. - Bulk reads: unusual result volumes or new client applications reading sensitive tables, mapped to MITRE ATT&CK T1213 Data from Information Repositories and T1530 Data from Cloud Storage.
Protect the audit trail itself. Microsoft notes that access to audit logs depends on permissions in the destination, and supports writing SQL audit records to immutable blob storage. The default storage retention is 0, which means unlimited; set an explicit retention that meets your policy. See the Cloud Logging and Audit Trail Guide.
Hardening baseline
The baseline below maps to the Microsoft cloud security benchmark (MCSB) controls named in the table. Enforce it with Azure Policy at management group scope so new servers and accounts are compliant from creation. See the Microsoft Cloud Security Benchmark Guide and the Azure Policy and Management Groups Guide.
| Area | Azure SQL setting | Cosmos DB setting | MCSB |
|---|---|---|---|
| Authentication | Microsoft Entra-only authentication enabled; Entra admin is a group | disableLocalAuth: true; data plane roles scoped to containers | IM-1, IM-3 |
| Least privilege | No application with db_owner; custom roles per schema | Cosmos DB Operator for platform staff; disableKeyBasedMetadataWriteAccess: true | PA-7 |
| Network exposure | Public network access Disabled with private endpoints, or Selected networks with named IP and VNet rules; no 0.0.0.0 rule | publicNetworkAccess: Disabled with private endpoints, or ipRules and VNet rules; no 0.0.0.0 entry | NS-2 |
| Egress | Outbound firewall rules restricting the server to named storage accounts and SQL servers | n/a | NS-2 |
| Transport | Minimum TLS version 1.2 (TLS 1.0 and 1.1 are retired); TCP 1433 only from approved networks | Minimum TLS enforced; Microsoft recommends TLS 1.3 where clients support it | DP-3 |
| Encryption at rest | TDE on (default for databases created after 2017); customer-managed key in Key Vault where required; nothing sensitive in master, which TDE cannot encrypt | Service-managed encryption by default; customer-managed key where required | DP-4, DP-5 |
| Data in use | Always Encrypted with role separation for columns DBAs must not see | Always Encrypted (client-side) for selected properties | DP-4 |
| Threat detection | Defender for SQL on all subscriptions | Defender for Azure Cosmos DB | LT-1 |
| Logging | Server-level auditing to a central workspace, immutable copy for evidence | ControlPlaneRequests and data plane logs to a central workspace | LT-3 |
| Backup | Long-term retention policy; restore tested | Continuous backup with point-in-time restore; restore tested | BR-1 |
Rolling it out without breaking applications
- Inventory: list every server and account, its public network setting, firewall rules, whether SQL logins or Cosmos keys are in use, and who connects (from SQL audit and Cosmos logs over at least 30 days).
- Audit-mode policy: assign the built-in Azure Policy definitions for Entra-only authentication, public network access and Cosmos local authentication with the Audit effect first, so you see non-compliance without blocking deployments.
- Migrate identities: move each application to a managed identity, test in a non-production copy, then remove its SQL login or key usage. For Cosmos, deploy the role assignment before changing the SDK client to token credentials.
- Close the network: add private endpoints and private DNS, confirm clients resolve the private address, then disable public access. Allow up to 15 minutes for Cosmos firewall changes to propagate.
- Switch off secrets: enable Entra-only authentication and
disableLocalAuthper environment, starting with development. Watch failed authentications for a week. - Enforce: change policy effects to Deny for new resources once exceptions are recorded.
- Rollback: Entra-only authentication and
disableLocalAuthcan be reverted by a suitably privileged role if a forgotten client breaks; time-box any rollback and alert on it. Note that the Azure SQL minimum TLS setting cannot be returned to the default once a version is enforced.
Small team or large estate
- Small team, a handful of databases: Entra-only authentication, managed identities, a private endpoint or tight IP rules and Defender plans give most of the value. Manual review of the firewall and role assignments each quarter is realistic.
- Large estate: policy-driven enforcement at management group scope, infrastructure as code as the only change path for firewall rules, a central Log Analytics workspace, and automated detection of exceptions. Exceptions need owners and expiry dates or they become permanent.
- Database-level versus server-level firewall rules: Microsoft recommends database-level rules (set through
sp_set_database_firewall_rule) where users need only one database, and server-level rules for administrators or many databases with identical access. Server-level rules admit the source to every database on the server.
Common misconfigurations
- "Allow Azure services and resources to access this server" switched on: the 0.0.0.0 rule admits any Azure resource with outbound connectivity, including resources in other customers' subscriptions. Microsoft's own documentation warns about this. The Cosmos DB "Accept connections from within public Azure datacenters" option has the same effect. Combined with a SQL password or account key, this is internet exposure in practice.
- Entra admin set, SQL authentication still on: teams add Entra users but never enable Entra-only authentication, so the original server admin password, often in a deployment script or wiki, remains a full-access back door.
- Cosmos keys in application settings, pipelines and notebooks: keys copied into App Service settings, CI variables and data science notebooks spread quickly and are rarely rotated. ChaosDB showed that even the provider's platform can leak them.
- Broad data plane scope: every application given Built-in Data Contributor at
/on a shared account, so one compromised workload can read and change every container. - Audit logs in a storage account anyone can read: the account used for SQL audit or Defender Vulnerability Assessment results sits in a resource group where many identities have Contributor, so evidence can be read or deleted.
Framework mapping
| Risk | MITRE ATT&CK | NIST SP 800-53 Rev. 5 | NIST CSF 2.0 |
|---|---|---|---|
| Use of stolen SQL logins, keys or Entra credentials | T1078.004 Cloud Accounts | IA-2, AC-6 | PR.AA-05 |
| Connection strings and keys in files and settings | T1552.001 Credentials In Files | IA-2, SC-28 | PR.DS-01 |
| Bulk data access from the database | T1213 Data from Information Repositories, T1530 Data from Cloud Storage | AC-6, SC-7 | PR.DS-01 |
Practitioner checklist
- Enable Microsoft Entra-only authentication on every Azure SQL server and managed instance, with a group as Entra admin and a tested emergency path.
- Set
disableLocalAuthanddisableKeyBasedMetadataWriteAccessto true on every Cosmos DB account, after moving clients to data plane RBAC. - Remove every 0.0.0.0 firewall entry and set public network access to Disabled where private endpoints exist.
- Move applications to managed identities; record any remaining SQL login or key as a time-limited exception with an owner.
- Give platform operators Cosmos DB Operator rather than Contributor, and alert on any
listKeyscall. - Set minimum TLS 1.2 or higher, after testing old drivers.
- Send Activity log, SQL auditing and Cosmos
ControlPlaneRequeststo a central workspace, with an immutable copy of audit records. - Enable Defender for SQL and Defender for Azure Cosmos DB on all subscriptions that hold data.
- Enforce the baseline with Azure Policy at management group scope, Audit first, then Deny.
- Review data plane role assignments and the Entra admin group membership every quarter.
Standards and references
- Microsoft Learn: Microsoft Entra-only authentication with Azure SQL
- Microsoft Learn: Playbook for addressing common security requirements with Azure SQL Database and Azure SQL Managed Instance
- Microsoft Learn: Azure SQL Database and Azure Synapse IP firewall rules
- Microsoft Learn: Auditing for Azure SQL Database and Azure Synapse Analytics
- Microsoft Learn: Connect to Azure Cosmos DB using role-based access control and Microsoft Entra ID
- Microsoft Learn: Configure IP firewall in Azure Cosmos DB
- Microsoft Learn: How to audit Azure Cosmos DB control plane operations
- Wiz: ChaosDB, how we hacked thousands of Azure customers' databases
Related NHI Mgmt Group resources: Database Credential and Access Security Guide · Azure Managed Identities Security Guide · Microsoft Azure Security Guide · Database Security Guide