Skip to content

Commit f7f1ae5

Browse files
committed
Add parameter EnableRbcAuthorization for 'New-AzKeyVault' and 'Update-AzKeyVault'.
1 parent aa0671e commit f7f1ae5

File tree

15 files changed

+1388
-876
lines changed

15 files changed

+1388
-876
lines changed

src/KeyVault/KeyVault.Test/Scripts/ControlPlane/KeyVaultManagementTests.ps1

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ function Test-CreateNewVault {
113113
# Soft delete and purge protection defaults to true
114114
Assert-True { $actual.EnableSoftDelete } "By default EnableSoftDelete should be true"
115115
Assert-Null $actual.EnablePurgeProtection "By default EnablePurgeProtection should be null"
116+
# RbacAuthorization defaults to false
117+
Assert-False { $actual.EnableRbacAuthorization } "By default EnableRbacAuthorization should be false"
116118
# Default retention days
117119
Assert-AreEqual 90 $actual.SoftDeleteRetentionInDays "By default SoftDeleteRetentionInDays should be 90"
118120

@@ -137,6 +139,10 @@ function Test-CreateNewVault {
137139
Assert-True { $actual.EnablePurgeProtection } "If -EnablePurgeProtection, EnablePurgeProtection should be null"
138140
Assert-AreEqual 10 $actual.SoftDeleteRetentionInDays "SoftDeleteRetentionInDays should be the same value as set"
139141

142+
# Test enable RbacAuthorization
143+
$actual = New-AzKeyVault -VaultName (getAssetName) -ResourceGroupName $rgName -Location $vaultLocation -EnableRbacAuthorization
144+
Assert-True { $actual.EnableRbacAuthorization } "If specified, EnableRbacAuthorization should be true"
145+
140146
# # Test use -DisableSoftDelete -EnablePurgeProtection together (TODO: uncomment this assert after keyvault team deploys their fix)
141147
# Assert-Throws { New-AzKeyVault -VaultName (getAssetName) -ResourceGroupName $rgName -Location $vaultLocation -Sku standard -DisableSoftDelete -EnablePurgeProtection }
142148

@@ -798,6 +804,15 @@ function Test-UpdateKeyVault {
798804
# Assert-Throws { $vault = $vault | Update-AzKeyVault -EnablePurgeProtection }
799805
# # Retention cannot be updated once set
800806
# Assert-Throws { $vault = $vault | Update-AzKeyVault -SoftDeleteRetentionInDays 80}
807+
808+
#Set EnableRbacAuthorization true
809+
$vault = $vault | Update-AzKeyVault -EnableRbacAuthorization $true
810+
Assert-True { $vault.EnableRbacAuthorization } "5. EnableRbacAuthorization should be true"
811+
812+
#Set EnableRbacAuthorization false
813+
$vault = $vault | Update-AzKeyVault -EnableRbacAuthorization $false
814+
Assert-False { $vault.EnableRbacAuthorization } "6. EnableRbacAuthorization should be false"
815+
801816
}
802817
finally {
803818
$rg | Remove-AzResourceGroup -Force

src/KeyVault/KeyVault.Test/SessionRecords/Microsoft.Azure.Commands.KeyVault.Test.ScenarioTests.KeyVaultManagementTests/TestCreateNewVault.json

Lines changed: 672 additions & 542 deletions
Large diffs are not rendered by default.

src/KeyVault/KeyVault.Test/SessionRecords/Microsoft.Azure.Commands.KeyVault.Test.ScenarioTests.KeyVaultManagementTests/TestUpdateVault.json

Lines changed: 632 additions & 326 deletions
Large diffs are not rendered by default.

src/KeyVault/KeyVault/ChangeLog.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818
- Additional information about change #1
1919
-->
2020
## Upcoming Release
21-
21+
* Added support to enable RBAC authorization [#10557]
22+
- `New-AzKeyVault` supports generating a key with RBAC authorization
23+
- `Update-AzKeyVault` supports enabling/disabling a key to authorize data actions by RBAC
24+
2225
## Version 2.0.0
2326
* Removed two aliases: `New-AzKeyVaultCertificateAdministratorDetails` and `New-AzKeyVaultCertificateOrganizationDetails`
2427
* Enabled soft delete by default when creating a key vault

src/KeyVault/KeyVault/Commands/NewAzureKeyVault.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ public class NewAzureKeyVault : KeyVaultManagementCmdletBase
9292
HelpMessage = "If specified, protection against immediate deletion is enabled for this vault; requires soft delete to be enabled as well. Enabling 'purge protection' on a key vault is an irreversible action. Once enabled, it cannot be changed or removed.")]
9393
public SwitchParameter EnablePurgeProtection { get; set; }
9494

95+
[Parameter(Mandatory = false,
96+
HelpMessage = "If specified, enables to authorize data actions by Role Based Access Control (RBAC), and then the access policies specified in vault properties will be ignored. Note that management actions are always authorized with RBAC.")]
97+
public SwitchParameter EnableRbacAuthorization { get; set; }
98+
9599
[Parameter(Mandatory = false, HelpMessage = "Specifies how long deleted resources are retained, and how long until a vault or an object in the deleted state can be purged. The default is " + Constants.DefaultSoftDeleteRetentionDaysString + " days.")]
96100
[ValidateRange(Constants.MinSoftDeleteRetentionDays, Constants.MaxSoftDeleteRetentionDays)]
97101
[ValidateNotNullOrEmpty]
@@ -162,6 +166,8 @@ public override void ExecuteCmdlet()
162166
EnabledForDiskEncryption = EnabledForDiskEncryption.IsPresent,
163167
EnableSoftDelete = !DisableSoftDelete.IsPresent,
164168
EnablePurgeProtection = EnablePurgeProtection.IsPresent ? true : (bool?)null, // false is not accepted
169+
EnableRbacAuthorization = EnableRbacAuthorization.IsPresent,
170+
165171
/*
166172
* If soft delete is enabled, but retention days is not specified, use the default value,
167173
* else use the vault user provides,

src/KeyVault/KeyVault/Commands/RemoveAzureKeyVaultAccessPolicy.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ public override void ExecuteCmdlet()
350350
EnabledForDiskEncryption.IsPresent ? false : existingVault.EnabledForDiskEncryption,
351351
existingVault.EnableSoftDelete,
352352
existingVault.EnablePurgeProtection,
353+
existingVault.EnableRbacAuthorization,
353354
existingVault.SoftDeleteRetentionInDays,
354355
existingVault.NetworkAcls,
355356
ActiveDirectoryClient);

src/KeyVault/KeyVault/Commands/SetAzureKeyVaultAccessPolicy.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,7 @@ public override void ExecuteCmdlet()
570570
EnabledForDiskEncryption.IsPresent ? true : vault.EnabledForDiskEncryption,
571571
vault.EnableSoftDelete,
572572
vault.EnablePurgeProtection,
573+
vault.EnableRbacAuthorization,
573574
vault.SoftDeleteRetentionInDays,
574575
vault.NetworkAcls,
575576
ActiveDirectoryClient);

src/KeyVault/KeyVault/Commands/UpdateAzureKeyVault.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ public class UpdateTopLevelResourceCommand : KeyVaultManagementCmdletBase
5555
[Parameter(Mandatory = false, HelpMessage = "Enable the purge protection functionality for this key vault. Once enabled it cannot be disabled. It requires soft-delete to be turned on.")]
5656
public SwitchParameter EnablePurgeProtection { get; set; }
5757

58+
[Parameter(Mandatory = false, HelpMessage = "Enable or disable this key vault to authorize data actions by Role Based Access Control (RBAC).")]
59+
public bool? EnableRbacAuthorization { get; set; }
60+
5861
[Parameter(Mandatory = false, HelpMessage = "Specifies how long deleted resources are retained, and how long until a vault or an object in the deleted state can be purged. The default is " + Constants.DefaultSoftDeleteRetentionDaysString + " days.")]
5962
[ValidateRange(Constants.MinSoftDeleteRetentionDays, Constants.MaxSoftDeleteRetentionDays)]
6063
[ValidateNotNullOrEmpty]
@@ -99,11 +102,13 @@ public override void ExecuteCmdlet()
99102
existingResource.EnabledForDiskEncryption,
100103
EnableSoftDelete.IsPresent ? (true as bool?) : null,
101104
EnablePurgeProtection.IsPresent ? (true as bool?) : null,
105+
EnableRbacAuthorization,
102106
this.IsParameterBound(c => c.SoftDeleteRetentionInDays)
103107
? (SoftDeleteRetentionInDays as int?)
104108
: (existingResource.SoftDeleteRetentionInDays ?? Constants.DefaultSoftDeleteRetentionDays),
105109
existingResource.NetworkAcls
106110
);
111+
107112
WriteObject(result);
108113
}
109114
}

src/KeyVault/KeyVault/Commands/VirtualNetworkRuleSet/KeyVaultNetworkRuleSetBase.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ protected PSKeyVault UpdateCurrentVault(PSKeyVault existingVault, PSKeyVaultNetw
114114
existingVault.EnabledForDiskEncryption,
115115
existingVault.EnableSoftDelete,
116116
existingVault.EnablePurgeProtection,
117+
existingVault.EnableRbacAuthorization,
117118
existingVault.SoftDeleteRetentionInDays,
118119
updatedNetworkAcls,
119120
ActiveDirectoryClient);

src/KeyVault/KeyVault/KeyVault.format.ps1xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,10 @@
365365
<ListItem>
366366
<Label>Enabled For Disk Encryption?</Label>
367367
<PropertyName>EnabledForDiskEncryption</PropertyName>
368+
</ListItem>
369+
<ListItem>
370+
<Label>Enabled For RBAC Authorization?</Label>
371+
<PropertyName>EnableRbacAuthorization</PropertyName>
368372
</ListItem>
369373
<ListItem>
370374
<Label>Soft Delete Enabled?</Label>

src/KeyVault/KeyVault/Models/PSKeyVault.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public PSKeyVault(Vault vault, ActiveDirectoryClient adClient)
5050
EnabledForDiskEncryption = vault.Properties.EnabledForDiskEncryption;
5151
EnableSoftDelete = vault.Properties.EnableSoftDelete;
5252
EnablePurgeProtection = vault.Properties.EnablePurgeProtection;
53+
EnableRbacAuthorization = vault.Properties.EnableRbacAuthorization;
5354
SoftDeleteRetentionInDays = vault.Properties.SoftDeleteRetentionInDays;
5455
AccessPolicies = vault.Properties.AccessPolicies.Select(s => new PSKeyVaultAccessPolicy(s, adClient)).ToArray();
5556
NetworkAcls = InitNetworkRuleSet(vault.Properties);
@@ -72,6 +73,8 @@ public PSKeyVault(Vault vault, ActiveDirectoryClient adClient)
7273
public bool? EnableSoftDelete { get; private set; }
7374

7475
public bool? EnablePurgeProtection { get; private set; }
76+
77+
public bool? EnableRbacAuthorization { get; private set; }
7578

7679
public int? SoftDeleteRetentionInDays { get; private set; }
7780

src/KeyVault/KeyVault/Models/VaultCreationParameters.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public class VaultCreationParameters
3131
public bool EnabledForDiskEncryption { get; set; }
3232
public bool? EnableSoftDelete { get; set; }
3333
public bool? EnablePurgeProtection { get; set; }
34+
public bool? EnableRbacAuthorization { get; set; }
3435
public int? SoftDeleteRetentionInDays { get; set; }
3536
public Guid TenantId { get; set; }
3637
public AccessPolicyEntry AccessPolicy { get; set; }

src/KeyVault/KeyVault/Models/VaultManagementClient.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public PSKeyVault CreateNewVault(VaultCreationParameters parameters, ActiveDirec
8686
properties.EnabledForDiskEncryption = parameters.EnabledForDiskEncryption;
8787
properties.EnableSoftDelete = parameters.EnableSoftDelete;
8888
properties.EnablePurgeProtection = parameters.EnablePurgeProtection;
89+
properties.EnableRbacAuthorization = parameters.EnableRbacAuthorization;
8990
properties.SoftDeleteRetentionInDays = parameters.SoftDeleteRetentionInDays;
9091
properties.TenantId = parameters.TenantId;
9192
properties.VaultUri = "";
@@ -164,6 +165,7 @@ public PSKeyVault UpdateVault(
164165
bool? updatedEnabledForDiskEncryption,
165166
bool? updatedSoftDeleteSwitch,
166167
bool? updatedPurgeProtectionSwitch,
168+
bool? updatedRbacAuthorization,
167169
int? softDeleteRetentionInDays,
168170
PSKeyVaultNetworkRuleSet updatedNetworkAcls,
169171
ActiveDirectoryClient adClient = null)
@@ -193,6 +195,10 @@ public PSKeyVault UpdateVault(
193195
&& updatedPurgeProtectionSwitch.Value)
194196
properties.EnablePurgeProtection = updatedPurgeProtectionSwitch;
195197

198+
// Update EnableRbacAuthorization when specified, otherwise stay current value
199+
if (updatedRbacAuthorization.HasValue)
200+
properties.EnableRbacAuthorization = updatedRbacAuthorization;
201+
196202
properties.AccessPolicies = (updatedPolicies == null) ?
197203
new List<AccessPolicyEntry>() :
198204
updatedPolicies.Select(a => new AccessPolicyEntry

src/KeyVault/KeyVault/help/New-AzKeyVault.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Creates a key vault.
1616
```
1717
New-AzKeyVault [-Name] <String> [-ResourceGroupName] <String> [-Location] <String> [-EnabledForDeployment]
1818
[-EnabledForTemplateDeployment] [-EnabledForDiskEncryption] [-DisableSoftDelete] [-EnablePurgeProtection]
19-
[-SoftDeleteRetentionInDays <Int32>] [-Sku <SkuName>] [-Tag <Hashtable>]
19+
[-EnableRbacAuthorization] [-SoftDeleteRetentionInDays <Int32>] [-Sku <SkuName>] [-Tag <Hashtable>]
2020
[-NetworkRuleSet <PSKeyVaultNetworkRuleSet>] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
2121
[<CommonParameters>]
2222
```
@@ -211,6 +211,21 @@ Accept pipeline input: False
211211
Accept wildcard characters: False
212212
```
213213
214+
### -EnableRbacAuthorization
215+
If specified, enables to authorize data actions by Role Based Access Control (RBAC), and then the access policies specified in vault properties will be ignored. Note that management actions are always authorized with RBAC.
216+
217+
```yaml
218+
Type: System.Management.Automation.SwitchParameter
219+
Parameter Sets: (All)
220+
Aliases:
221+
222+
Required: False
223+
Position: Named
224+
Default value: None
225+
Accept pipeline input: False
226+
Accept wildcard characters: False
227+
```
228+
214229
### -Location
215230
Specifies the Azure region in which to create the key vault. Use the command [Get-AzLocation](https://docs.microsoft.com/powershell/module/Azure/Get-AzLocation) to see your choices.
216231

src/KeyVault/KeyVault/help/Update-AzKeyVault.md

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,22 @@ Update the state of an Azure key vault.
1515
### UpdateByNameParameterSet (Default)
1616
```
1717
Update-AzKeyVault -ResourceGroupName <String> -VaultName <String> [-EnableSoftDelete] [-EnablePurgeProtection]
18-
[-SoftDeleteRetentionInDays <Int32>] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
19-
[<CommonParameters>]
18+
[-EnableRbacAuthorization <Boolean>] [-SoftDeleteRetentionInDays <Int32>]
19+
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
2020
```
2121

2222
### UpdateByInputObjectParameterSet
2323
```
2424
Update-AzKeyVault -InputObject <PSKeyVault> [-EnableSoftDelete] [-EnablePurgeProtection]
25-
[-SoftDeleteRetentionInDays <Int32>] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
26-
[<CommonParameters>]
25+
[-EnableRbacAuthorization <Boolean>] [-SoftDeleteRetentionInDays <Int32>]
26+
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
2727
```
2828

2929
### UpdateByResourceIdParameterSet
3030
```
3131
Update-AzKeyVault -ResourceId <String> [-EnableSoftDelete] [-EnablePurgeProtection]
32-
[-SoftDeleteRetentionInDays <Int32>] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
33-
[<CommonParameters>]
32+
[-EnableRbacAuthorization <Boolean>] [-SoftDeleteRetentionInDays <Int32>]
33+
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
3434
```
3535

3636
## DESCRIPTION
@@ -87,6 +87,21 @@ Accept pipeline input: False
8787
Accept wildcard characters: False
8888
```
8989
90+
### -EnableRbacAuthorization
91+
Enable or disable this key vault to authorize data actions by Role Based Access Control (RBAC).
92+
93+
```yaml
94+
Type: System.Nullable`1[System.Boolean]
95+
Parameter Sets: (All)
96+
Aliases:
97+
98+
Required: False
99+
Position: Named
100+
Default value: None
101+
Accept pipeline input: False
102+
Accept wildcard characters: False
103+
```
104+
90105
### -EnableSoftDelete
91106
Enable the soft-delete functionality for this key vault.
92107
Once enabled it cannot be disabled.

0 commit comments

Comments
 (0)