0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

DISKを暗号化してTPMで自動複合

0
Posted at

Ubuntu 26 でDISKを暗号化して、マシンから外されたら読めないように設定する
通常起動時はTPMで自動複合するように設定

インストール時にDISKをLUKSで暗号化

インストール時のパーティション設定時に「暗号化」を選択しておく
マシンが壊れるとDISKを永遠によめなくなって困るので、パスフレーズを設定しておく
※パスフレーズはなるべく長く複雑に

セキュアブートが有効であること

セキュアブートが有効でないと意味ないので確認

# ツールインストール
sudo  apt  install  mokutil

# Secure Boot 確認
sudo  mokutil  --sb-state
    SecureBoot enabled

LUKS暗号化確認

DISKがLuks暗号化されていることを確認しておく

sudo  cryptsetup  luksDump  /dev/sda3
    LUKS header information
    Version:       	2

    Data segments:
      0: crypt

    Keyslots:
      0: luks2

LUKS2暗号化状態

TPM 確認

マザーボードにTPMが乗っていることを確認

# TPMツールをインストール
sudo  apt  install  tpm2-tools

# TPMデバイスの確認(表示があればTPMデバイスあり)
sudo  systemd-cryptenroll   --tpm2-device=list
    PATH        DEVICE     DRIVER 
    /dev/tpmrm0 IFX0785:00 tpm_tis

Luksの複合にTPM利用を設定

# PCR 0: ファームウェア状態(UEFI、BIOS)変更されてたらTPM複合しない
# PCR 7: Secure Boot の状態が変更されてたらTPM複合しない
sudo  systemd-cryptenroll  --tpm2-device=auto  --tpm2-pcrs=0+7  /dev/sda3

UEFIやBIOS変更などで無効になってしまって困る場合は PCR7 だけにしてもOK

または 7+14 も有用

変更する場合は、登録済みを削除してから再登録を

# 現在の 0+7 を削除
sudo  systemd-cryptenroll  --wipe-slot=tpm2  /dev/sda3

# 7+14 を再登録
# PCR 14: PCR7のセキュアブートが信頼に足る状態でなければTPM複合しない(PCR7強化)
sudo  systemd-cryptenroll  --tpm2-device=auto  --tpm2-pcrs=7+14  /dev/sda3
    🔐 Please enter current passphrase for disk /dev/sda3: •••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••   
    New TPM2 token enrolled as key slot 1.

Luks + TPM 確認

# パスフレーズとTPM2 で設定
sudo systemd-cryptenroll /dev/sda3
    SLOT TYPE    
       0 password
       1 tpm2

# もっと詳細に
sudo  cryptsetup  luksDump  /dev/sda3
    LUKS header information
    Version:       	2
    
    Data segments:
      0: crypt
    
    Keyslots:
      0: luks2
        	PBKDF:      argon2id
      
      1: luks2
        	PBKDF:      pbkdf2
    
    Tokens:
      0: systemd-tpm2
    	tpm2-hash-pcrs:   7+14

PCRS 7+14 で設定されている

PCR確認

sudo  systemd-analyze  pcrs
    NR NAME                SHA256 
     0 platform-code       a4f9ccc4ddb58c6894106c
     1 platform-config     b9a0f360fefb5f0cf62411
     2 external-code       f013d74ae44f47b72f00c5
     3 external-config     3d458cfe55cc03ea1f443f
     4 boot-loader-code    2bbf53d070d4449c00c3c1
     5 boot-loader-config  0087ee5d19a13926306954
     6 host-platform       3d458cfe55cc03ea1f443f
     7 secure-boot-policy  78f6a39cc3d3e0ac321a8d
     8 -                   d07784e08d0f48b798e933
     9 kernel-initrd       ffc8aee4764abc34a2480a
    10 ima                 e0d0e657c440c7a95a9dc5
    11 kernel-boot         9d020013962e974f931a04
    12 kernel-config       857518dda246a40c39ea5d
    13 sysexts             c8df51c75e14a9fcf9a723
    14 shim-policy         306f9d8b94f17d93dc6e7c
    15 system-identity     59f3c9c04c150619b43367
    16 debug               681d4f51da825d852d6956
    17 -                   ffffffffffffffffffffff
    18 -                   ffffffffffffffffffffff
    19 -                   ffffffffffffffffffffff
    20 -                   ffffffffffffffffffffff
    21 -                   ffffffffffffffffffffff
    22 -                   ffffffffffffffffffffff
    23 application-support eec8df51c75e14a9fcf9a7

起動時にTPM複合利用を設定

/etc/crypttab
# 修正前
dm_crypt-0 UUID=xxxx-xxxx none luks

# 修正後
dm_crypt-0 UUID=xxxx-xxxx none luks,tpm2-device=auto

「 ,tpm2-device=auto 」 を追加

起動イメージの更新(initramfs)

sudo  update-initramfs  -u

以上、再起動して自動複合されることを確認!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?