Support setting GID when creating groups

Bug #1396362 reported by marvin
72
This bug affects 16 people
Affects Status Importance Assigned to Milestone
cloud-init
Expired
Low
Unassigned

Bug Description

Feature request add ability to set gid for cloud-init created groups

==== orig description ====
Hi, it would be awesome if the Group and User directives had attributes for setting UID and GIDs.

Revision history for this message
Robie Basak (racb) wrote :

Thank you for taking the time to report this bug and helping to make Ubuntu better.

Sounds like this is a wishlist item that needs to go upstream in the first instance.

affects: cloud-init (Ubuntu) → cloud-init
Revision history for this message
Chris Vigelius (chris-vigelius) wrote :

+1 for this, this is literally an one-liner and helpful in many situations:

--- cloudinit/distros/__init__.py 2015-01-26 16:14:06 +0000
+++ cloudinit/distros/__init__.py 2015-03-19 13:51:20 +0000
@@ -324,6 +324,7 @@
             "expiredate": '--expiredate',
             "inactive": '--inactive',
             "selinux_user": '--selinux-user',
+ "uid": '--uid',
         }

         adduser_flags = {

Revision history for this message
Chris Vigelius (chris-vigelius) wrote :
Revision history for this message
Uwe Menges (uwe-menges) wrote :

Please note that uid in the cloudinit script needs to be a string with that patch:
  uid: "2342"

This is because the adduser function in __init__.py checks for the options to be a string (for a reason not obvious to me):
  if key in adduser_opts and val and isinstance(val, str):

Revision history for this message
Chris Vigelius (chris-vigelius) wrote :

better patch which allows to specify gid for groups, too.

to specify gid, let group key point to a dict with 'gid' (and optional 'members') keys:

groups:
    foo:
       gid = '998'
       members: [u1, u2]
    bar:
       gid = '999'
       ...

Revision history for this message
Scott Moser (smoser) wrote :

this looks reasonable.

Changed in cloud-init:
importance: Undecided → Low
status: New → Triaged
Revision history for this message
Nick Timkovich (nicktimko) wrote :

The ChangeLog seems to claim this (or at least the UID part) was done in 0.7.7 : https://git.launchpad.net/cloud-init/tree/ChangeLog?id=3aa094b6917240e6654993b34a48403cb7e14b02#n35 though it looks like it took until post-0.7.9 to be documented at https://cloudinit.readthedocs.io/en/latest/topics/modules.html?highlight=uid#users-and-groups

Or am I mis-reading things?

Revision history for this message
Jon Gjengset (jonhoo) wrote :

I agree with nicktimko — this should be marked as fixed.

Revision history for this message
Jon Gjengset (jonhoo) wrote :
Revision history for this message
Marco Ceppi (marcoceppi) wrote :

Using the following cloud-init:

ii cloud-init 0.7.9-233-ge586fe35-0ubuntu1~16.04.2

With this script:

```
    #cloud-config
    apt:
    proxy: http://10.16.37.1:8000
    users:
      - name: marco
        sudo: ALL=(ALL) NOPASSWD:ALL
        uid: 9001
```

When the machine is booted this is the user entry:

```
marco:x:1000:1000::/home/marco:
```

It seems uid is not respected still.

Revision history for this message
Nick Timkovich (nicktimko) wrote :

IIRC, if the UID in the config file is parsed as an integer, it fails. It looks like that's the case with your demo script, Marco. See an earlier comment: https://bugs.launchpad.net/cloud-init/+bug/1396362/comments/4

Right now I'm struggling with random group IDs being created for multiple users. I specified the UIDs as 1000 and 1010, but I end up with groups to match them either u1000:g1000 and u1010:g1010 or u1000:g1011 and u1010:g1010.

The outstanding bug, imho, is the intolerance of integers in the YAML, and feature request for explicit group IDs.

Revision history for this message
manuel (boillodmanuel) wrote :

Hi,
I can see how to set the user uid (https://cloudinit.readthedocs.io/en/latest/topics/modules.html#users-and-groups) but it still seems impossible to set the group gid.

This is an important limitation to me.

My use case is to mount a remote disk (of type NFS) to a virtual machine and I have to set the uid and guid to keep the right file access.

Revision history for this message
Chris Read (chris-read) wrote :

Although this bug includes a patch to allow gid to be specified to create_groups, it looks like it was not included.

Any plans on getting this fixed?

Revision history for this message
Chad Smith (chad.smith) wrote :

Thanks for the bump on this bug. I can confirm the UID portion of this bug is fixed.
The patch attached is not applicable to today's cloud-init, but I can confirm the ability to gid on added groups isn't possible.

Given the low weight of this bug I'm not sure we are going to work it in the short-term, but if someone were to pick this up, we'd need to adapt the patch, add unittests and extend our JSON schema for users_groups.groups_by_groupname in cloudinit/config/schemas/schema-cloud-config-v1.json to define expected object keys for members and gid.

I've updated the description of the bug to capture today's state.

description: updated
summary: - Support UID and GID specification in user and group definitions
+ Support setting GID when creating groups
Revision history for this message
James Falcon (falcojr) wrote :
Changed in cloud-init:
status: Triaged → Expired
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.