Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

containers/ws: Support host-specific ssh keys #20904

Merged
merged 1 commit into from
Sep 27, 2024

Conversation

benniekiss
Copy link
Contributor

@benniekiss benniekiss commented Aug 18, 2024

This PR adds the ability to set host-specific ssh keys via env-var in the cockpit-ws container.

Users can pass environment variables in the format of COCKPIT_SSH_KEY_PATH_{HOSTNAME}, where HOSTNAME is the hostname used in the Connect to field of the cockpit login page, and cockpit will use the configured key to login to the host. If no host-specific key is set, it falls back to using the COCKPIT_SSH_KEY_PATH environment variable.

I still need to make a unit test, but I wanted to ask for suggestions as to the best route. The cockpit bastion test could be replicated, or it could be refactored to test host-specific keys. I wasn't sure what the best approach would be, and would appreciate any advice before proceeding!

This functionality will enable users to login to multiple hosts via ssh keys once the host-switcher is deprecated, providing a solution to user concerns such as #20901

cockpit/ws container: Support host specific SSH keys

The cockpit/ws container now supports adding multiple SSH private keys. In addition to the existing $COCKPIT_SSH_KEY_PATH environment variable, you can now set host specific $COCKPIT_SSH_KEY_PATH_{HOSTNAME} variables, where {HOSTNAME} is the host name (in capital letters) used in the Connect to: field of the login page.

Thanks to benniekiss for contributing this feature!

@martinpitt
Copy link
Member

Thanks @benniekiss ! This is a pretty cool feature! It does need an integration test, yes. I suggest you factorize that test a bit, with a do_test_key_login(options: str), and then call this several times in testKeyLogin() with the scenarios (only COCKPIT_SSH_KEY_PATH, the per-hostname ones, and the fallback). You can use invalid keys for the ones that you don't expect to get picked of course, so you don't need multiple VMs/SSH targets.

@benniekiss
Copy link
Contributor Author

Thank you! I'll start working on the test soon.

FWIW, I've been running this patch personally, and it's worked well.

@benniekiss benniekiss force-pushed the multiple_ssh_keys branch 2 times, most recently from 739b5bb to 8586737 Compare September 24, 2024 14:53
@benniekiss
Copy link
Contributor Author

I refactored the test to account for setting a host-specific key var and the fallback. I was not able to run these tests locally. I was having a lot of trouble getting the test infrastructure up on my aarch64 system -- M2 macbook on asahi. I tried following the docs in HACKING.md and in the test/README.md, but I struggled to get it working.

Copy link
Member

@martinpitt martinpitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cheers! This looks pretty good, I'd just like to adjust the documentation. Please also squash the commits together into a "containers/ws: Support host-specific ssh keys".

I triggered the fedora-coreos tests (the only relevant ones) to see how it fares.

containers/ws/README.md Outdated Show resolved Hide resolved
@martinpitt
Copy link
Member

The test failed in the second round, presumably as it tries to regenerate the RSA key a second time when it already exists. This needs to be taken out of the loop.

@martinpitt
Copy link
Member

@benniekiss as previously: Please tell me when you are fed up and want me to take over 😁

@benniekiss
Copy link
Contributor Author

rebased on main and squashed!

I moved the ssh-keygen calls and the self.addCleanup calls outside of the loop, and I updated the documentation as suggested.

If the tests don't pass, I'd appreciate if you'd be able to takeover and see this through! Just because I still haven't been able to get the tests running locally

@benniekiss
Copy link
Contributor Author

fixed a misplaced comment

@martinpitt martinpitt changed the title [FEAT] host-specific ssh keys for cockpit container containers/ws: Support host-specific ssh keys Sep 26, 2024
@martinpitt
Copy link
Member

@benniekiss Still unhappy.. I'll take over, thank you!

@benniekiss
Copy link
Contributor Author

You're welcome! And thank you, too

@martinpitt
Copy link
Member

Fixed ; it was missing the .upper() for the hostname and some cleanup.

Thanks!

@martinpitt
Copy link
Member

@benniekiss I added a release note to the description. Proof-reading much appreciated!

@martinpitt martinpitt merged commit b33deff into cockpit-project:main Sep 27, 2024
86 of 88 checks passed
@benniekiss
Copy link
Contributor Author

Release note looks good overall! I cleaned up some grammar.

This markdown formatting is a little hard to read, but I wasn't sure if there was a clearer way to write it.

$COCKPIT_SSH_KEY_PATH_HOSTNAME

I had used COCKPIT_SSH_KEY_PATH_{HOSTNAME} previously, so that would be my suggestion.

@martinpitt
Copy link
Member

@benniekiss you are right, I changed it to {}. Cheers!

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.

2 participants