Skip to content

Commit 200d33a

Browse files
committed
Improve AKS SSH key handling and documentation
Enhanced help text to clarify default SSH key behavior for AKS clusters. Updated SSH key validation logic to default to server-side key generation when no local key is present. Added and updated tests to cover scenarios without SSH keys.
1 parent 1a50871 commit 200d33a

File tree

4 files changed

+822
-3
lines changed

4 files changed

+822
-3
lines changed

src/azure-cli/azure/cli/command_modules/acs/_help.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@
9595
- name: --ssh-key-value
9696
type: string
9797
short-summary: Public key path or key contents to install on node VMs for SSH access. For example, 'ssh-rsa AAAAB...snip...UcyupgH azureuser@linuxvm'.
98+
long-summary: |-
99+
If omitted:
100+
- The CLI will use '~/.ssh/id_rsa.pub' when present
101+
- If that file is not present the CLI will default to server-side generated keys (equivalent to using --no-ssh-key)
98102
- name: --admin-username -u
99103
type: string
100104
short-summary: User account to create on node VMs for SSH access.
@@ -263,7 +267,7 @@
263267
- name: --no-ssh-key -x
264268
type: string
265269
short-summary: Do not use or create a local SSH key.
266-
long-summary: To access nodes after creating a cluster with this option, use the Azure Portal.
270+
long-summary: If omitted and no local public key exists, the CLI will default to this behavior. To access nodes after creating a cluster with this option, use the Azure Portal.
267271
- name: --pod-cidr
268272
type: string
269273
short-summary: A CIDR notation IP range from which to assign pod IPs when Azure CNI Overlay or Kubenet is used (On 31 March 2028, Kubenet will be retired).

src/azure-cli/azure/cli/command_modules/acs/_validators.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,16 @@ def validate_ssh_key(namespace):
6565
"file share, back up your keys to a safe location",
6666
private_key_filepath, public_key_filepath)
6767
else:
68-
raise CLIError('An RSA key file or key value must be supplied to SSH Key Value. '
69-
'You can use --generate-ssh-keys to let CLI generate one for you')
68+
if (not content or str(content).strip() == "" or
69+
(content == os.path.join(os.path.expanduser('~'), '.ssh', 'id_rsa.pub'))):
70+
namespace.no_ssh_key = True
71+
return
72+
raise CLIError(
73+
"The SSH key provided is not a valid RSA public key. "
74+
"Provide the contents of a valid SSH public key (for example, '~/.ssh/id_rsa.pub'), "
75+
"specify a path to a public key file, "
76+
"or add --generate-ssh-keys as a parameter to create a new key pair."
77+
)
7078
namespace.ssh_key_value = content
7179

7280

0 commit comments

Comments
 (0)