Support UID and GID specification in user and group definitions

Bug #1396362 reported by marvin on 2014-11-25
46
This bug affects 10 people
Affects Status Importance Assigned to Milestone
cloud-init
Low
Unassigned

Bug Description

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

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
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 = {

Chris Vigelius (chris-vigelius) wrote :
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):

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'
       ...

Scott Moser (smoser) wrote :

this looks reasonable.

Changed in cloud-init:
importance: Undecided → Low
status: New → Triaged
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?

Jon Gjengset (jonhoo) wrote :

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

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.

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.

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers