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

Benchmark fails: 10.5 Lock Inactive User Accounts #118

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Benchmark fails: 10.5 Lock Inactive User Accounts #118

wants to merge 2 commits into from

Conversation

cpliakas
Copy link
Contributor

@cpliakas cpliakas commented Sep 7, 2016

The changes for the 10.5 don't appear to be sticking. The CIS-CAT Benchmark Assessment Tool suggests using the useradd -D | grep INACTIVE command to check the default value, which always returns -1 despite the changes written to /etc/login.defs. The tool also suggests running the useradd -D -f 35 command to change the setting.

I am not 100% psyched about this PR, but it does result in a passing benchmark. Posting the issue to start the discussion.

@@ -98,22 +98,18 @@
- section10.4

- name: 10.5.1 Lock Inactive User Accounts (check) (Scored)
command: grep INACTIVE /etc/login.defs
command: bash -c "useradd -D | grep -oP '(?<=^INACTIVE=)-?[0-9]+'"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is bash -c required here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. When I just did useradd -D | grep -oP '(?<=^INACTIVE=)-?[0-9]+', for some reason it said that -P was not a valid option for useradd. I tried various methods of escaping the pipe and other things, but this is the only thing that worked.

I got the technique from http://stackoverflow.com/a/24685924. Seems like the shell module could also be a workaround.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. In that case I think using the shell module would be cleaner, since we end up using a shell anyway. @awailly What do you think?

Copy link
Owner

@awailly awailly Sep 8, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the command module will execute the process, and using the shell you will wrap the string with bash as you did. So yes, using the shell module is better here to keep the code simple.

@pchaigno
Copy link
Collaborator

pchaigno commented Sep 8, 2016

Thanks for the pull request!

The Travis build is failing because, when it does a second playbook run, it finds an incorrect INACTIVE value again. It's as if 10.5.2 wasn't applied. Does it work correctly on your end?

@pchaigno pchaigno added the bug label Sep 8, 2016
@cpliakas
Copy link
Contributor Author

cpliakas commented Sep 8, 2016

The assessment tool is reporting that it is working.

screen shot 2016-09-08 at 11 44 11 am

Digging in a little deeper, after running the role with the pull request applied, I get the following output when running the following commands as a normal user:

$ useradd -D | grep INACTIVE
INACTIVE=-1
$ sudo useradd -D | grep INACTIVE
INACTIVE=35

So, running useradd via sudo seems to pick up the value. Also, in the useradd man pages, the instructions for the -f option are below:

       -f, --inactive INACTIVE
           The number of days after a password expires until the account is permanently disabled. A value of 0 disables the account as soon as the password has expired, and a value of
           -1 disables the feature.

           If not specified, useradd will use the default inactivity period specified by the INACTIVE variable in /etc/default/useradd, or -1 by default.

Looking at the /etc/default/useradd file, I do see INACTIVE=35. This is the info I have, so whether the change I posted is valid or not, it looks like the /etc/login.defs file might not the right place to make this change regardless.

@awailly
Copy link
Owner

awailly commented Sep 9, 2016

I haven't tested, but will the user be locked if he was not created using useradd, like adduser? I feel like this solution is dependent on useradd, while login.defs was systemwide.

@awailly awailly self-assigned this Sep 11, 2016
@awailly awailly added this to the v1.1 milestone Sep 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants