Skip to content

nixos/pam: add option to control how pam_unix hashes passwords#208603

Draft
obadz wants to merge 1 commit intoNixOS:masterfrom
obadz:pam-unix-auth-args
Draft

nixos/pam: add option to control how pam_unix hashes passwords#208603
obadz wants to merge 1 commit intoNixOS:masterfrom
obadz:pam-unix-auth-args

Conversation

@obadz
Copy link
Copy Markdown
Contributor

@obadz obadz commented Jan 1, 2023

Description of changes

Once your computer is stolen or physically accessed, you might not care about your login password being brute-forced. Unless it is also used to encrypt your key for ecryptfs/fscrypt/or other similar home directory encryption, then you really care.

This change makes the hashing algorithm used for password encoding configurable as a NixOS module option and suggests yescrypt for cases which need good brute-force resistance.

Things done
  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandbox = true set in nix.conf? (See Nix manual)
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 23.05 Release Notes (or backporting 22.11 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
    • (Release notes changes) Ran nixos/doc/manual/md-to-db.sh to update generated release notes
  • Fits CONTRIBUTING.md.

@github-actions github-actions bot added 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` labels Jan 1, 2023
@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. labels Jan 1, 2023
Copy link
Copy Markdown
Contributor

@aneeshusa aneeshusa left a comment

Choose a reason for hiding this comment

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

Tested on NixOS x86_64 and aarch64

@SuperSandro2000 SuperSandro2000 added the 12.approvals: 1 This PR was reviewed and approved by one person. label Jan 23, 2023
@mweinelt mweinelt marked this pull request as draft March 30, 2023 22:27

Consider switching to "yescrypt rounds=10" for
better resistance against brute force, especially if
your login password is used as a key for encrypted
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I expect the most common case to be that the password is used to unwrap decryption keys for the very root filesystem that contains the shadow file. In that case choosing a weak hash function does not help an attacker who wishes to decrypt the filesystem, and yet this docstring suggests otherwise. I'm not sure how to phrase it in a way that is both succinct and precise, sadly.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I believe you are talking of whole-disk-encryption. In that case, the decryption passphrase and login password are independent (and in general different, especially if there is more than one user).

ecryptfs & friends are generally used to encrypt user home directories, not /etc/shadow. For convenience the passphrase is encrypted using the login password of each user, so being able to brute force these is an issue.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What happens when I just change this setting on my system?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Would types.listOf types.str make more sense here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@SuperSandro2000, passwords in /etc/shadow will then be hashed using the methodology you selected.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This affects the default for e.g. passwd.

description = lib.mdDoc ''
Arguments to the pam_unix module.

Consider switching to "yescrypt rounds=10" for
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I could easily find sources that recommend yescrypt over sha512 on the internet but none of those mentioned that you should use 10 rounds. I would leave that out of the recommendation for now.

Copy link
Copy Markdown
Contributor Author

@obadz obadz Apr 4, 2023

Choose a reason for hiding this comment

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

The recommendation is specific to people protecting other on-disk secrets with the same password. For this usecase, the default number of rounds (5) isn't good enough. Here's one blog post that discusses this: https://medium.com/@slimm609/cost-based-password-hashing-b383bbb355df

};

security.pam.unixAuthArgs = mkOption {
default = "sha512";
Copy link
Copy Markdown
Member

@mweinelt mweinelt Apr 1, 2023

Choose a reason for hiding this comment

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

Suggested change
default = "sha512";
default = "yescrypt";

The actual default on unstable right now.

And somewhat plausible alternatives:

https://github.com/besser82/libxcrypt/blob/v4.4.33/lib/hashes.conf#L42-L47

Most everyone should migrate away from sha512crypt to a more recent KDF that includes additional hardness properties.

@nixos-discourse
Copy link
Copy Markdown

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/hashing-plain-text-password-directly-in-configuration-nix/2093/27

Copy link
Copy Markdown
Contributor

@aneeshusa aneeshusa left a comment

Choose a reason for hiding this comment

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

Been using this and it's great!

@wegank wegank added 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md 2.status: merge conflict This PR has merge conflicts with the target branch labels Mar 19, 2024
@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Mar 20, 2024
@wegank wegank added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jul 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2.status: merge conflict This PR has merge conflicts with the target branch 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 12.approvals: 1 This PR was reviewed and approved by one person.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants