容器安全 - 通过SECCOMP过滤在容器中的风险操作

OpenShift 4.x HOL教程汇总

通过SECCOMP过滤在容器中的风险操作

  1. 查看podman当前有关SECCOMP的配置
$ podman info | grep seccomp
    seccompEnabled: true
      libseccomp: 2.5.1
  1. 使用任意用户运行ubi镜像。
$ podman run -it registry.access.redhat.com/ubi7/ubi
  1. 在容器中执行命令,确认可以修改“/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
  1. 创建SECCOMP的策略文件,其中定义了缺省操作都是被允许的,但是通过“syscalls”定义过滤,"SCMP_ACT_ERRNO"阻止系统调用“fchmodat”。
$ cat << EOF > chmod.json
{
  "defaultAction": "SCMP_ACT_ALLOW",
  "syscalls": [
    {
      "name": "fchmodat",
      "action": "SCMP_ACT_ERRNO"
    }
  ]
}
EOF
  1. 运行ubi镜像,这次使用SECCOMP的策略文件。
$ podman run -it --security-opt seccomp=./chmod.json registry.access.redhat.com/ubi7/ubi
  1. 确认这次无法修改“/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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值