Repository navigation
Conversation
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.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this change do?
Adds a
regenerate_ssh_host_keystep to thecisco_nxosdriver, and records the switch's SSH host keys during inspection. There are three commits:NX-API client: adds
configure()andshow_text(). Theshowmethods still refuse anything that isn't ashowcommand, soconfigure()is the only method that changes a switch.Inspection: reads
show ssh keyas text, in a second NX-API request, and storesplugin_data.ssh_host_keys, keyed by algorithm. Each entry haspublic_key(OpenSSH format) andfingerprint(SHA256, computed from the key because older NX-OS releases print MD5).bitsandgeneratedare included when the switch reports them. A switch that can't report its keys is logged, not failed.Management interface: adds
regenerate_ssh_host_key, a manual clean step, a priority-0 deploy step and a service step.algorithmisrsa(the default) orecdsa.bitsis 1024, 2048, 3072 or 4096. The default is 2048 because 3072 and 4096 need NX-OS 10.5(2)F or later.bitsis 256, 384 or 521, default 256.Following Cisco's procedure, the step sends
no feature ssh, thenssh key <alg> <bits> force, thenfeature 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 replacessh_host_keysin the stored inspection data.Example:
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:
show ssh keytext matches the layout in Cisco's example output, andcli_asciireturns the text undermsg. If the output differs, the keys aren't recorded and a warning is logged.no feature sshandssh key ... forcedon't ask for confirmation over NX-API.copy running-config startup-config.References:
Upgrade impact
upgrade-impactlabel and a release note: runscriv createfrom therepository root and describe the required action in the generated
changelog.d/file. See RELEASING.md.cisco_nxosis added toenabled_management_interfacesincomponents/ironic/values.yaml. A deployment that overrides that list needs to addcisco_nxosbefore it can use the step. Existingcisco_nxosnodes keep their current management interface until it's changed.