Skip to content

Commit 4fb64ab

Browse files
Support generation of Ed25519 SSH Key (#26027)
* Autogen code * Adding changes to New-Azsshkey * more changes * Changes --------- Co-authored-by: PSCmdAssistant <[email protected]>
1 parent 75742d5 commit 4fb64ab

File tree

6 files changed

+93
-10
lines changed

6 files changed

+93
-10
lines changed

src/Compute/Compute.Test/ScenarioTests/VirtualMachineTests.ps1

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7651,3 +7651,39 @@ function Test-VMSetAzOSCredentialNullRef
76517651
Clean-ResourceGroup $rgname;
76527652
}
76537653
}
7654+
7655+
function Test-VMwithSSHKeyEd25519
7656+
{
7657+
# Setup
7658+
$rgname = Get-ComputeTestResourceName;
7659+
$loc = Get-ComputeVMLocation;
7660+
7661+
try
7662+
{
7663+
New-AzResourceGroup -Name $rgname -Location $loc -Force;
7664+
7665+
7666+
# create credential
7667+
$securePassword = Get-PasswordForVM | ConvertTo-SecureString -AsPlainText -Force;
7668+
$user = Get-ComputeTestResourceName;
7669+
$cred = New-Object System.Management.Automation.PSCredential ($user, $securePassword);
7670+
7671+
# Add one VM from creation
7672+
$vmname = '1' + $rgname;
7673+
$domainNameLabel = "d1" + $rgname;
7674+
$sshKeyName = "s" + $rgname
7675+
$vm = New-AzVM -ResourceGroupName $rgname -Name $vmname -Credential $cred -Image CentOS85Gen2 -DomainNameLabel $domainNameLabel -SshKeyname $sshKeyName -generateSshkey -SshKeyType 'Ed25519'
7676+
7677+
$vm = Get-AzVm -ResourceGroupName $rgname -Name $vmname
7678+
$sshKey = Get-AzSshKey -ResourceGroupName $rgname -Name $sshKeyName
7679+
7680+
#assert compare
7681+
Assert-AreEqual $vm.OSProfile.LinuxConfiguration.Ssh.PublicKeys[0].KeyData $sshKey.publickey
7682+
7683+
}
7684+
finally
7685+
{
7686+
# Cleanup
7687+
Clean-ResourceGroup $rgname;
7688+
}
7689+
}

src/Compute/Compute/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
2121
-->
2222
## Upcoming Release
23+
* Added a new optional parameter `-GenerateSshKey-type` to the `New-AzVM` cmdlet, allowing users to specify the type of SSH key to generate (Ed25519 or RSA).
2324
* Added `EnableResilientVMCreate` and `EnableResilientVMDelete` parameters to `Update-AzVmss` and `New-AzVmssConfig` cmdlets for enhanced VM resilience options.
2425

2526
## Version 8.3.0

src/Compute/Compute/Usage/NewAzureSshKey.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,20 @@ public partial class NewAzureSshKey : ComputeAutomationBaseCmdlet
3737
ValueFromPipelineByPropertyName = true)]
3838
public string PublicKey { get; set; }
3939

40+
[Parameter(
41+
Mandatory = false,
42+
HelpMessage = "Specify the type of SSH key to generate. Allowed values are 'Ed25519' and 'RSA'.")]
43+
[ValidateSet("Ed25519", "RSA")]
44+
public string SshKeyType { get; set; }
45+
4046
public override void ExecuteCmdlet()
4147
{
4248
base.ExecuteCmdlet();
4349
ExecuteClientAction(() =>
4450
{
4551
string resourceGroupName = this.ResourceGroupName;
4652
string sshKeyName = this.Name;
53+
string sshKeyType = this.SshKeyType;
4754
SshPublicKeyResource result;
4855
SshPublicKeyResource sshkey = new SshPublicKeyResource();
4956
ResourceGroup rg = ArmClient.ResourceGroups.Get(resourceGroupName);
@@ -61,7 +68,7 @@ public override void ExecuteCmdlet()
6168
WriteDebug("No public key is provided. A key pair is being generated for you.");
6269

6370
result = SshPublicKeyClient.Create(resourceGroupName, sshKeyName, sshkey);
64-
SshPublicKeyGenerateKeyPairResult keypair = SshPublicKeyClient.GenerateKeyPair(resourceGroupName, sshKeyName);
71+
SshPublicKeyGenerateKeyPairResult keypair = SshPublicKeyClient.GenerateKeyPair(resourceGroupName, sshKeyName, sshKeyType);
6572
result.PublicKey = keypair.PublicKey;
6673

6774
string sshFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".ssh" );

src/Compute/Compute/VirtualMachine/Operation/NewAzureVMCommand.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// ----------------------------------------------------------------------------------
1+
// ----------------------------------------------------------------------------------
22
//
33
// Copyright Microsoft Corporation
44
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -453,6 +453,13 @@ public class NewAzureVMCommand : VirtualMachineBaseCmdlet
453453
HelpMessage = "Used to make a request conditional for the GET and HEAD methods. The server will only return the requested resources if none of the listed ETag values match the current entity. Used to make a request conditional for the GET and HEAD methods. The server will only return the requested resources if none of the listed ETag values match the current entity. Set to '*' to allow a new record set to be created, but to prevent updating an existing record set. Other values will result in error from server as they are not supported.")]
454454
public string IfNoneMatch { get; set; }
455455

456+
[Parameter(
457+
Mandatory = false,
458+
ParameterSetName = SimpleParameterSet,
459+
HelpMessage = "Specify the type of SSH key to generate. Allowed values are 'Ed25519' and 'RSA'.")]
460+
[ValidateSet("Ed25519", "RSA")]
461+
public string SshKeyType { get; set; }
462+
456463
public override void ExecuteCmdlet()
457464
{
458465
if (this.IsParameterBound(c => c.UserData))
@@ -1613,7 +1620,7 @@ private string GenerateOrFindSshKey()
16131620
SshPublicKeyResource sshkey = new SshPublicKeyResource();
16141621
sshkey.Location = this.Location != null ? this.Location : "eastus";
16151622
SshPublicKey = this.ComputeClient.ComputeManagementClient.SshPublicKeys.Create(this.ResourceGroupName, this.SshKeyName, sshkey);
1616-
SshPublicKeyGenerateKeyPairResult keypair = this.ComputeClient.ComputeManagementClient.SshPublicKeys.GenerateKeyPair(this.ResourceGroupName, this.SshKeyName);
1623+
SshPublicKeyGenerateKeyPairResult keypair = this.ComputeClient.ComputeManagementClient.SshPublicKeys.GenerateKeyPair(this.ResourceGroupName, this.SshKeyName, this.SshKeyType);
16171624

16181625
string sshFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".ssh");
16191626
if (!Directory.Exists(sshFolder))
@@ -1716,4 +1723,4 @@ private void validate()
17161723
}
17171724
}
17181725
}
1719-
}
1726+
}

src/Compute/Compute/help/New-AzSshKey.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ Create a SSH Public Key resource.
1313
## SYNTAX
1414

1515
```
16-
New-AzSshKey -ResourceGroupName <String> -Name <String> [-PublicKey <String>]
17-
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
16+
New-AzSshKey -ResourceGroupName <String> -Name <String> [-PublicKey <String>] [-SshKeyType <String>]
17+
[-DefaultProfile <IAzureContextContainer>] [-ProgressAction <ActionPreference>] [-WhatIf] [-Confirm]
1818
[<CommonParameters>]
1919
```
2020

@@ -99,6 +99,22 @@ Accept pipeline input: True (ByPropertyName)
9999
Accept wildcard characters: True
100100
```
101101
102+
### -SshKeyType
103+
Specify the type of SSH key to generate. Allowed values are 'Ed25519' and 'RSA'.
104+
105+
```yaml
106+
Type: System.String
107+
Parameter Sets: (All)
108+
Aliases:
109+
Accepted values: Ed25519, RSA
110+
111+
Required: False
112+
Position: Named
113+
Default value: None
114+
Accept pipeline input: False
115+
Accept wildcard characters: False
116+
```
117+
102118
### -Confirm
103119
Prompts you for confirmation before running the cmdlet.
104120

src/Compute/Compute/help/New-AzVM.md

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ New-AzVM [[-ResourceGroupName] <String>] [[-Location] <String>] [-EdgeZone <Stri
2828
[-UserData <String>] [-ImageReferenceId <String>] [-PlatformFaultDomain <Int32>] [-HibernationEnabled]
2929
[-vCPUCountAvailable <Int32>] [-vCPUCountPerCore <Int32>] [-DiskControllerType <String>]
3030
[-SharedGalleryImageId <String>] [-SecurityType <String>] [-EnableVtpm <Boolean>]
31-
[-EnableSecureBoot <Boolean>] [-IfMatch <String>] [-IfNoneMatch <String>]
32-
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
31+
[-EnableSecureBoot <Boolean>] [-IfMatch <String>] [-IfNoneMatch <String>] [-SshKeyType <String>]
32+
[-DefaultProfile <IAzureContextContainer>] [-ProgressAction <ActionPreference>] [-WhatIf] [-Confirm]
3333
[<CommonParameters>]
3434
```
3535

@@ -39,7 +39,7 @@ New-AzVM [-ResourceGroupName] <String> [-Location] <String> [-EdgeZone <String>]
3939
[[-Zone] <String[]>] [-DisableBginfoExtension] [-Tag <Hashtable>] [-LicenseType <String>] [-AsJob]
4040
[-OSDiskDeleteOption <String>] [-DataDiskDeleteOption <String>] [-SshKeyName <String>] [-GenerateSshKey]
4141
[-vCPUCountAvailable <Int32>] [-vCPUCountPerCore <Int32>] [-IfMatch <String>] [-IfNoneMatch <String>]
42-
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
42+
[-DefaultProfile <IAzureContextContainer>] [-ProgressAction <ActionPreference>] [-WhatIf] [-Confirm]
4343
[<CommonParameters>]
4444
```
4545

@@ -57,7 +57,7 @@ New-AzVM [[-ResourceGroupName] <String>] [[-Location] <String>] [-EdgeZone <Stri
5757
[-HostGroupId <String>] [-CapacityReservationGroupId <String>] [-UserData <String>]
5858
[-PlatformFaultDomain <Int32>] [-HibernationEnabled] [-vCPUCountAvailable <Int32>] [-vCPUCountPerCore <Int32>]
5959
[-IfMatch <String>] [-IfNoneMatch <String>] [-DefaultProfile <IAzureContextContainer>]
60-
[-WhatIf] [-Confirm] [<CommonParameters>]
60+
[-ProgressAction <ActionPreference>] [-WhatIf] [-Confirm] [<CommonParameters>]
6161
```
6262

6363
## DESCRIPTION
@@ -1120,6 +1120,22 @@ Accept pipeline input: False
11201120
Accept wildcard characters: False
11211121
```
11221122
1123+
### -SshKeyType
1124+
Specify the type of SSH key to generate. Allowed values are 'Ed25519' and 'RSA'.
1125+
1126+
```yaml
1127+
Type: System.String
1128+
Parameter Sets: SimpleParameterSet
1129+
Aliases:
1130+
Accepted values: Ed25519, RSA
1131+
1132+
Required: False
1133+
Position: Named
1134+
Default value: None
1135+
Accept pipeline input: False
1136+
Accept wildcard characters: False
1137+
```
1138+
11231139
### -SubnetAddressPrefix
11241140
The address prefix for the subnet which will be created for the VM.
11251141

0 commit comments

Comments
 (0)