-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Add usergroup support to user.present #48704
Add usergroup support to user.present #48704
Conversation
salt/modules/useradd.py
Outdated
@@ -187,6 +192,8 @@ def add(name, | |||
except OSError: | |||
# /etc/usermgmt.conf not present: defaults will be used | |||
pass | |||
if usergroup == False: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the default for 'usergroup' is None. Should you compare this to None too? I'm thinking to change this to: if not usergroup:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are three possibilities - we explicitly set usergroup
to False
to trigger -N
to require no user group be created, we set it to True
to trigger -U
to require a user group to be created, or don't touch it at all which will go with the OS defaults - which differs depending on the distribution or user preferences.
If you instead go with if not usergroup
, you'll be force overriding the OS defaults (or overriding whatever the user configured the OS to do), so I imagine most people won't be too happy about that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, okay. So it's intended to use the OS defaults unless specified.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we then document this so that a user knows when to set this to False
and what behavior that will produce?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rares-pop Correct. I don't see any reason to change things the user didn't request. @cachedout Yep, fair call. Will do.
f986ed7
to
e8f83ab
Compare
That has now been updated. I also rebased onto the latest develop branch. |
@boltronics Can you fix these lint errors? https://jenkinsci.saltstack.com/job/pr-lint/job/PR-48704/4/warnings52Result/ |
e8f83ab
to
9d013f4
Compare
@rallytime Hopefully the lint error is sorted now. Thanks for pointing that out. |
@boltronics Sure thing. The lint check is happy now, but now there are some related test failures with the user states and the git pillar tests: https://jenkinsci.saltstack.com/job/pr-kitchen-ubuntu1604-py3/job/PR-48704/5/#showFailuresLink Can you take a look? |
No worries, can do. |
Sorry for the hold-up. I've been busy, but will try to get to this this week. |
Hi @boltronics. Just checking in with you. :) |
Sorry for the delay. I haven't forgotten, just taking care of higher priorities first. I hope to get to this soon. |
@boltronics Many thanks! |
Hi @boltronics. Just checking back in with you. :) Any updates here? |
4fdf0f4
to
35260bd
Compare
Thanks @cachedout. I'm actually trying to look into this now (sorry again for the wait), but can't even push to my repo due to some GitHub issues it seems. My commits just keep disappearing... |
1 similar comment
Thanks @cachedout. I'm actually trying to look into this now (sorry again for the wait), but can't even push to my repo due to some GitHub issues it seems. My commits just keep disappearing... |
Hi @cachedout. Hopefully GitHub is working this time... I think I'm all good for fixing the tests (or I will be when GH is fixed so my pushed code doesn't go to
Of course, Apple, SuSE, etc. could change their mind about their default behaviour at any point which would break the test. If we set
but I'm not sure I see a useful test here. We're only validating that we guessed correctly what the OS might do when the user didn't request anything specific, as opposed to testing the Please let me know your thoughts. In the meantime, I'll proceed with this proposal for this PR. |
Hi @cachedout,
I'm trying to update my PR, but can't because GitHub is
completely broken right now. Unfortunately posting messages directly
to the PR is also broken, so I'm attempting one last time, this time
via e-mail.
This is my repo:
https://github.com/boltronics/salt/commits/develop-user_present-usergroup
Please let the tests run on it when you can. I think it fixes the
issues raised. Thanks.
|
85db08c
to
b7cc810
Compare
I have just rebased against the current develop HEAD, and looks like Jenkins triggered successfully now. ...and it also looks like all the comments came through from yesterday that reportedly failed to submit. 😄 |
b7cc810
to
52483af
Compare
@boltronics Sorry for the delay here. I think we're about ready to go with this. If you can resolve the merge conflict that snuck in then we'll get this merged. |
Fix saltstack#48640: user.present group regression if gid_from_name
The usergroup argument isn't available on all operating systems and is for the most part a convenience argument.
Here we replace test_user_present_gid_from_name_default (which tried to guess what different operating systems might do) with tests specifically for when usergroup is set to either True or False. Undefined behaviour (usergroup=None) is deliberately left untested since the results are not always predictable and aren't terribly useful.
52483af
to
b1fa539
Compare
@cachedout Done. |
I also just added the docstring commit since that's dealing with the same function. |
Thanks @boltronics ! This looks great to me. And thanks for following the PR for so long! |
since Salt version 3001 gid_from_name is no longer an valid argument see: saltstack/salt#48704 and: https://git.darmstadt.ccc.de/ffda/infra/salt/-/merge_requests/83
since Salt version 3001 gid_from_name is no longer an valid argument see: saltstack/salt#48704 and: https://git.darmstadt.ccc.de/ffda/infra/salt/-/merge_requests/83
What does this PR do?
Replaces the seemingly redundant
gid_from_name
argument fromuser.present
and replaces it with ausergroup
argument that has the effect of adding the--user-group
argument to theuseradd
command on GNU/Linux hosts.I whitelisted it to GNU/Linux for now since I don't know which other operating systems support the
-U
/--user-group
argument.I tested it on an OpenSUSE 42.3 and Debian Stretch by creating a basic state sls:
On both hosts the intended behaviour was observed.
What issues does this PR fix or reference?
#48640
Previous Behavior
gid_from_name
has been removed. AFAICT this command no longer has any practical benefit - please correct me if I'm overlooking something. The behaviour it intended to provide can be simulated just as easily by:(where we want a
test
group to match a test user). This is much easier to read and understand. It's also clearer that the group will not be automatically created in this case.Regardless of the
gid_from_name
option, the group will not be created since 2017.7.5 due to the regression referenced. This PR does not revert that regression (which is actually a pain to deal with on a stable release and IMO really should be fixed), but I believe this is a better approach for the long-term.New Behavior
We now mimic the existing
--user-group
option behaviour of theuseradd
command which I believe is closer to user expectations - even for users of distributions such as SuSE that don't typically use this.If
usergroup: True
is set in the user state sls file, the-U
argument will be passed to theuseradd
command causing the group with the same name as the user name to be created. Ifusergroup: False
is set, the-N
/--no-user-group
argument is added instead. If left undefined, the defaults that the distribution or user typically defines in/etc/default/useradd
and/etc/login.defs
are used as usual.Tests written?
No. There are no existing tests for
gid_from_name
either. I'm not sure what the best way to do this would be, but I suspect it would involve having the test inspect the constructedcmd
list in theuseradd.add
function to check for the presence of-U
instead, as opposed to just inspecting a return value of a mocked command.Commits signed with GPG?
Yes