An Azure NoSQL database service for app development.
Hello @Gajjala, Vinod Reddy,
To add a user in Azure Cosmos DB (with MongoDB compatibility) and enable Microsoft Entra ID authentication, follow these steps:
- Enable Microsoft Entra ID Authentication: Ensure that Microsoft Entra ID authentication is enabled on your Azure Cosmos DB cluster. This can typically be done through the Azure portal by navigating to your Cosmos DB account and enabling the authentication method in the settings. After enabling, both NativeAuth and MicrosoftEntraID should be listed as enabled methods. 1
- Add Microsoft Entra ID Principals: You can add one or more Microsoft Entra ID principals (users, service principals, or managed identities) as administrator or non-administrator users. For non-administrative users, you can grant them specific roles such as
readWriteorreadAnyDatabase. Administrative users have full privileges, while non-administrative users can be granted either read-write or read-only permissions. 2 - Register the User: Register the Microsoft Entra ID principal on the cluster. This is done by creating an Azure resource of type
Microsoft.DocumentDB/mongoClusters/userswith the naming format<cluster-name>/users/<principal-id>. 3 - Assign Roles: For non-administrative users, you can assign roles like
readWriteAnyDatabasefor full read-write access orreadAnyDatabasefor read-only access. Note that thereadWriteAnyDatabaseandclusterAdminroles must be assigned together for full read-write access. 4 - Connect Using Microsoft Entra ID: Once the user is added and roles are assigned, they can connect to the Azure Cosmos DB cluster using a connection string that includes their Microsoft Entra ID credentials. The connection string format should include the
mongodb+srvscheme and specify the authentication mechanism asMONGODB-OIDC
Connect to Azure DocumentDB using role-based access control and Microsoft Entra ID
If this answers your query, do click Accept Answer and Up-Vote for the same. And, if you have any further query do let us know.