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

implement fscrypt for PAM #101604

Closed
wants to merge 2 commits into from
Closed

implement fscrypt for PAM #101604

wants to merge 2 commits into from

Conversation

NeoTheFox
Copy link

Adresses #92352

Tested on a running NixOS 20.90

Copy link
Member

@andir andir left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution. Only had a brief look at this would like you to take a moment to reformat the changes in this PR.

You seem to be mixing tabs and spaces whereas we are (mostly) only using spaces in this repository. Usually these settings can be automatically applied by your editor (so you can keep on pressing TAB but still emit the correct number of spaces) by telling your to read editorconfig files. There are a lot of plugins available for most of the common editors: https://editorconfig.org/#download

Furthermore you can probably squash all of the changes into one commit that follows our commit style guide.
In your case this is likely something like this:

nixos/security/pam: support fscrypt

This PR adds support for doing XYZ using fscrypt in combination with PAM. This is desireable because reasons ….

nixos/modules/security/pam.nix Outdated Show resolved Hide resolved
@NeoTheFox NeoTheFox requested a review from andir October 25, 2020 15:11
This PR enables fscrypt pam module from fscrypt package. It allows the end users to use their passphrase to unlock encrypted directories on supported filesystems while logging in.
Copy link

@kamentomov kamentomov left a comment

Choose a reason for hiding this comment

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

@NeoTheFox I would like to add some changes to this Pull Request (already tested). Alternateively I can comment here about them. If you prefer the former could you please grant me access to your repo? You need to check the box in the pull request that says “Allow edits from maintainers.”

@NeoTheFox
Copy link
Author

The box was checked! I'm ok with any changes as long as fscrypt gets implemented

@kamentomov
Copy link

The box was checked! I'm ok with any changes as long as fscrypt gets implemented

I continue not to have rights. Could you please allow access to contributors in your fork so that I try to commit in NeoTheFox:master?

@primeos
Copy link
Member

primeos commented Feb 11, 2021

I continue not to have rights.

@kamentomov “Allow edits from maintainers.” won't work for you because you need commit access to Nixpkgs. I'd probably be better to suggest changes via the GH UI or link to your commit / post a patch so that @NeoTheFox could cherry-pick/apply it.

But in any case I'm not sure if this PR can get merged anytime soon (I'd recommend to find/ping some more appropriate reviewers).
The thing's I'm a bit concerned about:

@kamentomov
Copy link

@primeos Thanks for commenting. This looked so dead.

@kamentomov “Allow edits from maintainers.” won't work for you because you need commit access to Nixpkgs. I'd probably be better to suggest changes via the GH UI or link to your commit / post a patch so that @NeoTheFox could cherry-pick/apply it.

I pushed to @NeoTheFox's repo and that worked. @NeoTheFox thanks for graning me access.

But in any case I'm not sure if this PR can get merged anytime soon (I'd recommend to find/ping some more appropriate reviewers).

Could you please help us with this? I don't know who is qualified to review this.

The thing's I'm a bit concerned about:

Stragely the package is not experimental in other OSes. Nevertheless, experimental in the name seems good enough for me. I mean I don't think we shall do something additional except keeping the name as it is until they reach a non-experimental version. Please tell us if you have any furhter concerns?

The currently used approach to enable fscrypt seems OK to me. It fits with the rest in pam.nix.

  • I.e. we'd need to decide what's the best default for Nixpkgs.
  • I'm not sure if this belongs to nixos/modules/security/pam.nix (there's already a comment that "Most of these should be moved to specific modules.")

Moving to specific modules is a larger task so shouldn't we fit to the current approach until there is a volunteer to do a refactoring?

@NeoTheFox
Copy link
Author

I also think that this is not disruptive/overreaching. Since fscrypt-experimental exists in the repos and provides the required PAM module not having a way to enable it without resorting to hacks seems incomplete to me. After all this only adds a few lines of text to the config just to enable the functionality that's already there.

@primeos
Copy link
Member

primeos commented Feb 11, 2021

Could you please help us with this? I don't know who is qualified to review this.

In general I'd try to ping the users that contributed the most (or recently) to the file you're changing (listed here or via git shortlog -sne nixos/modules/security/pam.nix) and other active Nixpkgs reviewers (e.g. ping 1-4 potential reviewers and if there's no response withing a few days repeat that proces).
(Unfortunately the details are a bit more complicated... :o I guess we really should better document this process somewhere.)

I can try to review and help with the fscrypt stuff but I'm not comfortable merging this without another reviewer approving it.

Stragely the package is not experimental in other OSes.

Yeah, the name is pretty non-standard (this is my mistake because IIRC I packaged it pretty early and at that time there where some rough edges and I didn't want anyone to accidentally loose their data without knowing the risks).

The currently used approach to enable fscrypt seems OK to me. It fits with the rest in pam.nix.

Ok, I'll have a closer look at it.

Moving to specific modules is a larger task so shouldn't we fit to the current approach until there is a volunteer to do a refactoring?

This PR would of course only have to "move" the fscrypt part into a specific module (if that's possible without much effort). But maybe it's also fine in pam.nix.
(I'll try to give this a proper review but it might have to wait until tomorrow or even the weekend. Thanks for your fast response though!)

Copy link
Member

@primeos primeos left a comment

Choose a reason for hiding this comment

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

Sorry for the delay...
I added a few style nitpicks/improvements but overall the diff LGTM (though unfortunately I also realized how unfamiliar I'm with PAM and our NixOS module for it).

Edit: https://github.com/google/fscrypt/releases/tag/v0.3.0 is also relevant now.

@@ -207,6 +207,14 @@ let
'';
};

enableFscrypt = mkOption {
default = config.security.pam.enableFscrypt;
Copy link
Member

@primeos primeos Feb 17, 2021

Choose a reason for hiding this comment

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

It isn't clear to me why we need two options for this (e.g. config.security.pam.enableOTPW does the same but I don't immediately see an obvious reason for it / understand that part of the module).

Update: After looking at this a bit closer it seems like this part (pamOpts function, etc.) does the actual work to set/apply the config per PAM program/service and config.security.pam.enableFscrypt is used as a convenience option to easily enable it for all programs/services - in that case it might make sense to have both but security.pam.services.<name>.enableFscrypt is basically only useful to disable/blacklist it for some PAM programs/services or for "whitelisting" but then pkgs.fscrypt-experimental won't be installed (though it shouldn't be required anyway, only for the setup?)).

Update2: E.g. for eCryptfs only security.pam.enableEcryptfs is used, not the second per program/service option.
(And I'm also not sure if the NixOS approach of setting this for every PAM program/service by default makes that much sense - e.g. in the Arch Wiki it's only set for system-login and passwd: https://wiki.archlinux.org/index.php/Fscrypt#PAM_module)

Copy link
Member

Choose a reason for hiding this comment

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

Update3: It seems to me like the best approach to implement this would be default = false and set security.pam.services.$name.enableFscrypt = config.security.pam.enableFscrypt (the actual implementation would be a bit different) for the relevant services. But I'm not sure how realistic that approach currently is for NixOS.

Comment on lines +213 to +215
description = ''
Unlocks fscrypt-encrypted filesystems on login via PAM
'';
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
description = ''
Unlocks fscrypt-encrypted filesystems on login via PAM
'';
description = ''
Unlocks fscrypt-encrypted filesystems on login via PAM.
'';

Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should also link to e.g. https://github.com/google/fscrypt/blob/master/README.md via the description?

Comment on lines 439 to +442
${optionalString cfg.pamMount
"auth optional ${pkgs.pam_mount}/lib/security/pam_mount.so"}
${optionalString cfg.enableFscrypt
"auth optional ${pkgs.fscrypt-experimental}/lib/security/pam_fscrypt.so"}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
${optionalString cfg.pamMount
"auth optional ${pkgs.pam_mount}/lib/security/pam_mount.so"}
${optionalString cfg.enableFscrypt
"auth optional ${pkgs.fscrypt-experimental}/lib/security/pam_fscrypt.so"}
${optionalString cfg.enableFscrypt
"auth optional ${pkgs.fscrypt-experimental}/lib/security/pam_fscrypt.so"}
${optionalString cfg.pamMount
"auth optional ${pkgs.pam_mount}/lib/security/pam_mount.so"}

Nitpick but let's keep the order consistent with above.

@@ -622,6 +637,8 @@ in

security.pam.enableOTPW = mkEnableOption "the OTPW (one-time password) PAM module";

security.pam.enableFscrypt = mkEnableOption "fscrypt filesystem encryption PAM module";
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
security.pam.enableFscrypt = mkEnableOption "fscrypt filesystem encryption PAM module";
security.pam.enableFscrypt = mkEnableOption "the fscrypt filesystem encryption PAM module";

@@ -851,6 +868,7 @@ in
++ optional config.services.sssd.enable pkgs.sssd
++ optionals config.krb5.enable [pam_krb5 pam_ccreds]
++ optionals config.security.pam.enableOTPW [ pkgs.otpw ]
++ optionals config.security.pam.enableFscrypt [pkgs.fscrypt-experimental]
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
++ optionals config.security.pam.enableFscrypt [pkgs.fscrypt-experimental]
++ optionals config.security.pam.enableFscrypt [ pkgs.fscrypt-experimental ]

@@ -886,6 +904,7 @@ in
vlock = {};
xlock = {};
xscreensaver = {};
fscrypt = {};
Copy link
Member

@primeos primeos Feb 17, 2021

Choose a reason for hiding this comment

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

Is that part actually required / what is the use-case here?
Update: https://github.com/google/fscrypt#allowing-fscrypt-to-check-your-login-passphrase explains it and we seem to have a restrictive /etc/pam.d/other. But I'm starting to get the feeling that our NixOS module for PAM could need a rewrite and uses a bit of a lazy approach (setting options of every PAM module/service instead of only the ones that need it).

@@ -886,6 +904,7 @@ in
vlock = {};
xlock = {};
xscreensaver = {};
fscrypt = {};
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
fscrypt = {};
fscrypt.text = "auth required pam_unix.so";

Maybe this would be better (https://github.com/google/fscrypt#allowing-fscrypt-to-check-your-login-passphrase)?

@lorenz
Copy link
Contributor

lorenz commented Sep 23, 2021

@NeoTheFox Do you want to continue working on this? I'd like to see this merged and could take this over.

@NeoTheFox
Copy link
Author

@lorenz feel free to take over, it's been a long time and I don't have a system to test it on anymore

@stale
Copy link

stale bot commented Apr 16, 2022

I marked this as stale due to inactivity. → More info

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Apr 16, 2022
@mrvik
Copy link

mrvik commented Nov 3, 2022

I marked this as stale due to inactivity. → More info

Still important. Any updates on this?

@lorenz
Copy link
Contributor

lorenz commented Mar 13, 2023

This has been superseded by #199587 which has since been merged and is available as of 22.11 as security.pam.enableFscrypt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants