8.8. 部署对运行时监控的 Keylime

要验证受监控系统状态是否正确,Keylime 代理必须运行在监控的系统上。

重要

因为 Keylime 运行时监控使用完整性测量架构(IMA)来测量大量文件,所以可能会对系统性能产生重大影响。

在置备代理时,您还可以定义 Keylime 发送到被监控系统的文件。Keylime 对发送到代理的文件进行加密,只有在代理系统符合 TPM 策略并使用 IMA allowlist 时才解密。

您可以通过配置 Keylime excludelist 使 Keylime 忽略对特定文件或特定目录中文件的更改。

从 RHEL 9.3 中提供的 Keylime 版本 7.3.0 开始,allowlis 和 excludelist 合并到 Keylime 运行时策略中。

前提条件

流程

  1. 在配置并运行 Keylime 代理的受监控系统上,从系统的当前状态生成一个 allowlist:

    # /usr/share/keylime/scripts/create_allowlist.sh -o <allowlist.txt> -h sha256sum

    <allowlist.txt> 替换为 allowlist 的文件名。

    重要

    使用 SHA-256 哈希功能。SHA-1 不安全,在 RHEL 9 中已弃用。如需更多信息,请参阅 Red Hat Enterprise Linux 9 中的 SHA-1 弃用

  2. 将生成的 allowlist 复制到配置了 keylime_tenant 工具的系统中,例如:

    # scp <allowlist.txt> root@<tenant.ip>:/root/<allowlist.txt>
  3. 可选:您可以通过在租户系统上创建一个文件并输入要排除的文件和目录,来定义排除在 Keylime 测量之外的文件或目录列表。excludelist 接受 Python 正则表达式,每行一个正则表达式。有关特殊字符的完整列表,请参阅 docs.python.org 中的正则表达式操作。例如,要从 Keylime 测量中排除 /tmp/ 目录中的所有文件以及 /var/ 目录的一些子目录,请使用以下内容创建一个 /root/<excludelist.txt> 文件:

    /var/cache/.*
    /var/lock/.*
    /var/log/.*
    /var/run/.*
    /var/spool/.*
    /var/tmp/.*
    /tmp/.*

    在租户系统上保存 excludelist。

  4. 将 allowlist 和 excludelist 合并到 Keylime 运行时策略中:

    # keylime_create_policy -a <allowlist.txt> -e <excludelist.txt> -o <policy.json>
  5. 在配置了 Keylime 租户的系统上,使用 keylime_tenant 工具置备代理:

    # keylime_tenant -c add -t <agent_ip> -u <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:

      如果您不想使用证书,请使用 -f 选项,而不向代理发送文件。置备代理需要发送任何文件,即使是空文件。

      注意

      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 策略才对文件进行解密:

    # keylime_tenant -c add -t 127.0.0.1 -u d432fbb3-d2f1-4a97-9ef7-75bd81c00000 --cert default --runtime-policy policy.json
    注意

    您可以使用 # keylime_tenant -c delete -u <agent_uuid> 命令停止 Keylime 监控节点。

    您可以使用 keylime_tenant -c update 命令修改已注册的代理的配置。

验证

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

    # keylime_tenant -c cvstatus -u <agent.uuid>
    ...
    {"<agent.uuid>": {"operational_state": "Get Quote"..."attestation_count": 5
    ...

    <agent.uuid> 替换为代理的 UUID。

    如果 operational_state 的值为 Get Quote,并且 attestation_count 非零,则此代理的验证成功。

    如果 operational_state 的值为 Invalid QuoteFailed,则验证失败,命令会显示类似如下的输出:

    {"<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. 如果验证失败,请在验证器日志中显示更多详细信息:

    # journalctl -u 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

其他资源