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
1diff --git a/plainbox/impl/ctrl.py b/plainbox/impl/ctrl.py
2index 75c4332..6666e33 100644
3--- a/plainbox/impl/ctrl.py
4+++ b/plainbox/impl/ctrl.py
5@@ -1453,9 +1453,14 @@ class RootViaSudoExecutionController(
6 # On snappy, the group check does not work. Let's verify if snap
7 # create-user made a rule for the current user
8 in_sudoers_d = False
9+ # NOTE Sept 2017: snapd currently explicitly handles '.' chars in the
10+ # username by replacing with %2E
11+ # https://github.com/snapcore/snapd/blob/master/osutil/user.go#L84
12+ # Hence doing the same here:
13+ user_mod = os.getenv('USER').replace('.', '%2E')
14 if (os.getenv("SNAP")):
15 in_sudoers_d = os.path.exists(
16- '/etc/sudoers.d/create-user-{}'.format(os.getenv('USER')))
17+ '/etc/sudoers.d/create-user-{}'.format(user_mod))
18 self.user_can_sudo = in_sudo_group or in_admin_group or in_sudoers_d
19 self.warm_up_func = lambda: extcmd.ExternalCommand().call(
20 ['sudo', '-S', 'true'])

Subscribers

People subscribed via source and target branches