saltstack / saltstack/salt

[BUG] User creation fails on Ubuntu 20.04 due to missing -g flag for useradd

Open
#58,255 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug Confirmed Execution-Module severity-medium
Dominant language
Python
Stars
15.7k
Forks
5.6k
Avg merge
2d 44m
Merged PRs (30d)
80

Description

Description
We are upgrading from Ubuntu 16.04 to 20.04. This involves also upgrading Salt from 3000 to 3001 due to Python2 deprecation in both Ubuntu and Salt.

When trying to create users, Salt fails due to useradd returning error 9, caused by a missing -g flag:

host.example.com: [ERROR   ] Command '['useradd', '-s', '/bin/bash', '-U', '-m', '-d', '/home/XXX', 'XXX']' failed with return code: 9
host.example.com: [ERROR   ] stderr: useradd: group XXX exists - if you want to add this user to that group, use -g.

The documentation states that the users group must exist before trying to create the user:

If the group does not exist the state will fail.

This appears similar to errors back in 2013, for example: https://github.com/saltstack/salt/issues/6165

Setup

SLS to create a user with username XXX belonging to group XXX.

XXX:
   user:
     - present
     - fullname: Mr X
     - shell: /bin/bash
     - gid: XXX
     - home: /home/XXX
     - createhome: True
     - groups:
       - XXX
 {%- if sudo is defined and sudo=='sudo' %}
       - sudo
 {% endif %}
     - require:
       - group: XXX
   group:
     - present

Steps to Reproduce the behavior

host.example.com: [INFO    ] Executing state group.present for [XXX]
host.example.com: [INFO    ] Group XXX is present and up to date
host.example.com: [INFO    ] Completed state [XXX] at time 06:50:25.118560 (duration_in_ms=1.424)
host.example.com: [INFO    ] Running state [XXX] at time 06:50:25.120476
host.example.com: [INFO    ] Executing state user.present for [XXX]
host.example.com: [INFO    ] Executing command ['useradd', '-s', '/bin/bash', '-U', '-m', '-d', '/home/XXX', 'XXX'] in directory '/root'
host.example.com: [ERROR   ] Command '['useradd', '-s', '/bin/bash', '-U', '-m', '-d', '/home/XXX', 'XXX']' failed with return code: 9
host.example.com: [ERROR   ] stderr: useradd: group XXX exists - if you want to add this user to that group, use -g.
host.example.com: [ERROR   ] retcode: 9
host.example.com: [ERROR   ] Failed to create new user XXX
host.example.com: [INFO    ] Completed state [XXX] at time 06:50:25.130480 (duration_in_ms=10.004)

Expected behavior
Users are created.

Versions Report

salt --versions-report (Provided by running salt --versions-report. Please also mention any differences in master/minion versions.)
$ salt-call --versions-report
Salt Version:
           Salt: 3001.1

Dependency Versions:
           cffi: Not Installed
       cherrypy: Not Installed
       dateutil: 2.7.3
      docker-py: Not Installed
          gitdb: Not Installed
      gitpython: Not Installed
         Jinja2: 2.10.1
        libgit2: Not Installed
       M2Crypto: Not Installed
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.6.2
   mysql-python: Not Installed
      pycparser: Not Installed
       pycrypto: 2.6.1
   pycryptodome: 3.6.1
         pygit2: Not Installed
         Python: 3.8.2 (default, Jul 16 2020, 14:00:26)
   python-gnupg: 0.4.5
         PyYAML: 5.3.1
          PyZMQ: 18.1.1
          smmap: Not Installed
        timelib: Not Installed
        Tornado: 4.5.3
            ZMQ: 4.3.2

System Versions:
           dist: ubuntu 20.04 focal
         locale: utf-8
        machine: x86_64
        release: 5.4.0-42-generic
         system: Linux
        version: Ubuntu 20.04 focal

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No source file or test is named. Start at the user.present state and trace how the gid and groups options produce the useradd command shown; reproduce the SLS on Ubuntu 20.04 with an existing XXX group. Done means the user is created successfully with the requested primary and supplementary groups.

Written by the indexing model from the issue text.

Assessment

Tech stack
linux, python, ubuntu
Domain
devops, infrastructure, operating-systems
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.