You need to create a custom role that explicitly denies CRUD operations on the Cosmos DB account. Azure RBAC doesn't have explicit deny permissions, but you can create a custom role with limited access and assign it to the user.
{
"Name": "NoAccessToCosmosDB",
"IsCustom": true,
"Description": "Role to deny CRUD operations on Cosmos DB",
"Actions": [],
"NotActions": [
"Microsoft.DocumentDB/databaseAccounts/read",
"Microsoft.DocumentDB/databaseAccounts/listKeys/action",
"Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/read",
"Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/documents/*"
],
"AssignableScopes": ["/subscriptions/{subscription-id}"]
}
Replace {subscription-id}
with your actual subscription ID.
Use Azure CLI or Azure PowerShell to create the custom role.
Using Azure CLI:
az role definition create --role-definition customRole.json
Using Azure PowerShell:
New-AzRoleDefinition -InputFile customRole.json
Assign the custom role to the user who is the Subscription Owner.
Using Azure CLI:
az role assignment create --assignee user@example.com --role "NoAccessToCosmosDB" --scope /subscriptions/{subscription-id}
Using Azure PowerShell:
New-AzRoleAssignment -ObjectId (Get-AzADUser -UserPrincipalName user@example.com).Id -RoleDefinitionName "NoAccessToCosmosDB" -Scope /subscriptions/{subscription-id}