This document describes how you can use BPFContain to confine Docker containers.
- Start BPFContain
- Launch a Docker container
- Apply a policy to the Docker container
- Enforce policy rules on the Docker container
Note that implicitly the container receives access to any filesystem it mounts
name: docker-device
allow:
- dev: terminal
name: docker-server
allow:
- dev: terminal
- net: [server, send, recv]
Launch container
docker run -it busybox
Get container pid
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
7d109859d884 busybox "sh" 17 seconds ago Up 16 seconds
sudo docker inspect 7d109859d884 --format '{{.State.Pid}}'
15292
Apply policy to the container
bpfcontain confine 15292 device.yml
Launch container
docker run -p 9000:9000 -it python bash
Get container pid
docker ps
CONTAINER ID IMAGE COMMAND PORTS
2034ead7c760 python "bash" 0.0.0.0:9000->9000/tcp,:::9000->9000/tcp
sudo docker inspect 2034ead7c760 --format '{{.State.Pid}}'
21377
Apply policy to the container
bpfcontain confine 21377 server.yml
Start python web server
python -m http.server 9000