Skip to content

Commit

Permalink
Update Ubuntu version in "Install an encrypted Ubuntu" (hetzneronline…
Browse files Browse the repository at this point in the history
  • Loading branch information
svenja11 authored Apr 10, 2024
1 parent 124afd3 commit 64599f6
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 122 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
SPDX-License-Identifier: MIT
path: "/tutorials/install-encrypted-ubuntu-2004-with-automated-unlock-via-tang-and-clevis/de"
slug: "install-encrypted-ubuntu-2004-with-automated-unlock-via-tang-and-clevis"
date: "2021-06-29"
title: "Wie installiert man ein verschlüsseltes Ubuntu 20.04 mit automatisierter Entsperrung via tang und clevis"
short_description: "Dieses Tutorial beschreibt, wie Sie einen einfachen Tang-Server konfigurieren und ein verschlüsseltes Ubuntu 20.04 installieren, dass dann automatisch über clevis freigeschaltet wird."
date: "2024-04-10"
title: "Wie installiert man ein verschlüsseltes Ubuntu 22.04 mit automatisierter Entsperrung via tang und clevis"
short_description: "Dieses Tutorial beschreibt, wie man einen einfachen Tang-Server konfigurieren und ein verschlüsseltes Ubuntu 22.04 installieren, dass dann automatisch über clevis freigeschaltet wird."
tags: ["Ubuntu", "installimage", "encryption", "clevis", "tang", "FDE", "initramfs"]
author: "Philipp Roth"
author_link: "https://github.com/roth-wine"
Expand All @@ -20,88 +20,90 @@ cta: "cloud"

Das [installimage](https://docs.hetzner.com/robot/dedicated-server/operating-systems/installimage) Skript in dem [Hetzner Rescue System](https://docs.hetzner.com/robot/dedicated-server/troubleshooting/hetzner-rescue-system) bietet eine einfache Möglichkeit, verschiedene Linux-Distributionen zu installieren.

Dieses Tutorial zeigt, wie man mit Hilfe des `installimage` ein verschlüsseltes Ubuntu 20.04-System installiert und eine vollautomatische Entschlüsselung des Root Filesystems über clevis im initramfs hinzufügt, das in einer separaten `/boot`-Partition gespeichert ist.
Dieses Tutorial zeigt, wie man mit Hilfe des `installimage` ein verschlüsseltes Ubuntu 22.04-System installiert und eine vollautomatische Entschlüsselung des Root Filesystems über clevis im initramfs hinzufügt, das in einer separaten `/boot`-Partition gespeichert ist.

**Vorraussetzungen**

* Hetzner Konto
* Server mit installiertem Ubuntu 20.04 Betriebssystem
* Server im Rescue System
* Zwei Server:
* `tang-server` » Server mit installiertem Ubuntu 22.04 Betriebssystem
* `clevis-server`/`rescue` » Server im Rescue System
* Keine privaten Netzwerke über die Hetzner Cloud an den Servern angeschlossen

## Schritt 1 - Konfigurieren des tang-Server

Zunächst werden wir Tang und José (die C-Implementierung des von Tang verwendeten JavaScript Object Signing and Encryption Standards) auf dem Server installieren, auf dem bereits Ubuntu 20.04 installiert ist.
Zunächst werden wir Tang und José (die C-Implementierung des von Tang verwendeten JavaScript Object Signing and Encryption Standards) auf dem Server installieren, auf dem bereits Ubuntu 22.04 installiert ist.

```console
```shellsession
user@tang-server:~$ apt update
user@tang-server:~$ apt install tang jose
user@tang-server:~$ systemctl enable tangd.socket
user@tang-server:~$ systemctl start tangd.socket
```

Führen Sie `tang-show-keys` aus, um zu prüfen, ob alles korrekt installiert ist und um den Fingerabdruck des Signierschlüssels zu ermitteln.
Führe `tang-show-keys` aus, um zu prüfen, ob alles korrekt installiert ist und um den Fingerabdruck des Signierschlüssels zu ermitteln.

```console
```shellsession
user@tang-server:~$ tang-show-keys
3ZWS6-cDrCG61UPJS2BMmPU4I54
```

## Schritt 2 - Erzeugen oder Kopieren des öffentlichen SSH-Schlüssels auf dem clevis-server (Optional)

Um sich über einen SSH-Schlüssel anschließend am clevis-Server anzumelden, müssen wir vor der Installation den SSH-Schlüssel hinterlegen. Wenn Sie einen solchen Schlüssel nicht haben, müssen Sie einen generieren.
Um sich über einen SSH-Schlüssel anschließend am clevis-Server anzumelden, müssen wir vor der Installation den SSH-Schlüssel hinterlegen. Wenn du einen solchen Schlüssel nicht hast, musst du einen generieren.

Um z. B. einen SSH-Schlüssel ed25519 zu erzeugen, führen sie den folgenden Befehl auf dem Client aus:
Um z. B. einen SSH-Schlüssel ed25519 zu erzeugen, führe den folgenden Befehl auf dem Client aus:

```console
```shellsession
user@client:~$ ssh-keygen -t ed25519
```

Kopieren Sie anschließend den öffentlichen Schlüssel auf das Rescue System, z. B. mit `scp`:
Kopiere anschließend den öffentlichen Schlüssel auf das Rescue System des clevis-server, z. B. mit `scp`:

```console
```shellsession
user@client:~$ scp ~/.ssh/id_ed25519.pub root@<clevis-server>:/tmp/authorized_keys
```

Wenn Sie das `Rescue-System` mit einem vorhandenen SSH-Schlüssel gestartet haben, kopieren Sie den öffentlichen Schlüssel für die Installation in das korrekte Verzeichnis:
Wenn das `Rescue-System` mit einem vorhandenen SSH-Schlüssel gestartet wurde, kopiere den öffentlichen Schlüssel für die Installation in das korrekte Verzeichnis:

```console
```shellsession
root@rescue ~ # cp ~/.ssh/authorized_keys /tmp/authorized_keys
```

## Schritt 3 - Erstellen oder Kopieren der installimage-Konfigurationsdatei

Wenn `installimage` ohne Optionen aufgerufen wird, startet es im interaktiven Modus und öffnet einen Editor, nachdem ein Distributionsimage ausgewählt wurde. Nach dem Verlassen des Editors wird die Installation fortgesetzt und die entsprechende Konfiguration wird als `/installimage.conf` im installierten System gespeichert. In diesem Tutorial werden wir eine solche Konfigurationsdatei direkt zur Installation übergeben.

Erstellen Sie eine Datei `/tmp/setup.conf` mit folgendem Inhalt oder kopieren Sie diese auf den clevis-Server im Rescue-System.
Erstelle eine Datei `/tmp/setup.conf` mit folgendem Inhalt oder kopiere diese auf den clevis-Server im Rescue-System.

Hinweis: Ersetzen Sie `<secret>` durch ein sicheres Passwort und passen Sie Laufwerksnamen und Partitionierung nach Bedarf an.
Hinweis: Ersetze `<secret>` durch ein sicheres Passwort und passe Laufwerksnamen und Partitionierung nach Bedarf an.

```console
```conf
CRYPTPASSWORD <secret>
DRIVE1 /dev/sda
BOOTLOADER grub
HOSTNAME host.example.com
PART /boot/efi esp 256M
PART /boot ext4 1G
PART / ext4 all crypt
IMAGE /root/images/Ubuntu-2004-focal-64-minimal.tar.gz
IMAGE /root/images/Ubuntu-2204-jammy-amd64-base.tar.gz
```

Wenn in Schritt 2 ein SSH-Schlüssel konfiguriert wurde, fügen Sie bitte auch die folgende Zeile in `/tmp/setup.conf` ein.
Wenn in Schritt 2 ein SSH-Schlüssel konfiguriert wurde, füge bitte auch die folgende Zeile in `/tmp/setup.conf` ein.

```console
```conf
SSHKEYS_URL /tmp/authorized_keys
```

## Schritt 4 - Post-Installations-Skript erstellen oder kopieren

Um die verschlüsselte Partition automatisch über den tang-Server zu entsperren, müssen wir clevis installieren und zum initramfs hinzufügen, das auf der unverschlüsselten `/boot`-Partition installiert ist. Dies löst auch die Einbindung von `dhclient` aus, um das Netzwerk zu konfigurieren, allerdings ohne jegliche Extras. Um die Unterstützung für die Hetzner Cloud zu aktivieren, müssen wir einen Hook hinzufügen, der die Unterstützung für RFC3442-Routen beinhaltet.

Um diese zusätzlichen Schritte ausführen zu können, benötigen wir ein Post-Install-Skript für das `installimage`
Um diese zusätzlichen Schritte ausführen zu können, benötigen wir ein Post-Install-Skript für das `installimage`.

Erstellen Sie die Datei `/tmp/post-install.sh` im `Rescue-System` mit folgendem Inhalt.
Erstelle die Datei `/tmp/post-install.sh` im `Rescue-System` mit folgendem Inhalt.

Hinweis: Ersetzen Sie `<secret>` mit dem Passwort, das Sie für den Wert bei `CRYPTPASSWORD` gewählt haben und ersetzen Sie `<ip-tangserver>` mit der IP-Adresse Ihres tang-Servers.
Hinweis: Ersetze `<secret>` mit dem Passwort, das in der `/tmp/setup.conf`-Datei für den Wert bei `CRYPTPASSWORD` gewählt wurde und ersetze `<ip-tangserver>` mit der IP-Adresse deines tang-Servers.

```bash
#!/bin/bash
Expand Down Expand Up @@ -151,42 +153,42 @@ apt-get -y install clevis clevis-luks clevis-initramfs cryptsetup-initramfs

# Get the key from the tang server and then bind the device to the tang server
curl -sfg http://<ip-tangserver>/adv -o /tmp/adv.jws
echo '<secret>' | clevis luks bind -d /dev/sda2 tang '{"url": "http://<ip-tangserver>" , "adv": "/tmp/adv.jws" }'
echo '<secret>' | clevis luks bind -d /dev/sda3 tang '{"url": "http://<ip-tangserver>" , "adv": "/tmp/adv.jws" }'

# Update the existing initramfs
update-initramfs -u
```

Wichtiger Hinweis: Das Skript muss ausführbar gemacht werden:

```console
```shellsession
root@rescue ~ # chmod +x /tmp/post-install.sh
```

## Schritt 5 - Installation starten

Prüfen Sie vor dem Start der Installation nochmals den Inhalt der folgenden Dateien:
Prüfe vor dem Start der Installation nochmals den Inhalt der folgenden Dateien:

* `/tmp/setup.conf` - Installationskonfiguration
* `/tmp/post-install.sh` - ist ausführbar und enthält das Post-Installations-Skript
* wenn in Schritt 2 konfiguriert:
* `/tmp/authorized_keys` - Ihr öffentlicher SSH-Schlüssel

Jetzt können Sie die Installation mit dem folgenden Befehl starten:
Jetzt kann die Installation mit dem folgenden Befehl gestartet werden:

```console
```shellsession
root@rescue ~ # installimage -a -c /tmp/setup.conf -x /tmp/post-install.sh
```

Warten Sie, bis die Installation abgeschlossen ist, und prüfen Sie die `debug.txt` auf eventuelle Fehler.
Warte, bis die Installation abgeschlossen ist, und prüfe die `debug.txt`-Datei auf eventuelle Fehler.

## Schritt 6 - Das installiertes System booten

Nachdem die Installation abgeschlossen ist und alle Fehler behoben wurden, können Sie `reboot` ausführen, um den Server neu zu starten und das neu installierte Betriebssystem zu booten. Sie können den Boot-Vorgang beobachten, wenn Sie eine KVM angeschlossen haben oder über die Remote-Konsole auf der jeweiligen Cloud-Instanz.
Nachdem die Installation abgeschlossen ist und alle Fehler behoben wurden, kann `reboot` ausgeführt werden, um den Server neu zu starten und das neu installierte Betriebssystem zu booten. Der Boot-Vorgang kann beobachtet werden, wenn eine KVM angeschlossen ist oder über die Remote-Konsole auf der jeweiligen Cloud-Instanz.

## Fazit
## Ergebnis

Wenn Sie alle Schritte in diesem Tutorial befolgt haben, sollte der clevis-Server automatisch das Root-Dateisystem in initramfs entschluesseln und anschließend normal in das Betriebssystem booten.
Wenn alle Schritte in diesem Tutorial befolgt wurden, sollte der clevis-Server automatisch das Root-Dateisystem in initramfs entschlüsseln und anschließend normal in das Betriebssystem booten.

##### License: MIT

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
SPDX-License-Identifier: MIT
path: "/tutorials/install-encrypted-ubuntu-2004-with-automated-unlock-via-tang-and-clevis"
slug: "install-encrypted-ubuntu-2004-with-automated-unlock-via-tang-and-clevis"
date: "2021-06-29"
title: "How to install an encrypted Ubuntu 20.04 with automated unlocking via tang and clevis"
short_description: "This tutorial describes how to configure a basic tang server and how to install an encrypted Ubuntu 20.04, which then unlocks automatically via clevis."
date: "2024-04-10"
title: "How to install an encrypted Ubuntu 22.04 with automated unlocking via tang and clevis"
short_description: "This tutorial describes how to configure a basic tang server and how to install an encrypted Ubuntu 22.04, which then unlocks automatically via clevis."
tags: ["Ubuntu", "installimage", "encryption", "clevis", "tang", "FDE", "initramfs"]
author: "Philipp Roth"
author_link: "https://github.com/roth-wine"
Expand All @@ -20,20 +20,21 @@ cta: "cloud"

The [installimage](https://docs.hetzner.com/robot/dedicated-server/operating-systems/installimage) script in the [Hetzner Rescue System](https://docs.hetzner.com/robot/dedicated-server/troubleshooting/hetzner-rescue-system) provides an easy way to install various Linux distributions.

This tutorial shows how to use `installimage` to install an encrypted Ubuntu 20.04 system and add fully automated remote unlocking via clevis in initramfs stored in a separate `/boot` partition.
This tutorial shows how to use `installimage` to install an encrypted Ubuntu 22.04 system and add fully automated remote unlocking via clevis in initramfs stored in a separate `/boot` partition.

**Prerequisites**

* Hetzner account
* Server with Ubuntu 20.04 installed
* Server booted into the Rescue System
* Two servers:
* `tang-server` » Server with Ubuntu 22.04 installed
* `clevis-server`/`rescue` » Server booted into the Rescue System
* No private networks attached on Hetzner Cloud

## Step 1 - Configure the tang server

At first we will install Tang and José (which is the c implementation of the JavaScript Object Signing and Encryption standards used by Tang) on the Server where Ubuntu 20.04 is installed already.
At first we will install Tang and José (which is the c implementation of the JavaScript Object Signing and Encryption standards used by Tang) on the Server where Ubuntu 22.04 is installed already.

```console
```shellsession
user@tang-server:~$ apt update
user@tang-server:~$ apt install tang jose
user@tang-server:~$ systemctl enable tangd.socket
Expand All @@ -42,30 +43,30 @@ user@tang-server:~$ systemctl start tangd.socket

Execute `tang-show-keys` to check if everything is installed correctly and to determine the signing key’s fingerprint.

```console
```shellsession
user@tang-server:~$ tang-show-keys
3ZWS6-cDrCG61UPJS2BMmPU4I54
```

## Step 2 - Create or copy SSH public key to the clevis-server (Optional)

In order to log into the server remotely via an SSH-Key we need to deposite the SSH-Key before the installation. If you do not have such a key, you need to generate one.
In order to log into the server remotely via an SSH key, we need to deposit the SSH key before the installation. If you do not have such a key, you need to generate one.

For example to generate a ed25519 SSH key run:
For example to generate an ed25519 SSH key run:

```console
```shellsession
user@client:~$ ssh-keygen -t ed25519
```

Copy the public key to the rescue system, e.g. using `scp`:
Copy the public key to the rescue system of the clevis server, e.g. using `scp`:

```console
```shellsession
user@client:~$ scp ~/.ssh/id_ed25519.pub root@<clevis-server>:/tmp/authorized_keys
```

If you have started the `Rescue System` with an existing SSH-Key, copy the public key for the installation
If you have started the `Rescue System` with an existing SSH key, copy the public key for the installation:

```console
```shellsession
root@rescue ~ # cp ~/.ssh/authorized_keys /tmp/authorized_keys
```

Expand All @@ -77,31 +78,32 @@ Create a file `/tmp/setup.conf` with the following content or copy it to the ser

Note: Replace `<secret>` with a secure password and adjust drive names and partitioning as needed.

```console
```conf
CRYPTPASSWORD <secret>
DRIVE1 /dev/sda
BOOTLOADER grub
HOSTNAME host.example.com
PART /boot/efi esp 256M
PART /boot ext4 1G
PART / ext4 all crypt
IMAGE /root/images/Ubuntu-2004-focal-64-minimal.tar.gz
IMAGE /root/images/Ubuntu-2204-jammy-amd64-base.tar.gz
```

If an SSH-Key has been configured in Step 2, please also add the following line to `/tmp/setup.conf`.

```console
```conf
SSHKEYS_URL /tmp/authorized_keys
```

## Step 4 - Create or copy post-install script

In order to automaticly unlock the encrypted partition via the tang server, we need to install and add clevis to the initramfs which is stored on the unencrypted `/boot` partition. This will also trigger the inclusion of `dhclient` to configure networking, but without any extras. To enable support for Hetzner Cloud, we need to add a hook which includes support for RFC3442 routes.
In order to automatically unlock the encrypted partition via the tang server, we need to install and add clevis to the initramfs which is stored on the unencrypted `/boot` partition. This will also trigger the inclusion of `dhclient` to configure networking, but without any extras. To enable support for Hetzner Cloud, we need to add a hook which includes support for RFC3442 routes.

In order to run these additional steps we need a post-install script for `installimage`
In order to run these additional steps we need a post-install script for `installimage`.

Create a file `/tmp/post-install.sh` in the Rescue system with the following content.

Note: Replace `<secret>` with the passwort you have choosen for the `CRYPTPASSWORD` value and replace `<ip-tangserver>` with the IP-address of your tang-server.
Note: Replace `<secret>` with the password you set for the `CRYPTPASSWORD` value in the `/tmp/setup.conf` file, and replace `<ip-tangserver>` with the IP-address of your tang-server.

```bash
#!/bin/bash
Expand Down Expand Up @@ -151,15 +153,15 @@ apt-get -y install clevis clevis-luks clevis-initramfs cryptsetup-initramfs

# Get the key from the tang server and then bind the device to the tang server
curl -sfg http://<ip-tangserver>/adv -o /tmp/adv.jws
echo '<secret>' | clevis luks bind -d /dev/sda2 tang '{"url": "http://<ip-tangserver>" , "adv": "/tmp/adv.jws" }'
echo '<secret>' | clevis luks bind -d /dev/sda3 tang '{"url": "http://<ip-tangserver>" , "adv": "/tmp/adv.jws" }'

# Update the existing initramfs
update-initramfs -u
```

Important note: make the post-install script executable:

```console
```shellsession
root@rescue ~ # chmod +x /tmp/post-install.sh
```

Expand All @@ -174,19 +176,19 @@ Before starting the installation check again the content of the following files:

Now you are ready to start the installation with the following command:

```console
```shellsession
root@rescue ~ # installimage -a -c /tmp/setup.conf -x /tmp/post-install.sh
```

Wait until the installation completes and check the `debug.txt` for any errors.
Wait until the installation completes and check `debug.txt` for any errors.

## Step 6 - Boot installed system

After the installation has finished and any errors are resolved, you can run `reboot` to restart the server and boot the newly installed system. You can watch the boot process if you have a KVM attached or via remote console on a Cloud instance.

## Conclusion

If you have followed all the steps in this tutorial, the clevis-server should automaticlly decrypt the root filesystem in initramfs and afterwards boot normally into the OS.
If you have followed all the steps in this tutorial, the clevis-server should automatically decrypt the root filesystem in initramfs and afterwards boot normally into the OS.

##### License: MIT

Expand Down
Loading

0 comments on commit 64599f6

Please sign in to comment.