Debian Codegraph @

test/verify/check-superuser

raw
1 #!/usr/bin/python3 -cimport os, sys; os.execv(os.path.dirname(sys.argv[1]) + "/../common/pywrap", sys.argv)
2
3 #
4 # Copyright (C) 2020 Red Hat, Inc.
5 # SPDX-License-Identifier: LGPL-2.1-or-later
6
7
8 import time
9
10 import testlib
11
12
13 @testlib.nondestructive
14 class TestSuperuser(testlib.MachineCase):
15 def setUp(self):
16 super().setUp()
17 if self.has_sudo_rs:
18 self.sudo_prompt = "Password:"
19 else:
20 user = self.get_sudo_user()
21 self.sudo_prompt = f"Password for {user}:"
22
23 def testBasic(self):
24 b = self.browser
25 m = self.machine
26
27 # Log in with all defaults
28 self.login_and_go()
29 b.check_superuser_indicator("Administrative access")
30
31 b.assert_pixels("#topnav", "topnav-privileged")
32
33 # Drop privileges
34 b.open_superuser_dialog()
35 b.wait_text(".pf-v6-c-modal-box__title-text", "Switch to limited access")
36 b.click(".pf-v6-c-modal-box button:contains('Limit access')")
37 b.wait_not_present(".pf-v6-c-modal-box")
38 b.check_superuser_indicator("Limited access")
39
40 b.assert_pixels("#topnav", "topnav-unprivileged")
41
42 # Check they are still gone after logout
43 b.relogin()
44 b.leave_page()
45 b.check_superuser_indicator("Limited access")
46
47 # A reload should not lose privileges
48 b.become_superuser()
49 b.reload()
50 b.check_superuser_indicator("Administrative access")
51
52 # Drop privileges
53 b.drop_superuser()
54
55 # We want to be lectured again
56 self.restore_dir("/var/db/sudo/lectured")
57
58 m.execute("rm -rf /var/{db,lib}/sudo/lectured/admin")
59 # Sudo since 1.9.15 uses a UID not a username https://www.sudo.ws/releases/stable/#1.9.15
60 uid = m.execute("id -u admin").strip()
61 m.execute(f"rm -rf /var/{{db,lib}}/sudo/lectured/{uid}")
62
63 # Get the privileges back, this time in the mobile layout
64 b.set_layout("mobile")
65 b.open_superuser_dialog()
66 b.wait_text(".pf-v6-c-modal-box__title-text", "Switch to administrative access")
67 if "ubuntu" not in m.image and "debian" not in m.image:
68 b.wait_in_text(".pf-v6-c-modal-box", "We trust you have received the usual lecture")
69 b.wait_in_text(".pf-v6-c-modal-box", self.sudo_prompt)
70 b.set_input_text(".pf-v6-c-modal-box input", "foobar")
71 b.focus(".pf-v6-c-modal-box button:contains('Cancel')")
72 b.assert_pixels(".pf-v6-c-modal-box", "superuser-modal",
73 chrome_hack_double_shots=True)
74 b.click(".pf-v6-c-modal-box button:contains('Authenticate')")
75 b.wait_not_present(".pf-v6-c-modal-box")
76 b.check_superuser_indicator("Administrative access")
77 b.set_layout("desktop")
78
79 # Check we still have them after logout
80 b.relogin()
81 b.leave_page()
82 b.check_superuser_indicator("Administrative access")
83
84 # Test that closing instead of cancelling the dialog keeps the "switch
85 # to administrative button"
86 b.open_superuser_dialog()
87 b.wait_text(".pf-v6-c-modal-box__title-text", "Switch to limited access")
88 b.click(".pf-v6-c-modal-box button:contains('Limit access')")
89 b.wait_not_present(".pf-v6-c-modal-box")
90 b.check_superuser_indicator("Limited access")
91
92 b.open_superuser_dialog()
93 b.click(".pf-v6-c-modal-box__close button")
94 b.check_superuser_indicator("Limited access")
95
96 @testlib.skipImage("sudo-rs does not support IO logging", "ubuntu-2604")
97 def testSudoIOLogging(self):
98 b = self.browser
99 m = self.machine
100
101 self.write_file("/etc/sudoers.d/log", "Defaults log_output\n")
102
103 # with explicitly becoming superuser
104 self.login_and_go(superuser=False)
105 b.check_superuser_indicator("Limited access")
106 b.become_superuser()
107 self.assertIn("00\n", m.execute("ls /var/log/sudo-io"))
108 b.logout()
109
110 # with immediate superuser at login
111 b.login_and_go()
112 b.check_superuser_indicator("Administrative access")
113 b.logout()
114
115 def testNoPasswd(self):
116 b = self.browser
117
118 # Log in with limited access
119 self.login_and_go(superuser=False)
120 b.check_superuser_indicator("Limited access")
121
122 # Give us password-less sudo and use it
123 self.write_file("/etc/sudoers.d/admin", "admin ALL=(ALL) NOPASSWD:ALL")
124 b.become_superuser(passwordless=True)
125
126 @testlib.skipBeiboot("no local PAM config in beiboot mode")
127 @testlib.skipOstree("mock-pam-conv not installed")
128 def testTwoPasswds(self):
129 b = self.browser
130 m = self.machine
131
132 # Log in with limited access
133 self.login_and_go(superuser=False)
134 b.check_superuser_indicator("Limited access")
135
136 # Configure the sudo PAM stack to make two prompts
137 if "debian" in m.image or "ubuntu" in m.image:
138 self.write_file("/etc/pam.d/sudo", """
139 auth required pam_unix.so
140 auth required mock-pam-conv-mod.so
141 @include common-account
142 @include common-session-noninteractive
143 """)
144 else:
145 self.write_file("/etc/pam.d/sudo", """
146 auth required pam_unix.so
147 auth required mock-pam-conv-mod.so
148 account include system-auth
149 password include system-auth
150 session include system-auth
151 """)
152
153 b.open_superuser_dialog()
154 b.wait_text(".pf-v6-c-modal-box__title-text", "Switch to administrative access")
155 b.wait_in_text(".pf-v6-c-modal-box", self.sudo_prompt)
156 # Let the dialog sit there for 45 seconds, to test that this doesn't trigger a D-Bus timeout.
157 time.sleep(45)
158 b.set_input_text(".pf-v6-c-modal-box input", "foobar")
159 b.click(".pf-v6-c-modal-box button:contains('Authenticate')")
160 b.wait_in_text(".pf-v6-c-modal-box", "universe and everything")
161 b.set_input_text(".pf-v6-c-modal-box input", "42")
162 b.click(".pf-v6-c-modal-box button:contains('Authenticate')")
163 b.wait_not_present(".pf-v6-c-modal-box")
164 b.check_superuser_indicator("Administrative access")
165
166 def testWrongPasswd(self):
167 b = self.browser
168
169 fail_text = "Authentication failed, try again." if self.has_sudo_rs else "Sorry, try again"
170
171 # Log in with limited access
172 self.login_and_go(superuser=False)
173 b.check_superuser_indicator("Limited access")
174 b.open_superuser_dialog()
175 b.wait_text(".pf-v6-c-modal-box__title-text", "Switch to administrative access")
176 b.wait_in_text(".pf-v6-c-modal-box", self.sudo_prompt)
177 b.set_input_text(".pf-v6-c-modal-box input", "wrong")
178 b.click(".pf-v6-c-modal-box button:contains('Authenticate')")
179 b.wait_in_text(".pf-v6-c-modal-box", self.sudo_prompt)
180 b.set_input_text(".pf-v6-c-modal-box input", "wrong")
181 b.wait_in_text(".pf-v6-c-modal-box", fail_text)
182 b.set_input_text(".pf-v6-c-modal-box input", "wronger")
183 b.click(".pf-v6-c-modal-box button:contains('Authenticate')")
184 b.wait_in_text(".pf-v6-c-modal-box", self.sudo_prompt)
185 b.wait_in_text(".pf-v6-c-modal-box", fail_text)
186 b.set_input_text(".pf-v6-c-modal-box input", "wrongest")
187 b.click(".pf-v6-c-modal-box button:contains('Authenticate')")
188 b.wait_text(".pf-v6-c-modal-box__title-text", "Problem becoming administrator")
189 b.wait_text_matches(".pf-v6-c-modal-box", r".*3 incorrect (password|authentication) attempts.*")
190 b.click(".pf-v6-c-modal-box button:contains('Close')")
191 b.wait_not_present(".pf-v6-c-modal-box")
192 b.check_superuser_indicator("Limited access")
193
194 def testNotAdmin(self):
195 b = self.browser
196 m = self.machine
197
198 # Remove special treatment of the "admin" group on Ubuntu.
199 # Our main test user is unfortunately called "admin" and has
200 # "admin" as its primary group.
201 #
202 if "ubuntu" in m.image:
203 self.sed_file("/^%admin/d", "/etc/sudoers")
204
205 m.execute(f"gpasswd -d admin {m.get_admin_group()}")
206
207 self.login_and_go()
208 b.check_superuser_indicator("Limited access")
209
210 b.open_superuser_dialog()
211 if not self.has_sudo_rs:
212 # sudo-ws always asks for password, sudo-rs rejects immediately
213 b.wait_text(".pf-v6-c-modal-box__title-text", "Switch to administrative access")
214 b.set_input_text(".pf-v6-c-modal-box input", "foobar")
215 b.click(".pf-v6-c-modal-box button:contains('Authenticate')")
216 b.wait_text(".pf-v6-c-modal-box__title-text", "Problem becoming administrator")
217 b.wait_in_text(".pf-v6-c-modal-box__body",
218 "I'm sorry admin. I'm afraid I can't do that" if self.has_sudo_rs
219 else "Admin is not in the sudoers file.")
220 b.click(".pf-v6-c-modal-box button.btn-cancel")
221 b.wait_not_present(".pf-v6-c-modal-box")
222
223 # no stray/hanging sudo process
224 testlib.wait(lambda: "sudo" not in m.execute("loginctl --lines=0 user-status admin"), tries=5)
225 # cancelling auth dialog stops sudo (you can't do that without a prompt)
226 b.open_superuser_dialog()
227 if self.has_sudo_rs:
228 b.click(".pf-v6-c-modal-box button:contains('Close')")
229 else:
230 b.wait_in_text(".pf-v6-c-modal-box", "Switch to administrative access")
231 b.wait_in_text(".pf-v6-c-modal-box", self.sudo_prompt)
232 status = m.execute("loginctl --lines=0 user-status admin")
233 self.assertIn("sudo", status)
234 if not m.ws_container:
235 self.assertIn("cockpit-askpass", status)
236 b.click(".pf-v6-c-modal-box button:contains('Cancel')")
237 b.wait_not_present(".pf-v6-c-modal-box")
238
239 testlib.wait(lambda: "sudo" not in m.execute("loginctl --lines=0 user-status admin"), tries=5)
240
241 # logging out cleans up pending sudo auth; user should either go to "State: closing" or disappear completely
242 b.open_superuser_dialog()
243 if self.has_sudo_rs:
244 b.click(".pf-v6-c-modal-box button:contains('Close')")
245 else:
246 b.wait_in_text(".pf-v6-c-modal-box", self.sudo_prompt)
247 if not m.ws_container:
248 self.assertIn("cockpit-askpass", m.execute("loginctl --lines=0 user-status admin"))
249 b.click(".pf-v6-c-modal-box button:contains('Cancel')")
250 b.wait_not_present(".pf-v6-c-modal-box")
251 b.logout()
252 testlib.wait(lambda: "sudo" not in m.execute("loginctl --lines=0 user-status admin || true"), tries=10)
253 self.assertNotIn("cockpit", m.execute("loginctl --lines=0 user-status admin || true"))
254
255 @testlib.skipBeiboot("no local overrides/PAM config in beiboot mode")
256 def testBrokenBridgeConfig(self):
257 b = self.browser
258 m = self.machine
259
260 self.write_file("/etc/cockpit/shell.override.json", """
261 {
262 "bridges": [
263 {
264 "privileged": true,
265 "spawn": [
266 "sudo",
267 "-k",
268 "-A",
269 "cockpit-bridge",
270 "--privileged"
271 ]
272 }
273 ]
274 }
275 """)
276
277 # We don't want to be lectured in this test just to control
278 # the content of the dialog better.
279 m.execute("touch /var/{db,lib}/sudo/lectured/admin 2>/dev/null || true")
280
281 self.login_and_go(superuser=False)
282 b.check_superuser_indicator("Limited access")
283
284 b.open_superuser_dialog()
285 b.wait_text(".pf-v6-c-modal-box__title-text", "Problem becoming administrator")
286 b.wait_text_matches(".pf-v6-c-modal-box__body", "Sudo: [nN]o askpass program specified.*SUDO_ASKPASS")
287 b.click(".pf-v6-c-modal-box button.btn-cancel")
288 b.wait_not_present(".pf-v6-c-modal-box")
289 b.check_superuser_indicator("Limited access")
290
291 @testlib.skipBeiboot("no local overrides/PAM config in beiboot mode")
292 def testRemoveBridgeConfig(self):
293 m = self.machine
294 b = self.browser
295
296 self.login_and_go("/playground/pkgs", superuser=True)
297 b.leave_page()
298 b.check_superuser_indicator("Administrative access")
299 # superuser bridge is running
300 m.execute("pgrep -u root -a cockpit-bridge")
301
302 self.write_file("/etc/cockpit/shell.override.json", """
303 {
304 "bridges": [ ]
305 }
306 """)
307
308 b.enter_page("/playground/pkgs")
309 b.click("#reload")
310 b.leave_page()
311 b.check_superuser_indicator("Limited access")
312 # superuser bridge goes away
313 m.execute("while pgrep -u root -a cockpit-bridge; do sleep 1; done", timeout=5)
314
315 # Try to become superuser - should show error about no methods available
316 b.open_superuser_dialog()
317 b.wait_in_text(".pf-v6-c-modal-box:contains('Problem becoming administrator')",
318 "No methods to gain administrative access are available")
319 b.click(".pf-v6-c-modal-box button:contains('Close')")
320 b.wait_not_present(".pf-v6-c-modal-box:contains('Problem becoming administrator')")
321 b.check_superuser_indicator("Limited access")
322
323 # no banner for "running in limited access mode", there are no bridge configs
324 b.go("/system")
325 b.enter_page("/system")
326 b.wait_visible("#system_information_os_text")
327 b.wait_not_present(".pf-v6-c-alert:contains('Web console is running in limited access mode')")
328
329 @testlib.skipBeiboot("no local overrides/PAM config in beiboot mode")
330 def testSingleLabelBridgeConfig(self):
331 b = self.browser
332
333 # When there is a single labeled privileged bridge, Cockit will start it automatically.
334
335 self.write_file("/etc/cockpit/shell.override.json", """
336 {
337 "bridges": [
338 {
339 "privileged": true,
340 "label": "Always fails",
341 "spawn": [
342 "/bin/bash", "-c", "echo >&2 'Hello from the bash method'; exit 1"
343 ]
344 }
345 ]
346 }
347 """)
348
349 self.login_and_go("/playground/pkgs", superuser=False)
350 b.leave_page()
351 b.check_superuser_indicator("Limited access")
352 b.open_superuser_dialog()
353 b.wait_text(".pf-v6-c-modal-box__title-text", "Problem becoming administrator")
354 b.wait_in_text(".pf-v6-c-modal-box__body", "Hello from the bash method")
355 b.click(".pf-v6-c-modal-box button.btn-cancel")
356 b.wait_not_present(".pf-v6-c-modal-box")
357 b.check_superuser_indicator("Limited access")
358
359 @testlib.skipBeiboot("no local overrides/PAM config in beiboot mode")
360 def testMultipleBridgeConfig(self):
361 b = self.browser
362 m = self.machine
363
364 self.write_file("/etc/cockpit/shell.override.json", """
365 {
366 "bridges": [
367 {
368 "privileged": true,
369 "label": "Sudo",
370 "environ": [
371 "SUDO_ASKPASS=${libexecdir}/cockpit-askpass"
372 ],
373 "spawn": [
374 "sudo",
375 "-k",
376 "-A",
377 "cockpit-bridge",
378 "--privileged"
379 ]
380 },
381 {
382 "privileged": true,
383 "label": "Polkit",
384 "spawn": [
385 "pkexec",
386 "--disable-internal-agent",
387 "cockpit-bridge",
388 "--privileged"
389 ]
390 }
391 ]
392 }
393 """)
394
395 self.login_and_go("/playground/pkgs", superuser=False)
396 b.leave_page()
397 b.check_superuser_indicator("Limited access")
398
399 # Get admin rights with Polkit method
400 b.open_superuser_dialog()
401 b.wait_text(".pf-v6-c-modal-box__title-text", "Switch to administrative access")
402 b.set_val(".pf-v6-c-modal-box select", "Polkit")
403 b.wait_in_text(".pf-v6-c-modal-box select", "Polkit")
404 b.click(".pf-v6-c-modal-box button:contains('Authenticate')")
405 b.wait_in_text(".pf-v6-c-modal-box", "Please authenticate")
406 # wrong password
407 b.set_input_text(".pf-v6-c-modal-box input", "wrong")
408 b.click(".pf-v6-c-modal-box button:contains('Authenticate')")
409
410 # polkit only prompts once, so we expect Permission denied
411 b.wait_text(".pf-v6-c-modal-box__title-text", "Problem becoming administrator")
412 b.wait_in_text(".pf-v6-c-modal-box", "Not authorized")
413 b.click(".pf-v6-c-modal-box button:contains('Close')")
414
415 # try again with correct password
416 b.open_superuser_dialog()
417 b.wait_text(".pf-v6-c-modal-box__title-text", "Switch to administrative access")
418 b.set_val(".pf-v6-c-modal-box select", "Polkit")
419 b.wait_in_text(".pf-v6-c-modal-box select", "Polkit")
420 b.click(".pf-v6-c-modal-box button:contains('Authenticate')")
421 b.wait_in_text(".pf-v6-c-modal-box", "Please authenticate")
422 b.set_input_text(".pf-v6-c-modal-box input", "foobar")
423 b.click(".pf-v6-c-modal-box button:contains('Authenticate')")
424 b.wait_not_present(".pf-v6-c-modal-box")
425 b.check_superuser_indicator("Administrative access")
426
427 # Verify that sudo is not being used
428 self.assertEqual(m.execute(["pgrep", "-a", "sudo"], check=False).strip(), "")
429
430 # Drop them
431 b.open_superuser_dialog()
432 b.wait_text(".pf-v6-c-modal-box__title-text", "Switch to limited access")
433 b.click(".pf-v6-c-modal-box button:contains('Limit access')")
434 b.wait_not_present(".pf-v6-c-modal-box")
435 b.check_superuser_indicator("Limited access")
436
437 # On "new" OSes we expect the socket-based agent helper
438 if m.image == "debian-testing":
439 m.execute("test -S /run/polkit/agent-helper.socket")
440 # not suid
441 self.assertEqual(m.execute("stat -c %A /usr/lib/polkit-1/polkit-agent-helper-1").strip(),
442 "-rwxr-xr-x")
443 # reminder for ourselves in the distant future to remove the legacy path in the bridge
444 elif m.image.startswith("rhel-10"):
445 m.execute("! test -e /run/polkit/agent-helper.socket")
446 # suid root helper
447 self.assertEqual(m.execute("stat -c %A /usr/lib/polkit-1/polkit-agent-helper-1").strip(),
448 "-rwsr-xr-x")
449
450 # Run the regular sudo method, which should work as always
451 b.open_superuser_dialog()
452 b.wait_text(".pf-v6-c-modal-box__title-text", "Switch to administrative access")
453 b.set_val(".pf-v6-c-modal-box select", "Sudo")
454 b.wait_in_text(".pf-v6-c-modal-box select", "Sudo")
455 b.click(".pf-v6-c-modal-box button:contains('Authenticate')")
456 b.wait_in_text(".pf-v6-c-modal-box", self.sudo_prompt)
457 b.set_input_text(".pf-v6-c-modal-box input", "foobar")
458 b.click(".pf-v6-c-modal-box button:contains('Authenticate')")
459 b.wait_not_present(".pf-v6-c-modal-box")
460 b.check_superuser_indicator("Administrative access")
461
462 def testOverview(self):
463 b = self.browser
464
465 self.login_and_go("/system", superuser=False)
466 b.wait_in_text(".ct-limited-access-alert", "Web console is running in limited access mode.")
467 b.click(".ct-limited-access-alert button")
468 b.wait_text(".pf-v6-c-modal-box__title-text", "Switch to administrative access")
469 b.wait_in_text(".pf-v6-c-modal-box", self.sudo_prompt)
470 b.set_input_text(".pf-v6-c-modal-box input", "foobar")
471 b.click(".pf-v6-c-modal-box button:contains('Authenticate')")
472 b.wait_not_present(".pf-v6-c-modal-box")
473 b.wait_not_present(".ct-limited-access-alert")
474
475 def start_transient_unit_common(self):
476 b = self.browser
477 m = self.machine
478
479 # Log in with limited access
480 self.login_and_go(superuser=False)
481 b.check_superuser_indicator("Limited access")
482
483 if m.image.startswith('rhel-8-'): # SELINUX-5411
484 self.addCleanup(m.execute, ("setenforce", "1"))
485 m.execute(("setenforce", "0"))
486
487 # Open the superuser dialog and enter wrong password
488 b.open_superuser_dialog()
489 b.wait_text(".pf-v6-c-modal-box__title-text", "Switch to administrative access")
490 b.wait_in_text(".pf-v6-c-modal-box", "Please authenticate to gain administrative access")
491 b.set_input_text(".pf-v6-c-modal-box input", "wrong")
492 b.click(".pf-v6-c-modal-box button:contains('Authenticate')")
493
494 # StartTransientUnit only prompts once, so we expect Permission denied
495 # after one wrong attempt
496 b.wait_text(".pf-v6-c-modal-box__title-text", "Problem becoming administrator")
497 b.wait_in_text(".pf-v6-c-modal-box", "Permission denied")
498 b.click(".pf-v6-c-modal-box button:contains('Close')")
499
500 # There is a strange issue with AsyncExitStack in the polkit agent code
501 # in the bridge that seems to only impact Python 3.6, resulting in the
502 # agent not being unregistered after the first attempt. We're planning
503 # to move to Python 3.9 on RHEL 8 soon, but until we do that, we can
504 # workaround by logging out and logging back in.
505 if m.image.startswith('rhel-8-'):
506 b.logout()
507 b.login_and_go(superuser=False)
508
509 # Open the superuser dialog and use the right password this time
510 b.open_superuser_dialog()
511 b.wait_text(".pf-v6-c-modal-box__title-text", "Switch to administrative access")
512 b.wait_in_text(".pf-v6-c-modal-box", "Please authenticate to gain administrative access")
513 b.set_input_text(".pf-v6-c-modal-box input", "foobar")
514 b.click(".pf-v6-c-modal-box button:contains('Authenticate')")
515 b.wait_not_present(".pf-v6-c-modal-box")
516 b.check_superuser_indicator("Administrative access")
517
518 # Verify that neither sudo nor pkexec are being used
519 self.assertEqual(m.execute(["pgrep", "-a", "sudo"], check=False).strip(), "")
520 self.assertEqual(m.execute(["pgrep", "-a", "pkexec"], check=False).strip(), "")
521
522 @testlib.skipOstree("can't delete sudo")
523 def testStartTransientUnitNoSudo(self):
524 # Break sudo to force StartTransientUnit to be used
525 self.restore_file("/usr/bin/sudo")
526 self.machine.execute(["rm", "-f", "/usr/bin/sudo"])
527 self.start_transient_unit_common()
528
529 @testlib.skipOstree("can't replace sudo")
530 def testStartTransientUnitNoAskpass(self):
531 # sudo doesn't support -A: StartTransientUnit must be used
532 # we need to be a bit more explicit here because it might be a symlink
533 self.restore_file("/usr/bin/sudo")
534 self.machine.execute(["rm", "-f", "/usr/bin/sudo"])
535 self.machine.write("/usr/bin/sudo", """#!/bin/sh
536 echo "no -A support!" >&2
537 exit 1
538 """, perm="0755")
539 self.start_transient_unit_common()
540
541
542 @testlib.skipBeiboot("host switching disabled in beiboot mode")
543 class TestSuperuserDashboard(testlib.MachineCase):
544 provision = {
545 "machine1": {"address": "10.111.113.1/20"},
546 "machine2": {"address": "10.111.113.2/20"},
547 }
548
549 def test(self):
550 b = self.browser
551 self.setup_provisioned_hosts()
552 self.enable_multihost(self.machine)
553
554 self.login_and_go()
555 b.go("/@10.111.113.2")
556 b.click('#machine-troubleshoot')
557 b.wait_visible('#hosts_setup_server_dialog')
558 b.wait_visible('#hosts_setup_server_dialog button:contains("Add")')
559 b.click('#hosts_setup_server_dialog button:contains("Add")')
560 b.wait_visible('#hosts_connect_server_dialog')
561 b.click('#hosts_connect_server_dialog button.pf-m-warning')
562 b.wait_in_text('#hosts_setup_server_dialog', "You are connecting to 10.111.113.2 for the first time.")
563 b.click('#hosts_setup_server_dialog button.pf-m-primary')
564 b.wait_in_text('#hosts_setup_server_dialog', "Unable to log in")
565 b.set_input_text("#login-custom-password", "foobar")
566 b.click('#hosts_setup_server_dialog button:contains("Log in")')
567 b.wait_not_present('#hosts_setup_server_dialog')
568
569 # There should be no superuser indicator in the Overview
570
571 b.go("/@10.111.113.2/system")
572 b.enter_page("/system", host="10.111.113.2")
573 b.wait_not_present(".ct-overview-header-actions button:contains('Administrative access')")
574 b.wait_not_present(".ct-overview-header-actions button:contains('Limited access')")
575 b.leave_page()
576
577 # The superuser indicator in the Shell should apply to machine2
578
579 b.check_superuser_indicator("Limited access")
580 b.become_superuser()
581 b.go("/@10.111.113.2/playground/test")
582 b.enter_page("/playground/test", host="10.111.113.2")
583 b.click(".super-channel button")
584 b.wait_in_text(".super-channel span", 'result: ')
585 self.assertIn('result: uid=0', b.text(".super-channel span"))
586
587 # Logging out and logging back in should give us immediate
588 # superuser on m2 (once we have logged in there).
589 b.relogin()
590 b.wait_visible('#hosts_connect_server_dialog')
591 b.click('#hosts_connect_server_dialog button.pf-m-warning')
592 b.wait_visible('#hosts_setup_server_dialog')
593 b.set_input_text("#login-custom-password", "foobar")
594 b.click('#hosts_setup_server_dialog button:contains("Log in")')
595 b.wait_not_present('#hosts_setup_server_dialog')
596 b.check_superuser_indicator("Administrative access")
597
598 b.enter_page("/playground/test", host="10.111.113.2")
599 b.click(".super-channel button")
600 b.wait_in_text(".super-channel span", 'result: ')
601 self.assertIn('result: uid=0', b.text(".super-channel span"))
602
603 b.drop_superuser()
604 b.click(".super-channel button")
605 b.wait_in_text(".super-channel span", 'access-denied')
606
607 # back to superuser on machine2
608 b.become_superuser()
609 user = self.machines["machine2"].execute("loginctl user-status admin")
610 self.assertIn("cockpit-bridge --privileged", user)
611 # no stray askpass process
612 self.assertNotIn("cockpit-askpass", user)
613 # logging out cleans up logind sessions on both machines
614 b.logout()
615 for m in [self.machine, self.machines["machine2"]]:
616 m.execute('while [ "$(loginctl show-user --property=State --value admin)" = "active" ]; do sleep 1; done')
617 self.assertNotIn("cockpit", "loginctl user-status admin")
618
619 self.allow_hostkey_messages()
620
621
622 if __name__ == '__main__':
623 testlib.test_main()