21.7. 使用 Podman 事件进行审核
在以前的版本中,必须连接到事件才能正确解释事件。例如,container-create 事件必须与 image-pull 事件相关联,以了解已使用了哪个镜像。container-create 事件也不包含所有数据,如安全设置、卷、挂载等。
从 Podman v4.4 开始,您可以直接从单个事件和 journald 条目中收集关于容器的所有相关信息。数据采用 JSON 格式,与 podman container inspect 命令相同,并包含容器的所有配置和安全设置。您可以配置 Podman 来附加容器检查数据以进行审核。
先决条件
-
container-tools元数据包已安装。
流程
修改
~/.config/containers/containers.conf文件,并将events_container_create_inspect_data=true选项添加到[engine]部分:cat ~/.config/containers/containers.conf [engine] events_container_create_inspect_data=true
$ cat ~/.config/containers/containers.conf [engine] events_container_create_inspect_data=trueCopy to Clipboard Copied! Toggle word wrap Toggle overflow 对于系统范围的配置,修改
/etc/containers/containers.conf或/usr/share/container/containers.conf文件。创建容器:
podman create registry.access.redhat.com/ubi8/ubi:latest
$ podman create registry.access.redhat.com/ubi8/ubi:latest 19524fe3c145df32d4f0c9af83e7964e4fb79fc4c397c514192d9d7620a36cd3Copy to Clipboard Copied! Toggle word wrap Toggle overflow 显示 Podman 事件:
使用
podman events命令:Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
--format "{{.ContainerInspectData}}"选项显示检查数据。 -
jq ".Config.CreateCommand"将 JSON 数据转换为更易读的格式,并显示podman create命令的参数。
-
使用
journalctl命令:Copy to Clipboard Copied! Toggle word wrap Toggle overflow podman events和journalctl命令的输出数据是一样的。