cockpit-project / cockpit-machines

Cockpit UI for virtual machines
GNU Lesser General Public License v2.1
291 stars 74 forks source link

The SSH key without comments could not be added #1298

Closed yunmingyang closed 11 months ago

yunmingyang commented 11 months ago

Description of problem: When adding a SSH key wtihout comments, the key could not be added, and there is also no hint or error shown on the page

Version-Release number of selected components (if applicable): cockpit-300.1-1.el8_9.x86_64 cockpit-machines-301.1.2.gb0140b7-1.fc38.noarch libvirt-dbus-1.3.0-2.module+el8.9.0+18724+20190c23.x86_64

How reproducible: 100%

Steps to Reproduce: 1 Log in cockpit, then switch to the machines page 2 Click "Create VM", then select "Installation type" to "Cloud base image" 3 Go to the Automation tab, then click "Add SSH keys" 4 Input a SSH key without comment to the input appeared after clicking "Add SSH keys"

Actual results: 1 After step 4, the key could not be added automatically, and there is also no hint or error

Expected results: 1 After step 4, the key could be added successfully

Additional info: Maybe related with, in parseKey, after splitting the key, the code will determine whether the length of the array after splitting is greater than 2, but if there is no comment in the SSH key, the length of the array after splitting equals 2

jelly commented 11 months ago

I can reproduce this issue quite easily, we do have tests for this but we don't validate if the key was added successfully.

jelly commented 11 months ago

Actually, we do have tests for them, and we add multiple keys:

SSH KEYS ['ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDC5VeWn5jS33ViEm+B0YOjYVol/Ph9LRTQ17xJiWR5jTIU0gHi3jTRL1cUDgOFZeeeCK7xRCimYrENF11/EF7CMYHLSXnXjqtMWOy4DToKOCFPh/Am2ZwEkGmFmxljQLE/dbz89C/5JgBhpE1FUFyscotQuIPVVuY8i10snHbBf1BJFu/9UlG6eMxELhwuCFNBN/Op6ADF3RLP65XM1d6Hd0JmhJWP+Fij1ghDGKBVjs7Pby5OshZkpVGo3ECk+3hRWPPxTi8t4iQdqjv/oB3WB9BnFUubIoyGYKMfk1cItdodaRmnPL5eXakMiAIuCGTMT+UIuTxy8Y+c+3HK+b6pAVrLbw6xKcqVjJjrNdp9OgIZkKvVPdZUp4TZgV/dmM6YqgB21qFoFFq2ZPR7KHFFm65mxvhE/ZiVdEkDE6quhl/h1XJfTQ+hggpO
pWWJdWzCB/H3ELbT5vsDZKmC0NFyknSUVU6JdVc4x3eoaA1wEQ/GfZA/7DNfLB1f6Bnktbk= root@fedora-39-127-0-0-2-2201']
#cloud-config
users:
  - name: foo
    ssh_authorized_keys:
      - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDC5VeWn5jS33ViEm+B0YOjYVol/Ph9LRTQ17xJiWR5jTIU0gHi3jTRL1cUDgOFZeeeCK7xRCimYrENF11/EF7CMYHLSXnXjqtMWOy4DToKOCFPh/Am2ZwEkGmFmxljQLE/dbz89C/5JgBhpE1FUFyscotQuIPVVuY8i10snHbBf1BJFu/9UlG6eMxELhwuCFNBN/Op6ADF3RLP65XM1d6Hd0JmhJWP+Fij1ghDGKBVjs7Pby5OshZkpVGo3ECk+3hRWPPxTi8t4iQdqjv/oB3WB9BnFUubIoyGYKMfk1cItdodaRmnPL5eXakMiAIuCGTMT+UIuTxy8Y+c+3HK+b6pAVrLbw6xKcqVjJjrNdp9OgIZkKvVPdZUp4TZgV/dmM6YqgB21qFoFFq2ZPR7KHFFm65mxvhE/ZiVdEkDE6quhl/h1XJfTQ+hggpOpWW
JdWzCB/H3ELbT5vsDZKmC0NFyknSUVU6JdVc4x3eoaA1wEQ/GfZA/7DNfLB1f6Bnktbk= root@fedora-39-127-0-0-2-2201  ssh-dss AAAAB3NzaC1kc3MAAACBAL6EXVe5lmBP6KkzLBuhURsATqQHNSyFkY7VtsDW4uAKskc0wHdANTa5v3+p68wJJggiFu35hm6S0frM8ERA5XkzExSjeHiBTyL+6cZnDiNvy6i5vGUgdTa74lG9g4E2QfFItzvLqtfm6xzM2P3se5yCW+qnZEP91lR7nV+3cLnbAAAAFQDa55pvWn5rRczpTFBHrQSLyf5ivQAAAIEAilo6edfvV8q546jbdgfxc/n2GKplcUZds47mjEqAsv0gV+BzwaJ6+7mXxY/NTc0VfhyzztfRqncigW0l9CuhNpcD/R7si8TMkrMES43ZReveqFv0j2HFA5mmzt+qlWkgryIqMxf0AAg5XAY/DnZwT2
DcmH/RS6yTdrqNP+IQ/b0AAACAe8NP90knPaRLa0gimWcpPaIb93c03/917coVD602z4BZY7EteMagDhNlmYwRAwIzAInc+74joLb81v57RWL8m5Mc4XXzWdSLVpzZSxXnXu/s3f/iyrT37Og4aoNlnzU9uMFdOt+Uc9Q/ezC3u+wpF98uaOlCqqJzSSL1el76frc=
ssh_pwauth: true

Curiously we don't check for ssh-dss which should be in ssh_keys.

Test does add it correctly, but manually it fails.

image

jelly commented 11 months ago

If I add a space after the key it does work, that's what the test does as well. So fixing the test and the parts check.