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

SHA_CRYPT_MIN_ROUNDS should be increased in login.defs #365

Closed
joubbi opened this issue Dec 29, 2020 · 5 comments · Fixed by #452
Closed

SHA_CRYPT_MIN_ROUNDS should be increased in login.defs #365

joubbi opened this issue Dec 29, 2020 · 5 comments · Fixed by #452

Comments

@joubbi
Copy link
Contributor

joubbi commented Dec 29, 2020

Running Lynis against a hardened CentOS 7 gives this:

  * Check PAM configuration, add rounds if applicable and expire passwords to encrypt with new values [AUTH-9229] 
      https://cisofy.com/lynis/controls/AUTH-9229/

  * Configure password hashing rounds in /etc/login.defs [AUTH-9230] 
      https://cisofy.com/lynis/controls/AUTH-9230/

The login.defs has the default values 5000 commented out.

The manual for login.defs states this:

    With a lot of rounds, it is more difficult to brute forcing the password. 
       But note also that more CPU resources will be needed to authenticate users.

       If not specified, the libc will choose the default number of
       rounds (5000), which is orders of magnitude too low for
       modern hardware.

Describe the solution you'd like
I think there should be a variable for the SHA_CRYPT_MIN_ROUNDSand SHA_CRYPT_MAX_ROUNDS with a default value of 10000 or more.
Also the same value should then be used for the rounds option in /etc/pam.d/system-auth.

Additional context
https://gitlab.tails.boum.org/tails/tails/-/issues/15053

@schurzi schurzi self-assigned this Jan 2, 2021
@schurzi
Copy link
Contributor

schurzi commented Jan 2, 2021

our Puppet implementation has this already specified, I think we will take the same value for Ansible

@schurzi
Copy link
Contributor

schurzi commented Jan 2, 2021

interesting bit from the man page:

           Note: This only affect the generation of group passwords. The
           generation of user passwords is done by PAM and subject to
           the PAM configuration. It is recommended to set this variable
           consistently with the PAM configuration.

so setting this in login.defs alone will not be enough, we also need to set this in the pam configuration. see: https://wiki.archlinux.org/index.php/SHA_password_hashes

rndmh3ro pushed a commit that referenced this issue Jun 28, 2021
Fixes #365

Signed-off-by: rndmh3ro <github@gumpri.ch>
rndmh3ro pushed a commit that referenced this issue Jun 28, 2021
Fixes #365

Signed-off-by: rndmh3ro <github@gumpri.ch>
rndmh3ro pushed a commit that referenced this issue Jun 28, 2021
Fixes #365

Signed-off-by: rndmh3ro <github@gumpri.ch>
@schurzi
Copy link
Contributor

schurzi commented Jun 28, 2021

In short, changing SHA_CRYPT_MIN_ROUNDS in login.defs is enough (assuming you're using sha256 or sha512).

I did check this some time ago and just did a re-check. from what I see in my configuration (CentOS7) the explicit declaration of rounds= as a parameter to pam_unix.so is required to change the behaviour.

Can you explain further, how you did your tests to establish correct behaviour?

a rough example of what I did:

  • change /etc/login.defs
  • passwd
  • check /etc/shadow (password hash should contain the number of rounds) -> this is not the case, so this is not working
  • change /etc/pam.d/system-auth to add rounds= as a parameter to pam_unix.so
  • passwd
  • check /etc/shadow -> correct behaviour

You can further verify the correct behaviour by specifying a really large number of rounds. You will notice, that updating passwords takes considerbaly longer with larger number of rounds.

@rndmh3ro
Copy link
Member

Okay, let's add this to pam, too, then.
For RHEL we already configure system-auth. Sincewe don't have any support yet for the other OS, I'll only add it to RHEL..

@schurzi
Copy link
Contributor

schurzi commented Jun 29, 2021

Thanks for re-checking, this would have hit my own configs.

Sure. Thank you for providing further information to us. :)

Generally speaking, we want to support a wide range of linux distributions, so we will stick to specifying rounds in pam config. But I'm really interested in seeing how this evolves and when we can rely on login.defs alone.

rndmh3ro added a commit that referenced this issue Jun 30, 2021
* make sha rounds configurable and increase no of rounds

Fixes #365

Signed-off-by: rndmh3ro <github@gumpri.ch>

* Prettified Code!

* make password rounds configurable in pam system-auth

Signed-off-by: rndmh3ro <github@gumpri.ch>

* change wording of sha rounds documentation

Co-authored-by: schurzi <Martin.Schurz@t-systems.com>

Co-authored-by: schurzi <Martin.Schurz@t-systems.com>
divialth pushed a commit to divialth/ansible-collection-hardening that referenced this issue Aug 3, 2022
* make sha rounds configurable and increase no of rounds

Fixes dev-sec#365

Signed-off-by: rndmh3ro <github@gumpri.ch>

* Prettified Code!

* make password rounds configurable in pam system-auth

Signed-off-by: rndmh3ro <github@gumpri.ch>

* change wording of sha rounds documentation

Co-authored-by: schurzi <Martin.Schurz@t-systems.com>

Co-authored-by: schurzi <Martin.Schurz@t-systems.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants