当我以交互模式运行 docker 脚本时,它可以工作。我可以在控制台和 AWS CloudWatch Logs 中看到日志。下面的 docker 脚本以交互模式运行,我添加了 awslogs 配置,因此日志进入 cloudwatch。docker awslogs 配置
docker run --rm -i -t --log-driver awslogs \
--log-opt awslogs-region=us-east-1 \
--log-opt awslogs-group=falcoint \
--log-opt awslogs-create-group=true \
--privileged \
-v /dev:/host/dev \
-v /proc:/host/proc:ro \
-v /boot:/host/boot:ro \
-v /lib/modules:/host/lib/modules:ro \
-v /usr:/host/usr:ro \
-v /etc:/host/etc:ro \
falcosecurity/falco:latest
但是,一旦我在-d分离模式下运行,所有日志都不会进入 aws cloudwatch
docker run --rm -d --log-driver awslogs \
--log-opt awslogs-region=us-east-1 \
--log-opt awslogs-group=falcoint \
--log-opt awslogs-create-group=true \
--privileged \
-v /dev:/host/dev \
-v /proc:/host/proc:ro \
-v /boot:/host/boot:ro \
-v /lib/modules:/host/lib/modules:ro \
-v /usr:/host/usr:ro \
-v /etc:/host/etc:ro \
falcosecurity/falco:latest
当我在前台模式下运行相同的脚本时,即 no -it 或 -d 也没有日志发送到 cloudwatch。但是当 falco docker 停止时,所有数据都会被缓冲和发送。
docker run --rm --log-driver awslogs \
--log-opt awslogs-region=us-east-1 \
--log-opt awslogs-group=falcoint \
--log-opt awslogs-create-group=true \
--privileged \
-v /dev:/host/dev \
-v /proc:/host/proc:ro \
-v /boot:/host/boot:ro \
-v /lib/modules:/host/lib/modules:ro \
-v /usr:/host/usr:ro \
-v /etc:/host/etc:ro \
falcosecurity/falco:latest
当 falco docker 停止时,它将以下内容转储到日志中。理想情况下,带有“错误文件在下面创建...”的日志应该已经到达 CloudWatch Logs,而无需停止容器。
2020-06-04T02:33:44+0000: SIGINT received, exiting...
Syscall event drop monitoring:
- event drop detected: 0 occurrences
- num times actions taken: 0
2020-06-04T02:32:32.495581404+0000: Notice A shell was spawned in a container with an attached terminal (user=root <NA> (id=01ca7b2306b5) shell=sh parent=runc cmdline=sh terminal=34816 container_id=01ca7b2306b5 image=<NA>)
2020-06-04T02:33:00.014981252+0000: Error File created below /dev by untrusted program (user=root command=touch /dev/rootkit2 file=/dev/rootkit2 container_id=01ca7b2306b5 image=<NA>)
2020-06-04T02:33:30.226554205+0000: Error File created below /dev by untrusted program (user=root command=touch /dev/rootkit3 file=/dev/rootkit3 container_id=01ca7b2306b5 image=<NA>)
Events detected: 3
Rule counts by severity:
ERROR: 2
NOTICE: 1
Triggered rules by rule name:
Terminal shell in container: 1
Create files below dev: 2
要重现问题,请运行上述之一和另一个终端运行
docker run -it node:8-alpine sh
然后登录容器并运行
touch /dev/rootkit
更新:
我注意到,当我使用-d -t Logs 运行 docker 以转到 aws Cloudwatch 日志时。知道为什么会这样吗?