Skip to content

Commit d35fdee

Browse files
Added Azure.Cosmos.EntraID (#3575)
* Added Azure.Cosmos.EntraId * remove selector * Updates --------- Co-authored-by: Bernie White <[email protected]>
1 parent 6b0b782 commit d35fdee

File tree

5 files changed

+284
-0
lines changed

5 files changed

+284
-0
lines changed

docs/changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ See [upgrade notes][1] for helpful information when upgrading from previous vers
3434
- App Configuration:
3535
- Check that replica locations are in allowed regions by @BernieWhite.
3636
[#3441](https://github.com/Azure/PSRule.Rules.Azure/issues/3441)
37+
- Cosmos DB:
38+
- Check that MongoDB vCore clusters use Microsoft Entra ID authentication by @BenjaminEngeset.
39+
[#3369](https://github.com/Azure/PSRule.Rules.Azure/issues/3369)
3740
- Updated rules:
3841
- Application Gateway Policy:
3942
- Updated `Azure.AppGwWAF.RuleGroups` to use Microsoft Default Rule Set instead of legacy OWASP rule set by @BenjaminEngeset.
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
---
2+
reviewed: 2025-11-03
3+
severity: Critical
4+
pillar: Security
5+
category: SE:05 Identity and access management
6+
resource: Cosmos DB
7+
resourceType: Microsoft.DocumentDB/mongoClusters
8+
online version: https://azure.github.io/PSRule.Rules.Azure/en/rules/Azure.Cosmos.MongoEntraID/
9+
---
10+
11+
# MongoDB vCore clusters should use Microsoft Entra ID authentication
12+
13+
## SYNOPSIS
14+
15+
MongoDB vCore clusters should have Microsoft Entra ID authentication enabled.
16+
17+
## DESCRIPTION
18+
19+
MongoDB vCore clusters support multiple authentication modes including native authentication (connection string) and
20+
Microsoft Entra ID authentication.
21+
Native authentication uses MongoDB credentials (username/password) that are embedded in connection strings and
22+
managed locally within the cluster.
23+
24+
Using Microsoft Entra ID authentication provides several security benefits:
25+
26+
- **Centralized identity management** - Single authoritative source for all user identities.
27+
- **MongoDB role-based permissions** - Fine-grained access control using MongoDB's native role system with Entra ID identities.
28+
- **Enhanced security features** - Multi-factor authentication, conditional access, and identity protection.
29+
- **Reduced complexity** - Eliminates the need to manage separate database credentials.
30+
- **Audit and compliance** - Centralized logging and monitoring of authentication events.
31+
32+
Microsoft Entra ID authentication should be enabled to ensure secure and centralized identity management for
33+
MongoDB vCore clusters.
34+
35+
## RECOMMENDATION
36+
37+
Consider enabling Microsoft Entra ID authentication on MongoDB vCore clusters.
38+
39+
## EXAMPLES
40+
41+
### Configure with Azure template
42+
43+
To deploy MongoDB vCore clusters that pass this rule:
44+
45+
- Set the `properties.authConfig.allowedModes` array to include `MicrosoftEntraID`.
46+
47+
For example:
48+
49+
```json
50+
{
51+
"type": "Microsoft.DocumentDB/mongoClusters",
52+
"apiVersion": "2025-04-01-preview",
53+
"name": "[parameters('name')]",
54+
"location": "[parameters('location')]",
55+
"properties": {
56+
"serverVersion": "8.0",
57+
"authConfig": {
58+
"allowedModes": [
59+
"NativeAuth",
60+
"MicrosoftEntraID"
61+
]
62+
},
63+
"compute": {
64+
"tier": "M30"
65+
},
66+
"storage": {
67+
"sizeGb": 128,
68+
"type": "PremiumSSD"
69+
}
70+
}
71+
}
72+
```
73+
74+
### Configure with Bicep
75+
76+
To deploy MongoDB vCore clusters that pass this rule:
77+
78+
- Set the `properties.authConfig.allowedModes` array to include `MicrosoftEntraID`.
79+
80+
For example:
81+
82+
```bicep
83+
resource mongoCluster 'Microsoft.DocumentDB/mongoClusters@2025-04-01-preview' = {
84+
name: name
85+
location: location
86+
properties: {
87+
serverVersion: '8.0'
88+
authConfig: {
89+
allowedModes: [
90+
'NativeAuth'
91+
'MicrosoftEntraID'
92+
]
93+
}
94+
compute: {
95+
tier: 'M30'
96+
}
97+
storage: {
98+
sizeGb: 128
99+
type: 'PremiumSSD'
100+
}
101+
}
102+
}
103+
```
104+
105+
## NOTES
106+
107+
**Important:** For initial deployment, you must include both `NativeAuth` and `MicrosoftEntraID` in the `allowedModes` array.
108+
Deploying with only `MicrosoftEntraID` will cause the deployment to fail as the initial setup process requires native authentication.
109+
After deployment is complete and Entra ID users are configured, you can optionally remove `NativeAuth` for enhanced security.
110+
111+
## LINKS
112+
113+
- [SE:05 Identity and access management](https://learn.microsoft.com/azure/well-architected/security/design-identity-authentication)
114+
- [Security: Level 1](https://learn.microsoft.com/azure/well-architected/security/maturity-model?tabs=level1)
115+
- [Microsoft Entra ID authentication with Azure Cosmos DB for MongoDB vCore](https://learn.microsoft.com/azure/cosmos-db/mongodb/vcore/entra-authentication)
116+
- [Configure Microsoft Entra ID authentication for an Azure Cosmos DB for MongoDB vCore cluster](https://learn.microsoft.com/azure/cosmos-db/mongodb/vcore/how-to-configure-entra-authentication?tabs=portal%2Cazure-portal)
117+
- [Azure security baseline for Azure Cosmos DB](https://learn.microsoft.com/security/benchmark/azure/baselines/azure-cosmos-db-security-baseline)
118+
- [IM-1: Use centralized identity and authentication system](https://learn.microsoft.com/security/benchmark/azure/baselines/azure-cosmos-db-security-baseline#im-1-use-centralized-identity-and-authentication-system)
119+
- [IM-3: Manage application identities securely and automatically](https://learn.microsoft.com/security/benchmark/azure/baselines/azure-cosmos-db-security-baseline#im-3-manage-application-identities-securely-and-automatically)
120+
- [Azure deployment reference](https://learn.microsoft.com/azure/templates/microsoft.documentdb/mongoclusters)

src/PSRule.Rules.Azure/rules/Azure.Cosmos.Rule.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,27 @@ spec:
138138
- field: properties.backupPolicy.continuousModeProperties.tier
139139
hasValue: true
140140

141+
---
142+
# Synopsis: Cosmos DB accounts should use Entra ID authentication.
143+
apiVersion: github.com/microsoft/PSRule/v1
144+
kind: Rule
145+
metadata:
146+
name: Azure.Cosmos.MongoEntraID
147+
ref: AZR-000499
148+
tags:
149+
release: GA
150+
ruleSet: 2025_12
151+
Azure.WAF/pillar: Security
152+
labels:
153+
Azure.MCSB.v1/control: ['IM-1', 'IM-3']
154+
Azure.WAF/maturity: L1
155+
spec:
156+
type:
157+
- Microsoft.DocumentDB/mongoClusters
158+
condition:
159+
field: properties.authConfig.allowedModes[*]
160+
contains: MicrosoftEntraID
161+
141162
#endregion Rules
142163

143164
#region Selectors

tests/PSRule.Rules.Azure.Tests/Azure.Cosmos.Tests.ps1

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,22 @@ Describe 'Azure.Cosmos' -Tag 'Cosmos', 'CosmosDB' {
122122
$ruleResult.Length | Should -Be 3;
123123
$ruleResult.TargetName | Should -BeIn 'nosql-A', 'nosql-B', 'nosql-C';
124124
}
125+
126+
It 'Azure.Cosmos.MongoEntraID' {
127+
$filteredResult = $result | Where-Object { $_.RuleName -eq 'Azure.Cosmos.MongoEntraID' };
128+
129+
# Fail
130+
$ruleResult = @($filteredResult | Where-Object { $_.Outcome -eq 'Fail' });
131+
$ruleResult.Length | Should -Be 1;
132+
$ruleResult.TargetName | Should -BeIn 'mongodb-a';
133+
134+
$ruleResult[0].Reason | Should -Be "Path properties.authConfig.allowedModes[*]: The value 'System.String[]' does not contain any of 'System.String[]'.";
135+
136+
# Pass
137+
$ruleResult = @($filteredResult | Where-Object { $_.Outcome -eq 'Pass' });
138+
$ruleResult.Length | Should -Be 2;
139+
$ruleResult.TargetName | Should -BeIn 'mongodb-b', 'mongodb-c';
140+
}
125141
}
126142

127143
Context 'Resource name - Azure.Cosmos.AccountName' {

tests/PSRule.Rules.Azure.Tests/Resources.Cosmos.json

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,5 +381,129 @@
381381
"SubscriptionId": "00000000-0000-0000-0000-000000000000"
382382
}
383383
]
384+
},
385+
{
386+
"ResourceId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-test/providers/Microsoft.DocumentDB/mongoClusters/mongodb-a",
387+
"Id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-test/providers/Microsoft.DocumentDB/mongoClusters/mongodb-a",
388+
"Location": "East US",
389+
"ResourceName": "mongodb-a",
390+
"Name": "mongodb-a",
391+
"Properties": {
392+
"administrator": {
393+
"userName": "mongoAdmin"
394+
},
395+
"serverVersion": "8.0",
396+
"authConfig": {
397+
"allowedModes": [
398+
"NativeAuth"
399+
]
400+
},
401+
"compute": {
402+
"tier": "M30"
403+
},
404+
"storage": {
405+
"sizeGb": 128,
406+
"type": "PremiumSSD"
407+
},
408+
"sharding": {
409+
"shardCount": 1
410+
},
411+
"highAvailability": {
412+
"targetMode": "Disabled"
413+
},
414+
"backup": {},
415+
"publicNetworkAccess": "Enabled",
416+
"dataApi": {
417+
"mode": "Disabled"
418+
},
419+
"createMode": "Default"
420+
},
421+
"ResourceGroupName": "rg-test",
422+
"Type": "Microsoft.DocumentDB/mongoClusters",
423+
"ResourceType": "Microsoft.DocumentDB/mongoClusters",
424+
"Tags": null,
425+
"SubscriptionId": "00000000-0000-0000-0000-000000000000"
426+
},
427+
{
428+
"ResourceId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-test/providers/Microsoft.DocumentDB/mongoClusters/mongodb-b",
429+
"Id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-test/providers/Microsoft.DocumentDB/mongoClusters/mongodb-b",
430+
"Location": "East US",
431+
"ResourceName": "mongodb-b",
432+
"Name": "mongodb-b",
433+
"Properties": {
434+
"administrator": {
435+
"userName": "mongoAdmin"
436+
},
437+
"serverVersion": "8.0",
438+
"authConfig": {
439+
"allowedModes": [
440+
"NativeAuth",
441+
"MicrosoftEntraID"
442+
]
443+
},
444+
"compute": {
445+
"tier": "M40"
446+
},
447+
"storage": {
448+
"sizeGb": 256,
449+
"type": "PremiumSSD"
450+
},
451+
"sharding": {
452+
"shardCount": 2
453+
},
454+
"highAvailability": {
455+
"targetMode": "SameZone"
456+
},
457+
"backup": {},
458+
"publicNetworkAccess": "Disabled",
459+
"dataApi": {
460+
"mode": "Enabled"
461+
},
462+
"createMode": "Default"
463+
},
464+
"ResourceGroupName": "rg-test",
465+
"Type": "Microsoft.DocumentDB/mongoClusters",
466+
"ResourceType": "Microsoft.DocumentDB/mongoClusters",
467+
"Tags": null,
468+
"SubscriptionId": "00000000-0000-0000-0000-000000000000"
469+
},
470+
{
471+
"ResourceId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-test/providers/Microsoft.DocumentDB/mongoClusters/mongodb-c",
472+
"Id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-test/providers/Microsoft.DocumentDB/mongoClusters/mongodb-c",
473+
"Location": "East US",
474+
"ResourceName": "mongodb-c",
475+
"Name": "mongodb-c",
476+
"Properties": {
477+
"serverVersion": "8.0",
478+
"authConfig": {
479+
"allowedModes": [
480+
"MicrosoftEntraID"
481+
]
482+
},
483+
"compute": {
484+
"tier": "M50"
485+
},
486+
"storage": {
487+
"sizeGb": 512,
488+
"type": "PremiumSSD"
489+
},
490+
"sharding": {
491+
"shardCount": 3
492+
},
493+
"highAvailability": {
494+
"targetMode": "ZoneRedundantPreferred"
495+
},
496+
"backup": {},
497+
"publicNetworkAccess": "Disabled",
498+
"dataApi": {
499+
"mode": "Disabled"
500+
},
501+
"createMode": "Default"
502+
},
503+
"ResourceGroupName": "rg-test",
504+
"Type": "Microsoft.DocumentDB/mongoClusters",
505+
"ResourceType": "Microsoft.DocumentDB/mongoClusters",
506+
"Tags": null,
507+
"SubscriptionId": "00000000-0000-0000-0000-000000000000"
384508
}
385509
]

0 commit comments

Comments
 (0)