<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://tech.uvoo.io/index.php?action=history&amp;feed=atom&amp;title=LXD_security_luks</id>
	<title>LXD security luks - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://tech.uvoo.io/index.php?action=history&amp;feed=atom&amp;title=LXD_security_luks"/>
	<link rel="alternate" type="text/html" href="https://tech.uvoo.io/index.php?title=LXD_security_luks&amp;action=history"/>
	<updated>2026-05-16T01:02:03Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.35.2</generator>
	<entry>
		<id>https://tech.uvoo.io/index.php?title=LXD_security_luks&amp;diff=5663&amp;oldid=prev</id>
		<title>Busk: Created page with &quot;Setting up an encrypted storage pool for LXD is the closest you can get to the &quot;AWS EBS Encryption&quot; model on your own hardware. By using **LUKS** (Linux Unified Key Setup) und...&quot;</title>
		<link rel="alternate" type="text/html" href="https://tech.uvoo.io/index.php?title=LXD_security_luks&amp;diff=5663&amp;oldid=prev"/>
		<updated>2026-03-20T03:23:02Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;Setting up an encrypted storage pool for LXD is the closest you can get to the &amp;quot;AWS EBS Encryption&amp;quot; model on your own hardware. By using **LUKS** (Linux Unified Key Setup) und...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Setting up an encrypted storage pool for LXD is the closest you can get to the &amp;quot;AWS EBS Encryption&amp;quot; model on your own hardware. By using **LUKS** (Linux Unified Key Setup) underneath **ZFS**, even if someone pulls the physical drive from your server, the data is just random noise without the decryption passphrase.&lt;br /&gt;
&lt;br /&gt;
Here is how to build that secure foundation on Ubuntu 24.04.&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
### Phase 1: Prepare the Encrypted Partition&lt;br /&gt;
We will use a raw partition or a secondary drive (e.g., `/dev/sdb`). &lt;br /&gt;
&lt;br /&gt;
1.  **Install the necessary tools:**&lt;br /&gt;
    ```bash&lt;br /&gt;
    sudo apt update &amp;amp;&amp;amp; sudo apt install cryptsetup zfsutils-linux -y&lt;br /&gt;
    ```&lt;br /&gt;
2.  **Format the partition with LUKS:**&lt;br /&gt;
    *Choose a strong passphrase; you will need this every time the server boots.*&lt;br /&gt;
    ```bash&lt;br /&gt;
    sudo cryptsetup luksFormat /dev/sdb&lt;br /&gt;
    ```&lt;br /&gt;
3.  **Open the encrypted &amp;quot;container&amp;quot;:**&lt;br /&gt;
    This maps the encrypted physical drive to a virtual device at `/dev/mapper/lxd_encrypted`.&lt;br /&gt;
    ```bash&lt;br /&gt;
    sudo cryptsetup open /dev/sdb lxd_encrypted&lt;br /&gt;
    ```&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
### Phase 2: Create the LXD Storage Pool&lt;br /&gt;
Now that we have an open, decrypted block device, we tell LXD to use it for a ZFS pool.&lt;br /&gt;
&lt;br /&gt;
1.  **Create the Pool:**&lt;br /&gt;
    ```bash&lt;br /&gt;
    sudo lxc storage create secure-pool zfs source=/dev/mapper/lxd_encrypted&lt;br /&gt;
    ```&lt;br /&gt;
2.  **Verify the Pool:**&lt;br /&gt;
    ```bash&lt;br /&gt;
    lxc storage list&lt;br /&gt;
    ```&lt;br /&gt;
    You should see `secure-pool` listed with the driver `zfs`.&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
### Phase 3: Launch a Secure Container/VM&lt;br /&gt;
To ensure your workloads actually live on this encrypted disk, you must specify the pool during launch.&lt;br /&gt;
&lt;br /&gt;
* **For a Container:**&lt;br /&gt;
    ```bash&lt;br /&gt;
    lxc launch ubuntu:24.04 my-secure-app --storage secure-pool&lt;br /&gt;
    ```&lt;br /&gt;
* **For a VM (Even More Secure):**&lt;br /&gt;
    ```bash&lt;br /&gt;
    lxc launch ubuntu:24.04 my-vault --vm --storage secure-pool&lt;br /&gt;
    ```&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
### Phase 4: Handling Reboots (The &amp;quot;Unlock&amp;quot; Process)&lt;br /&gt;
Unlike a public cloud where the provider handles the hardware keys, **you** own the keys now. This means when your physical server reboots, the LXD pool will stay &amp;quot;offline&amp;quot; because the LUKS partition is locked.&lt;br /&gt;
&lt;br /&gt;
**To restore access after a reboot:**&lt;br /&gt;
1.  **Unlock the drive:**&lt;br /&gt;
    ```bash&lt;br /&gt;
    sudo cryptsetup open /dev/sdb lxd_encrypted&lt;br /&gt;
    ```&lt;br /&gt;
2.  **Restart LXD (if it didn't auto-detect):**&lt;br /&gt;
    ```bash&lt;br /&gt;
    sudo systemctl restart snap.lxd.daemon&lt;br /&gt;
    ```&lt;br /&gt;
&lt;br /&gt;
&amp;gt; [!TIP]&lt;br /&gt;
&amp;gt; If you want the server to unlock automatically at boot (less secure, but common for remote servers), you can use a **Keyfile** stored on a specialized USB drive or an initramfs configuration, though this technically means anyone with physical access to that USB drive can bypass the encryption.&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
### How this mimics &amp;quot;Cloud Security&amp;quot;&lt;br /&gt;
* **The &amp;quot;Admin&amp;quot; Problem:** If an admin tries to `cat` a file from the host's `/var/lib/lxd/storage-pools/`, they can only do so while the LUKS partition is &amp;quot;Open.&amp;quot; &lt;br /&gt;
* **Cold Boot Attacks:** If the server is powered off, the data is mathematically inaccessible. &lt;br /&gt;
* **Snapshot Safety:** Since the ZFS snapshots live inside the LUKS container, your backups are also encrypted by default if you replicate the ZFS stream.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# Automount&lt;br /&gt;
&lt;br /&gt;
Automating the unlock process is a balance between **convenience** and **security**. If you store the key on the same hard drive, you defeat the purpose of encryption (it’s like leaving the key in the lock). &lt;br /&gt;
&lt;br /&gt;
The &amp;quot;Pro&amp;quot; way to do this on-premise is to store the keyfile on a **separate USB drive** or a dedicated **microSD card** that stays plugged into the server.&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
### 1. Create the Keyfile&lt;br /&gt;
First, we generate a file full of random data to act as your &amp;quot;digital key.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
```bash&lt;br /&gt;
# Create a 4KB keyfile&lt;br /&gt;
sudo dd if=/dev/urandom of=/root/lxd_keyfile bs=1024 count=4&lt;br /&gt;
# Set strict permissions (Only root can read it)&lt;br /&gt;
sudo chmod 400 /root/lxd_keyfile&lt;br /&gt;
```&lt;br /&gt;
*(Note: For higher security, move this file to a USB drive mounted at `/mnt/usb/keyfile` instead of `/root/`.)*&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
### 2. Add the Keyfile to LUKS&lt;br /&gt;
LUKS has &amp;quot;slots&amp;quot; for multiple keys. We will keep your manual passphrase in Slot 0 and add this file to Slot 1.&lt;br /&gt;
&lt;br /&gt;
```bash&lt;br /&gt;
sudo cryptsetup luksAddKey /dev/sdb /root/lxd_keyfile&lt;br /&gt;
```&lt;br /&gt;
*You will be prompted for your **original passphrase** to authorize adding the new key.*&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
### 3. Configure `/etc/crypttab`&lt;br /&gt;
This file tells Ubuntu to unlock the drive automatically during the boot sequence using the keyfile.&lt;br /&gt;
&lt;br /&gt;
1.  **Get the UUID of your physical drive:**&lt;br /&gt;
    ```bash&lt;br /&gt;
    blkid /dev/sdb&lt;br /&gt;
    ```&lt;br /&gt;
    *Copy the UUID (e.g., `UUID=&amp;quot;1234-abcd-...&amp;quot;`).*&lt;br /&gt;
&lt;br /&gt;
2.  **Edit the crypttab file:**&lt;br /&gt;
    ```bash&lt;br /&gt;
    sudo nano /etc/crypttab&lt;br /&gt;
    ```&lt;br /&gt;
3.  **Add this line:**&lt;br /&gt;
    ```text&lt;br /&gt;
    lxd_encrypted  UUID=your-uuid-here  /root/lxd_keyfile  luks&lt;br /&gt;
    ```&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
### 4. Update Initramfs&lt;br /&gt;
Since storage is a core system component, you need to update the boot RAM disk so the kernel knows how to handle this mapping at startup.&lt;br /&gt;
&lt;br /&gt;
```bash&lt;br /&gt;
sudo update-initramfs -u&lt;br /&gt;
```&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
### 5. Final Step: The ZFS Mount&lt;br /&gt;
LXD is usually smart enough to see the `/dev/mapper/lxd_encrypted` device appear and then mount the ZFS pool. However, if the pool doesn't import automatically, you can add a simple systemd override or just run `lxc storage import` if needed.&lt;br /&gt;
&lt;br /&gt;
### The &amp;quot;Cloud-Level&amp;quot; Security Result&lt;br /&gt;
* **Rebooting:** The server boots, finds the keyfile, unlocks the drive, and LXD starts your containers.&lt;br /&gt;
* **Theft Scenario:** If someone steals the server but **unplugs the USB key** (or if you keep the keyfile on a network share that you disconnect), the data remains encrypted and unreadable.&lt;br /&gt;
* **Rogue Admin:** An admin with access to the running OS can still see the data (since it's unlocked), but an admin with physical access to the &amp;quot;cold&amp;quot; hardware cannot.&lt;br /&gt;
&lt;br /&gt;
&amp;gt; [!WARNING]&lt;br /&gt;
&amp;gt; If you lose both your manual passphrase **and** this keyfile, the data on that LXD pool is gone forever. There is no &amp;quot;Password Reset&amp;quot; in LUKS encryption.&lt;/div&gt;</summary>
		<author><name>Busk</name></author>
	</entry>
</feed>