Skip to content

Commit a3c6585

Browse files
committed
Improve AKS SSH key handling and help text
Enhanced the logic for SSH key validation in AKS cluster creation to default to server-side generated keys if no local public key is found and no value is provided. Updated help documentation to clarify SSH key behavior. Added a test and recording for AKS creation without an SSH key.
1 parent 6de9b42 commit a3c6585

File tree

4 files changed

+879
-5
lines changed

4 files changed

+879
-5
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: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,28 @@
4242
def validate_ssh_key(namespace):
4343
if hasattr(namespace, 'no_ssh_key') and namespace.no_ssh_key:
4444
return
45-
string_or_file = (namespace.ssh_key_value or
46-
os.path.join(os.path.expanduser('~'), '.ssh', 'id_rsa.pub'))
45+
46+
exists = os.path.exists(
47+
string_or_file := (
48+
namespace.ssh_key_value
49+
or os.path.join(os.path.expanduser('~'), '.ssh', 'id_rsa.pub')
50+
)
51+
)
4752
content = string_or_file
48-
if os.path.exists(string_or_file):
53+
54+
if exists:
4955
logger.info('Use existing SSH public key file: %s', string_or_file)
5056
with open(string_or_file, 'r') as f:
5157
content = f.read()
52-
elif not keys.is_valid_ssh_rsa_public_key(content):
58+
59+
if not (namespace.ssh_key_value or namespace.generate_ssh_keys):
60+
if exists:
61+
namespace.ssh_key_value = content
62+
return
63+
namespace.no_ssh_key = True
64+
return
65+
66+
if not exists and not keys.is_valid_ssh_rsa_public_key(content):
5367
if namespace.generate_ssh_keys:
5468
# figure out appropriate file names:
5569
# 'base_name'(with private keys), and 'base_name.pub'(with public keys)

0 commit comments

Comments
 (0)