🥙 Как расшифровать корневой раздел с LUKS-шифрованием во время загрузки |

🥙 Как расшифровать корневой раздел с LUKS-шифрованием во время загрузки

Мануал

Автоматически расшифровываем корневой раздел с LUKS-шифрованием во время загрузки с помощью TPM и clevis.

Установите clevis, автоматический механизм политики дешифрования.

Как стереть все слоты для ключей LUKS

sudo apt install clevis clevis-tpm2 clevis-luks clevis-initramfs
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
curl jose libjose0 libluksmeta0 libpwquality-tools libtss2-fapi1t64 luksmeta tpm2-tools
The following NEW packages will be installed:
clevis clevis-initramfs clevis-luks clevis-tpm2 curl jose libjose0 libluksmeta0 libpwquality-tools libtss2-fapi1t64 luksmeta tpm2-tools
0 upgraded, 12 newly installed, 0 to remove and 53 not upgraded.
Need to get 1465 kB of archives.
After this operation, 3946 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://pl.archive.ubuntu.com/ubuntu noble/universe amd64 libjose0 amd64 13-1 [44.5 kB]
Get:2 http://pl.archive.ubuntu.com/ubuntu noble-updates/main amd64 curl amd64 8.5.0-2ubuntu10.4 [227 kB]
Get:3 http://pl.archive.ubuntu.com/ubuntu noble/universe amd64 jose amd64 13-1 [48.8 kB]
Get:4 http://pl.archive.ubuntu.com/ubuntu noble/universe amd64 libpwquality-tools amd64 1.4.5-3build1 [9838 B]
Get:5 http://pl.archive.ubuntu.com/ubuntu noble/universe amd64 libluksmeta0 amd64 9-4 [8042 B]
Get:6 http://pl.archive.ubuntu.com/ubuntu noble/universe amd64 luksmeta amd64 9-4 [12.6 kB]
Get:7 http://pl.archive.ubuntu.com/ubuntu noble/universe amd64 clevis amd64 20-1 [24.2 kB]
Get:8 http://pl.archive.ubuntu.com/ubuntu noble/universe amd64 clevis-luks amd64 20-1 [24.6 kB]
Get:9 http://pl.archive.ubuntu.com/ubuntu noble/universe amd64 clevis-initramfs amd64 20-1 [6166 B]
Get:10 http://pl.archive.ubuntu.com/ubuntu noble-updates/main amd64 libtss2-fapi1t64 amd64 4.0.1-7.1ubuntu5.1 [315 kB]
Get:11 http://pl.archive.ubuntu.com/ubuntu noble/universe amd64 tpm2-tools amd64 5.6-1build4 [737 kB]
Get:12 http://pl.archive.ubuntu.com/ubuntu noble/universe amd64 clevis-tpm2 amd64 20-1 [7472 B]
Fetched 1465 kB in 1s (2556 kB/s)
Selecting previously unselected package libjose0:amd64.
(Reading database ... 152017 files and directories currently installed.)
Preparing to unpack .../00-libjose0_13-1_amd64.deb ...
Unpacking libjose0:amd64 (13-1) ...
Selecting previously unselected package curl.
Preparing to unpack .../01-curl_8.5.0-2ubuntu10.4_amd64.deb ...
Unpacking curl (8.5.0-2ubuntu10.4) ...
Selecting previously unselected package jose.
Preparing to unpack .../02-jose_13-1_amd64.deb ...
Unpacking jose (13-1) ...
Selecting previously unselected package libpwquality-tools.
Preparing to unpack .../03-libpwquality-tools_1.4.5-3build1_amd64.deb ...
Unpacking libpwquality-tools (1.4.5-3build1) ...
Selecting previously unselected package libluksmeta0:amd64.
Preparing to unpack .../04-libluksmeta0_9-4_amd64.deb ...
Unpacking libluksmeta0:amd64 (9-4) ...
Selecting previously unselected package luksmeta.
Preparing to unpack .../05-luksmeta_9-4_amd64.deb ...
Unpacking luksmeta (9-4) ...
Selecting previously unselected package clevis.
Preparing to unpack .../06-clevis_20-1_amd64.deb ...
Unpacking clevis (20-1) ...
Selecting previously unselected package clevis-luks.
Preparing to unpack .../07-clevis-luks_20-1_amd64.deb ...
Unpacking clevis-luks (20-1) ...
Selecting previously unselected package clevis-initramfs.
Preparing to unpack .../08-clevis-initramfs_20-1_amd64.deb ...
Unpacking clevis-initramfs (20-1) ...
Selecting previously unselected package libtss2-fapi1t64:amd64.
Preparing to unpack .../09-libtss2-fapi1t64_4.0.1-7.1ubuntu5.1_amd64.deb ...
Unpacking libtss2-fapi1t64:amd64 (4.0.1-7.1ubuntu5.1) ...
Selecting previously unselected package tpm2-tools.
Preparing to unpack .../10-tpm2-tools_5.6-1build4_amd64.deb ...
Unpacking tpm2-tools (5.6-1build4) ...
Selecting previously unselected package clevis-tpm2.
Preparing to unpack .../11-clevis-tpm2_20-1_amd64.deb ...
Unpacking clevis-tpm2 (20-1) ...
Setting up libpwquality-tools (1.4.5-3build1) ...
Setting up libjose0:amd64 (13-1) ...
Setting up jose (13-1) ...
Setting up curl (8.5.0-2ubuntu10.4) ...
Setting up libtss2-fapi1t64:amd64 (4.0.1-7.1ubuntu5.1) ...
Setting up libluksmeta0:amd64 (9-4) ...
Setting up tpm2-tools (5.6-1build4) ...
Setting up luksmeta (9-4) ...
Setting up clevis (20-1) ...
Setting up clevis-tpm2 (20-1) ...
Setting up clevis-luks (20-1) ...
Setting up clevis-initramfs (20-1) ...
Processing triggers for man-db (2.12.0-4build2) ...
Processing triggers for initramfs-tools (0.142ubuntu25.1) ...
update-initramfs: Generating /boot/initrd.img-6.8.0-48-generic
Processing triggers for libc-bin (2.39-0ubuntu8.3) ...

В процессе установки initramfs уже был обновлен, поэтому нам не нужно обновлять его вручную.

Идентифицируйте зашифрованное устройство.

lsblk --exclude 7
NAME                         MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINTS
nvme0n1                      259:0    0 476,9G  0 disk
├─nvme0n1p1                  259:1    0   512M  0 part  /boot/efi
├─nvme0n1p2                  259:2    0   488M  0 part  /boot
└─nvme0n1p3                  259:3    0   476G  0 part
└─nvme0n1p3_crypt          253:0    0 475,9G  0 crypt
├─notebook--1--vg-root   253:1    0   475G  0 lvm   /var/lib/containers/storage/overlay
│                                                   /
└─notebook--1--vg-swap_1 253:2    0   980M  0 lvm   [SWAP]

Изучите информацию заголовка LUKS, чтобы найти пустые слоты для ключей.

м $ sudo cryptsetup luksDump /dev/nvme0n1p3 
LUKS header information
Version:        2
Epoch:          3
Metadata area:  16384 [bytes]
Keyslots area:  16744448 [bytes]
UUID:           ba33dfdb-a549-4a33-b91f-35b8311e9e43
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:      argon2id
        Time cost:  9
        Memory:     1048576
        Threads:    4
        Salt:       16 4a 51 ca 09 43 61 03 6c 73 ab 24 f9 88 10 53 
                    61 d9 f2 52 4e 71 a8 22 1a 74 08 a6 42 61 27 1b 
        AF stripes: 4000
        AF hash:    sha256
        Area offset:32768 [bytes]
        Area length:258048 [bytes]
        Digest ID:  0
Tokens:
Digests:
  0: pbkdf2
        Hash:       sha256
        Iterations: 241830
        Salt:       83 af d1 31 40 3e b1 05 41 59 ab 38 c9 8b 8a cf 
                    71 db 40 08 cf 1f 90 ee 93 88 66 ab 28 1a 47 03 
        Digest:     fa 66 24 5b 53 16 eb ab 6b 5b a7 fc ee d7 81 92 
                    15 7d 67 8f 27 8f 45 c6 b4 15 1c 36 ba 4c bd 43 [/simterm]

Добавьте дополнительный ключ.

sudo cryptsetup luksAddKey --key-slot 31 /dev/nvme0n1p3
WARNING: The --key-slot parameter is used for new keyslot number.
Enter any existing passphrase:
Enter new passphrase for key slot: ***********
Verify passphrase:                 ***********

Отобразите информацию заголовка LUKS, чтобы подтвердить изменения.

sudo cryptsetup luksDump /dev/nvme0n1p3
LUKS header information
Version:        2
Epoch:          4
Metadata area:  16384 [bytes]
Keyslots area:  16744448 [bytes]
UUID:           ba33dfdb-a549-4a33-b91f-35b8311e9e43
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:      argon2id
Time cost:  9
Memory:     1048576
Threads:    4
Salt:       16 4a 51 ca 09 43 61 03 6c 73 ab 24 f9 88 10 53
61 d9 f2 52 4e 71 a8 22 1a 74 08 a6 42 61 27 1b
AF stripes: 4000
AF hash:    sha256
Area offset:32768 [bytes]
Area length:258048 [bytes]
Digest ID:  0
31: luks2
Key:        512 bits
Priority:   normal
Cipher:     aes-xts-plain64
Cipher key: 512 bits
PBKDF:      argon2id
Time cost:  9
Memory:     1048576
Threads:    4
Salt:       96 25 09 3e 71 08 eb 76 f4 bd 82 94 78 7b 1f 7f
c2 3b 8f 4c 00 52 a6 a9 54 2b 2f 38 27 2a b2 f9
AF stripes: 4000
AF hash:    sha256
Area offset:290816 [bytes]
Area length:258048 [bytes]
Digest ID:  0
Tokens:
Digests:
0: pbkdf2
Hash:       sha256
Iterations: 241830
Salt:       83 af d1 31 40 3e b1 05 41 59 ab 38 c9 8b 8a cf
71 db 40 08 cf 1f 90 ee 93 88 66 ab 28 1a 47 03
Digest:     fa 66 24 5b 53 16 eb ab 6b 5b a7 fc ee d7 81 92
15 7d 67 8f 27 8f 45 c6 b4 15 1c 36 ba 4c bd 43

Привязка устройства LUKS с помощью указанной политики.

sudo clevis luks bind -d /dev/nvme0n1p3 tpm2 '{"pcr_bank":"sha256"}'
Enter existing LUKS password: ***********

Список инстансов, привязанных к устройству LUKS.

sudo clevis luks list -d /dev/nvme0n1p3
1: tpm2 '{"hash":"sha256","key":"ecc"}'

Заголовок LUKS также будет содержать дополнительную информацию.

sudo cryptsetup luksDump /dev/nvme0n1p3
LUKS header information
Version:        2
Epoch:          14
Metadata area:  16384 [bytes]
Keyslots area:  16744448 [bytes]
UUID:           ba33dfdb-a549-4a33-b91f-35b8311e9e43
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:      argon2id
Time cost:  9
Memory:     1048576
Threads:    4
Salt:       16 4a 51 ca 09 43 61 03 6c 73 ab 24 f9 88 10 53
61 d9 f2 52 4e 71 a8 22 1a 74 08 a6 42 61 27 1b
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:      pbkdf2
Hash:       sha256
Iterations: 1000
Salt:       f0 1d f2 17 62 34 e3 76 ba 9b 9e 6c 2f b2 28 a5
93 39 15 03 1a 5a 53 4c 1e 39 70 4d a9 23 e0 57
AF stripes: 4000
AF hash:    sha256
Area offset:548864 [bytes]
Area length:258048 [bytes]
Digest ID:  0
31: luks2
Key:        512 bits
Priority:   normal
Cipher:     aes-xts-plain64
Cipher key: 512 bits
PBKDF:      argon2id
Time cost:  9
Memory:     1048576
Threads:    4
Salt:       96 25 09 3e 71 08 eb 76 f4 bd 82 94 78 7b 1f 7f
c2 3b 8f 4c 00 52 a6 a9 54 2b 2f 38 27 2a b2 f9
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: 241830
Salt:       83 af d1 31 40 3e b1 05 41 59 ab 38 c9 8b 8a cf
71 db 40 08 cf 1f 90 ee 93 88 66 ab 28 1a 47 03
Digest:     fa 66 24 5b 53 16 eb ab 6b 5b a7 fc ee d7 81 92
15 7d 67 8f 27 8f 45 c6 b4 15 1c 36 ba 4c bd 43

Перезагрузите операционную систему.

sudo reboot

Впоследствии вы можете отвязать определенный слот.

sudo clevis luks unbind -d /dev/nvme0n1p3 -s 1
The unbind operation will wipe a slot. This operation is unrecoverable.
Do you wish to erase LUKS slot 1 on /dev/nvme0n1p3? [ynYN] y
Enter any remaining passphrase: ***********

Дополнительные примечания

Этот процесс может быть применён как к операционным системам Debian, так и Ubuntu без изменений.

см. также:

Пожалуйста, не спамьте и никого не оскорбляйте. Это поле для комментариев, а не спамбокс. Рекламные ссылки не индексируются!
Добавить комментарий