Repository navigation
cephadm: test ssh key authorize/revoke and fix two edge cases - #74693
Open
abrahamperz wants to merge 1 commit into
Open
abrahamperz wants to merge 1 commit into
abrahamperz wants to merge 1 commit into
Conversation
authorize_ssh_key() and revoke_ssh_key() had no unit test coverage. Writing the tests turned up two bugs: - revoke_ssh_key() created its mkstemp() file before knowing whether the key was present, never closed the returned fd, and left the temporary file behind when the key was not found. - authorize_ssh_key() rejected a whitespace-only key but accepted an empty string, since ''.isspace() is False. Only create the temporary file when there is a line to remove, and reject empty keys explicitly. Fixes: https://tracker.ceph.com/issues/57621 Signed-off-by: Abraham Pérez <[email protected]>
|
Thank you for your contribution. Since you are not yet a member of the Ceph organization with write permissions on ceph/ceph.git, our CI will not automatically run. Any member of the Ceph organization may label this PR |
abrahamperz
marked this pull request as ready for review
December 1, 2026 15:02
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.
When cephadm bootstraps a cluster or adds a host, it manages the cephadm ssh user's authorized_keys file through two small helpers in cephadmlib/ssh.py: authorize_ssh_key() appends the cluster's public key, and revoke_ssh_key() removes it again. Neither had any unit test coverage, which is part of what the cephadm test coverage tracker asks for.
This adds tests/test_ssh.py, which covers adding a key (including creating the .ssh directory and fixing up a file that lacks a trailing newline), skipping a key that is already present, rejecting an empty key, removing only the matching line on revoke, and leaving the file alone when the key is unknown or the file does not exist.
Writing those tests turned up two real bugs, fixed here as well. revoke_ssh_key() called mkstemp() before it knew whether the key was in the file, never closed the returned fd, and left the temporary file in /tmp whenever the key was not found. It now only creates the temporary file when there is a line to drop. authorize_ssh_key() rejected a whitespace-only key but accepted an empty string, because ''.isspace() is False; it now rejects both. Behavior for valid keys is unchanged.
Two of the new tests failed against the current code (the leaked temporary file and the empty key) and pass with the fix. The full cephadm unit test suite passes, and flake8 and black are clean.
Fixes: https://tracker.ceph.com/issues/57621
Contribution Guidelines
To sign and title your commits, please refer to Submitting Patches to Ceph.
If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.
When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an
xbetween the brackets:[x]. Spaces and capitalization matter when checking off items this way.Checklist