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

Dissociate SSH key import from form submission #1895

Merged
merged 8 commits into from
Feb 13, 2024

Conversation

ogayot
Copy link
Member

@ogayot ogayot commented Jan 25, 2024

I started this work a year ago and never got a chance to finish it.
I spent some time today to clean it up and fix the tets. It looks correct now.

It brings several benefits over the existing implementation:

  • the user has the ability to import multiple keys
  • if running a partially automated installation, submitting the SSH form does not discard existing SSH keys that were imported using ssh: authorized-keys: directives.
  • the user has the ability to review the list of keys and remove any from the list

2024-02-08T15:55:26,631517913+01:00
2024-02-08T15:56:04,157201185+01:00
2024-02-08T15:56:46,090662972+01:00
2024-02-08T16:00:14,355106521+01:00
2024-01-25T17:53:51,011548411+01:00
2024-01-25T17:54:02,931649005+01:00
2024-01-25T17:54:14,203495984+01:00

@ogayot ogayot requested a review from mwhudson January 25, 2024 17:25
@ogayot
Copy link
Member Author

ogayot commented Jan 25, 2024

Pushed a change to fix the CI issue on focal:
https://paste.ubuntu.com/p/mvgBKkHs2g/

EDIT: dropped this change after rebasing on main since we removed focal test enforcement.

@ogayot ogayot force-pushed the pr/ssh-dissociate-form-submission branch from 2dd26a7 to 1f47914 Compare January 26, 2024 08:15
Copy link
Collaborator

@mwhudson mwhudson left a comment

Choose a reason for hiding this comment

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

I was sure I reviewed this last week but apparently not! I'm super happy to see this, and pleasantly surprised that it can all be done client side.

I have a few quibbles about widget enabling/disabling and a few pre-existing oddities I spotted when reviewing this. The former should probably be fixed (sorry, it'll be annoying) but feel free to ignore the latter for now.

else:
if isinstance(confirm_overlay, ConfirmSSHKeys):
break
await asyncio.sleep(0.1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Heh this is pretty gross. But well, all honest answers code is a bit gross.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It's a bit bikesheddy, but do we need the .1 portion of the sleep or are we just trying to allow other tasks to run? could asyncio.sleep(0) if it's just about the other tasks.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed.. I'll move this to a function in view_helpers which will wait for an overlay to show up. I think that should make the answers code easier to write/read.

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, asyncio.sleep(0) will cause high CPU load while fetching a key over the network. Maybe 0.01 if we want to speed things up ? @dbungert wdyt?

Copy link
Collaborator

Choose a reason for hiding this comment

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

WFM

id_.to_authorized_key() for id_ in identities
]
self.done(ssh_data)
if isinstance(self.ui.body, SSHView):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Again, it's not your fault but we do we only do this check in the success case?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Super nice to get answers-handling code out of the "production" workflow though.

Copy link
Member Author

Choose a reason for hiding this comment

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

Again, it's not your fault but we do we only do this check in the success case?

Actually, no, we have the same check for IMPORT_ERROR and FINGERPRINT_ERROR:

if isinstance(self.ui.body, SSHView):
self.ui.body.fetching_ssh_keys_failed(
_("Importing keys failed:"), response.error
)
return

if isinstance(self.ui.body, SSHView):
self.ui.body.fetching_ssh_keys_failed(
_("ssh-keygen failed to show fingerprint of downloaded keys:"),
response.error,
)
return

@ogayot ogayot force-pushed the pr/ssh-dissociate-form-submission branch from 1f47914 to f60679e Compare February 8, 2024 14:49
@ogayot ogayot requested a review from mwhudson February 8, 2024 14:51
Previously, on the SSH screen, the ability to enable/disable the SSH
server and the ability to import a SSH identity were both covered by a
single form. Therefore, there was no way to import multiple identities.

This change adds a button "Import SSH key" which opens a new form to
import an identity. The button can be pressed multiple times and the
resulting identities are all submitted when the user clicks on Done.

Furthermore, navigating back to the SSH screen does not "forget" already
imported identities.

Signed-off-by: Olivier Gayot <[email protected]>
@ogayot ogayot force-pushed the pr/ssh-dissociate-form-submission branch from f60679e to 2465373 Compare February 8, 2024 16:54
@ogayot ogayot force-pushed the pr/ssh-dissociate-form-submission branch from 2465373 to af5fb7f Compare February 12, 2024 08:10
When running answers-based automation, the SSH controller looks into
more than one section to find ssh-import-id directives.

If the "SSH" section exists, then it is where the ssh-import-id
directives must be placed. However, if the section does not exist, the
controller will also look for ssh-import-id directives in the "Identity"
section.

The answers.yaml file used this special mechanism. This is fine.
However, if one adds a SSH section to customize other settings (e.g.,
install_server, pwauth), then the ssh-import-id directives in the
Identity section suddently get ignored ; which is confusing and looks
as if there is a bug.

Let's move ssh-import-id directives to the SSH section.

Signed-off-by: Olivier Gayot <[email protected]>
A new table shows all the SSH identities/keys that are currently
imported. The user can select one and delete it from the list if he
wants to.

Signed-off-by: Olivier Gayot <[email protected]>
When selecting a SSH identity, the user can open a dialog showing the
contents of the key.

Signed-off-by: Olivier Gayot <[email protected]>
@ogayot ogayot force-pushed the pr/ssh-dissociate-form-submission branch from af5fb7f to 3f3bb29 Compare February 12, 2024 13:09
@ogayot ogayot merged commit ce938e6 into canonical:main Feb 13, 2024
12 checks passed
@ogayot ogayot deleted the pr/ssh-dissociate-form-submission branch February 13, 2024 18:20
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.

3 participants