Jira (PUP-8897) check_manage_home useradd provider needs to add -M on Debian

14 views
Skip to first unread message

Kevin Paulisse (JIRA)

unread,
May 29, 2018, 5:41:02 PM5/29/18
to puppe...@googlegroups.com
Kevin Paulisse created an issue
 
Puppet / Bug PUP-8897
check_manage_home useradd provider needs to add -M on Debian
Issue Type: Bug Bug
Assignee: Unassigned
Created: 2018/05/29 2:40 PM
Priority: Normal Normal
Reporter: Kevin Paulisse

Regarding the code here:

https://github.com/puppetlabs/puppet/blob/1c77bfb8961587ddf5399cd4a70fc908cac6a6ec/lib/puppet/provider/user/useradd.rb#L127-L135

There is an edge case that is missed. If force_local is true and manage_home is false, then "-M" should be added as a command line argument on Debian Jessie (and possibly others).

If this is not in place, a bug occurs as follows when running on Debian Jessie (and possibly others). First manually create `/home/bob` (like pam_mkhomedir might do) and then try to add `bob` with a resource like this, and it will fail:

user

{ 'bob':   force_local => true,   manage_home => false,   ... Other Params ... }
Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v7.7.1#77002-sha1:e75ca93)
Atlassian logo

Josh Cooper (JIRA)

unread,
Jun 4, 2018, 2:32:02 PM6/4/18
to puppe...@googlegroups.com
Josh Cooper updated an issue
Change By: Josh Cooper
Regarding the code here:

[https://github.com/puppetlabs/puppet/blob/1c77bfb8961587ddf5399cd4a70fc908cac6a6ec/lib/puppet/provider/user/useradd.rb#L127-L135]

There is an edge case that is missed. If force_local is true and manage_home is false, then "-M" should be added as a command line argument on Debian Jessie (and possibly others).

If this is not in place, a bug occurs as follows when running on Debian Jessie (and possibly others). First manually create `/home/bob` (like pam_mkhomedir might do) and then try to add `bob` with a resource like this, and it will fail:

{code:puppet}
user { 'bob':

  force_local => true,

  manage_home => false,

  ... Other Params ...

}

{code}

Josh Cooper (JIRA)

unread,
Jun 5, 2018, 5:56:03 PM6/5/18
to puppe...@googlegroups.com

Mihai Buzgau (Jira)

unread,
May 13, 2020, 4:33:02 AM5/13/20
to puppe...@googlegroups.com
Mihai Buzgau updated an issue
Change By: Mihai Buzgau
Story Points: 2
This message was sent by Atlassian Jira (v8.5.2#805002-sha1:a66f935)
Atlassian logo

Mihai Buzgau (Jira)

unread,
May 13, 2020, 4:33:03 AM5/13/20
to puppe...@googlegroups.com
Mihai Buzgau updated an issue
Change By: Mihai Buzgau
Sprint: PR NW - Triage 2020-05-27

Gabriel Nagy (Jira)

unread,
May 14, 2020, 7:33:02 AM5/14/20
to puppe...@googlegroups.com

Gabriel Nagy (Jira)

unread,
May 14, 2020, 11:14:03 AM5/14/20
to puppe...@googlegroups.com
Gabriel Nagy commented on Bug PUP-8897
 
Re: check_manage_home useradd provider needs to add -M on Debian

So, I did some digging on how shadow-utils and libuser implemented the -M flag, and on the assumptions that Puppet made regarding this flag.

First, the shadow library implemented the M flag (also known as -no-create-home) back in 2008, in this commit: https://github.com/shadow-maint/shadow/commit/b18d46e68ddf06869bc042297814369e02564c9. For reference, the first tag containing this commit was 4.1.3, which was released on April 15th 2009.

Second, RedHat has been maintaining their own patched version of shadow called shadow-utils. What they do is get the upstream shadow source, extensively patch it, then vendor it as shadow-utils, which is present on every RedHat-based OS starting with at least EL 5. Among the patches that RedHat applies is one that adds the same -M functionality as the upstream project did. However, RedHat has been doing this long before that. The oldest SRPM I could find was shadow-utils-4.0.17-12.el5.src.rpm, in which the related patch dates from July 2006.

As for the libuser package, the luseradd command seems to have had this option since the beginning of times (see https://pagure.io/libuser/blame/apps/luseradd.c?identifier=1dd9fb1dc8b421e8c1822ba514adabd5eda97f7f#_45, it's inside a suggestive ifdef but we're just going to ignore that for our own sanity). Based on this we can exclude libuser/forcelocal from the discussion, since they always had the flag.

Now, the last puzzle piece is the Puppet code itself:

def check_manage_home
  cmd = []
  if @resource.managehome? && (!@resource.forcelocal?)
    cmd << "-m"
  elsif (!@resource.managehome?) && Facter.value(:osfamily) == 'RedHat'
    cmd << "-M"
  end
  cmd
end

What we can conclude now is that the -M flag should be added in all cases where managehome is false, but the current code also adds an OS check. Going as far back as git can take us on this, we find the flag added in this commit: https://github.com/puppetlabs/puppet/commit/12452ee9ca294563f2e2724ff36f179004f9846f#diff-f5b9cc80dd02278d845d220721ac0217R32-R33 dated August 14th 2006. Back then it made sense that the only OSes that had -M were RedHat-based, since the upstream shadow project was almost 3 years away from releasing their own version of -M.This also matches what we saw in the RedHat SRPM.

The solution here would be to remove the OS check altogether, since most Linux distros have integrated the -M change from shadow. However, this provider is also being used by Solaris, which does not have this flag (obviously). Then there's SLES 11 which we still officially support, and which uses pwdutils instead of shadow for user information management, and which does not have the -M flag. SUSE switched to shadow beginning with SLES 12.

So... to make this as future-proof as possible, we should pass -M for everything except Solaris and SLES 11. I think.

Mihai Buzgau (Jira)

unread,
May 27, 2020, 4:02:03 AM5/27/20
to puppe...@googlegroups.com
Mihai Buzgau updated an issue
Change By: Mihai Buzgau
Sprint: NW - 2020-05-27 , NW - 2020-06-10

Ciprian Badescu (Jira)

unread,
Jul 2, 2020, 6:05:03 AM7/2/20
to puppe...@googlegroups.com

Claire Cadman (Jira)

unread,
Jul 8, 2020, 5:39:03 AM7/8/20
to puppe...@googlegroups.com
Claire Cadman updated an issue
Change By: Claire Cadman
Labels: doc_reviewed platform-os

Ciprian Badescu (Jira)

unread,
Jul 8, 2020, 9:09:04 AM7/8/20
to puppe...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages