Open hoyho opened 5 years ago
如果在一个容器中(Mac 机器使用 remote-dev 的方式起了一个go开发容器)执行 sudo su 再去执行 unshare -u /bin/sh 还是会报错:unshare: unshare failed: Operation not permitted 这是为什么呢?
@chengyayu 如果在一个容器中(Mac 机器使用 remote-dev 的方式起了一个go开发容器)执行 sudo su 再去执行 unshare -u /bin/sh 还是会报错:unshare: unshare failed: Operation not permitted 这是为什么呢?
如果是说在容器里面执行的,由于unshare命令涉及到system call,是需要特权设置的(类似的比如mount等操作也会屏蔽)。container runtime即docker层应该会做限制所以会报权限问题。 可以在docker run的时候设置CAP_SYS_ADMIN
特权模式。 比如 docker run --privileged xxx
或者加--cap-add=SYS_ADMIN
如果是在kubernetes下启动的加上下面的参数:
containers:
- name: myapp
securityContext:
privileged: true
capabilities:
add: ["SYS_ADMIN"]
allowPrivilegeEscalation: true
image: your-img:v1.2.3
https://here2say.tw/35/
Hoyho's Blog,to record my coding life;D day