salt icon indicating copy to clipboard operation
salt copied to clipboard

State user.present will fail to create home if user exists and homedir doesn't

Open calvinhp opened this issue 11 years ago • 34 comments

Ran into this today, it appears that in one of our installs, the user got created at some point, but their home dir didn't. When I ran the highstate today, it errored out with the following: local:

ID: xxxxxxx
Function: user.present
Result: False
Comment: These values could not be changed: {'homeDoesNotExist': '/home/xxxxxxx'}
Started: 11:30:43.057275
Duration: 6.189 ms
Changes:

It looks like here the change doesn't get made, but reports it back as a change that is remaining.

https://github.com/saltstack/salt/blob/2014.7/salt/states/user.py#L110

Should the user.add module be called to create the home dir or should user.chhome be modified to create a homedir if one doesn't exist.

calvinhp avatar Dec 09 '14 16:12 calvinhp

Thanks for the report @calvinhp! Can you post the output of salt --versions-report as well as let us know what OS and OS version you're running?

rallytime avatar Dec 09 '14 17:12 rallytime

The Master:

salt01% salt --versions-report
       Salt: 2014.7.0
       Python: 2.7.8 (default, Dec  3 2014, 04:17:02)
       Jinja2: 2.7.3
       M2Crypto: 0.22
       msgpack-python: 0.4.2
       msgpack-pure: Not Installed
       pycrypto: 2.6.1
       libnacl: Not Installed
      PyYAML: 3.11
      ioflo: Not Installed
      PyZMQ: 14.3.1
      RAET: Not Installed
      ZMQ: 4.0.4
      Mako: Not Installed

The Minion:

 $ salt --versions-report
       Salt: 2014.7.0
       Python: 2.6.6 (r266:84292, Nov 21 2013, 10:50:32)
       Jinja2: 2.2.1
       M2Crypto: 0.20.2
       msgpack-python: 0.1.13
       msgpack-pure: Not Installed
       pycrypto: 2.0.1
       libnacl: Not Installed
       PyYAML: 3.10
       ioflo: Not Installed
       PyZMQ: 14.3.1
       RAET: Not Installed
       ZMQ: 3.2.4
       Mako: Not Installed

calvinhp avatar Dec 09 '14 19:12 calvinhp

Thanks! We'll get this fixed up.

rallytime avatar Dec 09 '14 19:12 rallytime

@calvinhp Can you post your user state?

salt.modules.user.chhome already creates the home directory if one doesn't exist when persist is True as it specified -m flag which according to the documentation says If the -m option is given, the contents of the current home directory will be moved to the new home directory, which is created if it does not already exist. There is something else going on here. The logic seems to be too complicated.

nmadhok avatar Dec 16 '14 10:12 nmadhok

Here is an example of a user state in our salt:

    xxxxxxx-user:
      user.present:
        - name: xxxxxxx
        - fullname: xxxxxxx xxxxxxx
        - uid: 11976
        - gid_from_name: True
        - home: /home/xxxxxxx
        - shell: /bin/zsh
        - groups:
          - staff
          {% if grains['os_family'] == 'Debian' -%}
          - sudo
          {% else %}
          - wheel
          {% endif %}
        - require:
          - pkg: zsh

calvinhp avatar Dec 17 '14 16:12 calvinhp

Some additional analysis of this issue in #19250

djs52 avatar Dec 24 '14 17:12 djs52

This is still broken in 2014.7.1. It seems odd this is closed in favor of #19250, when #19250 is marked as a duplicate of this bug! This issue still exists:

          ID: salt-minion-user-g2prefix
    Function: user.present
        Name: g2prefix
      Result: False
     Comment: These values could not be changed: {'homeDoesNotExist': '/home/g2prefix'}
     Started: 18:37:16.610962
    Duration: 307.768 ms
     Changes:   

state:

salt-minion-user-g2prefix:
  user.present:
    - name: g2prefix
    - fullname: Salt Owner Account
    - password: {redacted}
    - shell: /bin/bash
    - home: /home/g2prefix
    - uid: 4004
    - gid: 4004
    - require:
      - group: salt-minion-group-g2prefix

smithjm avatar Feb 04 '15 17:02 smithjm

@smithjm Thanks for the update. The bug referenced above was indeed closed in favor of this one as it was a duplicate, but this issue is still open. It's a bit confusing with "Closed" label right above your comment, so I can see why this issue would appear closed.

We haven't been abel to get a fix in for this yet, but we will get to it as soon as we can. The extra information and state you provided is definitely helpful!

@nmadhok Were you going to take a crack at this one? No worries if not, just curious.

rallytime avatar Feb 04 '15 18:02 rallytime

I got the same error

salt-call --versions-report
           Salt: 2014.7.1
         Python: 2.7.3 (default, Dec 18 2014, 19:10:20)
         Jinja2: 2.6
       M2Crypto: 0.21.1
 msgpack-python: 0.1.10
   msgpack-pure: Not Installed
       pycrypto: 2.4.1
        libnacl: Not Installed
         PyYAML: 3.10
          ioflo: Not Installed
          PyZMQ: 13.0.0
           RAET: Not Installed
            ZMQ: 3.2.2
           Mako: Not Installed

        ID: web
    Function: user.present
        Name: www-data
      Result: False
     Comment: These values could not be changed: {'homeDoesNotExist': '/var/www'}
     Started: 05:46:14.205666
    Duration: 17.365 ms
     Changes:
              ----------
              shell:
                  /usr/sbin/nologin

hvnsweeting avatar Feb 05 '15 10:02 hvnsweeting

@rallytime I was going to but haven't gotten the time yet. I will look at the earliest. Last time I looked, I remember the logic needed a drastic change.

nmadhok avatar Feb 05 '15 19:02 nmadhok

Confirmed. I just ran into this exact same issue with:

# salt-call --versions
           Salt: 2014.7.2
         Python: 2.7.5 (default, Feb 11 2014, 07:46:25)
         Jinja2: 2.7.2
       M2Crypto: 0.21.1
 msgpack-python: 0.4.2
   msgpack-pure: Not Installed
       pycrypto: 2.6.1
        libnacl: Not Installed
         PyYAML: 3.10
          ioflo: Not Installed
          PyZMQ: 14.3.1
           RAET: Not Installed
            ZMQ: 4.0.4
           Mako: Not Installed

SEJeff avatar Mar 30 '15 15:03 SEJeff

just throwing in a "me too"

# salt-call --versions-report
           Salt: 2014.7.2
         Python: 2.6.6 (r266:84292, Jan 22 2014, 01:49:05)
         Jinja2: unknown
       M2Crypto: 0.20.2
 msgpack-python: 0.1.13
   msgpack-pure: Not Installed
       pycrypto: 2.0.1
        libnacl: Not Installed
         PyYAML: 3.10
          ioflo: Not Installed
          PyZMQ: 2.2.0.1
           RAET: Not Installed
            ZMQ: 3.2.4
           Mako: Not Installed

gmcwhistler avatar Apr 02 '15 04:04 gmcwhistler

this also hit 2015.2

 salt --versions-report
           Salt: 2015.2.0rc2
         Python: 2.7.6 (default, Mar 22 2014, 22:59:56)
         Jinja2: 2.7.2
       M2Crypto: 0.21.1
 msgpack-python: 0.3.0
   msgpack-pure: Not Installed
       pycrypto: 2.6.1
        libnacl: Not Installed
         PyYAML: 3.10
          ioflo: Not Installed
          PyZMQ: 14.0.1
           RAET: Not Installed
            ZMQ: 4.0.4
           Mako: 0.9.1

hvnsweeting avatar Apr 03 '15 02:04 hvnsweeting

Is this fixed in 2015.5? I still have this error

           Salt: 2015.5.0-128-gca7729d
         Python: 2.7.9 (default, Jan  7 2015, 11:50:42)
         Jinja2: 2.7.3
       M2Crypto: 0.22
 msgpack-python: 0.4.6
   msgpack-pure: 0.1.3
       pycrypto: 2.6.1
        libnacl: Not Installed
         PyYAML: 3.11
          ioflo: 1.2.1
          PyZMQ: 14.6.0
           RAET: Not Installed
            ZMQ: 4.0.5
           Mako: 1.0.1
----------
          ID: couchdb_user
    Function: user.present
        Name: couchdb
      Result: False
     Comment: These values could not be changed: {'home': '/var/lib/couchdb'}
     Started: 14:29:04.011125
    Duration: 23.977 ms
     Changes:
couchdb_user:
  user.present:
    - name: {{couchdb.user}}
    - fullname: CouchDB Admin
    - createhome: False
    - home: /var/lib/couchdb
    - shell: /bin/bash
    - empty_password: True
    - system: True

h0jeZvgoxFepBQ2C avatar May 20 '15 18:05 h0jeZvgoxFepBQ2C

@lichtamberg is there any error log when you run that? anw, this is not exactly the origin error of this issue:

Comment: These values could not be changed: {'homeDoesNotExist': '/home/xxxxxxx'}

New one:

Comment: These values could not be changed: {'home': '/var/lib/couchdb'}

hvnsweeting avatar May 21 '15 03:05 hvnsweeting

+1

                  Salt: 2015.5.0
                Python: 2.7.3 (default, Mar 13 2014, 11:03:55)
                Jinja2: 2.6
              M2Crypto: 0.21.1
        msgpack-python: 0.1.10
          msgpack-pure: Not Installed
              pycrypto: 2.6
               libnacl: Not Installed
                PyYAML: 3.10
                 ioflo: Not Installed
                 PyZMQ: 13.1.0
                  RAET: Not Installed
                   ZMQ: 3.2.3
                  Mako: 0.7.0
 Debian source package: 2015.5.0+ds-1~bpo70+1
         ID: www-data
    Function: user.present
      Result: False
     Comment: These values could not be changed: {'home': '/home/www-data'}
     Started: 18:36:32.334948
    Duration: 25.436 ms
     Changes:   

amontalban avatar Jul 02 '15 18:07 amontalban

I've got this too.

                  Salt: 2014.7.5
                Python: 2.7.3 (default, Dec 18 2014, 19:10:20)
                Jinja2: 2.6
              M2Crypto: 0.21.1
        msgpack-python: 0.1.10
          msgpack-pure: Not Installed
              pycrypto: 2.4.1
               libnacl: Not Installed
                PyYAML: 3.10
                 ioflo: Not Installed
                 PyZMQ: 14.0.1
                  RAET: Not Installed
                   ZMQ: 4.0.4
                  Mako: Not Installed
 Debian source package: 2014.7.5+ds-1precise1

DaveQB avatar Aug 24 '15 07:08 DaveQB

@DaveQB sure, because the fix is not on that version:

https://github.com/saltstack/salt/commit/c4e95b9f487671ee09252c966de6dca3653e7999

You need 2014.7.6+

hvnsweeting avatar Aug 24 '15 07:08 hvnsweeting

@hvnsweeting Oh bugger.

Thanks.

DaveQB avatar Aug 24 '15 07:08 DaveQB

@DaveQB if you cannot upgrade to higher version for any reason, you can add this module to your states/_states : https://github.com/bclermont/states/blob/master/_states/user.py

It just ports the fix back to use with 2014.7.5

hvnsweeting avatar Aug 24 '15 07:08 hvnsweeting