7.10. 为运行时监控配置 Keylime
要验证受监控系统状态是否正确,Keylime 代理必须运行在监控的系统上。
因为 Keylime 运行时监控使用完整性测量架构(IMA)来测量大量文件,所以可能会对系统性能产生重大影响。
在置备代理时,您还可以定义 Keylime 发送到被监控系统的文件。Keylime 对发送到代理的文件进行加密,只有在代理系统符合 TPM 策略并使用 IMA allowlist 时才解密。
您可以通过配置 Keylime excludelist 使 Keylime 忽略对特定文件或特定目录中文件的更改。排除的文件仍可由 IMA 进行测量。
从 RHEL 9.3 中提供的 Keylime 版本 7.3.0 开始,allowlis 和 excludelist 合并到 Keylime 运行时策略中。
前提条件
您有对配置了 Keylime 组件的系统的网络访问权限:
- 验证器
- 更多信息请参阅 第 7.2 节 “从软件包部署 Keylime 验证器”。
- 注册器
- 更多信息请参阅 第 7.4 节 “从软件包部署 Keylime 注册器”。
- 租户
- 更多信息请参阅 第 7.8 节 “从软件包部署 Keylime 租户”。
- Agent
- 更多信息请参阅 第 7.9 节 “从软件包部署 Keylime 代理”。
流程
在配置并运行 Keylime 代理的受监控系统中,安装
python3-keylime
软件包,其中包含keylime-policy
工具:Copy to Clipboard Copied! Toggle word wrap Toggle overflow dnf -y install python3-keylime
# dnf -y install python3-keylime
从代理系统的当前状态创建运行时策略:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow keylime-policy create runtime --ima-measurement --rootfs '/' --ramdisk-dir '/boot/' --output <policy.json>
# keylime-policy create runtime --ima-measurement --rootfs '/' --ramdisk-dir '/boot/' --output <policy.json>
在这个命令中,
-
将
<policy.json
> 替换为运行时策略的文件名。 以下目录会自动不包括在测量中:
-
/sys
-
/run
-
/proc
-
/lost+found
-
/dev
-
/media
-
/snap
-
/mnt
-
/var
-
/tmp
-
-
另外,您可以通过添加 a
-excludelist <excludelist.txt>
选项,从测量中排除其他特定路径。excludelist 接受 Python 正则表达式,每行一个正则表达式。有关特殊字符的完整列表,请参阅 docs.python.org 中的正则表达式操作。
-
将
将生成的运行时策略复制到配置了
keylime_tenant
工具的系统中,例如:Copy to Clipboard Copied! Toggle word wrap Toggle overflow scp <policy.json> root@<tenant.ip>:/root/<policy.json>
# scp <policy.json> root@<tenant.ip>:/root/<policy.json>
在配置了 Keylime 租户的系统上,使用
keylime_tenant
工具置备代理:Copy to Clipboard Copied! Toggle word wrap Toggle overflow keylime_tenant --command add --targethost <agent_ip> --uuid <agent_uuid> --runtime-policy <policy.json> --cert default
# keylime_tenant --command add --targethost <agent_ip> --uuid <agent_uuid> --runtime-policy <policy.json> --cert default
-
将
<agent_ip>
替换为代理的 IP 地址。 -
将
<agent_uuid>
替换为代理的 UUID。 -
将
<policy.json>
替换为 Keylime 运行时策略文件的路径。 使用
--cert
选项时,租户通过使用指定目录或默认的/var/lib/keylime/ca/
目录中的 CA 证书和密钥为代理生成和签名证书。如果目录不包含 CA 证书和密钥,则租户将根据/etc/keylime/ca.conf
文件中的配置自动生成它们,并将其保存到指定的目录中。然后,租户将这些密钥和证书发送给代理。在生成 CA 证书或签名代理证书时,可能会提示您输入访问 CA 私钥的密码:
Please enter the password to decrypt your keystore:
注意Keylime 对发送到代理的文件进行加密,只有在代理系统符合 TPM 策略和 IMA allowlist 时才解密该文件。默认情况下,Keylime 解压缩发送的
.zip
文件。
例如,使用以下命令,
keylime_tenant
在127.0.0.1
处添加一个新的 UUID 为d432fbb3-d2f1-4a97-9ef7-75bd81c00000
的 Keylime 代理,并加载运行时策略policy.json
。它还在默认目录中生成一个证书,并将证书文件发送给代理。只有满足/etc/keylime/verifier.conf
中的 TPM 策略才对文件进行解密:Copy to Clipboard Copied! Toggle word wrap Toggle overflow keylime_tenant --command add --targethost 127.0.0.1 --uuid d432fbb3-d2f1-4a97-9ef7-75bd81c00000 --runtime-policy policy.json --cert default
# keylime_tenant --command add --targethost 127.0.0.1 --uuid d432fbb3-d2f1-4a97-9ef7-75bd81c00000 --runtime-policy policy.json --cert default
注意您可以使用
# keylime_tenant --command delete --uuid < agent_uuid>
命令停止对节点监控 Keylime。您可以使用
keylime_tenant --command update
命令修改已注册代理的配置。-
将
验证
- 可选:重启被监控的系统,以验证设置是否持久。
验证代理是否成功:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow keylime_tenant --command cvstatus --uuid <agent.uuid>
# keylime_tenant --command cvstatus --uuid <agent.uuid> ... {"<agent.uuid>": {"operational_state": "Get Quote"..."attestation_count": 5 ...
将
<agent.uuid>
替换为代理的 UUID。如果
operational_state
的值为Get Quote
,并且attestation_count
为非零,则此代理的证明成功。如果
operational_state
的值为Invalid Quote
或Failed
,则验证失败,命令会显示类似如下的输出:Copy to Clipboard Copied! Toggle word wrap Toggle overflow {"<agent.uuid>": {"operational_state": "Invalid Quote", ... "ima.validation.ima-ng.not_in_allowlist", "attestation_count": 5, "last_received_quote": 1684150329, "last_successful_attestation": 1684150327}}
{"<agent.uuid>": {"operational_state": "Invalid Quote", ... "ima.validation.ima-ng.not_in_allowlist", "attestation_count": 5, "last_received_quote": 1684150329, "last_successful_attestation": 1684150327}}
如果验证失败,请在验证器日志中显示更多详细信息:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow journalctl --unit keylime_verifier
# journalctl --unit keylime_verifier keylime.tpm - INFO - Checking IMA measurement list... keylime.ima - WARNING - File not found in allowlist: /root/bad-script.sh keylime.ima - ERROR - IMA ERRORS: template-hash 0 fnf 1 hash 0 good 781 keylime.cloudverifier - WARNING - agent D432FBB3-D2F1-4A97-9EF7-75BD81C00000 failed, stopping polling
其他资源
- 有关 IMA 的更多信息,请参阅使用内核完整性子系统增强安全性。