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

pam module: enable pam_keyinit.so by default #30333

Closed
wants to merge 1 commit into from

Conversation

obadz
Copy link
Contributor

@obadz obadz commented Oct 11, 2017

Closes #27574

Motivation for this change

Fixes ecryptfs regression (from 17.03 to 17.09) as explained in #27574 (comment)

I'm unfortunately not entirely sure what other side-effects this might have, though this thread seems to say that enabling pam_keyinit is "recommended" anyway.

Hopefully someone more competent can opine.

From pam_keyinit's man page:

The pam_keyinit PAM module ensures that the invoking process has a session keyring other than the user default session keyring.

The session component of the module checks to see if the process's session keyring is the user default, and, if it is, creates a new anonymous session keyring with which to replace it.

If a new session keyring is created, it will install a link to the user common keyring in the session keyring so that keys common to the user will be automatically accessible through it.

The session keyring of the invoking process will thenceforth be inherited by all its children unless they override it.

This module is intended primarily for use by login processes. Be aware that after the session keyring has been replaced, the old session keyring and the keys it contains will no longer be accessible.

This module should not, generally, be invoked by programs like su, since it is usually desirable for the key set to percolate through to the alternate context. The keys have their own permissions system to manage this.

AFAIK we don't have a separate pam.nix for su and sudo so can't carve them out.

This module should be included as early as possible in a PAM configuration, so that other PAM modules can attach tokens to the keyring.

force

  • Causes the session keyring of the invoking process to be replaced unconditionally.

(Without force, regression wouldn't go away)

revoke

  • Causes the session keyring of the invoking process to be revoked when the invoking process exits if the session keyring was created for this process in the first place.

(Wasn't sure about this one but it sounded conservative so I put it in)

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option build-use-sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Fits CONTRIBUTING.md.

@obadz
Copy link
Contributor Author

obadz commented Oct 12, 2017

cc @edolstra @grahamc @ttuegel @globin

@obadz
Copy link
Contributor Author

obadz commented Oct 19, 2017

Ping.

@obadz obadz requested a review from edolstra October 19, 2017 17:00
@ttuegel
Copy link
Member

ttuegel commented Oct 20, 2017

I admit I don't totally understand what this does, but if it's upstream-recommended and it fixes ecryptfs, then I'm all for it! 😄

@obadz
Copy link
Contributor Author

obadz commented Oct 30, 2017

We're not in a great place as this is a regression in 17.09. When we get this approved I think we should keep it in master for at least 2 weeks before cherry-picking it in 17.09 to make sure there are no side-effect to the pam change. The saving grace is this probably affects very few people…

@Chiiruno
Copy link
Contributor

Any updates?

@fpletz
Copy link
Member

fpletz commented Jan 29, 2018

Debian and Ubuntu only have it in a few PAM configs:

$ grep keyinit /etc/pam.d/ -R
/etc/pam.d/runuser:session		optional	pam_keyinit.so revoke
/etc/pam.d/runuser-l:session		optional	pam_keyinit.so force revoke
/etc/pam.d/sshd:session    optional     pam_keyinit.so force revoke

This can also be done with our NixOS PAM module.

Can somebody test that this is enough to make ecryptfs work?

@obadz
Copy link
Contributor Author

obadz commented Jan 30, 2018

@fpletz, well I'm biased but I've been running with it since I opened the PR & it's worked for me..

@fpletz fpletz added this to the 17.09 milestone Jan 30, 2018
@fpletz fpletz added 6.topic: nixos 0.kind: regression Something that worked before working no longer labels Jan 30, 2018
@fpletz
Copy link
Member

fpletz commented Jan 30, 2018

Okay. I'll try to give this a spin soon. We'll also have to find out why our ecryptfs test doesn't catch this.

@obadz
Copy link
Contributor Author

obadz commented Jan 31, 2018

I vaguely recall trying to extend the test to cover the failing usecases but it went nowhere (and now don't recall much of the subtleties). Mostly I think it had to do with mounting encrypted directories at other times than login.

@obadz
Copy link
Contributor Author

obadz commented Feb 10, 2018

(I've rebased this on fresh master)

@obadz
Copy link
Contributor Author

obadz commented Feb 18, 2018

@fpletz, shall we merge this?

@obadz
Copy link
Contributor Author

obadz commented Feb 18, 2018

Looks like this fixes other issues: #32279 (comment)

@obadz
Copy link
Contributor Author

obadz commented Feb 18, 2018

So @eternaleye, based on #32279 (comment), you don't think we should merge it?

@Chiiruno
Copy link
Contributor

Chiiruno commented Mar 2, 2018

I would like to see this merged, bcachefs with it's own encryption is very alluring.

@eternaleye
Copy link

@obadz Sorry I took so long to reply - that is correct, I think this should not be merged.

The issue is that this exposes shared, mutable, security-relevant state (the keyring) to all PAM sessions.

In addition, the issue with ecryptfs and bcachefs was fixed upstream; as a result, the next release of systemd (v238) will make this workaround superfluous.

@Chiiruno
Copy link
Contributor

This should be fixed now by #37647 and 361bd59...2d2ab94 which upgraded systemd to 238.

@Chiiruno
Copy link
Contributor

My comment on the bottom of #32279 may be relevant here.

@fpletz
Copy link
Member

fpletz commented Mar 28, 2018

Could one of you please try a recent 18.03 beta release with the systemd bump #36918? It's supposed to also fix this issue.

@fpletz fpletz closed this Mar 28, 2018
@Chiiruno
Copy link
Contributor

@fpletz That's what I did. See #32279
Unfortunately, for some strange reason the same problem exists. Have there been any other changes since #36918 that I should attempt a new try with?

@fpletz
Copy link
Member

fpletz commented Mar 28, 2018

Thanks! There was a bump to systemd to use the stable tree but I haven't checked if fixes for this issue went in there.

@Chiiruno
Copy link
Contributor

I'll try again with that commit to make sure it's just not user error, we'll see if this is still the case.

@Chiiruno
Copy link
Contributor

Chiiruno commented Mar 28, 2018

@fpletz
I can confirm that the same problem is occurring. It is having trouble requesting the key, and then can't allocate memory. I tested on a staging-18.03 USB drive.

fpletz referenced this pull request Apr 1, 2018
This fixes a bug with changed qemu network interface names and also generally
should be preferred to using a release tag.
@ttuegel
Copy link
Member

ttuegel commented Apr 24, 2018

I am still experiencing #27574 after the systemd-238 update.

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

6 participants