Merge ~jocave/plainbox:dot-username-rootctrl into plainbox:master

Proposed by Jonathan Cave
Status: Merged
Approved by: Sylvain Pineau
Approved revision: b796c493aec6acc850e4809a8fe94deec880cf3b
Merged at revision: b919aae5a546cc3dd8e58b4fda679bdfd0d9906d
Proposed branch: ~jocave/plainbox:dot-username-rootctrl
Merge into: plainbox:master
Diff against target: 20 lines (+6/-1)
1 file modified
plainbox/impl/ctrl.py (+6/-1)
Reviewer Review Type Date Requested Status
Sylvain Pineau (community) Approve
Review via email: mp+330305@code.launchpad.net

Description of the change

The RootViaSudoExecutionController tries to establish that a user running tests from a checkbox snap has ability to sudo by, amongst other things, testing if there is a file matching /etc/sudoers.d/create-user-<USERNAME>

However, the snapd code itself replaces '.' characters in the user name with %2E (see the link in the comment in the code).

This updates the plainbox code to do the same.

Tested as working on hohhot.

To post a comment you must log in.
Revision history for this message
Sylvain Pineau (sylvain-pineau) wrote :

Good catch, thanks for the fix

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/plainbox/impl/ctrl.py b/plainbox/impl/ctrl.py
index 75c4332..6666e33 100644
--- a/plainbox/impl/ctrl.py
+++ b/plainbox/impl/ctrl.py
@@ -1453,9 +1453,14 @@ class RootViaSudoExecutionController(
1453 # On snappy, the group check does not work. Let's verify if snap1453 # On snappy, the group check does not work. Let's verify if snap
1454 # create-user made a rule for the current user1454 # create-user made a rule for the current user
1455 in_sudoers_d = False1455 in_sudoers_d = False
1456 # NOTE Sept 2017: snapd currently explicitly handles '.' chars in the
1457 # username by replacing with %2E
1458 # https://github.com/snapcore/snapd/blob/master/osutil/user.go#L84
1459 # Hence doing the same here:
1460 user_mod = os.getenv('USER').replace('.', '%2E')
1456 if (os.getenv("SNAP")):1461 if (os.getenv("SNAP")):
1457 in_sudoers_d = os.path.exists(1462 in_sudoers_d = os.path.exists(
1458 '/etc/sudoers.d/create-user-{}'.format(os.getenv('USER')))1463 '/etc/sudoers.d/create-user-{}'.format(user_mod))
1459 self.user_can_sudo = in_sudo_group or in_admin_group or in_sudoers_d1464 self.user_can_sudo = in_sudo_group or in_admin_group or in_sudoers_d
1460 self.warm_up_func = lambda: extcmd.ExternalCommand().call(1465 self.warm_up_func = lambda: extcmd.ExternalCommand().call(
1461 ['sudo', '-S', 'true'])1466 ['sudo', '-S', 'true'])

Subscribers

People subscribed via source and target branches