Skip to content
An`s Weblog
Go back

Working with Docker Security

1. Thực hành Seccomp Profile (giới hạn system calls)

docker container run --rm -it alpine sh
whoami   # --> root
mount /dev/sda1 /tmp  # bị từ chối do profile seccomp mặc định
swapoff -a            # cũng bị từ chối
mkdir -p seccomp/profiles/chmod
cd seccomp/profiles/chmod
wget https://raw.githubusercontent.com/moby/moby/master/profiles/seccomp/default.json
docker container run --rm -it \
  --security-opt seccomp=./default.json \
  alpine sh
chmod +r /usr   # --> bị từ chối

2. Thực hành Capabilities

docker container run --rm -it alpine sh
mknod /dev/random2 c 1 8  # Thành công
docker container run --rm -it \
  --cap-drop=MKNOD \
  alpine sh
mknod /dev/random2 c 1 8  # --> Permission denied

Liệt kê các capabilities có thể add/drop: link tham khảo từ Docker docs.

3. Giới hạn CPU, Memory, Swap

docker container run -d --name resource-limits \
  --cpus=0.5 \
  --memory=512M \
  --memory-swap=1G \
  <dockerhub-user>/weather-app
docker container inspect resource-limits

4. Docker Bench for Security

docker container run --rm -it \
  --net host \
  --pid host \
  --userns host \
  --cap-add audit_control \
  -e DOCKER_CONTENT_TRUST=1 \
  -v /var/lib:/var/lib \
  -v /var/run/docker.sock:/var/run/docker.sock \
  -v /usr/lib/systemd:/usr/lib/systemd \
  -v /etc:/etc \
  --label docker-bench-security \
  docker/docker-bench-security

Tổng kết

Nội dungMục đích
Seccomp profileGiới hạn system calls
CapabilitiesBổ sung hoặc giảm bớt quyền root
Resource limitsGiới hạn CPU, Memory, Swap
Docker BenchĐánh giá bảo mật host Docker

Share this post:

Previous Post
Docker Content Trust
Next Post
Introduction to Docker Security