Skip to content

Update the list of valid ssh keys.#487

Merged
blackboxsw merged 28 commits into
canonical:masterfrom
omBratteng:update-ssh-keys
Aug 21, 2020
Merged

Update the list of valid ssh keys.#487
blackboxsw merged 28 commits into
canonical:masterfrom
omBratteng:update-ssh-keys

Conversation

@omBratteng
Copy link
Copy Markdown
Contributor

@omBratteng omBratteng commented Jul 12, 2020

@omBratteng
Copy link
Copy Markdown
Contributor Author

I tried testing locally with tox, worked fine. But not sure what the best way to test the newly added keys are.

@OddBloke OddBloke self-assigned this Jul 13, 2020
Copy link
Copy Markdown
Collaborator

@OddBloke OddBloke left a comment

Choose a reason for hiding this comment

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

Hi @omBratteng, thanks for the submission! The actual change here LGTM, it just needs tests adding to https://github.com/canonical/cloud-init/blob/master/tests/unittests/test_sshutil.py. (The last time this was done was in 853df0a which should give you a rough idea of how to proceed. 👍)

@omBratteng
Copy link
Copy Markdown
Contributor Author

omBratteng commented Jul 13, 2020

Thanks @OddBloke, I'll try to get some tests. I'm a bit unfamiliar with tox, is there a way I can run the specific test https://github.com/canonical/cloud-init/blob/master/tests/unittests/test_sshutil.py ?

@omBratteng omBratteng marked this pull request as draft July 13, 2020 23:43
@omBratteng omBratteng marked this pull request as ready for review July 14, 2020 01:52
@omBratteng omBratteng requested a review from OddBloke July 14, 2020 01:52
@OddBloke
Copy link
Copy Markdown
Collaborator

Thanks for the update @omBratteng! You've presumably figured this out, but tox -e py3 -- path/to/test/file.py will run all the tests in a file, or tox -e py3 -- path/to/test/file.py::SpecificTestClass will run a single class in a file. (More generally, anything after the -- is passed to pytest.)

I notice that the tests only include new cases for a subset of the key types you're adding; is it feasible to expand that list out further, to cover all the newly-added types?

@OddBloke
Copy link
Copy Markdown
Collaborator

(Oh and as a note to my future self: I have confirmed you've signed the CLA.)

@omBratteng
Copy link
Copy Markdown
Contributor Author

I just spun up a faster VM for running the tests, but I'll try it later.
Yeah, I can try to add tests for the -cert variants too, I just have never used ssh certs. I can also add tests for the rest of the valid SSH keys, as I see it's just a subset of all the valid ones.

@OddBloke
Copy link
Copy Markdown
Collaborator

OddBloke commented Jul 14, 2020 via email

Update ssh_util.py with latest list of keys (from openssh-8.3p1/sshkey.c),

Added keys:
  rsa-sha2-256-cert-v01@openssh.com
  rsa-sha2-512-cert-v01@openssh.com
  sk-ecdsa-sha2-nistp256-cert-v01@openssh.com
  sk-ecdsa-sha2-nistp256@openssh.com
  sk-ssh-ed25519-cert-v01@openssh.com
  sk-ssh-ed25519@openssh.com
  ssh-xmss-cert-v01@openssh.com
  ssh-xmss@openssh.com
  webauthn-sk-ecdsa-sha2-nistp256@openssh.com
Thanks to @djmdjm for pointing me in the right direction.
… a valid entry in authorized_keys

They are just the short names used for human interactions, e.g. "ssh-keygen -t rsa" and they should never appear in public keys
@omBratteng
Copy link
Copy Markdown
Contributor Author

@OddBloke added more tests now, and removed some key types which @djmdjm pointed out for me which actually are signatures.
Plus removed dsa, rsa, ecdsa and ed25519, as they're not valid public keys, as they're the short names used for human interactions, e.g. "ssh-keygen -t rsa" and they should never appear in public keys

@OddBloke
Copy link
Copy Markdown
Collaborator

Plus removed dsa, rsa, ecdsa and ed25519, as they're not valid public keys, as they're the short names used for human interactions, e.g. "ssh-keygen -t rsa" and they should never appear in public keys

Older versions of OpenSSH (I tested with 7.2, the version in Ubuntu 16.04 which we still actively backport cloud-init to) will allow you to SSH in if an authorized_keys line starts with "rsa", so removing these is premature.

(I'm running to a meeting, so haven't reviewed anything more than this.)

@omBratteng
Copy link
Copy Markdown
Contributor Author

Gotcha, I can either revert the last three commits, or just f77a723 which is the one that removes dsa, rsa, ecdsa and ed25519 from the valid key types, the other two are just testing.

@OddBloke
Copy link
Copy Markdown
Collaborator

I'd opt for reverting all three commits, if you're happy doing that?

Revert "test_sshutil: replace the rsa and dsa with ssh-rsa and ssh-dsa the places I missed it"
Revert "test_sshutil: remove dsa, ecdsa, ed25519 and rsa, as they're not actually a valid entry in authorized_keys"
Revert "ssh_util: remove dsa, ecdsa, ed25519 and rsa, as they're not actually a valid entry in authorized_keys"
@omBratteng
Copy link
Copy Markdown
Contributor Author

Commits reverted

Copy link
Copy Markdown
Collaborator

@OddBloke OddBloke left a comment

Choose a reason for hiding this comment

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

Thanks for the update! Determining the list of public key types is more involved than I was expecting, so I've asked for an update to an explanatory comment inline (and also have a minor test improvement Q).

Comment thread tests/unittests/test_sshutil.py Outdated
Comment thread cloudinit/ssh_util.py Outdated
@omBratteng
Copy link
Copy Markdown
Contributor Author

I've added some comments, both in the source and docs, about where the list comes from. Let me know if you want me to change to wording of it, writing documentation for this sized project isn't something I have done before.

@paride
Copy link
Copy Markdown
Contributor

paride commented Jul 28, 2020

Related PR: #506.

@omBratteng
Copy link
Copy Markdown
Contributor Author

@paride I cherry picked @tsanghan's commit into my branch, updated the _is_printable_key list.
And added a pointer in both cc_ssh_authkey_fingerprints and ssh_util, both pointing to eachother, so the next person knows to update all the lists.

@omBratteng omBratteng marked this pull request as draft August 6, 2020 21:08
@omBratteng omBratteng marked this pull request as ready for review August 6, 2020 21:23
Copy link
Copy Markdown
Collaborator

@OddBloke OddBloke left a comment

Choose a reason for hiding this comment

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

One question about the additional commit that was added here.

Comment thread cloudinit/config/cc_ssh_authkey_fingerprints.py Outdated
@omBratteng omBratteng requested a review from OddBloke August 13, 2020 18:12
Copy link
Copy Markdown
Collaborator

@blackboxsw blackboxsw left a comment

Choose a reason for hiding this comment

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

+1

@blackboxsw blackboxsw dismissed OddBloke’s stale review August 21, 2020 16:22

Review comments were addressed sufficiently by the author. So, I'm dismissing this review as "addressed" by the author

@blackboxsw blackboxsw merged commit c73ab56 into canonical:master Aug 21, 2020
@omBratteng omBratteng deleted the update-ssh-keys branch August 21, 2020 16:59
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.

7 participants