0

I would like to setup an as simple as possible encryption at rest solution for a remote dedicated server. The host I am using will provide physical disks and there is no off the shelf solution for encrypted block level storage.

I was thinking of the following setup. Keep the primary server partition unencrypted so the server can boot without a key being provided to it. Create an encrypted volume via LUKs as an additional partition, encrypt it with a key, and then encrypt that key with a passphrase and store it on the server. Then I'de author a script to mount the volume given the passphrase via SSH (using nohup or screen to ensure the mount persists after the SSH session is closed), keeping the decrypted key in memory at all times. The encrypted volume would contain all the sensitive data as well as the software needed to run my services.

Now the next thing which worries me is swap, if its enabled then all of those secrets could be cached on the root partition unencrypted, so one solution would be to disable swap but it is useful to me as my services are memory hungry and could temporarily spike memory usage beyond what is available physically.

Before I have used encrypted volumes and swap files on encrypted volumes to deal with this but this was on servers I had physical access to so could leverage either manually entering luks passwords or using usb keys, neither is a possible solution in my case.

I was wondering what is the behaviour of having a swap file on the encrypted volume or an entire encryted swap volume that is not mounted at boot. What happens when the server reboots and cannot find this swap file / volume. I'de think it would prevent it booting but is there some fstab setting (like nofail or noauto) which would enable the server to boot without swap and then enable it with my mount script (have it turn swap on post decryption and mount) but in a way such that if that swap file is unavailable during boot it still boots but with swap off. I hope this makes sense.

New contributor
Uzer is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

1 Answer 1

1

You could configure the server to boot without swap, and have the same script that you'll use to mount your encrypted volume to activate an encrypted swap area too.

4
  • So have no swap file in fstab, and run this in the script sudo swapon /path/to/swapfile ? And this would not "leave" swap enable on reboot? I'm not 100% sure how to achieve this.
    – Uzer
    Commented Jun 23 at 11:37
  • Exactly like that. If you place the swap file within the encrypted volume, it cannot possibly activate without the encryption key. Just remember to update your initramfs file after removing/commenting out the swap from /etc/fstab.
    – telcoM
    Commented Jun 23 at 11:50
  • @telcoM Just remember to update your initramfs file after removing/commenting out the swap from /etc/fstab. hmm why? does any distro / early init "process" (a copy of) the file before switch root these days?
    – Tom Yan
    Commented Jun 23 at 18:02
  • @TomYan At least on Debian (and related distributions?) /etc/fstab gets copied into initramfs, so probably something uses it. And if that's not how the early boot process finds and activates the first swap, that would mean there is something else that would need to be modified too. The OP did not really mention the name of the distribution they're using, so I cannot check the specifics.
    – telcoM
    Commented Jun 23 at 19:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .