feature statement
As a user, I want copy-paste to "just work" when pasting SSH private keys into Cloudron.
context
When setting up SSHFS, either for backups or volume mounts, a private key is needed. These typically have the form
-----BEGIN OPENSSH PRIVATE KEY-----
MULTIPLE/ASDFLAKSJDFLKAJASDFLKJASDF
LINES/ASDFASDFKLJASDLFJKSADFLKJASDF
OF/ASDFLKJASDFLKJASDFLKJASDFLJKASDL
BASE64/ASDFJKLASDFLKJASDLFJKASDFLKJ
DATA/ANDPADDING=
-----END OPENSSH PRIVATE KEY-----
As a user, I might be copy-pasting this from a number of places.
I might cat a private key on my terminal, and have to use a three-key sequence (CTRL-SHIFT-C) to copy
I might cat a private key in a web terminal, and have to CTRL-INS to copy (because that is how the web terminal is configured)
I might use Bitwarden/Vaultwarden, and have it generate a keypair for me. That key will then have a "copy icon" that I can click for both the public and private keys
I might use a web gui in another product (e.g. TrueNAS Scale) to generate the keys, and copy-paste out of a web text area
In each case, the way whitespace is handled may vary.
Further, it appears (based on skimming things on the web) that SSH defines the protocol, but there are not good definitions for how SSH keys should be stored. That is, the bytestream representation for communicating them between client and server is specified, but it is a bit up-in-the-air as to how they should be stored at rest.
On inspection, it looks like it is common for a MIME encoding to be used on the Base64 content. Base64 does not consider __ (that's a space) to be a valid character. Some encodings, like MIME, specify maximum line lengths, but the use of spaces/newlines/etc. as separators should be ignored.
https://en.wikipedia.org/wiki/Base64
(Apologies for not linking to authoritative sources/RFCs.)
the problem
Long story short: when I paste a private key into Cloudron, I am pasting a lot of text into a small text area. How whitespaces or linebreaks are or are not used once I hit "Save" or "Submit" is invisible to me as a user. However, it is clear that it has impact.
When I copy-paste and carefully preserve line breaks, it appears to work.
When I use Bitwarden, and copy-paste from an auto-generated keypair, it appears to fail.
replicating the error
Go to your Bitwarden install
Generate and save an SSH keypair
Copy the private key
Create an SSHFS volume mount
Paste in the private key
On another system, add the public key to the authorized_keys file
It should fail.
It is also possible that there is some kind of subtle user error taking place; however, I'm uncertain where to look in my Cloudron instance to debug this under the covers.
what i want as a user
I want things to "just work."
In this case, I would like Cloudron to either:
Warn me my key is not well-formatted, or
Make a best effort to format the key appropriately behind-the-scenes
If I paste something like this (the Bitwarden example):
-----BEGIN OPENSSH PRIVATE KEY----- MULTIPLE/ASDFLAKSJDFLKAJASDFLKJASDF LINES/ASDFASDFKLJASDLFJKSADFLKJASDF ... -----END OPENSSH PRIVATE KEY-----
with whitespaces instead of newlines, I expect Cloudron to write it to disk replacing my spaces with newlines, so it becomes:
-----BEGIN OPENSSH PRIVATE KEY-----
MULTIPLE/ASDFLAKSJDFLKAJASDFLKJASDF
LINES/ASDFASDFKLJASDLFJKSADFLKJASDF ...
-----END OPENSSH PRIVATE KEY-----
if that is necessary to "make it just work." Or, I expect it to complain, and tell me the format is invalid. Either way, I don't want to be able to paste a key and then have SSH failures that are inscrutable. (SSHFS mount failed for unknown reason, or whatever the vague error case is.)
other solutions I'd think work for me as a user
I'd also be happy to:
Have Cloudron generate the keypair for me, and let me copy the key(s) (pub/priv) to my local machine. Or, you could put them on a page and say "copy these and don't lose them." Either way, if you control key generation, you guarantee that I can't mess them up. (Or, if I mess them up elsewhere, that's my problem, not yours).
Upload a file for the key. It would be OK if I uploaded the keyfile. This way, I can inspect it on disk, and the upload process won't (shouldn't?) mangle the file en route.
The spirit here is that I'm excited about anything that doesn't have invisible errors.
fun find
https://superuser.com/questions/1444319/how-to-check-ssh-key-version-locally
You can do
ssh-keygen -l -f <file>
and if it is a valid pub or priv keyfile, it will spit out
<bits> <SHA> <comment> (<type>)
which may be a good check to add to the backend after writing the key. Then, you could either get a valid SHA, or you could say "Could not generate SHA of SSH key; see <docs> for more info."
side note: types of key
Some (probably poorly written) systems only accept RSA keys (vs ED25519, etc.). This probably has to do with OpenSSL version(s) that are installed.
If there are any known limitations to Cloudron's use of pub/priv keypairs (e.g. "Cloudron can only use RSA keys up to 2048 bits"), then that should be communicated to the user up front. I think Cloudron is fine with any valid kind of SSH key, but that would be invisible to me at the moment.