Join our Newsletter — 33% off our NHI Course
Home› Guides› Azure SQL and Cosmos DB Security Guide: Entra-only…
Guide Cloud Security

Azure SQL and Cosmos DB Security Guide: Entra-only authentication, network isolation and key control

PDF for newsletter subscribers · free to read online

← All guides
By NHI Mgmt Group, edited by Lalit Choda Updated 8 November 2026 16 min read
On this page

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 disableLocalAuth disables 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 ControlPlaneRequests diagnostics 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 disableLocalAuth to true on 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.
QuestionAzure SQLCosmos DB (NoSQL API)
Shared secret pathSQL logins and contained users with passwords, server adminPrimary and secondary keys, read-only keys, connection strings
Setting that removes itMicrosoft Entra-only authentication (az sql server ad-only-auth enable)disableLocalAuth: true
Identity-based data accessEntra users, groups, service principals, managed identities mapped to database usersData plane role assignments to Entra principals
Where data permissions liveInside the database (T-SQL roles and GRANTs)Inside the account (Cosmos role definitions and assignments, not Azure IAM)
Control plane logAzure Activity logAzure Activity log plus ControlPlaneRequests diagnostic category
Data plane logAzure SQL auditingDiagnostic 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 permissionWhat it can doWhy it matters
Owner, Contributor on the subscription or resource groupChange any server or account setting, read Cosmos keysIndirect data access through key retrieval or firewall change
SQL Server Contributor, SQL Managed Instance ContributorManage servers and instancesMicrosoft documents that these roles cannot enable or disable Entra-only authentication, which is useful for separation of duties
SQL Security ManagerManage security policies, including Microsoft.Sql/servers/azureADOnlyAuthentications/*Can switch SQL authentication back on: restrict and alert
Microsoft Entra admin of a SQL serverFull administrative rights in every database on the serverAssign a group, not an individual; keep membership small and reviewed
db_ownerEverything in the database, including reading all dataCannot 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 regenerateKeyThe right role for platform operators who should not touch data
Any role with Microsoft.DocumentDB/databaseAccounts/listKeys/actionRetrieve the primary keyEquivalent to full data access while keys are enabled
Cosmos data plane role assignment at scope /Data access across every database and containerScope 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 disableKeyBasedMetadataWriteAccess to true so 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

SourceHow to enableWhat it shows
Azure Activity logSubscription diagnostic setting to Log Analytics or SIEMFirewall changes, key listing and regeneration, Entra admin changes, Entra-only toggles, public network access changes
Azure SQL auditingServer-level auditing to Log Analytics, Event Hubs or a storage accountDefault action groups BATCH_COMPLETED_GROUP, SUCCESSFUL_DATABASE_AUTHENTICATION_GROUP and FAILED_DATABASE_AUTHENTICATION_GROUP: queries, procedures, successful and failed logins
Microsoft Defender for SQLDefender for Cloud plan per subscriptionAdvanced Threat Protection alerts (for example SQL injection and anomalous access) and Vulnerability Assessment findings
Cosmos DB ControlPlaneRequestsDiagnostic setting on the accountOperations 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 logsDiagnostic setting on the accountRequest-level activity, including 403 responses from the IP firewall
Microsoft Defender for Azure Cosmos DBDefender for Cloud planThreat alerts for unusual access to accounts

Detections worth writing

  • Secret path reopened: Entra-only authentication disabled, disableLocalAuth set to false, or public network access set back to enabled.
  • Key retrieval: listKeys or listConnectionStrings on 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_GROUP events 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.

AreaAzure SQL settingCosmos DB settingMCSB
AuthenticationMicrosoft Entra-only authentication enabled; Entra admin is a groupdisableLocalAuth: true; data plane roles scoped to containersIM-1, IM-3
Least privilegeNo application with db_owner; custom roles per schemaCosmos DB Operator for platform staff; disableKeyBasedMetadataWriteAccess: truePA-7
Network exposurePublic network access Disabled with private endpoints, or Selected networks with named IP and VNet rules; no 0.0.0.0 rulepublicNetworkAccess: Disabled with private endpoints, or ipRules and VNet rules; no 0.0.0.0 entryNS-2
EgressOutbound firewall rules restricting the server to named storage accounts and SQL serversn/aNS-2
TransportMinimum TLS version 1.2 (TLS 1.0 and 1.1 are retired); TCP 1433 only from approved networksMinimum TLS enforced; Microsoft recommends TLS 1.3 where clients support itDP-3
Encryption at restTDE on (default for databases created after 2017); customer-managed key in Key Vault where required; nothing sensitive in master, which TDE cannot encryptService-managed encryption by default; customer-managed key where requiredDP-4, DP-5
Data in useAlways Encrypted with role separation for columns DBAs must not seeAlways Encrypted (client-side) for selected propertiesDP-4
Threat detectionDefender for SQL on all subscriptionsDefender for Azure Cosmos DBLT-1
LoggingServer-level auditing to a central workspace, immutable copy for evidenceControlPlaneRequests and data plane logs to a central workspaceLT-3
BackupLong-term retention policy; restore testedContinuous backup with point-in-time restore; restore testedBR-1

Rolling it out without breaking applications

  1. 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).
  2. 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.
  3. 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.
  4. 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.
  5. Switch off secrets: enable Entra-only authentication and disableLocalAuth per environment, starting with development. Watch failed authentications for a week.
  6. Enforce: change policy effects to Deny for new resources once exceptions are recorded.
  7. Rollback: Entra-only authentication and disableLocalAuth can 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

RiskMITRE ATT&CKNIST SP 800-53 Rev. 5NIST CSF 2.0
Use of stolen SQL logins, keys or Entra credentialsT1078.004 Cloud AccountsIA-2, AC-6PR.AA-05
Connection strings and keys in files and settingsT1552.001 Credentials In FilesIA-2, SC-28PR.DS-01
Bulk data access from the databaseT1213 Data from Information Repositories, T1530 Data from Cloud StorageAC-6, SC-7PR.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 disableLocalAuth and disableKeyBasedMetadataWriteAccess to 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 listKeys call.
  • Set minimum TLS 1.2 or higher, after testing old drivers.
  • Send Activity log, SQL auditing and Cosmos ControlPlaneRequests to 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

Related NHI Mgmt Group resources: Database Credential and Access Security Guide · Azure Managed Identities Security Guide · Microsoft Azure Security Guide · Database Security Guide

PDF for subscribers

Take this guide with you

Every section, table and checklist in one PDF, with links to the sources and related guides. Subscribe to our weekly NHI & AI Identity Journal and we’ll email you a download link.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

NHIMG Editorial Note
Researched and written by the NHI Mgmt Group editorial team using AI tools, under the editorial direction of Lalit Choda. Facts are drawn from the sources listed on this page and checked by our automated quality process. Last updated 8 November 2026. Spotted an error? Use our contact page.
NHI Mgmt Group, the independent authority on Non-Human Identity, IAM and Agentic AI security. nhimg.org

PDF Downloads for Newsletter Subscribers

Get the guide

Enter your details and we’ll email you a download link.

The full guide is free to read online. The PDF is a thank you for subscribing.

Fill in all fields marked * and tick the PDF box to continue.