Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.

Bug 1701174

Summary: Not able to connect to other hosts from non-localhost Cockpit login screen
Product: Red Hat Enterprise Linux 8 Reporter: Stef Walter <stefw>
Component: cockpitAssignee: Martin Pitt <mpitt>
Status: CLOSED ERRATA QA Contact: Release Test Team <release-test-team-automation>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 8.0CC: sraymaek
Target Milestone: rcKeywords: Rebase
Target Release: 8.1Flags: pm-rhel: mirror+
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2019-11-05 22:03:23 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Stef Walter 2019-04-18 09:52:15 UTC
Description of problem:

Cockpit Login screen has an option to connect to other hosts. Make sure cockpit-ssh installed to see it.

However when I try to use that option I see the following message:

"Refusing to connect. Host is unknown"

And in the journal I see the following log:

Apr 18 05:38:03 m2.cockpit.lan cockpit-ssh[4596]: cockpit-ssh m1.cockpit.lan: refusing to connect to unknown host: m1.cockpit.lan:22

Version-Release number of selected component (if applicable):

cockpit-185-2.el8.x86_64
cockpit-ws-185-2.el8.x86_64
cockpit-bridge-185-2.el8.x86_64
cockpit-system-185-2.el8.noarch

How reproducible:

Every time.

Steps to Reproduce:
1. Open Cockpit login screen
2. Expand 'Other options' section
3. Type a host you've never connected to be fore in 'Connect to'

Actual results:

"Refusing to connect. Host is unknown"

Expected results:

Either "Could not connect to host" or a "SSH Key verification prompt to approve the hosts's server key".

Additional info:

This used to work on RHEL 7.4 or 7.5 (can't remember). But now on RHEL 7.6 has also regressed. This works on Fedora 29.

The following is an insecure workaround:

$ cat /etc/cockpit/cockpit.conf 
[Ssh-Login]
connectToUnknownHosts = True

Comment 1 Martin Pitt 2019-05-03 07:10:01 UTC
I tried this on our fedora-30 and rhel-8-0 cockpit test VMs, and can confirm that on both I get "Refusing to connect. Host is unknown". But on my Fedora 30 laptop, with the exact same packages, I get 
"The authenticity of host '192.168.2.106:22' can't be established. Do you want to proceed this time? SHA256 Fingerprint (ssh-ed25519):", as expected. So this seems less about Fedora vs. RHEL (i. e. about different libssh versions), and more about some specific circumstances how these get run. I'll investigate this more closely.

In which environment were you running this?

Comment 2 Martin Pitt 2019-05-03 08:30:11 UTC
I tried "cockpit-bridge --interact=---" on a remote host on both my laptop (where it works) and the fedora-30 test VM (where it fails), and in both cases it looks the same:

(cockpit-ssh:21520): cockpit-ssh-DEBUG: 09:32:23.047: cockpit-ssh 192.168.2.106: host not known in any local file, asking sssd
(cockpit-ssh:21520): cockpit-ssh-DEBUG: 09:32:23.049: cockpit-ssh 192.168.2.106: Failed to run sss_ssh_knownhostsproxy: Failed to execute child process ?sss_ssh_knownhostsproxy? (No such file or directory)
(cockpit-ssh:21520): cockpit-ssh-DEBUG: 09:32:23.050: cockpit-ssh 192.168.2.106: using known hosts file (null)
(cockpit-ssh:21520): cockpit-ssh-DEBUG: 09:32:23.096: cockpit-ssh 192.168.2.106: connected

{"command":"authorize", [...],"message":"The authenticity of host '192.168.2.106:22' can't be established. Do you want to proceed this time?","default":"SHA256:AIJoCTtgu/0t0uYrHks9L4CfWrd5IBAcOWqK9Qk3JHA","host-key":"192.168.2.106 ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIB3vmfHvYyCruT6E9NQZleFCKx7lPN/lpLlINREOCZd/\n","echo":true}

But (only) in the non-working case, I see this in the journal:

  cockpit-ssh 172.27.0.15: refusing to connect to unknown host: 172.27.0.15:22

Indeed the difference between these two scenarios is that data->ssh_options->connect_to_unknown_hosts is 1 locally (working case) and 0 in the VM (broken case). It turns out that cockpit-ssh's $COCKPIT_REMOTE_PEER value is bogus: On my laptop it's ::1, while in my VM it's 172.27.0.2, both of which are the IP addresses of the cockpit-ws instance, *not* the address of the remote ssh host to connect to. That explains the symptom, as get_connect_to_unknown_hosts() allows connections to localhost with unknown host keys.

Comment 3 Martin Pitt 2019-05-03 08:48:50 UTC
This actually seems like a really ancient bug, from as far back as https://github.com/cockpit-project/cockpit/commit/f087f5ca3be097 . $COCKPIT_REMOTE_PEER is really confusing -- cockpit-ws sets it to the connecting user from *its* point of view, but cockpit-ssh tries to interpret it as the IP to connect to with ssh.

I just wonder how our tests are missing this -- check-multi-machine covers both direct URL login (where unknown hosts should fail) and "Connect to:" login page logins, where they should prompt. They use the browser on the outside on the redirected port 9090 (i. e. something like 127.0.0.2:9091) just as I do interactively.

Comment 4 Martin Pitt 2019-05-03 11:13:07 UTC
Stef, Sanne: In https://github.com/martinpitt/cockpit/commits/ssh-remote-peer I fixed the mis-interpretation of COCKPIT_REMOTE_PEER, so that on the login page unknown hosts are now consistently rejected. Adding unknown servers on the Dashboard prompts. As COCKPIT_SSH_CONNECT_TO_UNKNOWN_HOSTS isn't set anywhere except /usr/share/cockpit/ssh/manifest.json in the "session: private" case, I suppose the Dashboard takes that code path. This connection to private sessions isn't quite obvious, and feels rather hackish - it should at least be documented better in doc/protocol.md. Stef, could you please explain the background there, how private sessions relate to trustworthiness of unknown remote ssh  servers?

To fix that properly, I think login.js needs to tell apart the "direct URL" case (like http://localhost:9999/=192.168.2.106), which should always fail for unknown hosts, from the "remote server specified in the Connect to: field", which should prompt. In the latter case, COCKPIT_SSH_CONNECT_TO_UNKNOWN_HOSTS needs to be passed. Does that make sense? Is there a less complicated way to do that?

Comment 5 Martin Pitt 2019-05-03 13:26:23 UTC
> I just wonder how our tests are missing this

Got it -- testDirectLogin() writes allowUnknown to cockpit.conf for the direct URL login check and then forgets to remove it again for the "Connect to:" test.

Comment 6 Martin Pitt 2019-05-03 14:02:36 UTC
> login.js needs to tell apart the "direct URL" case from the "remote server specified in the Connect to: field"

This is rather hard -- in both cases, the URL path is something like /cockpit+=10.111.113.2/login and the application is something like "cockpit+=10.111.113.2", so cockpitauth.c cannot tell these apart. So it seems it needs to become a hack in login.js, and be passed through the protocol as a new option? Stef, any idea about that one?

Comment 7 Martin Pitt 2019-05-03 14:51:20 UTC
I now have a fix which isn't *too* bad, I think: https://github.com/cockpit-project/cockpit/pull/11736

Comment 8 Martin Pitt 2019-05-06 07:57:01 UTC
Fix landed upstream, will be in 194

Comment 12 errata-xmlrpc 2019-11-05 22:03:23 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2019:3518