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 运行时策略中。

前提条件

流程

  1. 在配置并运行 Keylime 代理的受监控系统中,安装 python3-keylime 软件包,其中包含 keylime-policy 工具:

    Copy to Clipboard Toggle word wrap
    # dnf -y install python3-keylime
  2. 从代理系统的当前状态创建运行时策略:

    Copy to Clipboard Toggle word wrap
    # 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 中的正则表达式操作
  3. 将生成的运行时策略复制到配置了 keylime_tenant 工具的系统中,例如:

    Copy to Clipboard Toggle word wrap
    # scp <policy.json> root@<tenant.ip>:/root/<policy.json>
  4. 在配置了 Keylime 租户的系统上,使用 keylime_tenant 工具置备代理:

    Copy to Clipboard Toggle word wrap
    # 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_tenant127.0.0.1 处添加一个新的 UUID 为 d432fbb3-d2f1-4a97-9ef7-75bd81c00000 的 Keylime 代理,并加载运行时策略 policy.json。它还在默认目录中生成一个证书,并将证书文件发送给代理。只有满足 /etc/keylime/verifier.conf 中的 TPM 策略才对文件进行解密:

    Copy to Clipboard Toggle word wrap
    # 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 命令修改已注册代理的配置。

验证

  1. 可选:重启被监控的系统,以验证设置是否持久。
  2. 验证代理是否成功:

    Copy to Clipboard Toggle word wrap
    # 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 QuoteFailed,则验证失败,命令会显示类似如下的输出:

    Copy to Clipboard Toggle word wrap
    {"<agent.uuid>": {"operational_state": "Invalid Quote", ... "ima.validation.ima-ng.not_in_allowlist", "attestation_count": 5, "last_received_quote": 1684150329, "last_successful_attestation": 1684150327}}
  3. 如果验证失败,请在验证器日志中显示更多详细信息:

    Copy to Clipboard Toggle word wrap
    # 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

其他资源

返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat, Inc.