第 5 章 加密 cinder 卷
您可以使用 barbican 来管理 Block Storage (cinder)加密密钥。此配置使用 LUKS 加密附加到您的实例的磁盘,包括引导磁盘。密钥管理对用户是透明的;当您使用 luks
作为加密类型创建新卷时,cinder 为卷生成对称密钥 secret,并将它存储在 barbican 中。引导实例时(或附加加密卷)时,nova 将密钥从 barbican 检索,并在本地存储为 Compute 节点上的 Libvirt secret。
Nova 会在其第一次使用时格式化加密卷(如果它们未加密)。然后,生成的块设备会提供给 Compute 节点。
如果您打算更新任何配置文件,请注意某些 OpenStack 服务现在在容器内运行;这适用于 keystone、nova 和 cinder 等。因此,有一些管理实践需要考虑:
-
不要更新您在物理节点的主机操作系统上找到的任何配置文件,例如:
/etc/cinder/cinder.conf
。容器化服务不引用此文件。 不要更新容器中运行的配置文件。重新启动容器后,更改将会丢失。
相反,如果您必须更改容器化服务,请更新
/var/lib/config-data/puppet-generated/
中的配置文件,该配置文件用于生成容器。例如:
-
keystone:
/var/lib/config-data/puppet-generated/keystone/etc/keystone/keystone.conf
-
cinder:
/var/lib/config-data/puppet-generated/cinder/etc/cinder/cinder.conf
nova:
/var/lib/config-data/puppet-generated/nova_libvirt/etc/nova/nova.conf
在重启容器后,会应用更改。
在运行
cinder-volume
和nova-compute
服务的节点上,确认 nova 和 cinder 都配置为使用 barbican 进行密钥管理:$ crudini --get /var/lib/config-data/puppet-generated/cinder/etc/cinder/cinder.conf key_manager backend castellan.key_manager.barbican_key_manager.BarbicanKeyManager $ crudini --get /var/lib/config-data/puppet-generated/nova_libvirt/etc/nova/nova.conf key_manager backend castellan.key_manager.barbican_key_manager.BarbicanKeyManager
创建使用加密的卷模板。当您创建新卷时,它们可以从您在这里定义的设置中建模:
$ openstack volume type create --encryption-provider nova.volume.encryptors.luks.LuksEncryptor --encryption-cipher aes-xts-plain64 --encryption-key-size 256 --encryption-control-location front-end LuksEncryptor-Template-256 +-------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Field | Value | +-------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | description | None | | encryption | cipher='aes-xts-plain64', control_location='front-end', encryption_id='9df604d0-8584-4ce8-b450-e13e6316c4d3', key_size='256', provider='nova.volume.encryptors.luks.LuksEncryptor' | | id | 78898a82-8f4c-44b2-a460-40a5da9e4d59 | | is_public | True | | name | LuksEncryptor-Template-256 | +-------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
创建新卷,并指定它使用
LuksEncryptor-Template-256
设置:注意确保创建加密的卷的用户在项目上具有
创建者
barbican 角色。如需更多信息,请参阅Grant 用户访问创建者角色
部分。$ openstack volume create --size 1 --type LuksEncryptor-Template-256 'Encrypted-Test-Volume' +---------------------+--------------------------------------+ | Field | Value | +---------------------+--------------------------------------+ | attachments | [] | | availability_zone | nova | | bootable | false | | consistencygroup_id | None | | created_at | 2018-01-22T00:19:06.000000 | | description | None | | encrypted | True | | id | a361fd0b-882a-46cc-a669-c633630b5c93 | | migration_status | None | | multiattach | False | | name | Encrypted-Test-Volume | | properties | | | replication_status | None | | size | 1 | | snapshot_id | None | | source_volid | None | | status | creating | | type | LuksEncryptor-Template-256 | | updated_at | None | | user_id | 0e73cb3111614365a144e7f8f1a972af | +---------------------+--------------------------------------+
生成的 secret 会自动上传到 barbican 后端。
使用 barbican 确认存在磁盘加密。在本例中,时间戳与 LUKS 卷创建时间匹配:
$ openstack secret list +------------------------------------------------------------------------------------+------+---------------------------+--------+-------------------------------------------+-----------+------------+-------------+------+------------+ | Secret href | Name | Created | Status | Content types | Algorithm | Bit length | Secret type | Mode | Expiration | +------------------------------------------------------------------------------------+------+---------------------------+--------+-------------------------------------------+-----------+------------+-------------+------+------------+ | https://192.168.123.169:9311/v1/secrets/24845e6d-64a5-4071-ba99-0fdd1046172e | None | 2018-01-22T02:23:15+00:00 | ACTIVE | {u'default': u'application/octet-stream'} | aes | 256 | symmetric | None | None | +------------------------------------------------------------------------------------+------+---------------------------+--------+-------------------------------------------+-----------+------------+-------------+------+------------+
将新卷附加到现有实例。例如:
$ openstack server add volume testInstance Encrypted-Test-Volume
然后,卷会呈现给客户端操作系统,并可使用内置工具挂载。
5.1. 将现有卷密钥迁移到 Barbican
在以前的版本中,部署可能已使用 ConfKeyManager
来管理磁盘加密密钥。这意味着生成了固定密钥,然后存储在 nova 和 cinder 配置文件中。可以使用以下步骤将密钥 ID 迁移到 barbican。这个工具适用于通过扫描范围中的 encryption_key_id
条目迁移到 barbican 来实现。每个条目获得一个新的 barbican 密钥 ID,并且保留现有的 ConfKeyManager
secret。
在以前的版本中,您可以使用 ConfKeyManager
来为加密的卷重新分配所有权。对于具有由 barbican 管理的密钥的卷来说,这不可能实现。
激活 barbican 不会破坏现有的 keymgr
卷。
启用后,迁移过程会自动运行,但需要一些配置,具体如下一节中所述。实际迁移在 cinder-volume
和 cinder-backup
进程中运行,您可以在 cinder 日志文件中跟踪进度。
-
cinder-volume
- 迁移存储在 Cinder 卷和快照表中的密钥。 -
cinder-backup
- 在备份表中迁移密钥。
5.1.1. 迁移步骤概述
- 部署 barbican 服务。
将
创建者
角色添加到 cinder 服务。例如:#openstack role create creator #openstack role add --user cinder creator --project service
-
重启
cinder-volume
和cinder-backup
服务。 -
cinder-volume
和cinder-backup
会自动开始迁移过程。 -
监控日志中的显示显示迁移完成的消息,并检查更多的卷是否使用
ConfKeyManager
all-zeros 加密密钥 ID。 -
从
cinder.conf
和nova.conf
删除fixed_key
选项。您必须确定哪个节点已经配置有此设置。 -
从 cinder 服务中删除
创建
者角色。
5.1.2. 行为差异
Barbican 管理的加密卷的行为与使用 ConfKeyManager
的卷不同:
- 您无法转让加密卷的所有权,因为目前无法传输 barbican secret 的所有权。
- Barbican 对允许读取和删除 secret 的限制更为严格的,可能会影响一些 Cinder 卷操作。例如,用户无法附加、分离或删除不同用户的卷。
5.1.3. 查看迁移过程
本节论述了如何查看迁移任务的状态。启动进程后,日志中会显示这些条目之一。这表明迁移是否正确启动,或者它识别了它遇到的问题:
-
没有迁移加密密钥,因为 ConfKeyManager 仍在使用。
-
没有迁移加密密钥,因为 ConfKeyManager 的 fixed_key 没有被使用。
-
不支持迁移加密密钥,因为迁移到 'XXX' key_manager 后端不被支持。
- 此消息不太可能出现 - 这个信息。它是一种安全检查,可以处理使用 barbican 以外的其他密钥管理器后端代码。这是因为代码只支持一个迁移场景: From ConfKeyManager to barbican。 -
没有迁移加密密钥,因为没有与此主机关联的卷。
- 当cinder-volume
在多个主机上运行时,特定主机没有关联任何卷。这是因为每个主机负责处理自己的卷。 -
开始迁移 ConfKeyManager 键。
将卷 <UUID> 加密密钥迁移到 Barbican
- 迁移期间,将检查所有主机的卷;如果卷仍在使用 ConfKeyManager 的密钥 ID (识别它的所有零事实(00000000-0000-0000-0000-0000-0000-00000000000000
0000000000),则会出现这个消息。-
对于
cinder-backup
,这个消息使用略有不同的大写:Migrating Volume [...]
或Migrating Backup [...]
-
对于
每个主机检查其所有卷后,主机会显示摘要状态信息:
`No volumes are using the ConfKeyManager's encryption_key_id.` `No backups are known to be using the ConfKeyManager's encryption_key_id.`
您可能还会看到以下条目:
使用 ConfKeyManager 的全零加密密钥 ID
请注意,这两个消息都可能会出现在仍然有 %d 卷。
仍然会使用 ConfKeyManager 的全零加密密钥 ID 来 %d 备份。cinder-volume
和cinder-backup
日志中。每个服务只处理其自身条目的迁移,但该服务知道了另一个状态。因此,cinder-volume
知道cinder-backup
仍然具有要迁移的备份,cinder-backup
知道cinder-volume
服务是否具有要迁移的卷。虽然每个主机仅迁移自己的卷,但摘要信息基于全局评估,确定是否有卷是否还需要迁移。收到确认后,从
cinder.conf
和nova.conf
中删除fixed_key
设置。如需更多信息,请参阅 清理下面的固定密钥 部分。
5.1.4. 对迁移过程进行故障排除
5.1.4.1. 角色分配
barbican secret 只能在 requestor 具有创建者角色时才会 创建
。这意味着 cinder 服务本身需要创建者角色,否则会出现类似以下内容的日志序列:
-
开始迁移 ConfKeyManager 键。
-
将卷 <UUID> 加密密钥迁移到 Barbican
-
迁移加密密钥时出错: Forbidden: Secret creationtries not allowed - 请检查您的用户/项目权限
-
ConfKeyManager 的 all-zeros 加密密钥 ID 仍存在 %d 卷。
关键信息是第三条: Secret 创建尝试没有被允许。
要解决这个问题,更新 cinder
帐户的权限:
-
运行
openstack role add --project service --user cinder creator
-
重启
cinder-volume
和cinder-backup
服务。
因此,迁移的下一次尝试应该会成功。
5.1.5. 清理固定密钥
encryption_key_id
最近仅添加到 Backup
表中,作为 Queens 发行版本的一部分。因此,已存在的加密卷备份可能会存在。all-zeros encryption_key_id
存储在备份本身中,但它不会出现在 备份
数据库中。因此,迁移过程无法了解某些加密卷的备份是否仍依赖于全零的 ConfKeyMgr
密钥 ID。
将密钥 ID 迁移到 barbican 后,固定的密钥将保留在配置文件中。这可能会对某些用户造成安全问题,因为 fixed_key
值没有在 .conf
文件中加密。要解决这个问题,您可以从 nova 和 cinder 配置中手动删除 fixed_key
值。但是,在进行前,首先完成测试并检查日志文件的输出,因为仍然依赖于此值的磁盘无法访问。
检查现有的
fixed_key
值。值必须与这两个服务匹配。crudini --get /var/lib/config-data/puppet-generated/cinder/etc/cinder/cinder.conf keymgr fixed_key crudini --get /var/lib/config-data/puppet-generated/nova_libvirt/etc/nova/nova.conf keymgr fixed_key
-
重要信息:备份现有的
fixed_key
值。这可让您在出现问题时恢复该值,或者需要恢复使用旧加密密钥的备份。 删除
fixed_key
值:crudini --del /var/lib/config-data/puppet-generated/cinder/etc/cinder/cinder.conf keymgr fixed_key crudini --del /var/lib/config-data/puppet-generated/nova_libvirt/etc/nova/nova.conf keymgr fixed_key