Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicit addition of a user's primary_group breaks the user creation #3641

Open
ubuntu-server-builder opened this issue May 12, 2023 · 7 comments
Labels
bug Something isn't working correctly launchpad Migrated from Launchpad

Comments

@ubuntu-server-builder
Copy link
Collaborator

This bug was originally filed in Launchpad as LP: #1870310

Launchpad details
affected_projects = []
assignee = None
assignee_name = None
date_closed = None
date_created = 2020-04-02T09:44:14.630245+00:00
date_fix_committed = None
date_fix_released = None
id = 1870310
importance = medium
is_complete = False
lp_url = https://bugs.launchpad.net/cloud-init/+bug/1870310
milestone = None
owner = saviq
owner_name = Michał Sawicz
private = False
status = triaged
submitter = saviq
submitter_name = Michał Sawicz
tags = []
duplicates = []

Launchpad user Michał Sawicz(saviq) wrote on 2020-04-02T09:44:14.630245+00:00

$ multipass launch --cloud-init - <<EOF
users:

  • name: $USER
    groups: [ubuntu]
    ssh_authorized_keys:
    • $( cat ~/.ssh/id_rsa.pub )
      EOF

times out due to missing ubuntu user

$ multipass ls

find the IP

$ ssh $IP

/var/log/cloud-init.log

2020-04-02 09:40:27,551 - init.py[DEBUG]: Adding user ubuntu
2020-04-02 09:40:27,551 - util.py[DEBUG]: Running hidden command to protect sensitive input/output logstring: ['useradd', 'ubuntu', '--comment', 'Ubuntu', '--groups', 'adm,audio,cdrom,dialout,dip,floppy,lxd,netdev,plugdev,sudo,video', '--shell', '/bin/bash', '-m']
2020-04-02 09:40:27,555 - util.py[WARNING]: Failed to create user ubuntu
2020-04-02 09:40:27,556 - util.py[DEBUG]: Failed to create user ubuntu
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/cloudinit/distros/init.py", line 481, in add_user
util.subp(useradd_cmd, logstring=log_useradd_cmd)
File "/usr/lib/python3/dist-packages/cloudinit/util.py", line 2102, in subp
cmd=args)
cloudinit.util.ProcessExecutionError: Unexpected error while running command.
Command: ['useradd', 'ubuntu', '--comment', 'Ubuntu', '--groups', 'adm,audio,cdrom,dialout,dip,floppy,lxd,netdev,plugdev,sudo,video', '--shell', '/bin/bash', '-m']
Exit code: 9
Reason: -
Stdout:
Stderr: useradd: group ubuntu exists - if you want to add this user to that group, use -g.
2020-04-02 09:40:27,560 - handlers.py[DEBUG]: finish: init-network/config-users-groups: FAIL: running config-users-groups with frequency once-per-instance

It looks as if a user's primary_group is created prior to that user being created, the user addition fails.

@ubuntu-server-builder ubuntu-server-builder added bug Something isn't working correctly launchpad Migrated from Launchpad labels May 12, 2023
@ubuntu-server-builder
Copy link
Collaborator Author

Launchpad user Michael Hudson-Doyle(mwhudson) wrote on 2020-04-02T19:23:13.976135+00:00

Isn't this just the fact that if you specify a user the default user doesn't get created?

@ubuntu-server-builder
Copy link
Collaborator Author

Launchpad user Ryan Harper(raharper) wrote on 2020-04-02T20:01:07.278247+00:00

No, it's slighty more subtle.

It appears that you want to add a user $USER, and make them part of 'ubuntu' group , where 'ubuntu' group is the Ubuntu default user in cloud images.

If you intend to keep default user 'ubuntu' and add a user $USER, then you need two entries in your list. From the docs:

The users config key takes a list of users to configure. The first entry in
this list is used as the default user for the system. To preserve the standard
default user for the distro, the string default may be used as the first
entry of the users list. Each entry in the users list, other than a
default entry, should be a dictionary of options for the user.

So:
multipass launch --cloud-init - <<EOF
users:

  • default
  • name: $USER
    groups: [ubuntu]
    ssh_authorized_keys:
    • $( cat ~/.ssh/id_rsa.pub )
      EOF

And the error appears that since your $USER has group "ubuntu" when the default user was created, it tried to use the group 'ubuntu' which was already created. So another options would be:

multipass launch --cloud-init - <<EOF
users:

  • name: $USER
    groups: [$USER]
    ssh_authorized_keys:
    • $( cat ~/.ssh/id_rsa.pub )
      EOF

That said, you can run 'cloud-init collect-logs' and attach the tarball we can see of something else is going on.

@ubuntu-server-builder
Copy link
Collaborator Author

Launchpad user Michał Sawicz(saviq) wrote on 2020-04-03T07:17:31.615822+00:00

And the error appears that since your $USER has group "ubuntu"
when the default user was created, it tried to use the group
'ubuntu' which was already created. So another options would be:

Yes, that's exactly it. And I had the tarball collected, just forgot to attach, sorry!

@ubuntu-server-builder
Copy link
Collaborator Author

Launchpad user Michał Sawicz(saviq) wrote on 2020-04-03T07:18:11.857616+00:00

Launchpad attachments: cloud-init.tar.gz

@ubuntu-server-builder
Copy link
Collaborator Author

Launchpad user Michał Sawicz(saviq) wrote on 2020-04-03T07:20:06.085749+00:00

users:

  • default
  • name: $USER
    groups: [ubuntu]
    ssh_authorized_keys:
    • $( cat ~/.ssh/id_rsa.pub )

This is actually what happens with Multipass, since we enforce the default user. And this breaks in the same way - the "ubuntu" group gets created before the default user is created - and that then breaks.

@ubuntu-server-builder
Copy link
Collaborator Author

Launchpad user Ryan Harper(raharper) wrote on 2020-04-03T14:48:44.645990+00:00

Thanks for the logs; here we can see that the the specified user is created prior to the default user; and since their groups overlap; there's a failure.

2020-04-02 09:40:26,700 - util.py[DEBUG]: Running command ['groupadd', 'ubuntu'] with allowed return codes [0] (shell=False, capture=True)
2020-04-02 09:40:26,907 - init.py[INFO]: Created new group ubuntu
2020-04-02 09:40:26,908 - init.py[DEBUG]: created group 'ubuntu' for user 'michal'
2020-04-02 09:40:26,908 - init.py[DEBUG]: Adding user michal
2020-04-02 09:40:26,909 - util.py[DEBUG]: Running hidden command to protect sensitive input/output logstring: ['useradd', 'michal', '--groups', 'ubuntu', '-m']
2020-04-02 09:40:27,480 - util.py[DEBUG]: Running command ['passwd', '-l', 'michal'] with allowed return codes [0] (shell=False, capture=True)
2020-04-02 09:40:27,551 - init.py[DEBUG]: Adding user ubuntu
2020-04-02 09:40:27,551 - util.py[DEBUG]: Running hidden command to protect sensitive input/output logstring: ['useradd', 'ubuntu', '--comment', 'Ubuntu', '--groups', 'adm,audio,cdrom,dialout,dip,floppy,lxd,netdev,plugdev,sudo,video', '--shell', '/bin/bash', '-m']
2020-04-02 09:40:27,555 - util.py[WARNING]: Failed to create user ubuntu
2020-04-02 09:40:27,556 - util.py[DEBUG]: Failed to create user ubuntu
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/cloudinit/distros/init.py", line 481, in add_user
util.subp(useradd_cmd, logstring=log_useradd_cmd)
File "/usr/lib/python3/dist-packages/cloudinit/util.py", line 2102, in subp
cmd=args)
cloudinit.util.ProcessExecutionError: Unexpected error while running command.
Command: ['useradd', 'ubuntu', '--comment', 'Ubuntu', '--groups', 'adm,audio,cdrom,dialout,dip,floppy,lxd,netdev,plugdev,sudo,video', '--shell', '/bin/bash', '-m']
Exit code: 9
Reason: -
Stdout:
Stderr: useradd: group ubuntu exists - if you want to add this user to that group, use -g.

@ubuntu-server-builder
Copy link
Collaborator Author

Launchpad user Michał Sawicz(saviq) wrote on 2020-04-04T14:55:12.102893+00:00

It would be a similar problem if we just had a:

groups:

  • ubuntu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly launchpad Migrated from Launchpad
Projects
None yet
Development

No branches or pull requests

1 participant