通过使用网络绑定磁盘加密(NBDE),无需手动输入密码即可打开加密磁盘。
从安全的角度来看,对敏感数据进行加密以保护其免受窥探和黑客的攻击是很重要的。Linux 统一密钥设置Linux Unified Key Setup(LUKS)是一个很好的工具,也是 Linux 磁盘加密的通用标准。因为它将所有相关的设置信息存储在分区头部中,所以它使数据迁移变得简单。
要使用 LUKS 配置加密磁盘或分区,你需要使用 cryptsetup 工具。不幸的是,加密磁盘的一个缺点是,每次系统重启或磁盘重新挂载时,你都必须手动提供密码。
然而,网络绑定磁盘加密Network-Bound Disk Encryption(NBDE) 可以在没有任何用户干预的情况下自动安全地解锁加密磁盘。它可以在一些 Linux 发行版中使用,包括从 Red Hat Enterprise Linux 7.4、CentOS 7.4 和 Fedora 24 开始,以及之后的后续版本。
NBDE 采用以下技术实现:
Clevis 框架:一个可插拔的框架工具,可自动解密和解锁 LUKS 卷 Tang 服务器:用于将加密密钥绑定到网络状态的服务Tang 向 Clevis 客户端提供加密密钥。据 Tang 的开发人员介绍,这为密钥托管服务提供了一个安全、无状态、匿名的替代方案。
由于 NBDE 使用客户端-服务器架构,你必须同时配置客户端和服务器。你可以在你的本地网络上使用一个虚拟机作为 Tang 服务器。
服务器安装
用 sudo 安装 Tang:
> sudoyum install tang –y启用 Tang 服务器:
> sudosystemctl enable tangd.socket —nowTang 服务器工作在 80 端口,需加入到 firewalld 防火墙。添加相应的 firewalld 规则:
> sudo firewall–cmd —add–port=tcp/80—perm sudo firewall–cmd —reload现在安装好了服务器。
客户端安装
在本例中,假设你已经添加了一个名为 /dev/vdc 的新的 1GB 磁盘到你的系统中。
使用 fdisk 或 parted 创建主分区:
> sudofdisk/dev/vdc完成以下步骤来安装客户端:
> Welcome to fdisk(util–linux 2.23.2). Changes will remain in memory only,until you decide to write them. Be careful before using the write command. Device does not contain a recognized partition table Building a new DOS disklabel with disk identifier 0x4a6812d4. Command(m for help):输入 n 来创建新的分区:
> Partition type: p primary (0 primary,0 extended,4 free) e extended Select(default p):按下回车键选择主分区:
> Usingdefault response p Partition number (1–4,default1):按下回车键选择默认分区号:
> First sector (2048–2097151,default2048): Usingdefault value 2048 Last sector,+sectors or+size{K,M,G}(2048–2097151,default2097151):按回车键选择最后一个扇区:
> Usingdefault value 2097151 Partition1 of type Linuxand of size1023MiBisset Command(m for help): wq输入 wq 保存更改并退出 fdisk:
> The partition table has been altered! Calling ioctl() to re–read partition table. Syncing disks.运行 partprobe 通知系统分区表的变化:
> sudo partprobe使用 sudo 安装 cryptsetup 软件包:
> sudoyum install cryptsetup –y使用 cryptsetup luksFormat 命令对磁盘进行加密。当提示时,你需要输入大写的 YES,并输入密码来加密磁盘:
> sudo cryptsetup luksFormat /dev/vdc1 WARNING! ======== This will overwrite data on /dev/vdc1 irrevocably. Are you sure?(Type uppercase yes): Enter passphrase for/dev/vdc1: Verify passphrase:使用 cryptsetup luksOpen 命令将加密的分区映射到一个逻辑设备上。例如,使用 encryptedvdc1 作为名称。你还需要再次输入密码:
> sudo cryptsetup luksOpen /dev/vdc1 encryptedvdc1 Enter passphrase for/dev/vdc1:加密分区现在在 /dev/mapper/encryptedvdc1 中可用。
在加密的分区上创建一个 XFS 文件系统:
> sudomkfs.xfs /dev/mapper/encryptedvdc1创建一个挂载加密分区的目录:
> sudomkdir/encrypted使用 cryptsetup luksClose 命令锁定分区:
> cryptsetup luksClose encryptedvdc1使用 sudo 安装 Clevis 软件包:
> sudoyum install clevis clevis–luks clevis–dracut –y修改 /etc/crypttab,在启动时打开加密卷:
> sudovim/etc/crypttab增加以下一行:
> encryptedvdc1 /dev/vdc1 none _netdev修改 /etc/fstab,在重启时或启动时自动挂载加密卷:
> sudovim/etc/fstab增加以下一行:
> /dev/mapper/encryptedvdc1 /encrypted xfs _netdev 12在这个例子中,假设 Tang 服务器的 IP 地址是 192.168.1.20。如果你喜欢,也可以使用主机名或域名。
运行以下 clevis 命令:
> sudo clevis bind luks –d /dev/vdc1 tang {“url”:”http://192.168.1.20″} The advertisement contains the following signing keys: rwA2BAITfYLuyNiIeYUMBzkhk7M Do you wish to trust these keys?[ynYN] Y Enter existing LUKS password:输入 Y 接受 Tang 服务器的密钥,并提供现有的 LUKS 密码进行初始设置。
通过 systemctl 启用 clevis-luks-askpass.path,以防止非根分区被提示输入密码。
> sudosystemctl enable clevis–luks–askpass.path客户端已经安装完毕。现在,每当你重启服务器时,加密后的磁盘应该会自动解密,并通过 Tang 服务器取回密钥进行挂载。
如果 Tang 服务器因为任何原因不可用,你需要手动提供密码,才能解密和挂载分区。