Bugfix/classic sudo #266

Merged
merged 10 commits into from Jan 7, 2016

Conversation

Projects
None yet
5 participants
Collaborator

mvo5 commented Dec 18, 2015

This branch fixes two issues:

  • the user in the classic environment is not in the "sudo" group so the sudo command won't work
  • when enabling classic fails for whatever reason the broken/incomplete dir is now removed.
  • pass the environment to the child when re-execing with sudo

mvo5 added some commits Dec 18, 2015

Add "$SUDO_USER" to the "sudo" group in the classic environment
The $SUDO_USER in classic is not in the sudo group by default.
We enable it at classic creation time to ensure that sudo works
as expected.
Remove classic dir if "create" fails
If creating of the classic environment fails for whatever reason
we need to remove it instead of leaving a broken classic directory
around.
Pass the parent environemnt when re-execing for "sudo"
The "snappy shell classic" command checks if it is running as
a normal user and if that is the case it will re-exec itself
with the "sudo" command. Its using syscall.Exec() for this.

In order to have a working environment (so that e.g. TERM is
correct) we now pass the parent environment.
+ return fmt.Errorf("failed to add %s to the sudo users: %s", sudoUser, err)
+ }
+ }
+
@pedronis

pedronis Dec 18, 2015

Contributor

maybe I'm not understanding but shouldn't we copy the whole sudo group from outside to inside? it feels a bit strange to copy exactly the user that created the classic env

@mvo5

mvo5 Dec 21, 2015

Collaborator

Yes we should. I fixed that now, the lack of getgrnam() put me off a bit when I did the initial implementation. But you are correct, we should consider all users.

@niemeyer

niemeyer Jan 5, 2016

Contributor

Not sure about what's the vanilla state of an installed system these days, but FWIW my main local user has local access because I'm in the admin group, rather than sudo. Both are in sudoers by default, IIRC. Again, not a very reliable data point, but makes me wonder about what the plain image in 16.04 is likely to have.

@mvo5

mvo5 Jan 5, 2016

Collaborator

@niemeyer On older installs there is indeed the "admin" group instead of the (newer) "sudo" group. This is not be a problem for us because we control how the snappy image is created. Currently this is the default user permission: http://bazaar.launchpad.net/~ubuntu-core-dev/livecd-rootfs/trunk/view/head:/live-build/ubuntu-core/hooks/01-setup_user.chroot (adm, sudo). If people add users manually we will honor the groups of those users too this way on install of classic.

mvo5 added some commits Dec 21, 2015

Implement new "group" package that wraps getgrnam_r()
The classic mode will need support for reading all group members
of the "sudo" group. There is no native getgrnam() in golang, so
this package implements that.
Add all users from the snappy "sudo" group in classic
Lookup all members of the sudo group in the snappy system
and add them to the classic environment.
Member

elopio commented Jan 4, 2016

This is a bug fix, so can you please report the bugs in launchpad with steps to reproduce them?

Collaborator

mvo5 commented Jan 5, 2016

@elopio thanks! https://bugs.launchpad.net/snappy/+bug/1530827 has steps to reproduce it now

Collaborator

mvo5 commented Jan 5, 2016

retest this please

Collaborator

mvo5 commented Jan 5, 2016

Fwiw, the travis failure is a panic in "go vet" from go tip - I tried to reproduce this here but with the version of go vet from 5. Jan I do not get the error. Travis is using the go vet version 19. Dec for some reason.

group/group_linux.go
+
+ p := unsafe.Pointer(result.gr_mem)
+ for {
+ if (*(**C.char)(p)) == nil {
@niemeyer

niemeyer Jan 5, 2016

Contributor

The conditional can go into the for statement above instead. I'd also check that p itself isn't nil, just for extra safety. Shouldn't happen, but good practice before dereferencing a pointer from an external API.

group/group_linux_test.go
+ cmd := exec.Command("getent", "group", name)
+ output, err := cmd.Output()
+ if err != nil {
+ return grp, fmt.Errorf("getenv failed for %s: %s", name, err)
@niemeyer

niemeyer Jan 5, 2016

Contributor

s/env/ent/

group/group_linux_test.go
+ c.Assert(err, IsNil)
+ groups, err := Getgrnam("adm")
+ c.Assert(err, IsNil)
+ c.Assert(expected, DeepEquals, groups)
@niemeyer

niemeyer Jan 5, 2016

Contributor

FWIW, the order of arguments is reversed here: Assert(obtained, DeepEquals, expected)

group/group.go
+ *
+ */
+
+package group
@niemeyer

niemeyer Jan 5, 2016

Contributor

Feels slightly too fine grained to have a package just for this. Do we have some sort of "osutil" package? Should we have one?

@mvo5

mvo5 Jan 5, 2016

Collaborator

I have no strong opinion either way, happy to rename to "osutil".

Contributor

niemeyer commented Jan 5, 2016

A few comments, but overall LGTM.

mvo5 added some commits Jan 6, 2016

Collaborator

mvo5 commented Jan 6, 2016

Thanks for the excellent feedback! I addressed the comments. Please let me know if there is anything else I can do.

Contributor

niemeyer commented Jan 6, 2016

Thanks Michael! LGTM

Member

chipaca commented Jan 6, 2016

👍

mvo5 added a commit that referenced this pull request Jan 7, 2016

@mvo5 mvo5 merged commit 1282a18 into snapcore:master Jan 7, 2016

2 of 3 checks passed

continuous-integration/travis-ci/pr The Travis CI build failed
Details
Integration tests Success 54 tests run, 0 skipped, 0 failed.
Details
coverage/coveralls Coverage decreased (-0.003%) to 67.386%
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment