An Azure Cosmos DB for NoSQL account has dynamic data masking enabled. The customer container in the cosmicworks database has a masking policy for /emailAddress and /phoneNumber. Two workloads use separate managed identities, and each has a single role assignment scoped to /dbs/cosmicworks/colls/customer. No other role assignments exist.
- Support application: runs point reads and queries. It must receive masked email addresses and phone numbers. It must not create, replace, upsert, patch or delete items.
- Reporting job: reads the container's change feed in latest version mode by using the pull model. It must not create, replace, upsert, patch or delete items.
The exhibit shows the data actions of the available role definitions.
| Role definition | Data actions |
|---|---|
| Cosmos DB Built-in Data Reader | Microsoft.DocumentDB/databaseAccounts/readMetadata, Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/items/read, Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/executeQuery, Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/readChangeFeed |
| Cosmos DB Built-in Data Contributor | Microsoft.DocumentDB/databaseAccounts/readMetadata, Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/*, Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/items/* |
| ContosoCustomRole1 | Microsoft.DocumentDB/databaseAccounts/readMetadata, Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/items/read, Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/executeQuery, Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/readChangeFeed, Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/items/unmask |
Which role definition should you assign to each managed identity?
Assign to the support application's managed identity, and assign to the reporting job's managed identity.
- Blank 1: Cosmos DB Built-in Data Reader (correct answer)
Data Reader allows reads and queries and has no unmask permission, so the support application receives masked values and cannot write. Data Contributor includes unmask through items/* and also grants writes. ContosoCustomRole1 includes items/unmask, so the support application would receive original values.
- Blank 2: ContosoCustomRole1 (correct answer)
On an account with dynamic data masking enabled, the change feed is unavailable without unmask permission. ContosoCustomRole1 adds items/unmask to the read-only Reader actions, so the job can read the change feed without write access. Data Reader has readChangeFeed but no unmask, so the job could not read the change feed. Data Contributor would work for the change feed but grants writes.
When dynamic data masking is enabled, a reader without unmask permission sees masked values. The change feed is unavailable to that reader, in both latest version and all versions and deletes modes, even when readChangeFeed is granted. Data Reader therefore fits the support application but not the reporting job. A custom read-only role with the Reader actions plus items/unmask gives the reporting job change feed access without write permissions. Data Contributor includes unmask but also grants writes, which both workloads must not have.
- Secure an Azure Cosmos DB solution: Configure dynamic data maskingMicrosoft Learn
- Dynamic Data Masking (DDM) - Azure Cosmos DBMicrosoft Learn