Skip to content

Commit e2f6357

Browse files
Add parameter EnableRbcAuthorization for 'New-AzKeyVault' and 'Update-AzKeyVault' (Azure#12459)
* Add parameter EnableRbcAuthorization for 'New-AzKeyVault' and 'Update-AzKeyVault'. * Update src/KeyVault/KeyVault/ChangeLog.md Co-authored-by: Yeming Liu <[email protected]> * Update src/KeyVault/KeyVault/KeyVault.format.ps1xml Co-authored-by: Yeming Liu <[email protected]> * Simplify codes in VaultManagementClient.cs. Co-authored-by: Yeming Liu <[email protected]>
1 parent b964fcd commit e2f6357

File tree

15 files changed

+1384
-875
lines changed

15 files changed

+1384
-875
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

@@ -810,6 +816,15 @@ function Test-UpdateKeyVault {
810816
# Assert-Throws { $vault = $vault | Update-AzKeyVault -EnablePurgeProtection }
811817
# # Retention cannot be updated once set
812818
# Assert-Throws { $vault = $vault | Update-AzKeyVault -SoftDeleteRetentionInDays 80}
819+
820+
#Set EnableRbacAuthorization true
821+
$vault = $vault | Update-AzKeyVault -EnableRbacAuthorization $true
822+
Assert-True { $vault.EnableRbacAuthorization } "5. EnableRbacAuthorization should be true"
823+
824+
#Set EnableRbacAuthorization false
825+
$vault = $vault | Update-AzKeyVault -EnableRbacAuthorization $false
826+
Assert-False { $vault.EnableRbacAuthorization } "6. EnableRbacAuthorization should be false"
827+
813828
}
814829
finally {
815830
$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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- Additional information about change #1
1919
-->
2020
## Upcoming Release
21+
* Added support for RBAC authorization [#10557]
2122
* Enhanced error handling in `Set-AzKeyVaultAccessPolicy` [#4007]
2223

2324
## Version 2.1.0

src/KeyVault/KeyVault/Commands/NewAzureKeyVault.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ public class NewAzureKeyVault : KeyVaultManagementCmdletBase
9898
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.")]
9999
public SwitchParameter EnablePurgeProtection { get; set; }
100100

101+
[Parameter(Mandatory = false,
102+
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.")]
103+
public SwitchParameter EnableRbacAuthorization { get; set; }
104+
101105
[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.")]
102106
[ValidateRange(Constants.MinSoftDeleteRetentionDays, Constants.MaxSoftDeleteRetentionDays)]
103107
[ValidateNotNullOrEmpty]
@@ -168,6 +172,8 @@ public override void ExecuteCmdlet()
168172
EnabledForDiskEncryption = EnabledForDiskEncryption.IsPresent,
169173
EnableSoftDelete = !DisableSoftDelete.IsPresent,
170174
EnablePurgeProtection = EnablePurgeProtection.IsPresent ? true : (bool?)null, // false is not accepted
175+
EnableRbacAuthorization = EnableRbacAuthorization.IsPresent,
176+
171177
/*
172178
* If soft delete is enabled, but retention days is not specified, use the default value,
173179
* 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
@@ -59,6 +59,9 @@ public class UpdateTopLevelResourceCommand : KeyVaultManagementCmdletBase
5959
[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.")]
6060
public SwitchParameter EnablePurgeProtection { get; set; }
6161

62+
[Parameter(Mandatory = false, HelpMessage = "Enable or disable this key vault to authorize data actions by Role Based Access Control (RBAC).")]
63+
public bool? EnableRbacAuthorization { get; set; }
64+
6265
[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.")]
6366
[ValidateRange(Constants.MinSoftDeleteRetentionDays, Constants.MaxSoftDeleteRetentionDays)]
6467
[ValidateNotNullOrEmpty]
@@ -103,11 +106,13 @@ public override void ExecuteCmdlet()
103106
existingResource.EnabledForDiskEncryption,
104107
EnableSoftDelete.IsPresent ? (true as bool?) : null,
105108
EnablePurgeProtection.IsPresent ? (true as bool?) : null,
109+
EnableRbacAuthorization,
106110
this.IsParameterBound(c => c.SoftDeleteRetentionInDays)
107111
? (SoftDeleteRetentionInDays as int?)
108112
: (existingResource.SoftDeleteRetentionInDays ?? Constants.DefaultSoftDeleteRetentionDays),
109113
existingResource.NetworkAcls
110114
);
115+
111116
WriteObject(result);
112117
}
113118
}

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
@@ -366,6 +366,10 @@
366366
<Label>Enabled For Disk Encryption?</Label>
367367
<PropertyName>EnabledForDiskEncryption</PropertyName>
368368
</ListItem>
369+
<ListItem>
370+
<Label>Enabled For RBAC Authorization?</Label>
371+
<PropertyName>EnableRbacAuthorization</PropertyName>
372+
</ListItem>
369373
<ListItem>
370374
<Label>Soft Delete Enabled?</Label>
371375
<PropertyName>EnableSoftDelete</PropertyName>

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: 5 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,9 @@ public PSKeyVault UpdateVault(
193195
&& updatedPurgeProtectionSwitch.Value)
194196
properties.EnablePurgeProtection = updatedPurgeProtectionSwitch;
195197

198+
// Update EnableRbacAuthorization when specified, otherwise stay current value
199+
properties.EnableRbacAuthorization = updatedRbacAuthorization;
200+
196201
properties.AccessPolicies = (updatedPolicies == null) ?
197202
new List<AccessPolicyEntry>() :
198203
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)