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

consoles: Don't use listening address to connect to VNC #1982

Merged
merged 1 commit into from
Jan 28, 2025

Conversation

mvollmer
Copy link
Member

@mvollmer mvollmer commented Jan 17, 2025

The listening address is most likely 127.0.0.1 (libvirt default) or 0.0.0.0 (yolo config). Neither of these works remotely.

Let's tell the remote viewer some address that has a chance of working. More complicated setups, like a bastion host or connecting via SSH inside Cockpit, might not work because of networking routing challanges, but at least we get better error messages like "No route to host" etc.

Also, with the libvirt default of only listening on 127.0.0.1, no remote connection will work. But again, we now at least get the expected "Connection refused" error message.

Demo: https://youtu.be/zjQlyt3SzG4


Machines: "Launch viewer" now uses correct address

The "Launch viewer" button in the "Console" card of a virtual machine would tell the remote viewer application to connect to the listening address of the VNC server. This is wrong when the server listens on 127.0.0.1 (libvirt default) or 0.0.0.0 (allow connections on all interfaces). Now Cockpit will tell the remote viewer application to connect to the same domain name or IP address that Cockpit itself is using to reach the virtual machine host.

@mvollmer mvollmer force-pushed the consoles-correct-connection branch 4 times, most recently from 02946bd to 887cde1 Compare January 22, 2025 11:44
@mvollmer mvollmer force-pushed the consoles-correct-connection branch 2 times, most recently from 235c6fd to 4b2534b Compare January 27, 2025 13:17
@mvollmer mvollmer marked this pull request as ready for review January 27, 2025 13:17
@mvollmer mvollmer requested a review from martinpitt January 27, 2025 13:17
Comment on lines +96 to +97
if (app.startsWith("cockpit+=")) {
address = app.substr(9);
Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, this should run...

}
}

domainDesktopConsole({ name: vm.name, consoleDetail: Object.assign({}, consoleDetail, { address }) });
Copy link
Member

Choose a reason for hiding this comment

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

{...consoleDetail, address} reads a bit nicer IMHO, but up to you.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done, thanks!

Copy link
Member

@martinpitt martinpitt left a comment

Choose a reason for hiding this comment

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

Thanks! Let's discuss this a little bit. My first two comments were not part of the review.

Comment on lines 261 to 264
class TestMultiMachinesConsoles(ConsoleCase):
provision = { # noqa: RUF012
"machine": {"address": "10.111.113.1/20"},
}
Copy link
Member

Choose a reason for hiding this comment

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

This is still only one machine -- seems you could get this more cheaply with the already running nondestructive machine? 172.27.0.15 is reliable, a couple of cockpit tests refer to it as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

Right, I thought I'd seen something like that... Will that work also with TF?

Copy link
Member Author

Choose a reason for hiding this comment

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

I have made the new test destructive and use that address.

Comment on lines +281 to +278
b.open(f"/={my_ip}/machines")
b.set_val('#login-user-input', "admin")
b.set_val('#login-password-input', "foobar")
b.click("#login-button")
Copy link
Member

Choose a reason for hiding this comment

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

That should be self.login_and_go("/machines", host=my_ip). I wonder why you don't' have to m.start_cockpit() here, it's usually required?

Copy link
Member Author

Choose a reason for hiding this comment

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

That should be self.login_and_go("/machines", host=my_ip)

The host parameter gives you a "/@{host}" prefix, but I want a "/={host}" prefix.

Copy link
Member Author

Choose a reason for hiding this comment

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

I wonder why you don't' have to m.start_cockpit() here, it's usually required?

Good question... I guess cockpit is enabled by default somewhere already?

Copy link
Member Author

Choose a reason for hiding this comment

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

I have added a call to "start_cockpit".

Comment on lines +304 to +299
# Login from Shell via SSH

Copy link
Member

Choose a reason for hiding this comment

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

Is that actually something different? I thought transport-wise bastion host and shell host selector would be the same?

Copy link
Member Author

Choose a reason for hiding this comment

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

The new code in the PR handles that differently.. maybe it doesn't have to.

Bastion host has:

  • cockpit.transport.host == "localhost"
  • application == "cockpit+=address"

where "address" is the string typed into the login page, and visible in the browser URL as "/=address". But it's not in the frame URL.

SSH from the Shell has:

  • cockpit.transport.host == "address"

where "address" is the string typed into the "add remote host" dialog.

Copy link
Member Author

Choose a reason for hiding this comment

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

(I don't really understand our "application" business, tbh.)

@mvollmer mvollmer force-pushed the consoles-correct-connection branch 3 times, most recently from 06e86cb to 9c6e8b6 Compare January 27, 2025 15:21
The listening address is most likely 127.0.0.1 (libvirt default) or
0.0.0.0 (yolo config). Neither of these works remotely.

Let's tell the remote viewer some address that has a chance of
working. More complicated setups, like a bastion host or connecting
via SSH inside Cockpit, might not work because of networking routing
challanges, but at least we get better error messages like "No route
to host" etc.

Also, with the libvirt default of only listening on 127.0.0.1, no
remote connection will work. But again, we now at least get the
expected "Connection refused" error message.
@mvollmer mvollmer force-pushed the consoles-correct-connection branch from 9c6e8b6 to 5ac4425 Compare January 27, 2025 16:05
Comment on lines +96 to +97
if (app.startsWith("cockpit+=")) {
address = app.substr(9);
Copy link
Contributor

Choose a reason for hiding this comment

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

These 2 added lines are not executed by any test.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't understand this... these lines clearly run.

Copy link
Member

Choose a reason for hiding this comment

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

@mvollmer is investigating this in #2006, so I suppose we can land this PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, coverage collection must be buggy somehow... grr.

Copy link
Member

@martinpitt martinpitt left a comment

Choose a reason for hiding this comment

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

TF is still running, but it seems it already skips the console tests there (the 172.27.0.15 IP is specific to our bots images), and some tests already passed.

This is a significant improvement, let's get this in without more bikeshedding. Thank you!

@mvollmer mvollmer merged commit 8a11a18 into cockpit-project:main Jan 28, 2025
28 checks passed
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