18.10+ cloud images have the LXD group as gid 1000

Bug #1844498 reported by Stéphane Graber
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
cloud-images
New
Undecided
Unassigned
snapd
Incomplete
Undecided
Unassigned
cloud-init (Ubuntu)
Invalid
Undecided
Unassigned
livecd-rootfs (Ubuntu)
Fix Released
Undecided
Michael Hudson-Doyle
snapd (Ubuntu)
Invalid
Undecided
Unassigned

Bug Description

The LXD group is meant to be a system group (< 1000).
The logic in our deb and snap packages is to create it with --system.

However, we've recently had a report that on cosmic and higher, the LXD group is at gid 1000.
The lxd user itself isn't affected and is getting a system uid as expected.

The image itself doesn't contain that group in /etc/group so it appears to be created on first boot.

Some investigation made me think of this part of /etc/cloud/cloud.cfg:
   default_user:
     name: ubuntu
     lock_passwd: True
     gecos: Ubuntu
     groups: [adm, audio, cdrom, dialout, dip, floppy, lxd, netdev, plugdev, sudo, video]
     sudo: ["ALL=(ALL) NOPASSWD:ALL"]
     shell: /bin/bash

As the group will only exist when the snap gets installed, it seems possible that cloud-init would be the one automatically creating the group in such case, wrongly creating it as a user group rather than a system group.

The easiest way out of this would be to either have the image build process or cloud-init itself create it as a system group ahead of user creation.

   groupadd --system lxd

This would then have cloud-init use the system group for the default user and the LXD snap will happily use the existing group too.

Related branches

Revision history for this message
Robert C Jennings (rcj) wrote :

I have added two other packages to this bug.

livecd-rootfs - For the ubuntu-server and ubuntu-cpc projects a chroot hook should be added to create the lxd system group.

cloud-init - We have the suggestion that user creation should not initially create user groups that do not exist. You may consider adding a second pass in a final cloud-init module which would add groups for the default user which did not exist during the first pass (or create them if they still do not exist; and adding a mechanism for identifying system groups would be a good enhancement). This 2-stage approach would allow packages and snaps that get installed during boot (after cloud-init creates the default user) to create their own groups and manage them while ensuring the default user does get added to these.

tags: added: id-5d84bb1ca26b0679a708dc40
Revision history for this message
Scott Moser (smoser) wrote :

I don't love the idea of two passes on adding users/groups.

https://stackoverflow.com/questions/57605982/how-to-make-a-custom-gid-in-groupadd-cloud-init
has an idea for another solution. sort of.

Revision history for this message
Dan Watkins (oddbloke) wrote :

This is complicated.

The root cause, I believe, is lxd moving from a deb (which created the lxd system group when installed during image build) to a snap (which creates the group after/during first boot but, crucially, after cloud-init has created users and therefore the lxd group itself). As a result, the expected Ubuntu experience (`ubuntu` user is in the `lxd` system group when created) degraded. This is another symptom of snaps being poorly integrated into classic Ubuntu systems, I think.

My feeling is that this is really a snap-seeding-on-classic issue. The lxd snap should have a way of expressing "I want a lxd system group" and the seeding process should ensure that the system is configured in a way that won't cause these problems. There are some changes to the seeding process in the works, so I've added a snapd task to get input on whether that's at all realistic to hope for.

In the absence of snapd changes, from a cloud-init perspective this feels like an image misconfiguration to me. lxd is a core part of the Ubuntu Server experience that we provide[0], and not having a lxd system group in the image was not an intentional change, but an accident brought about by the move to a snap.

[0] IIRC, the minimal cloud images don't include lxd, so we should also consider what the desired behaviour there should be.

> We have the suggestion that user creation should not initially create user groups that do not exist.

Changing the default behaviour would be a non-starter for backport to stable releases[0], but we could consider doing this with an additional configuration option in the user specification (e.g. "create_if_missing: False"). This wouldn't result in the `ubuntu` user being in the `lxd` group by default, though, without additional 2-stage changes also proposed.

Alternatively, we could allow specifying that groups should be created as system groups (e.g. "system: True"). This would mean that the lxd system group would exist on systems where lxd isn't seeded (such as the minimal cloud images), which is less than ideal IMO[1].

Either of these options would require a fundamental modification of the schema for groups[2] (and cloud-init SRUs), so should not be considered a quick route to resolving this issue, IMO. And, further, it's not clear to me that they are actually _correct_ ways to resolve this.

Cheers,

Dan

[0] People could be happily relying on cloud-init to create user groups they specify for users today, and we don't want to break those people.
[1] As a security-conscious user launching a minimal cloud image and manually installing lxd later, I probably wouldn't expect any users to be able to interact with lxd by default.
[2] The current schema doesn't have support for any options for groups; they're just strings. Furthermore, dicts already have specific meaning in that code (group name -> list of group members). So we would need to do the investigation into the schema changes and the work to add support for options to groups, in addition to support for the specific options we want.

Revision history for this message
Michael Vogt (mvo) wrote :

I wonder if adding something to cloud.cfg that ensures there is a lxd group created as a system-group would be the way forward? Especially since we already reference this group in cloud.cfg.

Revision history for this message
Steve Langasek (vorlon) wrote : Re: [Bug 1844498] Re: 18.10+ cloud images have the LXD group as gid 1000

On Thu, Sep 26, 2019 at 05:27:22PM -0000, Michael Vogt wrote:
> I wonder if adding something to cloud.cfg that ensures there is a lxd
> group created as a system-group would be the way forward? Especially
> since we already reference this group in cloud.cfg.

For the specific case of a preseeded snap which we know should have an
associated group, I think we should handle this in livecd-rootfs and
statically create the group in the image since both are static aspects of
the image mastering. We CAN instruct cloud-init to create this as a system
group, but the point is that this is a layering violation; we should not
have to keep the cloud.cfg and the lxd snap in sync with regards to the
properties of the groups being created.

The reason I think that there should be extensions to cloud-init for this at
all is for the case where you have a *non* preseeded package which you want
to install as part of the instance config, and you want to add your user to
the group that will be created by that package. That could be either a deb
or a snap, doesn't matter. I don't think it smells good to have cloud-init
creating the group in this case.

Revision history for this message
Dan Watkins (oddbloke) wrote :

Per Steve's comment, I'm going to move the cloud-init task to Invalid. I don't fully understand the "extensions" referenced in comment #5, but it seems clear to me that they should be tracked in a separate bug. I'll let someone who _does_ understand that ask file that bug. :)

Changed in cloud-init (Ubuntu):
status: New → Invalid
Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :
Changed in livecd-rootfs (Ubuntu):
status: New → In Progress
assignee: nobody → Michael Hudson-Doyle (mwhudson)
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package livecd-rootfs - 2.618

---------------
livecd-rootfs (2.618) eoan; urgency=medium

  [ Michael Hudson-Doyle ]
  * Do not create a hook manually for ubuntu-cpc builds, make-hooks does not
    like that.

 -- Steve Langasek <email address hidden> Tue, 08 Oct 2019 21:21:45 -0700

Changed in livecd-rootfs (Ubuntu):
status: In Progress → Fix Released
Revision history for this message
Dimitri John Ledkov (xnox) wrote :

This has now added
lxd:x:101:

Into ubuntu-base tarballs http://cdimage.ubuntu.com/ubuntu-base/daily/pending/ which is a bit problematic.

Was that intended?

core20 snap builds started to fail now, as it installs a few more packages on top of base, and expects to maintain stable gids

Currently the below gids were already in use

netdev:x:101:
crontab:x:102:
messagebus:x:103:
snappypkg:x:104:
ssh:x:105:
systemd-journal:x:106:
systemd-timesync:x:108:
systemd-network:x:109:
systemd-resolve:x:110:
systemd-bus-proxy:x:111:
kvm:x:112:
docker:x:113:
syslog:x:114:
pkcs11:x:115:
tss:x:116:
input:x:107:
render:x:117:

Imho ubuntu-base should not contain any gids that are not declared statically by base-files.

Revision history for this message
Dimitri John Ledkov (xnox) wrote :
Revision history for this message
Oliver Grawert (ogra) wrote :

note that the build scripts for core do have an md5sum check to detect changes to /etc/passwd|group|shadow because this file is orignally readonly.
dirs created with specific UIDs/GIDs by package postinist scripts that get copied into the writable area of the rootfs during first boot would fail to be owned by the daemon users the packages set up for them during a core update...

adding a new entry to one of the readonly password db files is fine but requires changes in livecd-rootfs and an update of the expected md5sum ...

additionally to the above, since /etc/group is readonly, you can not add users to the lxd group if you add lxd there so unprivileged containers on core will become impossible, the GID of lxd should be transferred into /var/lib/extrausers/group to make it possible to add a local system user to this group.

Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :

On Thu, 10 Oct 2019, 23:41 Dimitri John Ledkov, <email address hidden>
wrote:

> This has now added
> lxd:x:101:
>
> Into ubuntu-base tarballs http://cdimage.ubuntu.com/ubuntu-
> base/daily/pending/ which is a bit problematic.
>
> Was that intended?
>

I think it was sort of known, vs actively intended.

core20 snap builds started to fail now, as it installs a few more
> packages on top of base, and expects to maintain stable gids
>

Ok. Making this hook not run for ubuntu-base seems ok to me. Can we make
autopkgtests fail in this case for next time?

>
>

Revision history for this message
Steve Langasek (vorlon) wrote :

> core20 snap builds started to fail now, as it installs a
> few more packages on top of base, and expects to maintain stable gids

In principle, the snap build should follow the changes in behavior in livecd-rootfs, rather than blocking us from making any changes; it's a sanity check against accidental drift. As Oliver says:

> adding a new entry to one of the readonly password
> db files is fine but requires changes in livecd-rootfs
> and an update of the expected md5sum ...

So it needs a separate confirmation for the snap builds to work, but I don't see any reason we should special case a revert for the ubuntu-base build.

Revision history for this message
Michael Vogt (mvo) wrote :

Closing the ubuntu snapd task as this bug is already on the project snapd

Changed in snapd:
status: New → In Progress
Changed in snapd (Ubuntu):
status: New → Invalid
Revision history for this message
Michael Vogt (mvo) wrote :

If snapd should change for this I think we need to have some design to discuss how this should look. AIUI there is a desire to express that some snaps needs groups created on the host (like lxd) when a snap gets installed. We could make this work, but even then with our current model where snaps are seeded during boot we would still need to make sure that cloud-init does things in the right order, i.e. first wait for seeding and then do the user creation.

Changed in snapd:
status: In Progress → Incomplete
tags: added: id-5d9f086c55aa263ba7e2f5e5
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.