If I am running a container in privileged mode, does it have all the Kernel capabilities or do I need to add them separately?
相关问题
- Microk8s, MetalLB, ingress-nginx - How to route ex
- How do I change the storage class of existing pers
- Docker task in Azure devops won't accept "$(pw
- Use awslogs with kubernetes 'natively'
- Unable to run mariadb when mount volume
There is a good article covering from RedHat covering this
While docker container running as "root" has less privileges than root on host, it still may need hardening depending on your use case (using as your development environment vs shared production cluster)
Running in privileged mode indeed gives the container all capabilities. But it is good practice to always give a container the minimum requirements it needs If you look at Docker docs they also refer to this flag
You can give specific capabilities using
--cap-add
flag. Seeman 7 capabilities
for more info on those capabilities. The literal names can be used, e.g.--cap-add CAP_FOWNER
.As this post is high on google search rank I wanted to add information on why you never want to run a container using
--privileged
I am doing this on my laptop which has NVMe drives but it will work for any host.
First lets do something minor, to test the /proc file system
From the container:
OK did it change it for the container or for the host?
OOPS!, we can arbitrarily change the hosts kernel parameters. But this is just a DOS situation, lets see if we can collect privileged information from the parent host.
Lets walk the
/sys
tree and find the major minor number for the boot disk.Note: I have two NVMe drives and containers are running under LVM on another drive
OK lets make a device file in a location where the dbus rules won't auto scan.
OK, we can read the bootdisk, lets make a device file for one of the partitions. While we can't mount it as it will be open we can still use
dd
to copy it.OK lets mount it and see if our efforts worked!!!
So basically any container host that you allow anyone to launch a
--privileged
container on is the same as giving them root access to every container on that host.Unfortunately the docker project has chosen the trusted computing model, and outside of auth plugins there is no way to protect against this, so always error on the side of adding needed features vs. using
--privileged