Skip to content

Commit 233b3d4

Browse files
authored
Relax Azure.Cognitive.ManagedIdentity to required configurations Azure#2559 (Azure#2626)
1 parent 30658c3 commit 233b3d4

11 files changed

+645
-593
lines changed

.vscode/settings.json

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
"DEPLOYIFNOTEXISTS",
6969
"DISPLAYNAME",
7070
"endregion",
71+
"Entra",
7172
"exfiltration",
7273
"failover",
7374
"GREATEROREQUAL",

docs/CHANGELOG-v1.md

+2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ What's changed since v1.32.1:
4040
- Added option for excluding subnets to `Azure.VNET.UseNSGs` by @BernieWhite.
4141
[#2572](https://github.com/Azure/PSRule.Rules.Azure/issues/2572)
4242
- To add a subnet exclusion, set the `AZURE_VNET_SUBNET_EXCLUDED_FROM_NSG` option.
43+
- Relax `Azure.Cognitive.ManagedIdentity` to required configurations by @BernieWhite.
44+
[#2559](https://github.com/Azure/PSRule.Rules.Azure/issues/2559)
4345
- Engineering:
4446
- Bump xunit to v2.6.4.
4547
[#2618](https://github.com/Azure/PSRule.Rules.Azure/pull/2618)

docs/en/rules/Azure.Cognitive.ManagedIdentity.md

+14-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
2-
reviewed: 2023-10-01
2+
reviewed: 2024-01-03
33
severity: Important
44
pillar: Security
5-
category: Authentication
5+
category: SE:05 Identity and access management
66
resource: Cognitive Services
77
online version: https://azure.github.io/PSRule.Rules.Azure/en/rules/Azure.Cognitive.ManagedIdentity/
88
---
@@ -22,7 +22,7 @@ Using Azure managed identities have the following benefits:
2222

2323
- You don't need to store or manage credentials.
2424
Azure automatically generates tokens and performs rotation.
25-
- You can use managed identities to authenticate to any Azure service that supports Azure AD authentication.
25+
- You can use managed identities to authenticate to any Azure service that supports Entra ID (previously Azure AD) authentication.
2626
- Managed identities can be used without any additional cost.
2727

2828
## RECOMMENDATION
@@ -52,7 +52,7 @@ For example:
5252
"sku": {
5353
"name": "S0"
5454
},
55-
"kind": "CognitiveServices",
55+
"kind": "TextAnalytics",
5656
"properties": {
5757
"publicNetworkAccess": "Disabled",
5858
"networkAcls": {
@@ -73,7 +73,7 @@ To deploy accounts that pass this rule:
7373
For example:
7474

7575
```bicep
76-
resource account 'Microsoft.CognitiveServices/accounts@2023-05-01' = {
76+
resource language 'Microsoft.CognitiveServices/accounts@2023-05-01' = {
7777
name: name
7878
location: location
7979
identity: {
@@ -82,7 +82,7 @@ resource account 'Microsoft.CognitiveServices/accounts@2023-05-01' = {
8282
sku: {
8383
name: 'S0'
8484
}
85-
kind: 'CognitiveServices'
85+
kind: 'TextAnalytics'
8686
properties: {
8787
publicNetworkAccess: 'Disabled'
8888
networkAcls: {
@@ -101,9 +101,16 @@ To address this issue at runtime use the following policies:
101101
/providers/Microsoft.Authorization/policyDefinitions/fe3fd216-4f83-4fc1-8984-2bbec80a3418
102102
```
103103

104+
## NOTES
105+
106+
Configuration of additional Azure resources is not required for all Cognitive Services.
107+
This rule will run for the following Cognitive Services:
108+
109+
- `TextAnalytics` - Language service.
110+
104111
## LINKS
105112

106-
- [Use identity-based authentication](https://learn.microsoft.com/azure/well-architected/security/design-identity-authentication#use-identity-based-authentication)
113+
- [SE:05 Identity and access management](https://learn.microsoft.com/azure/well-architected/security/identity-access#resource-identity)
107114
- [Azure Policy built-in policy definitions for Azure AI services](https://learn.microsoft.com/azure/ai-services/policy-reference)
108115
- [IM-1: Use centralized identity and authentication system](https://learn.microsoft.com/security/benchmark/azure/baselines/cognitive-services-security-baseline#im-1-use-centralized-identity-and-authentication-system)
109116
- [IM-3: Manage application identities securely and automatically](https://learn.microsoft.com/security/benchmark/azure/baselines/cognitive-services-security-baseline#im-3-manage-application-identities-securely-and-automatically)

docs/examples-cognitive.bicep

+19-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,25 @@ param name string
99
@description('The location resources will be deployed.')
1010
param location string = resourceGroup().location
1111

12-
// An example multi-service cognitive services account
12+
// An example multi-service cognitive services account.
1313
resource account 'Microsoft.CognitiveServices/accounts@2023-05-01' = {
14+
name: name
15+
location: location
16+
sku: {
17+
name: 'S0'
18+
}
19+
kind: 'CognitiveServices'
20+
properties: {
21+
publicNetworkAccess: 'Disabled'
22+
networkAcls: {
23+
defaultAction: 'Deny'
24+
}
25+
disableLocalAuth: true
26+
}
27+
}
28+
29+
// An example of the language services account.
30+
resource language 'Microsoft.CognitiveServices/accounts@2023-05-01' = {
1431
name: name
1532
location: location
1633
identity: {
@@ -19,7 +36,7 @@ resource account 'Microsoft.CognitiveServices/accounts@2023-05-01' = {
1936
sku: {
2037
name: 'S0'
2138
}
22-
kind: 'CognitiveServices'
39+
kind: 'TextAnalytics'
2340
properties: {
2441
publicNetworkAccess: 'Disabled'
2542
networkAcls: {

docs/examples-cognitive.json

+20-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"metadata": {
55
"_generator": {
66
"name": "bicep",
7-
"version": "0.21.1.54444",
8-
"templateHash": "17850178672994683728"
7+
"version": "0.24.24.22086",
8+
"templateHash": "4359857000491870165"
99
}
1010
},
1111
"parameters": {
@@ -24,6 +24,23 @@
2424
}
2525
},
2626
"resources": [
27+
{
28+
"type": "Microsoft.CognitiveServices/accounts",
29+
"apiVersion": "2023-05-01",
30+
"name": "[parameters('name')]",
31+
"location": "[parameters('location')]",
32+
"sku": {
33+
"name": "S0"
34+
},
35+
"kind": "CognitiveServices",
36+
"properties": {
37+
"publicNetworkAccess": "Disabled",
38+
"networkAcls": {
39+
"defaultAction": "Deny"
40+
},
41+
"disableLocalAuth": true
42+
}
43+
},
2744
{
2845
"type": "Microsoft.CognitiveServices/accounts",
2946
"apiVersion": "2023-05-01",
@@ -35,7 +52,7 @@
3552
"sku": {
3653
"name": "S0"
3754
},
38-
"kind": "CognitiveServices",
55+
"kind": "TextAnalytics",
3956
"properties": {
4057
"publicNetworkAccess": "Disabled",
4158
"networkAcls": {

pipeline.build.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ task BuildRuleDocs Build, Dependencies, {
409409
Recommendation = $_.Info.Recommendation
410410
Pillar = $_.Tag.'Azure.WAF/pillar'
411411
Control = $_.Tag.'Azure.MCSB.v1/control'
412-
Source = "https://github.com/Azure/PSRule.Rules.Azure/blob/main/src/PSRule.Rules.Azure/rules/$(($_.Source.Path -split '/')[-1])"
412+
Source = "https://github.com/Azure/PSRule.Rules.Azure/blob/main/src/PSRule.Rules.Azure/rules/$(($_.Source.Path -split '/', '\')[-1])"
413413
}
414414
}
415415
$metadata | ConvertTo-Json -Depth 5 | Set-Content -Path ./docs/es/rules/metadata.json -Force;

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,17 @@ metadata:
4040
tags:
4141
release: GA
4242
ruleSet: 2022_09
43-
Azure.WAF/pillar: 'Security'
43+
Azure.WAF/pillar: Security
4444
labels:
4545
Azure.MCSB.v1/control: [ 'IM-1', 'IM-3' ]
4646
Azure.Policy/id: /providers/Microsoft.Authorization/policyDefinitions/fe3fd216-4f83-4fc1-8984-2bbec80a3418
4747
spec:
4848
type:
4949
- Microsoft.CognitiveServices/accounts
50+
where:
51+
field: kind
52+
in:
53+
- TextAnalytics
5054
condition:
5155
field: Identity.Type
5256
in:

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

+18-6
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Describe 'Azure.Cognitive' -Tag 'Cognitive' {
3333
ErrorAction = 'Stop'
3434
}
3535
$dataPath = Join-Path -Path $here -ChildPath 'Resources.Cognitive.json';
36-
$result = Invoke-PSRule @invokeParams -InputPath $dataPath;
36+
$result = Invoke-PSRule @invokeParams -InputPath $dataPath -Outcome All;
3737
}
3838

3939
It 'Azure.Cognitive.PublicAccess' {
@@ -58,14 +58,20 @@ Describe 'Azure.Cognitive' -Tag 'Cognitive' {
5858
# Fail
5959
$ruleResult = @($filteredResult | Where-Object { $_.Outcome -eq 'Fail' });
6060
$ruleResult | Should -Not -BeNullOrEmpty;
61-
$ruleResult.Length | Should -Be 2;
62-
$ruleResult.TargetName | Should -BeIn 'luis-A', 'luis-A-authoring';
61+
$ruleResult.Length | Should -Be 1;
62+
$ruleResult.TargetName | Should -BeIn 'textanalytics-A';
6363

6464
# Pass
6565
$ruleResult = @($filteredResult | Where-Object { $_.Outcome -eq 'Pass' });
6666
$ruleResult | Should -Not -BeNullOrEmpty;
67+
$ruleResult.Length | Should -Be 1;
68+
$ruleResult.TargetName | Should -BeIn 'textanalytics-B';
69+
70+
# Fail
71+
$ruleResult = @($filteredResult | Where-Object { $_.Outcome -eq 'None' });
72+
$ruleResult | Should -Not -BeNullOrEmpty;
6773
$ruleResult.Length | Should -Be 2;
68-
$ruleResult.TargetName | Should -BeIn 'textanalytics-A', 'textanalytics-B';
74+
$ruleResult.TargetName | Should -BeIn 'luis-A', 'luis-A-authoring';
6975
}
7076

7177
It 'Azure.Cognitive.DisableLocalAuth' {
@@ -148,8 +154,14 @@ Describe 'Azure.Cognitive' -Tag 'Cognitive' {
148154
# Pass
149155
$ruleResult = @($filteredResult | Where-Object { $_.Outcome -eq 'Pass' });
150156
$ruleResult | Should -Not -BeNullOrEmpty;
151-
$ruleResult.Length | Should -Be 2;
152-
$ruleResult.TargetName | Should -BeIn 'cognitive-01', 'cognitive-03';
157+
$ruleResult.Length | Should -Be 1;
158+
$ruleResult.TargetName | Should -BeIn 'cognitive-03';
159+
160+
# None
161+
$ruleResult = @($filteredResult | Where-Object { $_.Outcome -eq 'None' });
162+
$ruleResult | Should -Not -BeNullOrEmpty;
163+
$ruleResult.Length | Should -Be 1;
164+
$ruleResult.TargetName | Should -BeIn 'cognitive-01';
153165
}
154166

155167
It 'Azure.Cognitive.DisableLocalAuth' {

0 commit comments

Comments
 (0)