Skip to content

Commit a067414

Browse files
authored
Refactoring and doc updates for Key Vault (Azure#2939)
* Refactoring and doc updates for Key Vault * Bump change log * Updates
1 parent 2df2145 commit a067414

13 files changed

+104
-49
lines changed

data/policy-ignore.json

+15-7
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,6 @@
7878
"reason": "Duplicate",
7979
"value": "Azure.MySQL.UseSSL"
8080
},
81-
{
82-
"policyDefinitionIds": [
83-
"/providers/Microsoft.Authorization/policyDefinitions/0b60c0b2-2dc2-4e1c-b5c9-abbed971de53"
84-
],
85-
"reason": "Duplicate",
86-
"value": "Azure.KeyVault.PurgeProtect"
87-
},
8881
{
8982
"policyDefinitionIds": [
9083
"/providers/Microsoft.Authorization/policyDefinitions/b6e2945c-0b7b-40f5-9233-7a5323b5cdc6"
@@ -128,13 +121,28 @@
128121
"reason": "Duplicate",
129122
"value": "Azure.KeyVault.SoftDelete"
130123
},
124+
{
125+
"policyDefinitionIds": [
126+
"/providers/Microsoft.Authorization/policyDefinitions/0b60c0b2-2dc2-4e1c-b5c9-abbed971de53"
127+
],
128+
"reason": "Duplicate",
129+
"value": "Azure.KeyVault.PurgeProtect"
130+
},
131131
{
132132
"policyDefinitionIds": [
133133
"/providers/Microsoft.Authorization/policyDefinitions/12d4fa5e-1f9f-4c21-97a9-b99b3c6611b5"
134134
],
135135
"reason": "Duplicate",
136136
"value": "Azure.KeyVault.RBAC"
137137
},
138+
{
139+
"policyDefinitionIds": [
140+
"/providers/Microsoft.Authorization/policyDefinitions/55615ac9-af46-4a59-874e-391cc3dfb490",
141+
"/providers/Microsoft.Authorization/policyDefinitions/ac673a9a-f77d-4846-b2d8-a57f8e1c01dc"
142+
],
143+
"reason": "Duplicate",
144+
"value": "Azure.KeyVault.Firewall"
145+
},
138146
{
139147
"policyDefinitionIds": [
140148
"/providers/Microsoft.Authorization/policyDefinitions/5d4e3c65-4873-47be-94f3-6f8b953a3598",

docs/CHANGELOG-v1.md

+6
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ See [upgrade notes][1] for helpful information when upgrading from previous vers
2929

3030
## Unreleased
3131

32+
What's changed since pre-release v1.38.0-B0011:
33+
34+
- Engineering:
35+
- Quality updates to rule documentation by @BernieWhite.
36+
[#2570](https://github.com/Azure/PSRule.Rules.Azure/issues/2570)
37+
3238
## v1.38.0-B0011 (pre-release)
3339

3440
What's changed since v1.37.0:

docs/en/rules/Azure.KeyVault.AccessPolicy.md

+18-9
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
2-
reviewed: 2023-02-18
2+
reviewed: 2024-06-17
33
severity: Important
44
pillar: Security
5-
category: Identity and access management
5+
category: SE:05 Identity and access management
66
resource: Key Vault
77
online version: https://azure.github.io/PSRule.Rules.Azure/en/rules/Azure.KeyVault.AccessPolicy/
88
---
@@ -32,15 +32,17 @@ Consider assigning access to Key Vault data based on the principle of least priv
3232

3333
To deploy Key Vaults that pass this rule:
3434

35-
- Avoid assigning `purge` and `all` permissions for Key Vault objects.
36-
Use specific permissions such as `get` and `set`.
35+
- Use Azure RBAC as the authorization system instead. _OR_
36+
- Configure the access policies by setting `properties.accessPolicies`:
37+
- Avoid assigning `purge` and `all` permissions for Key Vault objects.
38+
Use specific permissions such as `get` and `set`.
3739

3840
For example:
3941

4042
```json
4143
{
4244
"type": "Microsoft.KeyVault/vaults",
43-
"apiVersion": "2022-07-01",
45+
"apiVersion": "2023-07-01",
4446
"name": "[parameters('name')]",
4547
"location": "[parameters('location')]",
4648
"properties": {
@@ -73,13 +75,15 @@ For example:
7375

7476
To deploy Key Vaults that pass this rule:
7577

76-
- Avoid assigning `purge` and `all` permissions for Key Vault objects.
77-
Use specific permissions such as `get` and `set`.
78+
- Use Azure RBAC as the authorization system instead. _OR_
79+
- Configure the access policies by setting `properties.accessPolicies`:
80+
- Avoid assigning `purge` and `all` permissions for Key Vault objects.
81+
Use specific permissions such as `get` and `set`.
7882

7983
For example:
8084

8185
```bicep
82-
resource vault 'Microsoft.KeyVault/vaults@2022-07-01' = {
86+
resource vault 'Microsoft.KeyVault/vaults@2023-07-01' = {
8387
name: name
8488
location: location
8589
properties: {
@@ -108,8 +112,13 @@ resource vault 'Microsoft.KeyVault/vaults@2022-07-01' = {
108112
}
109113
```
110114

115+
<!-- external:avm avm/res/key-vault/vault accessPolicies -->
116+
111117
## LINKS
112118

113-
- [Automate and use least privilege](https://learn.microsoft.com/azure/architecture/framework/security/security-principles#automate-and-use-least-privilege)
119+
- [SE:05 Identity and access management](https://learn.microsoft.com/azure/well-architected/security/identity-access)
120+
- [Provide access to Key Vault keys, certificates, and secrets with an Azure role-based access control](https://learn.microsoft.com/azure/key-vault/general/rbac-guide)
121+
- [Azure role-based access control vs. access policies](https://learn.microsoft.com/azure/key-vault/general/rbac-access-policy)
122+
- [Migrate from vault access policy to an Azure role-based access control permission model](https://learn.microsoft.com/azure/key-vault/general/rbac-migration)
114123
- [Best practices to use Key Vault](https://learn.microsoft.com/azure/key-vault/general/best-practices)
115124
- [Azure deployment reference](https://learn.microsoft.com/azure/templates/microsoft.keyvault/vaults)

docs/en/rules/Azure.KeyVault.AutoRotationPolicy.md

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
2-
reviewed: 2022-09-09
2+
reviewed: 2024-06-17
33
severity: Important
44
pillar: Security
5-
category: Key and secret management
5+
category: SE:09 Application secrets
66
resource: Key Vault
77
online version: https://azure.github.io/PSRule.Rules.Azure/en/rules/Azure.KeyVault.AutoRotationPolicy/
88
---
@@ -31,8 +31,8 @@ Consider enabling auto-rotation on Key Vault keys.
3131

3232
To set auto-rotation for a key:
3333

34-
- Set `properties.rotationPolicy.lifetimeActions[*].action.type` to `Rotate`.
35-
- Set `properties.rotationPolicy.lifetimeActions[*].trigger.timeAfterCreate` to the time duration after key creation to rotate.
34+
- Set the `properties.rotationPolicy.lifetimeActions[*].action.type` property to `Rotate`.
35+
- Set the `properties.rotationPolicy.lifetimeActions[*].trigger.timeAfterCreate` property to a time duration such as `P30D`.
3636

3737
For example:
3838

@@ -80,9 +80,8 @@ For example:
8080

8181
To set auto-rotation for a key:
8282

83-
- Set `properties.rotationPolicy.lifetimeActions[*].action.type` to `Rotate`.
84-
- Set `properties.rotationPolicy.lifetimeActions[*].trigger.timeAfterCreate` to the time duration
85-
after key creation to rotate.
83+
- Set the `properties.rotationPolicy.lifetimeActions[*].action.type` property to `Rotate`.
84+
- Set the `properties.rotationPolicy.lifetimeActions[*].trigger.timeAfterCreate` property to a time duration such as `P30D`.
8685

8786
For example:
8887

@@ -127,7 +126,7 @@ resource vaultName_key1 'Microsoft.KeyVault/vaults/keys@2021-06-01-preview' = {
127126

128127
## LINKS
129128

130-
- [Operational considerations](https://learn.microsoft.com/azure/architecture/framework/security/design-storage-keys#operational-considerations)
129+
- [SE:09 Application secrets](https://learn.microsoft.com/azure/well-architected/security/application-secrets)
131130
- [IM-3: Manage application identities securely and automatically](https://learn.microsoft.com/security/benchmark/azure/security-controls-v3-identity-management#im-3-manage-application-identities-securely-and-automatically)
132131
- [Configure cryptographic key auto-rotation in Azure Key Vault](https://learn.microsoft.com/azure/key-vault/keys/how-to-configure-key-rotation)
133132
- [Azure deployment reference](https://learn.microsoft.com/azure/templates/microsoft.keyvault/vaults/keys)

docs/en/rules/Azure.KeyVault.Firewall.md

+15-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
2-
reviewed: 2023-08-20
2+
reviewed: 2024-06-17
33
severity: Important
44
pillar: Security
5-
category: Application endpoints
5+
category: SE:06 Network controls
66
resource: Key Vault
77
online version: https://azure.github.io/PSRule.Rules.Azure/en/rules/Azure.KeyVault.Firewall/
88
---
@@ -101,12 +101,21 @@ resource vault 'Microsoft.KeyVault/vaults@2023-02-01' = {
101101
}
102102
```
103103

104+
<!-- external:avm avm/res/key-vault/vault networkAcls -->
105+
106+
### Configure with Azure Policy
107+
108+
To address this issue at runtime use the following policies:
109+
110+
- [Azure Key Vault should have firewall enabled](https://github.com/Azure/azure-policy/blob/master/built-in-policies/policyDefinitions/Key%20Vault/FirewallEnabled_Audit.json)
111+
`/providers/Microsoft.Authorization/policyDefinitions/55615ac9-af46-4a59-874e-391cc3dfb490`.
112+
- [Configure key vaults to enable firewall](https://github.com/Azure/azure-policy/blob/master/built-in-policies/policyDefinitions/Key%20Vault/FirewallEnabled_Modify.json)
113+
`/providers/Microsoft.Authorization/policyDefinitions/ac673a9a-f77d-4846-b2d8-a57f8e1c01dc`.
114+
104115
## LINKS
105116

106-
- [Public endpoints](https://learn.microsoft.com/azure/architecture/framework/security/design-network-endpoints#public-endpoints)
117+
- [SE:06 Network controls](https://learn.microsoft.com/azure/well-architected/security/networking)
118+
- [NS-2: Secure cloud services with network controls](https://learn.microsoft.com/security/benchmark/azure/baselines/key-vault-security-baseline#disable-public-network-access)
107119
- [Configure Azure Key Vault firewalls and virtual networks](https://learn.microsoft.com/azure/key-vault/general/network-security)
108-
- [Azure security baseline for Key Vault - Disable Public Network Access](https://learn.microsoft.com/security/benchmark/azure/baselines/key-vault-security-baseline#disable-public-network-access)
109-
- [Azure Policies - Azure Key Vault should have firewall enabled](https://www.azadvertizer.net/azpolicyadvertizer/55615ac9-af46-4a59-874e-391cc3dfb490.html)
110-
- [Azure Key Vault should have firewall enabled](https://portal.azure.com/#view/Microsoft_Azure_Policy/PolicyDetailBlade/definitionId/%2Fproviders%2FMicrosoft.Authorization%2FpolicyDefinitions%2F55615ac9-af46-4a59-874e-391cc3dfb490)
111120
- [Trusted services](https://learn.microsoft.com/azure/key-vault/general/overview-vnet-service-endpoints#trusted-services)
112121
- [Azure deployment reference](https://learn.microsoft.com/azure/templates/microsoft.keyvault/vaults)

docs/en/rules/Azure.KeyVault.KeyName.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
severity: Awareness
33
pillar: Operational Excellence
4-
category: Repeatable infrastructure
4+
category: OE:04 Continuous integration
55
resource: Key Vault
66
online version: https://azure.github.io/PSRule.Rules.Azure/en/rules/Azure.KeyVault.KeyName/
77
---
@@ -32,7 +32,7 @@ This rule does not check if Key names are unique.
3232

3333
## LINKS
3434

35-
- [Repeatable infrastructure](https://learn.microsoft.com/azure/architecture/framework/devops/automation-infrastructure)
35+
- [OE:04 Continuous integration](https://learn.microsoft.com/azure/well-architected/operational-excellence/release-engineering-continuous-integration)
3636
- [Naming rules and restrictions for Azure resources](https://learn.microsoft.com/azure/azure-resource-manager/management/resource-name-rules#microsoftkeyvault)
37-
- [Azure deployment reference](https://learn.microsoft.com/azure/templates/microsoft.keyvault/vaults/secrets)
3837
- [Tagging and resource naming](https://learn.microsoft.com/azure/architecture/framework/devops/app-design#tagging-and-resource-naming)
38+
- [Azure deployment reference](https://learn.microsoft.com/azure/templates/microsoft.keyvault/vaults/secrets)

docs/en/rules/Azure.KeyVault.PurgeProtect.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ resource vault 'Microsoft.KeyVault/vaults@2023-07-01' = {
9393
}
9494
```
9595

96+
<!-- external:avm avm/res/key-vault/vault enablePurgeProtection -->
97+
9698
### Configure with Azure CLI
9799

98100
```bash
@@ -109,7 +111,8 @@ Update-AzKeyVault -ResourceGroupName '<resource_group>' -Name '<name>' -EnablePu
109111

110112
To address this issue at runtime use the following policies:
111113

112-
- [Key vaults should have deletion protection enabled](https://github.com/Azure/azure-policy/blob/master/built-in-policies/policyDefinitions/Key%20Vault/KeyVault_Recoverable_Audit.json)
114+
- [Key vaults should have deletion protection enabled](https://github.com/Azure/azure-policy/blob/master/built-in-policies/policyDefinitions/Key%20Vault/Recoverable_Audit.json)
115+
`/providers/Microsoft.Authorization/policyDefinitions/0b60c0b2-2dc2-4e1c-b5c9-abbed971de53`.
113116

114117
## LINKS
115118

docs/en/rules/Azure.KeyVault.RBAC.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ resource vault 'Microsoft.KeyVault/vaults@2023-07-01' = {
9292
}
9393
```
9494

95+
<!-- external:avm avm/res/key-vault/vault enableRbacAuthorization -->
96+
9597
### Configure with Azure CLI
9698

9799
```bash
@@ -108,7 +110,8 @@ Update-AzKeyVault -ResourceGroupName '<resource_group>' -Name '<name>' -EnableRb
108110

109111
To address this issue at runtime use the following policies:
110112

111-
- [Azure Key Vault should use RBAC permission model](https://github.com/Azure/azure-policy/blob/master/built-in-policies/policyDefinitions/Key%20Vault/AzureKeyVault_Should_Use_RBAC.json)
113+
- [Azure Key Vault should use RBAC permission model](https://github.com/Azure/azure-policy/blob/master/built-in-policies/policyDefinitions/Key%20Vault/Should_Use_RBAC.json)
114+
`/providers/Microsoft.Authorization/policyDefinitions/12d4fa5e-1f9f-4c21-97a9-b99b3c6611b5`.
112115

113116
## NOTES
114117

@@ -119,11 +122,11 @@ For information about limitations see _Azure role-based access control vs. acces
119122
## LINKS
120123

121124
- [SE:05 Identity and access management](https://learn.microsoft.com/azure/well-architected/security/identity-access)
125+
- [IM-1: Use centralized identity and authentication system](https://learn.microsoft.com/security/benchmark/azure/baselines/key-vault-security-baseline#im-1-use-centralized-identity-and-authentication-system)
122126
- [What is Azure role-based access control?](https://learn.microsoft.com/azure/role-based-access-control/overview)
123127
- [Provide access to Key Vault keys, certificates, and secrets with an Azure role-based access control](https://learn.microsoft.com/azure/key-vault/general/rbac-guide)
124128
- [Azure role-based access control vs. access policies](https://learn.microsoft.com/azure/key-vault/general/rbac-access-policy)
125129
- [Migrate from vault access policy to an Azure role-based access control permission model](https://learn.microsoft.com/azure/key-vault/general/rbac-migration)
126130
- [Azure Key Vault security](https://learn.microsoft.com/azure/key-vault/general/security-features)
127131
- [Azure security baseline for Key Vault](https://learn.microsoft.com/security/benchmark/azure/baselines/key-vault-security-baseline)
128-
- [IM-1: Use centralized identity and authentication system](https://learn.microsoft.com/security/benchmark/azure/baselines/key-vault-security-baseline#im-1-use-centralized-identity-and-authentication-system)
129132
- [Azure deployment reference](https://learn.microsoft.com/azure/templates/microsoft.keyvault/vaults)

docs/en/rules/Azure.KeyVault.SoftDelete.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ resource vault 'Microsoft.KeyVault/vaults@2023-07-01' = {
9191
}
9292
```
9393

94+
<!-- external:avm avm/res/key-vault/vault enableSoftDelete -->
95+
9496
### Configure with Azure CLI
9597

9698
```bash
@@ -101,7 +103,8 @@ az keyvault update -n '<name>' -g '<resource_group>' --retention-days 90
101103

102104
To address this issue at runtime use the following policies:
103105

104-
- [Key vaults should have soft delete enabled](https://github.com/Azure/azure-policy/blob/master/built-in-policies/policyDefinitions/Key%20Vault/KeyVault_SoftDeleteMustBeEnabled_Audit.json)
106+
- [Key vaults should have soft delete enabled](https://github.com/Azure/azure-policy/blob/master/built-in-policies/policyDefinitions/Key%20Vault/SoftDeleteMustBeEnabled_Audit.json)
107+
`/providers/Microsoft.Authorization/policyDefinitions/1e66c121-a66a-4b1f-9b83-0fd99bf0fc2d`.
105108

106109
## LINKS
107110

docs/examples-keyvault.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"metadata": {
55
"_generator": {
66
"name": "bicep",
7-
"version": "0.24.24.22086",
8-
"templateHash": "3218451149490833125"
7+
"version": "0.28.1.47646",
8+
"templateHash": "14429599704704727241"
99
}
1010
},
1111
"parameters": {

src/PSRule.Rules.Azure/rules/Azure.KeyVault.Rule.ps1

-5
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,3 @@ Rule 'Azure.KeyVault.AutoRotationPolicy' -Ref 'AZR-000123' -Type 'Microsoft.KeyV
124124
);
125125
}
126126
}
127-
128-
# Synopsis: KeyVaults should only accept explicitly allowed traffic.
129-
Rule 'Azure.KeyVault.Firewall' -Ref 'AZR-000355' -Type 'Microsoft.KeyVault/vaults' -Tag @{ release = 'GA'; ruleSet = '2023_03'; 'Azure.WAF/pillar' = 'Security'; } {
130-
$Assert.HasFieldValue($TargetObject, 'Properties.networkAcls.defaultAction', 'Deny')
131-
}

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

+24-4
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ metadata:
1515
name: Azure.KeyVault.SoftDelete
1616
ref: AZR-000124
1717
tags:
18-
release: 'GA'
19-
ruleSet: '2020_06'
18+
release: GA
19+
ruleSet: 2020_06
2020
Azure.WAF/pillar: Reliability
2121
spec:
2222
type:
@@ -33,8 +33,8 @@ metadata:
3333
name: Azure.KeyVault.PurgeProtect
3434
ref: AZR-000125
3535
tags:
36-
release: 'GA'
37-
ruleSet: '2020_06'
36+
release: GA
37+
ruleSet: 2020_06
3838
Azure.WAF/pillar: Reliability
3939
spec:
4040
type:
@@ -64,4 +64,24 @@ spec:
6464
field: properties.enableRbacAuthorization
6565
equals: true
6666

67+
---
68+
# Synopsis: Vaults should only accept explicitly allowed traffic.
69+
apiVersion: github.com/microsoft/PSRule/v1
70+
kind: Rule
71+
metadata:
72+
name: Azure.KeyVault.Firewall
73+
ref: AZR-000355
74+
tags:
75+
release: GA
76+
ruleSet: 2023_03
77+
Azure.WAF/pillar: Security
78+
labels:
79+
Azure.MCSB.v1/control: NS-2
80+
spec:
81+
type:
82+
- Microsoft.KeyVault/vaults
83+
condition:
84+
field: properties.networkAcls.defaultAction
85+
equals: Deny
86+
6787
#endregion Rules

tests/PSRule.Rules.Azure.Tests/PolicyAssignmentVisitorTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public void GetPolicyDefinitionWithIgnore()
9595

9696
var definitions = context.GetDefinitions();
9797
Assert.NotNull(definitions);
98-
Assert.Equal(113, definitions.Length);
98+
Assert.Equal(112, definitions.Length);
9999

100100
// Check category and version
101101
var actual = definitions.FirstOrDefault(definition => definition.DefinitionId == "/providers/Microsoft.Authorization/policyDefinitions/34c877ad-507e-4c82-993e-3452a6e0ad3c");

0 commit comments

Comments
 (0)