-
Notifications
You must be signed in to change notification settings - Fork 4.1k
[Az.Aks] Enforce RSA as the GenerateSSHKeys default key type #28998
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -30,6 +30,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| using Microsoft.Rest; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| using Microsoft.WindowsAzure.Commands.Common; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| using Microsoft.WindowsAzure.Commands.Utilities.Common; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| using System.Runtime.InteropServices; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| namespace Microsoft.Azure.Commands.Aks | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -311,6 +312,61 @@ private void PreValidate() | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // From OpenSSH 9.4 onwards, the default key type is ed25519, which is not supported in AKS. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // To ensure backward compatibility, we need to check the OpenSSH version installed and adjust the parameters accordingly. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| static Version GetOpenSSHVersion() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| using (Process process = new Process()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Using runtime information to determine the path to ssh.exe based on OS type. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bool isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| string defaultWindowsSshPath = @"C:\Windows\System32\OpenSSH\ssh.exe"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| process.StartInfo.FileName = isWindows && File.Exists(defaultWindowsSshPath) ? defaultWindowsSshPath : "ssh"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| process.StartInfo.Arguments = "-V"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| process.StartInfo.UseShellExecute = false; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| process.StartInfo.RedirectStandardInput = true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| process.StartInfo.RedirectStandardError = true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| process.StartInfo.RedirectStandardOutput = true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| process.StartInfo.CreateNoWindow = true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| process.Start(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| string standardOutput = process.StandardOutput.ReadToEnd() + process.StandardError.ReadToEnd(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| process.WaitForExit(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // OpenSSH version output follows formats like: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Windows: "OpenSSH_for_Windows_8.6p1, LibreSSL 3.4.3" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Windows: "OpenSSH_for_Windows_9.5p1, LibreSSL 3.8.2" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Linux/macOS: "OpenSSH_9.5p1, OpenSSL 3.0.13 30 Jan 2024" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // We match the common "OpenSSH_" prefix and make "for_Windows_" optional so this works across platforms. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var regMatch = System.Text.RegularExpressions.Regex.Match(standardOutput, @"OpenSSH_(?:for_Windows_)?(\d+)\.(\d+)"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // We don't really care about the patch version, so only return major and minor version. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return regMatch.Success ? new Version(int.Parse(regMatch.Groups[1].Value), int.Parse(regMatch.Groups[2].Value)) : null; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // We're not expecting ssh to be missing, but just in case, we catch any exception and return null. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| catch | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return null; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+348
to
+352
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // We're not expecting ssh to be missing, but just in case, we catch any exception and return null. | |
| catch | |
| { | |
| return null; | |
| } | |
| // We're not expecting ssh to be missing, but just in case, we catch specific exceptions and return null. | |
| catch (FileNotFoundException ex) | |
| { | |
| WriteDebug($"Failed to detect SSH version: SSH executable not found. Detail: {ex.Message}"); | |
| return null; | |
| } | |
| catch (Win32Exception ex) | |
| { | |
| WriteDebug($"Failed to detect SSH version due to a Win32 error when starting the SSH process. Detail: {ex.Message}"); | |
| return null; | |
| } | |
| catch (InvalidOperationException ex) | |
| { | |
| WriteDebug($"Failed to detect SSH version due to an invalid process configuration. Detail: {ex.Message}"); | |
| return null; | |
| } | |
| catch (Exception ex) | |
| { | |
| WriteDebug($"Failed to detect SSH version due to an unexpected error. Detail: {ex.Message}"); | |
| return null; | |
| } |
Copilot
AI
Dec 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ChangeLog.md file is missing an entry for this SSH key generation change. According to the repository's contribution guidelines, you SHOULD update the ChangeLog.md file under the "Upcoming Release" section to document this change. Add a bullet point describing the enforcement of RSA as the default key type for OpenSSH 9.4 and above to ensure AKS compatibility.
jovieir marked this conversation as resolved.
Show resolved
Hide resolved
jovieir marked this conversation as resolved.
Show resolved
Hide resolved
jovieir marked this conversation as resolved.
Show resolved
Hide resolved
Copilot
AI
Dec 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new OpenSSH version detection logic and conditional SSH key type generation are not covered by automated tests. Given that the Aks.Test project contains comprehensive test scenarios for other module functionality, this new behavior should have test coverage to verify correct version detection, version comparison logic, and proper argument construction for both OpenSSH versions below and above 9.4.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The process output reading on line 335 may cause a deadlock if the output buffers fill up. Reading both StandardOutput and StandardError synchronously after process.Start() can block if either buffer becomes full before WaitForExit is called. Consider using asynchronous reading with BeginOutputReadLine and BeginErrorReadLine, or read StandardError and StandardOutput separately to avoid potential deadlock situations.