搜索

7.9. 配置 Keylime 代理

download PDF

Keylime 代理是部署到被 Keylime 监控的所有系统的组件。

默认情况下,Keylime 代理将其所有数据保存在被监控系统的 /var/lib/keylime/ 目录中。

注意

要将配置文件保留在置入目录中,请使用具有两位数字前缀的文件名,例如 /etc/keylime/agent.conf.d/00-registrar-ip.conf。配置处理以字典顺序读取置入目录中的文件,并对每个选项设置为它读取的最后一个值。

前提条件

  • 您有对被监控系统的 root 权限。
  • 监控的系统有一个受信任的平台模块(TPM)。要验证,请输入 tpm2_pcrread 命令。如果输出返回多个哈希,则代表 TPM 可用。
  • 您对配置了其他 Keylime 组件的系统有网络访问权限:

    验证器
    如需更多信息,请参阅 配置 Keylime 验证器
    注册器
    如需更多信息,请参阅 配置 Keylime 注册器
    租户
    如需更多信息,请参阅 配置 Keylime 租户
  • 在监控的系统上启用了完整性测量架构(IMA)。如需更多信息,请参阅 启用完整性测量架构和扩展验证模块

流程

  1. 安装 Keylime 代理:

    # dnf install keylime-agent

    这个命令会安装 keylime-agent-rust 软件包。

  2. 在配置文件中定义代理的 IP 地址和端口。在 /etc/keylime/agent.conf.d/ 目录中创建一个新的 .conf 文件,例如:/etc/keylime/agent.conf.d/00-agent-ip.conf,其内容如下:

    [agent]
    ip = '<agent_ip>'
    注意

    Keylime 代理配置使用 TOML 格式,它与用于其他组件配置的 INI 格式不同。因此,使用有效 TOML 语法输入值,例如,在带单引号的路径以及带方括号的多个路径的数组。

    • <agent_IP_address> 替换为代理的 IP 地址。或者,使用 ip = '*'ip = '0.0.0.0' 将代理绑定到所有可用 IP 地址。
    • 另外,您还可以使用 port = '<agent_port>' 选项更改代理端口的默认值 9002
  3. 在配置文件中定义注册的 IP 地址和端口。在 /etc/keylime/agent.conf.d/ 目录中创建一个新的 .conf 文件,例如: /etc/keylime/agent.conf.d/00-registrar-ip.conf,其内容如下:

    [agent]
    registrar_ip = '<registrar_IP_address>'
    • <registrar_IP_address> 替换为注册中心的 IP 地址。
    • 另外,您还可以使用 registrar_port = '<registrar_port>' 选项更改注册器端口的默认值 8890
  4. 可选:定义代理的通用唯一标识符(UUID)。如果没有定义,则使用默认 UUID。在 /etc/keylime/agent.conf.d/ 目录中创建一个新的 .conf 文件,例如:/etc/keylime/agent.conf.d/00-agent-uuid.conf,其内容如下:

    [agent]
    uuid = '<agent_UUID>'
    • <agent_UUID> 替换为代理的 UUID,如 d432fbb3-d2f1-4a97-9ef7-abcdef012345。您可以使用 uuidgen 工具生成 UUID。
  5. 可选:加载代理的现有密钥和证书。如果代理没有接收 server_keyserver_cert,它会生成自己的密钥和自签名证书。

    在配置中定义密钥和证书的位置。在 /etc/keylime/agent.conf.d/ 目录中创建一个新的 .conf 文件,例如: /etc/keylime/agent.conf.d/00-keys-and-certs.conf,其内容如下:

    [agent]
    server_key = '</path/to/server_key>'
    server_key_password = '<passphrase1>'
    server_cert = '</path/to/server_cert>'
    trusted_client_ca = '[</path/to/ca/cert3>, </path/to/ca/cert4>]'
    注意

    使用绝对路径定义密钥和证书位置。Keylime 代理不接受相对路径。

  6. 在防火墙中打开端口:

    # firewall-cmd --add-port 9002/tcp
    # firewall-cmd --runtime-to-permanent

    如果您使用不同的端口,请将 9002 替换为 .conf 文件中定义的端口号。

  7. 启用并启动 keylime_agent 服务:

    # systemctl enable --now keylime_agent
  8. 可选:在配置了 Keylime 租户的系统中,验证代理是否已正确配置,并可以连接到注册器。

    # keylime_tenant -c regstatus --uuid <agent_uuid>
    Reading configuration from ['/etc/keylime/logging.conf']
    ...
    ==\n-----END CERTIFICATE-----\n", "ip": "127.0.0.1", "port": 9002, "regcount": 1, "operational_state": "Registered"}}}
    • <agent_uuid> 替换为代理的 UUID。

      如果正确配置了注册器和代理,输出会显示代理的 IP 地址和端口,后跟 "operational_state":"Registered"

  9. 通过在 /etc/ima/ima-policy 文件中输入以下内容来创建新的 IMA 策略:

    # PROC_SUPER_MAGIC = 0x9fa0
    dont_measure fsmagic=0x9fa0
    # SYSFS_MAGIC = 0x62656572
    dont_measure fsmagic=0x62656572
    # DEBUGFS_MAGIC = 0x64626720
    dont_measure fsmagic=0x64626720
    # TMPFS_MAGIC = 0x01021994
    dont_measure fsmagic=0x1021994
    # RAMFS_MAGIC
    dont_measure fsmagic=0x858458f6
    # DEVPTS_SUPER_MAGIC=0x1cd1
    dont_measure fsmagic=0x1cd1
    # BINFMTFS_MAGIC=0x42494e4d
    dont_measure fsmagic=0x42494e4d
    # SECURITYFS_MAGIC=0x73636673
    dont_measure fsmagic=0x73636673
    # SELINUX_MAGIC=0xf97cff8c
    dont_measure fsmagic=0xf97cff8c
    # SMACK_MAGIC=0x43415d53
    dont_measure fsmagic=0x43415d53
    # NSFS_MAGIC=0x6e736673
    dont_measure fsmagic=0x6e736673
    # EFIVARFS_MAGIC
    dont_measure fsmagic=0xde5e81e4
    # CGROUP_SUPER_MAGIC=0x27e0eb
    dont_measure fsmagic=0x27e0eb
    # CGROUP2_SUPER_MAGIC=0x63677270
    dont_measure fsmagic=0x63677270
    # OVERLAYFS_MAGIC
    # when containers are used we almost always want to ignore them
    dont_measure fsmagic=0x794c7630
    # MEASUREMENTS
    measure func=BPRM_CHECK
    measure func=FILE_MMAP mask=MAY_EXEC
    measure func=MODULE_CHECK uid=0

    此策略针对已执行的应用程序的运行时监控。您可以根据您的场景调整此策略。您可以在 statfs (2) 手册页中找到 MAGIC 常量。

  10. 更新内核参数:

    # grubby --update-kernel DEFAULT --args 'ima_appraise=fix ima_canonical_fmt ima_policy=tcb ima_template=ima-ng'
  11. 重启系统以应用新的 IMA 策略。

验证

  1. 验证代理是否正在运行:

    # systemctl status keylime_agent
    ● keylime_agent.service - The Keylime compute agent
         Loaded: loaded (/usr/lib/systemd/system/keylime_agent.service; enabled; preset: disabled)
         Active: active (running) since ...

后续步骤

在您要监控的所有系统上配置了代理后,您可以部署 Keylime 来执行以下一个或多个功能:

Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

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

让开源更具包容性

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

關於紅帽

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

© 2024 Red Hat, Inc.