Skip to content

feat(ironic): add cisco_nxos step to regenerate the SSH host key - #2843

Draft
cardoe wants to merge 3 commits into
mainfrom
nxos-ssh-host-key
Draft

cardoe wants to merge 3 commits into
mainfrom
nxos-ssh-host-key

Conversation

@cardoe

@cardoe cardoe commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

What does this change do?

Adds a regenerate_ssh_host_key step to the cisco_nxos driver, and records the switch's SSH host keys during inspection. There are three commits:

  1. NX-API client: adds configure() and show_text(). The show methods still refuse anything that isn't a show command, so configure() is the only method that changes a switch.

  2. Inspection: reads show ssh key as text, in a second NX-API request, and stores plugin_data.ssh_host_keys, keyed by algorithm. Each entry has public_key (OpenSSH format) and fingerprint (SHA256, computed from the key because older NX-OS releases print MD5). bits and generated are included when the switch reports them. A switch that can't report its keys is logged, not failed.

  3. Management interface: adds regenerate_ssh_host_key, a manual clean step, a priority-0 deploy step and a service step.

    • algorithm is rsa (the default) or ecdsa.
    • For RSA, bits is 1024, 2048, 3072 or 4096. The default is 2048 because 3072 and 4096 need NX-OS 10.5(2)F or later.
    • For ECDSA, bits is 256, 384 or 521, default 256.
    • ed25519 isn't offered because NX-OS doesn't support it, and DSA isn't offered because it's deprecated.
    • Arguments are checked before the switch is contacted.

    Following Cisco's procedure, the step sends no feature ssh, then ssh key <alg> <bits> force, then feature ssh. Each command is its own request, so SSH is turned back on even if the key command is rejected. NX-OS keeps one host key per algorithm, so only that algorithm's key changes. The step doesn't save the config, because that would also save any other unsaved changes on the switch. The new keys replace ssh_host_keys in the stored inspection data.

Example:

openstack baremetal node clean <node> --clean-steps \
  '[{"interface": "management", "step": "regenerate_ssh_host_key", "args": {"algorithm": "ecdsa", "bits": 384}}]'

Not tested against a switch

We don't have a lab switch, so these assumptions come from Cisco's docs, not from a real device. Each should be checked on the first real switch:

  • The show ssh key text matches the layout in Cisco's example output, and cli_ascii returns the text under msg. If the output differs, the keys aren't recorded and a warning is logged.
  • no feature ssh and ssh key ... force don't ask for confirmation over NX-API.
  • A regenerated key survives a reload without copy running-config startup-config.
  • A switch older than 10.5(2)F rejects 3072 or 4096 bits with an ordinary command error.

References:

Upgrade impact

  • This change requires operator action to upgrade. If checked, add the
    upgrade-impact label and a release note: run scriv create from the
    repository root and describe the required action in the generated
    changelog.d/ file. See RELEASING.md.

cisco_nxos is added to enabled_management_interfaces in components/ironic/values.yaml. A deployment that overrides that list needs to add cisco_nxos before it can use the step. Existing cisco_nxos nodes keep their current management interface until it's changed.

NxosClient only ran show commands with structured output. Add
configure(), which sends configuration commands in one request and
raises the first one the switch rejects, and show_text(), which runs a
show command through cli_ascii for commands that have no JSON output.

The show methods still refuse anything but show commands; configure()
is the only way to change the switch, so the callers that do are easy
to find.
Read show ssh key, as text, in a second NX-API request and store the
host keys in the inspection plugin data as ssh_host_keys, keyed by
algorithm. Each has the OpenSSH public key and its SHA256 fingerprint,
computed from the key since older NX-OS releases print MD5, plus the
bit count and generation date when reported.

The keys describe the switch's configuration rather than its hardware,
so they go in the plugin data, not the inventory. A switch that cannot
report them is logged, not failed, like the other optional details.
Add a cisco_nxos management interface with regenerate_ssh_host_key, a
manual clean, deploy and service step. It takes algorithm (rsa, the
default, or ecdsa) and bits: 1024, 2048, 3072 or 4096 for RSA, default
2048 since 3072 and 4096 need NX-OS 10.5(2)F or later, and 256, 384 or
521 for ECDSA, default 256. ed25519 is unsupported by NX-OS and DSA is
deprecated. Arguments are checked before the switch is contacted.

As Cisco documents, SSH is disabled while the key is generated (no
feature ssh, ssh key <algorithm> <bits> force, feature ssh). Each
command is its own NX-API request so SSH is re-enabled even when the
key is rejected. NX-OS keeps one key per algorithm, so only that
algorithm's key changes. The configuration is not saved, since that
would also save unrelated pending changes. The new keys replace
ssh_host_keys in the node's stored inspection data.

This has not been run against a switch: the behaviour without a saved
configuration across reload, and whether these commands prompt over
NX-API, are taken from the documentation.
@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown

Python test results

2 571 tests  +34   2 566 ✅ +34   2m 1s ⏱️ +23s
    7 suites ± 0       5 💤 ± 0 
    7 files   ± 0       0 ❌ ± 0 

Results for commit c99f05c. ± Comparison against base commit 2adb896.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant