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

nixos-generate-config: encrypt swap partitions by default #18443

Closed
wants to merge 1 commit into from

Conversation

obadz
Copy link
Contributor

@obadz obadz commented Sep 8, 2016

Motivation for this change

Modify nixos-generate-config so that swap partitions are encrypted by defaults, and use a UUID/label insensitive addressing.

Swap Encryption is really the sensible default given the amount of sensitive information that RAM can contain. See also #8277.

cc @edolstra

Things done

Tested with:

nix-build '<nixpkgs/nixos>' -A config.system.build.nixos-generate-config &&
  ./result/bin/nixos-generate-config --dir .
  • Tested using sandboxing
    (nix.useSandbox on NixOS,
    or option build-use-sandbox in nix.conf
    on non-NixOS)
  • Built on platform(s)
    • NixOS
    • OS X
    • Linux
  • 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.

@mention-bot
Copy link

@obadz, thanks for your PR! By analyzing the annotation information on this pull request, we identified @edolstra, @aszlig and @wkennington to be potential reviewers

@aszlig
Copy link
Member

aszlig commented Sep 8, 2016

👎 on this, because first of all this breaks hibernation and second, I'd only make it default if we have sufficient NixOS VM test(s) for that. For example which configuration gets generated if you already use LVM or dmcrypt? For these configurations you usually have (or at least should have) an encrypted swap device that's using either a derived or a different keyslot for the swap device which you can use to unlock the machine after hibernation.

@obadz
Copy link
Contributor Author

obadz commented Sep 8, 2016

Preserving the hibernation feature for the (I suspect) small subset of users that use it would be nice and I'd certainly be happy to see improvements that make this work (I don't use it myself so can't really work on that).

However, I don't think it should come in the way of what I believe is an important security improvement.

Until the feature that enables hibernation users to use encrypted swap spaces, they'll have to decide whether they'd rather take the security risk or if they need the feature more in which case they can toggle randomEncryption to false.

@aszlig
Copy link
Member

aszlig commented Sep 8, 2016

@obadz: Well, we should have an option in the template configuration.nix then for users to be aware of this and also turn it off.

@obadz
Copy link
Contributor Author

obadz commented Sep 8, 2016

@aszlig: what would this option do?

@aszlig
Copy link
Member

aszlig commented Sep 8, 2016

Either override the randomEncryption option with false or note users to set their passphrases if they want hibernation.

@obadz
Copy link
Contributor Author

obadz commented Sep 8, 2016

I don't really like the option that overrides randonEncryption to false, but if there is a way to disable the hibernation feature, we could have an assertion that validates that either hibernation is disabled or swaps aren't encrypted?

@ocharles
Copy link
Contributor

ocharles commented Mar 17, 2017

It sounds like this change is too contentious to be a pull request at the moment, perhaps an RFC should be opened first?

@primeos
Copy link
Member

primeos commented Apr 2, 2017

(triage) Should an RFC be opened for this? I also think that this would be a good idea but I'm not sure if it would be worth the extra effort. But if we can fix all/most of the issues I don't think we would need an RFC.

Swap Encryption is really the sensible default given the amount of sensitive information that RAM can contain.

Do we have any sources on this? I don't really think that this is wrong but IIRC programs like OpenSSH, GnuPG, ... should prevent sensitive information (like keys or passwords) from getting swapped so that it actually shouldn't be that bad (but I might be very wrong about this...).

Edit: Some sources:
https://linux.die.net/man/2/mlock

mlock() and mlockall() respectively lock part or all of the calling process's virtual address space into RAM, preventing that memory from being paged to the swap area.

https://www.gnupg.org/faq/gnupg-faq.html

GnuPG tries to lock memory so that no other process can see it and so that the memory will not be written to swap.

But of course this doesn't mean that all applications that should use this are actually using it...

Also I'd say that this only makes sense with at least an encrypted home partition and on a fully encrypted system (e.g. via LVM) the swap should already be encrypted and we would loose performance by encrypting it twice (imho we should at least put a note inside the manual that the swap shouldn't be on an already encrypted LVM-VG/PV).

👎 on this, because first of all this breaks hibernation

IMHO we should solve that as well, at least by placing a comment in the config file (and in the install part manual).

I'd only make it default if we have sufficient NixOS VM test(s) for that.

👍 - I already experienced two problems with encryption (due to advanced use-cases tho). It might easily break some setups in unexpected ways.

Another possible problem could be the performance on old/low-end systems or systems with very fast SSDs (on my system the latter shouldn't be a problem (theoretically) but it could be on other systems).

Edit: I also don't know if we should allow discards/TRIM or not (and if TRIM makes sense for a swap). AFAIK it shouldn't have a huge security impact and therefore it usually shouldn't be a problem. I guess the best source for this is a blog post from the main cryptsetup developer Milan Broz: TRIM & dm-crypt ... problems?

Edit (forgot to mention...): Overall I really like this idea but I think we should further discuss the actual implementation. E.g., if possible, it might be a good idea to offer an option for nixos-generate-config to disable encryption. And imho we should better document encryption inside the nixos manual (can be done after this PR).

@arianvp
Copy link
Member

arianvp commented Mar 5, 2019

(triage) since this hasnt moved in over 2 years, shall we close this ?

@c0bw3b
Copy link
Contributor

c0bw3b commented Apr 20, 2019

No consensus to make swap encryption the default.

@c0bw3b c0bw3b closed this Apr 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants