8.9. 在测试时为测量的引导部署主精简

当您为测量的引导验证配置 Keylime 时,Keylime 会检查测量系统上的引导过程是否与您定义的状态相符。

前提条件

流程

  1. 在配置并运行 Keylime 代理的监控系统上,安装 python3-keylime 软件包,其包含 create_mb_refstate 脚本:

    # dnf -y install python3-keylime
  2. 在被监控的系统上,使用 create_mb_refstate 脚本从系统当前状态的测量引导日志中生成一个策略:

    # /usr/share/keylime/scripts/create_mb_refstate /sys/kernel/security/tpm0/binary_bios_measurements <./measured_boot_reference_state.json>

    <./measured_boot_reference_state.json> 替换为保存所生成的策略的路径。

    重要

    使用 create_mb_refstate 脚本生成的策略基于系统的当前状态,非常严格。任何系统修改,包括内核更新和系统更新都会更改引导过程,系统就会失败。

  3. 将生成的策略复制到配置了 keylime_tenant 工具的系统上,例如:

    # scp root@<agent_ip>:<./measured_boot_reference_state.json> <./measured_boot_reference_state.json>
  4. 在配置了 Keylime 租户的系统上,使用 keylime_tenant 工具置备代理:

    # keylime_tenant -c add -t <agent_ip> -u <agent_uuid> --mb_refstate <./measured_boot_reference_state.json>
    • <agent_ip> 替换为代理的 IP 地址。
    • <agent_uuid> 替换为代理的 UUID。
    • <./measured_boot_reference_state.json> 替换为计算引导策略的路径。

    如果将测量引导与运行时监控结合起来进行配置,请在输入 keylime_tenant -c add 命令时提供这两个用例中的所有选项。

    注意

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

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

验证

  1. 重启被监控的系统,并验证代理是否成功:

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

    # journalctl -u keylime_verifier
    {"d432fbb3-d2f1-4a97-9ef7-75bd81c00000": {"operational_state": "Tenant Quote Failed", ... "last_event_id": "measured_boot.invalid_pcr_0", "attestation_count": 0, "last_received_quote": 1684487093, "last_successful_attestation": 0}}