Frage :Wie erstelle ich ein verschlüsseltes XFS-Dateisystem, das beim Booten automatisch mit Clevis (Client) und Tang (Server) entsperrt wird?
Red Hat hat die Festplattenverschlüsselung seit Jahren mit Linux Unified Key Setup-on-Disk-Format (LUKS) integriert. Diese Lösung ist einfach zu implementieren und für Ihre Verschlüsselungsanforderungen zu konfigurieren, aber die Verwaltung und Praktikabilität der Schlüsselverwaltung ist für Server schrecklich. Es erfordert eine Passphrase beim Booten oder Mounten, die manuell eingegeben werden muss. Dies macht die Lösung zu Kopfschmerzen für Systemadministratoren.
Ab RHEL 7.4 hat Red Hat mit vollständiger Unterstützung in RHEL 7.5 eine zusätzliche Komponente implementiert, die genutzt werden kann, um LUKS-Festplatten remote zu aktivieren. Dies wird als Network Bound Disk Encryption (NBDE) bezeichnet.
Netzwerkgebundene Festplattenverschlüsselung (NBDE) ist:
- Linux Unified Key Setup (LUKS) ist ein Festplattenverschlüsselungsstandard.
- Cryptsetup konfiguriert festplattenbasierte Verschlüsselung und beinhaltet Unterstützung für LUKS
- Tang ist ein Netzwerkdienst, der kryptografische Dienste über HTTP bereitstellt
- Clevis ist ein Verschlüsselungs-Framework. Clevis kann von Tang bereitgestellte Schlüssel als Passphrase verwenden, um LUKS-Volumes zu entsperren
- Der Client, clevis, muss CentOS/RHEL 8 sein, da clevis auf CentOS/RHEL 7 eine eingeschränkte Funktionalität hat und einen anderen Befehlssatz erfordert, der in diesem Beitrag nicht behandelt wird.
- Der Server tang kann auf CentOS/RHEL 7 oder 8 ausgeführt werden
Tang-Server einrichten
1. Installieren Sie die RPMs:
# dnf install -y tang
2. Erlauben Sie den erforderlichen Port durch die Firewall:
# firewall-cmd --add-service=http --permanent # firewall-cmd --reload
3. Aktivieren Sie den Dienst:
# systemctl enable --now tangd.socket
Clevis-Client einrichten
Erstelle ein verschlüsseltes Dateisystem
1. Installieren Sie die erforderlichen Pakete auf dem Client:
# dnf install -y cryptsetup clevis-systemd clevis-luks
2. Erstellen einer verschlüsselten Festplatte auf /dev/xvdc:
Hinweis :Stellen Sie sicher, dass xvdc ein leeres Laufwerk ist, da alle Daten darauf gelöscht werden.# cryptsetup luksFormat --type luks2 --cipher aes-xts-plain64 --key-size 512 --hash sha256 --use-random /dev/xvdc WARNING! ======== This will overwrite data on /dev/xvdc irrevocably. Are you sure? (Type uppercase yes): YES Enter passphrase for /dev/xvdc: Verify passphrase:
3. Entsperren Sie das Blockgerät:
# cryptsetup --verbose luksOpen /dev/xvdc demodisk Enter passphrase for /dev/xvdc: Key slot 0 unlocked. Command successful.
4. Erstellen Sie ein Dateisystem auf der verschlüsselten Festplatte:
# mkfs.xfs /dev/mapper/demodisk meta-data=/dev/mapper/demodisk isize=512 agcount=4, agsize=326656 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=1, sparse=1, rmapbt=0 = reflink=1 data = bsize=4096 blocks=1306624, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0, ftype=1 log =internal log bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0
5. Identifizieren Sie die UUID des neuen Dateisystems:
# blkid -s UUID /dev/mapper/demodisk /dev/mapper/demodisk: UUID="24f9bfe9-1f6d-491d-8fa2-eab946464166"
6. Erstellen Sie einen fstab-Eintrag für das Dateisystem:
# echo "UUID=24f9bfe9-1f6d-491d-8fa2-eab946464166 /encrypted xfs defaults 0 0" | sudo tee -a /etc/fstab UUID=24f9bfe9-1f6d-491d-8fa2-eab946464166 /encrypted xfs defaults 0 0
7. Mounten Sie das Dateisystem:
# mkdir /encrypted # mount /encrypted
Fügen Sie dem verschlüsselten Gerät einen Remote-Schlüssel hinzu
1. Zeigen Sie die Schlüssel an:
# cryptsetup luksDump /dev/xvdc LUKS header information Version: 2 Epoch: 3 Metadata area: 16384 [bytes] Keyslots area: 16744448 [bytes] UUID: 47e0d1c3-d74b-41f0-9bc7-5ea367e9cb26 Label: (no label) Subsystem: (no subsystem) Flags: (no flags) Data segments: 0: crypt offset: 16777216 [bytes] length: (whole device) cipher: aes-xts-plain64 sector: 512 [bytes] Keyslots: 0: luks2 Key: 512 bits Priority: normal Cipher: aes-xts-plain64 Cipher key: 512 bits PBKDF: argon2i Time cost: 4 Memory: 399588 Threads: 4 Salt: 0d 75 99 50 22 e2 2a 93 82 51 fc 49 6f 54 61 fe 10 b6 24 62 21 2e 07 2b 04 0a 56 c8 03 23 6f 8f AF stripes: 4000 AF hash: sha256 Area offset:32768 [bytes] Area length:258048 [bytes] Digest ID: 0 Tokens: Digests: 0: pbkdf2 Hash: sha256 Iterations: 30284 Salt: de a0 3f 92 e1 c7 1d 5e 0e 52 65 37 19 84 2b 3c 46 2a ba 56 77 25 78 c3 27 fa 5b 07 e1 9a 25 24 Digest: 5b 95 93 af 0e a9 8d 24 cb 35 1e 77 e5 9f 15 85 eb d1 53 85 5b e4 10 2a 68 d0 11 6b 9b 71 f4 05
2. Fernbedienungsschlüssel hinzufügen:
# clevis luks bind -d /dev/xvdc tang '{"url":"http://"}' The advertisement contains the following signing keys: KlbbdbNpdMrVwrk6hZ1wCCeabOY Do you wish to trust these keys? [ynYN] Y Enter existing LUKS password:
3. Zeigen Sie, dass Clevis in Slot 1 einen neuen Keyslot verwendet:
# cryptsetup luksDump /dev/xvdc LUKS header information Version: 2 Epoch: 5 Metadata area: 16384 [bytes] Keyslots area: 16744448 [bytes] UUID: 47e0d1c3-d74b-41f0-9bc7-5ea367e9cb26 Label: (no label) Subsystem: (no subsystem) Flags: (no flags) Data segments: 0: crypt offset: 16777216 [bytes] length: (whole device) cipher: aes-xts-plain64 sector: 512 [bytes] Keyslots: 0: luks2 Key: 512 bits Priority: normal Cipher: aes-xts-plain64 Cipher key: 512 bits PBKDF: argon2i Time cost: 4 Memory: 399588 Threads: 4 Salt: 0d 75 99 50 22 e2 2a 93 82 51 fc 49 6f 54 61 fe 10 b6 24 62 21 2e 07 2b 04 0a 56 c8 03 23 6f 8f AF stripes: 4000 AF hash: sha256 Area offset:32768 [bytes] Area length:258048 [bytes] Digest ID: 0 1: luks2 Key: 512 bits Priority: normal Cipher: aes-xts-plain64 Cipher key: 512 bits PBKDF: argon2i Time cost: 4 Memory: 508554 Threads: 4 Salt: 21 c8 91 58 22 9f 50 83 77 6f fe 12 0b 3a 66 3c d2 47 70 88 45 70 5e f1 c1 1e d0 e1 8f 96 97 ce AF stripes: 4000 AF hash: sha256 Area offset:290816 [bytes] Area length:258048 [bytes] Digest ID: 0 Tokens: 0: clevis Keyslot: 1 Digests: 0: pbkdf2 Hash: sha256 Iterations: 30284 Salt: de a0 3f 92 e1 c7 1d 5e 0e 52 65 37 19 84 2b 3c 46 2a ba 56 77 25 78 c3 27 fa 5b 07 e1 9a 25 24 Digest: 5b 95 93 af 0e a9 8d 24 cb 35 1e 77 e5 9f 15 85 eb d1 53 85 5b e4 10 2a 68 d0 11 6b 9b 71 f4 05
Mounten Sie das verschlüsselte Dateisystem beim Booten
1. Identifizieren Sie die UUID des Blockgeräts zur späteren Verwendung:
# blkid -s UUID /dev/xvdc /dev/xvdc: UUID="47e0d1c3-d74b-41f0-9bc7-5ea367e9cb26"
2. Aktivieren Sie den Dienst mit der für „/dev/xvdc“ ermittelten UUID:
# systemctl enable [email protected] Created symlink /etc/systemd/system/basic.target.wants/[email protected] → /usr/lib/systemd/system/[email protected].
3. Lassen Sie das Blockgerät während des Bootvorgangs entsperren:
# echo "encrypteddisk UUID=47e0d1c3-d74b-41f0-9bc7-5ea367e9cb26 - _netdev" | sudo tee -a /etc/crypttab encrypteddisk UUID=47e0d1c3-d74b-41f0-9bc7-5ea367e9cb26 - _netdev
4. Mounten Sie das Dateisystem später beim Booten:
# vi /etc/fstab
Ändere den Eintrag:
UUID=24f9bfe9-1f6d-491d-8fa2-eab946464166 /encrypted xfs defaults 0 0
zu:
/dev/mapper/encrypteddisk /encrypted xfs _netdev 0 0
5. Starten Sie den Server neu und überprüfen Sie die Funktionalität:
# reboot
# df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 1.8G 0 1.8G 0% /dev tmpfs 1.8G 0 1.8G 0% /dev/shm tmpfs 1.8G 8.5M 1.8G 1% /run tmpfs 1.8G 0 1.8G 0% /sys/fs/cgroup /dev/mapper/ol_dhcp-root 22G 1.6G 20G 8% / /dev/xvda1 1014M 221M 794M 22% /boot tmpfs 365M 0 365M 0% /run/user/0 /dev/mapper/encrypteddisk 5.0G 68M 5.0G 2% /encrypted
Optional:Bekannte Passphrase entfernen
Sie können die bekannte Passphrase aus Steckplatz 0 entfernen und die Verwendung des Tang-Servers vorschreiben. Wenn der Tang-Server nicht erreichbar ist, kann die Festplatte nicht entsperrt und das Dateisystem nicht aufgerufen werden.
1. Entfernen Sie die Passphrase:
# cryptsetup --verbose luksRemoveKey /dev/xvdc Enter passphrase to be deleted: Key slot 0 unlocked. Keyslot 0 is selected for deletion. Key slot 0 removed. Command successful.
2. Zeigen Sie, dass es jetzt nur noch Clevis-Steckplätze gibt:
# cryptsetup --verbose luksRemoveKey /dev/xvdc Enter passphrase to be deleted: Key slot 0 unlocked. Keyslot 0 is selected for deletion. Key slot 0 removed. Command successful.
# cryptsetup luksDump /dev/xvdc LUKS header information Version: 2 Epoch: 6 Metadata area: 16384 [bytes] Keyslots area: 16744448 [bytes] UUID: 47e0d1c3-d74b-41f0-9bc7-5ea367e9cb26 Label: (no label) Subsystem: (no subsystem) Flags: (no flags) Data segments: 0: crypt offset: 16777216 [bytes] length: (whole device) cipher: aes-xts-plain64 sector: 512 [bytes] Keyslots: 1: luks2 Key: 512 bits Priority: normal Cipher: aes-xts-plain64 Cipher key: 512 bits PBKDF: argon2i Time cost: 4 Memory: 508554 Threads: 4 Salt: 21 c8 91 58 22 9f 50 83 77 6f fe 12 0b 3a 66 3c d2 47 70 88 45 70 5e f1 c1 1e d0 e1 8f 96 97 ce AF stripes: 4000 AF hash: sha256 Area offset:290816 [bytes] Area length:258048 [bytes] Digest ID: 0 Tokens: 0: clevis Keyslot: 1 Digests: 0: pbkdf2 Hash: sha256 Iterations: 30284 Salt: de a0 3f 92 e1 c7 1d 5e 0e 52 65 37 19 84 2b 3c 46 2a ba 56 77 25 78 c3 27 fa 5b 07 e1 9a 25 24 Digest: 5b 95 93 af 0e a9 8d 24 cb 35 1e 77 e5 9f 15 85 eb d1 53 85 5b e4 10 2a 68 d0 11 6b 9b 71 f4 05
3. Starten Sie neu und überprüfen Sie die Funktionalität:
# reboot
# df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 1.8G 0 1.8G 0% /dev tmpfs 1.8G 0 1.8G 0% /dev/shm tmpfs 1.8G 8.5M 1.8G 1% /run tmpfs 1.8G 0 1.8G 0% /sys/fs/cgroup /dev/mapper/ol_dhcp-root 22G 1.6G 20G 8% / /dev/xvda1 1014M 221M 794M 22% /boot /dev/mapper/encrypteddisk 5.0G 68M 5.0G 2% /encrypted tmpfs 365M 0 365M 0% /run/user/0