Skip to content

Commit c7557fd

Browse files
author
Maddie Clayton
authored
Merge pull request Azure#5963 from dragav/kv-apr-18-bugfixes
KeyVault: adding support for specifying key size on creation
2 parents 1b9e789 + 3e7dc4c commit c7557fd

File tree

10 files changed

+124
-22
lines changed

10 files changed

+124
-22
lines changed

src/ResourceManager/KeyVault/Commands.KeyVault/Commands/AddAzureKeyVaultKey.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,17 @@ public class AddAzureKeyVaultKey : KeyVaultCmdletBase
201201
[Alias(Constants.TagsAlias)]
202202
public Hashtable Tag { get; set; }
203203

204+
205+
[Parameter(Mandatory = false,
206+
ParameterSetName = InputObjectCreateParameterSet,
207+
HelpMessage = "RSA key size, in bits. If not specified, the service will provide a safe default.")]
208+
[Parameter(Mandatory = false,
209+
ParameterSetName = InteractiveCreateParameterSet,
210+
HelpMessage = "RSA key size, in bits. If not specified, the service will provide a safe default.")]
211+
[Parameter(Mandatory = false,
212+
ParameterSetName = ResourceIdCreateParameterSet,
213+
HelpMessage = "RSA key size, in bits. If not specified, the service will provide a safe default.")]
214+
public int? Size { get; set; }
204215
#endregion
205216

206217
public override void ExecuteCmdlet()
@@ -228,7 +239,8 @@ public override void ExecuteCmdlet()
228239
keyBundle = this.DataServiceClient.CreateKey(
229240
VaultName,
230241
Name,
231-
CreateKeyAttributes());
242+
CreateKeyAttributes(),
243+
Size);
232244
}
233245
else
234246
{

src/ResourceManager/KeyVault/Commands.KeyVault/Commands/ManagedStorageAccounts/RemoveAzureKeyVaultManagedStorageAccount.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using System.Management.Automation;
1818
using KeyVaultProperties = Microsoft.Azure.Commands.KeyVault.Properties;
1919
using Microsoft.Azure.Commands.KeyVault.Models.ManagedStorageAccounts;
20+
using Microsoft.Azure.Commands.KeyVault.Properties;
2021

2122
namespace Microsoft.Azure.Commands.KeyVault
2223
{
@@ -43,6 +44,13 @@ public class RemoveAzureKeyVaultManagedStorageAccount : KeyVaultCmdletBase
4344
[Alias( Constants.StorageAccountName, Constants.Name )]
4445
public string AccountName { get; set; }
4546

47+
/// <summary>
48+
/// If present, operate on the deleted entity.
49+
/// </summary>
50+
[Parameter(Mandatory = false,
51+
HelpMessage = "Permanently remove the previously deleted managed storage account.")]
52+
public SwitchParameter InRemovedState { get; set; }
53+
4654
/// <summary>
4755
/// If present, do not ask for confirmation
4856
/// </summary>
@@ -58,6 +66,24 @@ public class RemoveAzureKeyVaultManagedStorageAccount : KeyVaultCmdletBase
5866

5967
public override void ExecuteCmdlet()
6068
{
69+
if (InRemovedState.IsPresent)
70+
{
71+
ConfirmAction(
72+
Force.IsPresent,
73+
string.Format(
74+
CultureInfo.InvariantCulture,
75+
Resources.RemoveDeletedManagedStorageAccountWarning,
76+
AccountName),
77+
string.Format(
78+
CultureInfo.InvariantCulture,
79+
Resources.RemoveDeletedManagedStorageAccountWhatIfMessage,
80+
AccountName),
81+
AccountName,
82+
() => { DataServiceClient.PurgeManagedStorageAccount(VaultName, AccountName); });
83+
84+
return;
85+
}
86+
6187
PSDeletedKeyVaultManagedStorageAccount managedManagedStorageAccount = null;
6288
ConfirmAction(
6389
Force.IsPresent,

src/ResourceManager/KeyVault/Commands.KeyVault/Commands/RemoveAzureKeyVaultCertificate.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public class RemoveAzureKeyVaultCertificate : KeyVaultCmdletBase
6969
public PSKeyVaultCertificateIdentityItem InputObject { get; set; }
7070

7171
/// <summary>
72-
/// If present, operate on the deleted key entity.
72+
/// If present, operate on the deleted entity.
7373
/// </summary>
7474
[Parameter(Mandatory = false,
7575
HelpMessage = "Permanently remove the previously deleted certificate.")]

src/ResourceManager/KeyVault/Commands.KeyVault/Models/IKeyVaultDataServiceClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace Microsoft.Azure.Commands.KeyVault.Models
2525
{
2626
public interface IKeyVaultDataServiceClient
2727
{
28-
PSKeyVaultKey CreateKey(string vaultName, string keyName, PSKeyVaultKeyAttributes keyAttributes);
28+
PSKeyVaultKey CreateKey(string vaultName, string keyName, PSKeyVaultKeyAttributes keyAttributes, int? size);
2929

3030
PSKeyVaultKey ImportKey(string vaultName, string keyName, PSKeyVaultKeyAttributes keyAttributes, JsonWebKey webKey, bool? importToHsm);
3131

src/ResourceManager/KeyVault/Commands.KeyVault/Models/KeyVaultDataServiceClient.cs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,22 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
using Microsoft.Azure.KeyVault.WebKey;
1615
using System;
1716
using System.Collections;
1817
using System.Collections.Generic;
1918
using System.IO;
2019
using System.Linq;
20+
using System.Net;
2121
using System.Security;
22-
using Microsoft.Azure.Commands.Common.Authentication;
23-
using Microsoft.Azure.Commands.Common.Authentication.Models;
2422
using System.Security.Cryptography.X509Certificates;
2523
using System.Xml;
26-
using KeyVaultProperties = Microsoft.Azure.Commands.KeyVault.Properties;
27-
using Microsoft.Azure.KeyVault.Models;
28-
using Microsoft.Azure.KeyVault;
29-
using Microsoft.Rest.Azure;
3024
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
31-
using System.Net;
3225
using Microsoft.Azure.Commands.KeyVault.Models.ManagedStorageAccounts;
26+
using Microsoft.Azure.KeyVault;
27+
using Microsoft.Azure.KeyVault.Models;
28+
using Microsoft.Azure.KeyVault.WebKey;
29+
using Microsoft.Rest.Azure;
30+
using KeyVaultProperties = Microsoft.Azure.Commands.KeyVault.Properties;
3331

3432
namespace Microsoft.Azure.Commands.KeyVault.Models
3533
{
@@ -59,7 +57,7 @@ public KeyVaultDataServiceClient()
5957
{
6058
}
6159

62-
public PSKeyVaultKey CreateKey(string vaultName, string keyName, PSKeyVaultKeyAttributes keyAttributes)
60+
public PSKeyVaultKey CreateKey(string vaultName, string keyName, PSKeyVaultKeyAttributes keyAttributes, int? size)
6361
{
6462
if (string.IsNullOrEmpty(vaultName))
6563
throw new ArgumentNullException(nameof(vaultName));
@@ -75,9 +73,10 @@ public PSKeyVaultKey CreateKey(string vaultName, string keyName, PSKeyVaultKeyAt
7573
try
7674
{
7775
keyBundle = this.keyVaultClient.CreateKeyAsync(
78-
vaultAddress,
79-
keyName,
80-
keyAttributes.KeyType,
76+
vaultBaseUrl: vaultAddress,
77+
keyName: keyName,
78+
kty: keyAttributes.KeyType,
79+
keySize: size,
8180
keyOps: keyAttributes.KeyOps == null ? null : new List<string> (keyAttributes.KeyOps),
8281
keyAttributes: attributes,
8382
tags: keyAttributes.TagsDirectionary).GetAwaiter().GetResult();

src/ResourceManager/KeyVault/Commands.KeyVault/Models/PSKeyVaultKeyAttributes.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ public class PSKeyVaultKeyAttributes
2626
public PSKeyVaultKeyAttributes()
2727
{ }
2828

29-
internal PSKeyVaultKeyAttributes(bool? enabled, DateTime? expires, DateTime? notBefore, string keyType,
30-
string[] keyOps, Hashtable tags)
29+
internal PSKeyVaultKeyAttributes(bool? enabled, DateTime? expires, DateTime? notBefore, string keyType, string[] keyOps, Hashtable tags)
3130
{
3231
this.Enabled = enabled;
3332
this.Expires = expires;

src/ResourceManager/KeyVault/Commands.KeyVault/Properties/Resources.Designer.cs

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ResourceManager/KeyVault/Commands.KeyVault/Properties/Resources.resx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,4 +474,10 @@ You can find the object ID using Azure Active Directory Module for Windows Power
474474
<data name="RecoverManagedStorageSasDefinition" xml:space="preserve">
475475
<value>Recover KeyVault-managed storage account SAS definition.</value>
476476
</data>
477+
<data name="RemoveDeletedManagedStorageAccountWarning" xml:space="preserve">
478+
<value>Are you sure you want to purge managed storage account '{0}'</value>
479+
</data>
480+
<data name="RemoveDeletedManagedStorageAccountWhatIfMessage" xml:space="preserve">
481+
<value>Purge managed storage account</value>
482+
</data>
477483
</root>

src/ResourceManager/KeyVault/Commands.KeyVault/help/Add-AzureKeyVaultKey.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Creates a key in a key vault or imports a key into a key vault.
1616
### InteractiveCreate (Default)
1717
```
1818
Add-AzureKeyVaultKey [-VaultName] <String> [-Name] <String> -Destination <String> [-Disable]
19-
[-KeyOps <String[]>] [-Expires <DateTime>] [-NotBefore <DateTime>] [-Tag <Hashtable>]
19+
[-KeyOps <String[]>] [-Expires <DateTime>] [-NotBefore <DateTime>] [-Tag <Hashtable>] [-Size <Int32>]
2020
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
2121
```
2222

@@ -31,7 +31,7 @@ Add-AzureKeyVaultKey [-VaultName] <String> [-Name] <String> -KeyFilePath <String
3131
### InputObjectCreate
3232
```
3333
Add-AzureKeyVaultKey [-InputObject] <PSKeyVault> [-Name] <String> -Destination <String> [-Disable]
34-
[-KeyOps <String[]>] [-Expires <DateTime>] [-NotBefore <DateTime>] [-Tag <Hashtable>]
34+
[-KeyOps <String[]>] [-Expires <DateTime>] [-NotBefore <DateTime>] [-Tag <Hashtable>] [-Size <Int32>]
3535
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
3636
```
3737

@@ -46,7 +46,7 @@ Add-AzureKeyVaultKey [-InputObject] <PSKeyVault> [-Name] <String> -KeyFilePath <
4646
### ResourceIdCreate
4747
```
4848
Add-AzureKeyVaultKey [-ResourceId] <String> [-Name] <String> -Destination <String> [-Disable]
49-
[-KeyOps <String[]>] [-Expires <DateTime>] [-NotBefore <DateTime>] [-Tag <Hashtable>]
49+
[-KeyOps <String[]>] [-Expires <DateTime>] [-NotBefore <DateTime>] [-Tag <Hashtable>] [-Size <Int32>]
5050
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
5151
```
5252

@@ -399,6 +399,21 @@ Accept pipeline input: True (ByPropertyName)
399399
Accept wildcard characters: False
400400
```
401401

402+
### -Size
403+
RSA key size, in bits. If not specified, the service will provide a safe default.
404+
405+
```yaml
406+
Type: Int32
407+
Parameter Sets: InteractiveCreate, InputObjectCreate, ResourceIdCreate
408+
Aliases:
409+
410+
Required: False
411+
Position: Named
412+
Default value: None
413+
Accept pipeline input: False
414+
Accept wildcard characters: False
415+
```
416+
402417
### -Tag
403418
Key-value pairs in the form of a hash table. For example:
404419

src/ResourceManager/KeyVault/Commands.KeyVault/help/Remove-AzureKeyVaultManagedStorageAccount.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ Removes a Key Vault managed Azure Storage Account and all associated SAS definit
1313
## SYNTAX
1414

1515
```
16-
Remove-AzureKeyVaultManagedStorageAccount [-VaultName] <String> [-AccountName] <String> [-Force] [-PassThru]
17-
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
16+
Remove-AzureKeyVaultManagedStorageAccount [-VaultName] <String> [-AccountName] <String> [-InRemovedState]
17+
[-Force] [-PassThru] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
1818
```
1919

2020
## DESCRIPTION
@@ -36,6 +36,18 @@ PS C:\> Remove-AzureKeyVaultManagedStorageAccount -VaultName 'myvault' -AccountN
3636

3737
Disassociates Azure Storage Account 'mystorageaccount' from Key Vault 'myvault' and stops Key Vault from managing its keys. The account 'mystorageaccount' will not be removed. All Key Vault managed Storage SAS definitions associated with this account will be removed.
3838

39+
### Example 3: Permanently delete (purge) a Key Vault managed Azure Storage Account and all associated SAS definitions from a soft-delete-enabled vault.
40+
```
41+
PS C:\> Remove-AzureKeyVaultManagedStorageAccount -VaultName 'myvault' -AccountName 'mystorageaccount'
42+
PS C:\> Get-AzureKeyVaultManagedStorageAccount -VaultName 'myvault' -AccountName 'mystorageaccount' -InRemovedState
43+
PS C:\> Remove-AzureKeyVaultManagedStorageAccount -VaultName 'myvault' -AccountName 'mystorageaccount' -InRemovedState
44+
```
45+
46+
The example assumes that soft-delete is enabled for this vault. Verify whether that is the case by examining the vault properties, or the RecoveryLevel attribute of an entity in the vault.
47+
The first cmdlet disassociates Azure Storage Account 'mystorageaccount' from Key Vault 'myvault' and stops Key Vault from managing its keys. The account 'mystorageaccount' will not be removed. All Key Vault managed Storage SAS definitions associated with this account will be removed.
48+
The second cmdlet verifies that the storage account is in a deleted, but recoverable state. Reaching this state may require some time, please allow ~30s before attempting.
49+
The third cmdlet permanently removes the storage account - recovery will no longer be possible.
50+
3951
## PARAMETERS
4052

4153
### -AccountName
@@ -83,6 +95,21 @@ Accept pipeline input: False
8395
Accept wildcard characters: False
8496
```
8597
98+
### -InRemovedState
99+
Permanently remove the previously deleted managed storage account.
100+
101+
```yaml
102+
Type: SwitchParameter
103+
Parameter Sets: (All)
104+
Aliases:
105+
106+
Required: False
107+
Position: Named
108+
Default value: None
109+
Accept pipeline input: False
110+
Accept wildcard characters: False
111+
```
112+
86113
### -PassThru
87114
Cmdlet does not return an object by default.
88115
If this switch is specified, cmdlet returns the managed storage account that was deleted.

0 commit comments

Comments
 (0)