Skip to content

Commit 4cb9238

Browse files
committed
shell: Don't allow connections to remote machines via URLs...
...when the host switcher is disabled. Instead, redirect them to localhost. The tests that use multiple machines add those machines by navigating to their URL and then logging into them via the trouble shooting dialog. Those tests have to explicitly enable the host switcher for this to continue to work.
1 parent ee43bc0 commit 4cb9238

File tree

8 files changed

+47
-12
lines changed

8 files changed

+47
-12
lines changed

pkg/shell/indexes.jsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,14 @@ function MachinesIndex(index_options, machines, loader) {
179179

180180
if (!state)
181181
state = index.retrieve_state();
182+
183+
// Force a redirect to localhost when the host switcher is
184+
// disabled. That way, people won't accidentally connect to
185+
// remote machines via URL bookmarks or similar that point to
186+
// them.
187+
if (!host_switcher_enabled)
188+
state.host = "localhost";
189+
182190
let machine = machines.lookup(state.host);
183191

184192
/* No such machine */

test/verify/check-shell-host-switching

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -124,19 +124,32 @@ class TestHostSwitching(testlib.MachineCase, HostSwitcherHelpers):
124124
m2.execute("hostnamectl set-hostname machine2")
125125
m3.execute("hostnamectl set-hostname machine3")
126126

127+
# Switch the switcher off for the begining of this test.
128+
if self.multihost_enabled:
129+
m1.write("/etc/cockpit/cockpit.conf",
130+
'[WebService]\nAllowMultiHost=no\n')
131+
127132
# This should all work without being admin on machine1
128133
self.login_and_go(superuser=False)
129134

130-
# on recent OSes, switcher is disabled by default
131-
if not self.multihost_enabled:
132-
b.wait_text("#hosts-sel .ct-switcher-localonly", "admin@localhost")
133-
self.assertFalse(b.is_present("#hosts-sel button"))
134-
b.assert_pixels("#hosts-sel", "no-switching", skip_layouts=["mobile"])
135-
b.logout()
135+
b.wait_text("#hosts-sel .ct-switcher-localonly", "admin@localhost")
136+
self.assertFalse(b.is_present("#hosts-sel button"))
137+
b.assert_pixels("#hosts-sel", "no-switching", skip_layouts=["mobile"])
136138

137-
# enable host switcher for this test
138-
self.enable_multihost(m1)
139-
b.login_and_go(superuser=False)
139+
# Check that URLs to remore hosts get redirected to the local
140+
# session.
141+
b.wait_js_cond('window.location.pathname == "/system"')
142+
b.go("/@10.111.113.2/storage")
143+
b.wait_js_cond('window.location.pathname == "/storage"')
144+
145+
# Enable host switcher for the rest of the test
146+
b.logout()
147+
if self.multihost_enabled:
148+
# clean up AllowMultiHost=no from above
149+
m1.execute("rm /etc/cockpit/cockpit.conf")
150+
self.enable_multihost(m1)
151+
m1.restart_cockpit()
152+
b.login_and_go(superuser=False)
140153

141154
b.assert_pixels("#nav-system", "nav-system", skip_layouts=["mobile"])
142155
b.set_layout("mobile")

test/verify/check-shell-multi-machine

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ class TestMultiMachineAdd(testlib.MachineCase):
134134
# and failing to load sofware updates breaks pixel tests in release builds
135135
self.setup_provisioned_hosts(disable_preload=True)
136136
self.setup_ssh_auth()
137+
self.enable_multihost(self.machine)
137138

138139
def testBasic(self):
139140
b = self.browser
@@ -250,6 +251,7 @@ class TestMultiMachine(testlib.MachineCase):
250251
self.allow_journal_messages("sudo: unable to resolve host machine1: .*")
251252

252253
self.setup_provisioned_hosts(disable_preload=True)
254+
self.enable_multihost(self.machine)
253255

254256
def checkDirectLogin(self, root='/', known_host=False):
255257
b = self.browser
@@ -381,7 +383,7 @@ class TestMultiMachine(testlib.MachineCase):
381383

382384
hostname_selector = "#system_information_hostname_text"
383385

384-
m.write("/etc/cockpit/cockpit.conf", "[WebService]\nUrlRoot = cockpit-new")
386+
m.write("/etc/cockpit/cockpit.conf", "[WebService]\nUrlRoot = cockpit-new\nAllowMultiHost=yes\n")
385387
m.start_cockpit()
386388

387389
# Make sure normal urls don't work.

test/verify/check-shell-multi-os

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class TestRHEL8(testlib.MachineCase):
3333

3434
stock_m = self.machines['stock']
3535
stock_m.execute("hostnamectl set-hostname stock")
36+
self.enable_multihost(dev_m)
3637

3738
# Wait for connectivity between the two
3839
stock_m.execute("ping -q -w5 -c5 10.111.113.1")

test/verify/check-superuser

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ class TestSuperuserDashboard(testlib.MachineCase):
405405
def test(self):
406406
b = self.browser
407407
self.setup_provisioned_hosts()
408+
self.enable_multihost(self.machine)
408409

409410
self.login_and_go()
410411
b.go("/@10.111.113.2")

test/verify/check-system-realms

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,13 @@ class CommonTests:
437437
do_test(alice_user_pass, ['HTTP/1.1 200 OK', '"csrf-token"'], session_leader='cockpit-session', retry=True)
438438

439439
# enable cert based auth
440-
m.write("/etc/cockpit/cockpit.conf", '[WebService]\nClientCertAuthentication = true\n', append=True)
440+
# FIXME: this is ugly, and we don't currently accept multiple [WebService] sections
441+
if self.multihost_enabled:
442+
# no previous cockpit.conf
443+
m.write("/etc/cockpit/cockpit.conf", '[WebService]\nClientCertAuthentication = true\n', append=True)
444+
else:
445+
# enable_multihost above already wrote [WebService]
446+
m.write("/etc/cockpit/cockpit.conf", 'ClientCertAuthentication = true\n', append=True)
441447
# cert auth should work now
442448
do_test(alice_cert_key, ['HTTP/1.1 200 OK', '"csrf-token"'])
443449
# password auth, too
@@ -495,6 +501,7 @@ class TestRealms(testlib.MachineCase):
495501
self.op_admin_password = "#realms-op-admin-password"
496502
self.domain_sel = "#system_information_domain_button"
497503
self.machine.execute("hostnamectl set-hostname x0.cockpit.lan")
504+
self.enable_multihost(self.machine)
498505

499506
# realmd times out on inactivity, which occasionally races with the proxy
500507
self.allow_journal_messages("couldn't get all properties of org.freedesktop.realmd.Service.*org.freedesktop.DBus.Error.NoReply: Remote peer disconnected")
@@ -989,6 +996,7 @@ class TestKerberos(testlib.MachineCase):
989996
def setUp(self):
990997
super().setUp()
991998
maybe_setup_fake_chrony(self.machine)
999+
self.enable_multihost(self.machine)
9921000

9931001
def configure_kerberos(self, keytab):
9941002
self.machines["services"].execute("/root/run-freeipa")

test/verify/check-system-shutdown-restart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ class TestShutdownRestart(testlib.MachineCase):
3838
m2 = self.machines['machine2']
3939
b2 = self.new_browser(m2)
4040

41+
self.enable_multihost(m2)
42+
4143
m.start_cockpit()
4244

4345
self.login_and_go("/system")

0 commit comments

Comments
 (0)