文章目录
通过SECCOMP过滤在容器中的风险操作
- 查看podman当前有关SECCOMP的配置
$ podman info | grep seccomp
seccompEnabled: true
libseccomp: 2.5.1
- 使用任意用户运行ubi镜像。
$ podman run -it registry.access.redhat.com/ubi7/ubi
- 在容器中执行命令,确认可以修改“/etc/hosts”属性,然后退出容器。
[root@f785305238e7 /]# chmod 777 /etc/hosts
[root@f785305238e7 /]# ls -al /etc/hosts
-rwxrwxrwx. 1 root root 199 Nov 12 07:12 /etc/hosts
[root@f785305238e7 /]# exit
exit
- 创建SECCOMP的策略文件,其中定义了缺省操作都是被允许的,但是通过“syscalls”定义过滤,"SCMP_ACT_ERRNO"阻止系统调用“fchmodat”。
$ cat << EOF > chmod.json
{
"defaultAction": "SCMP_ACT_ALLOW",
"syscalls": [
{
"name": "fchmodat",
"action": "SCMP_ACT_ERRNO"
}
]
}
EOF
- 运行ubi镜像,这次使用SECCOMP的策略文件。
$ podman run -it --security-opt seccomp=./chmod.json registry.access.redhat.com/ubi7/ubi
- 确认这次无法修改“/etc/hosts”属性,即便是root用户也不能修改。
[root@4703a74ad176 /]# chmod 777 /etc/hosts
chmod: changing permissions of '/etc/hosts': Operation not permitted
参考
https://github.com/docker/labs/blob/master/security/seccomp/README.md