Skip to content

Commit c8f156b

Browse files
authored
Merge pull request #2 from dash14/harden/replace-privileged-with-cap-add
Replace privileged: true with minimum required capabilities
2 parents 8390181 + 8a5af1f commit c8f156b

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.DS_Store

compose.yml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,28 @@ services:
33
build:
44
context: docker
55
dockerfile: Dockerfile
6-
privileged: true
6+
# Instead of privileged: true, grant only the minimum privileges required
7+
# to run BuildKit and iptables. This avoids granting full device access
8+
# and unrestricted /sys write permissions that privileged mode includes.
9+
#
10+
# BuildKit OCI worker requires SYS_ADMIN for mount, namespaces, and cgroups.
11+
# iptables and CNI networking require NET_ADMIN.
12+
# runc needs SYS_PTRACE to access /proc/PID/ns/mnt for mount namespace setup.
13+
cap_add:
14+
- SYS_ADMIN
15+
- NET_ADMIN
16+
- SYS_PTRACE
17+
# BuildKit/runc needs syscalls (mount, unshare, pivot_root) blocked by
18+
# default seccomp and AppArmor profiles.
19+
security_opt:
20+
- seccomp=unconfined
21+
- apparmor=unconfined
22+
# Share the host's cgroup namespace so BuildKit can manage cgroups for
23+
# build containers. The volume mount makes /sys/fs/cgroup writable
24+
# (read-only by default in non-privileged containers).
25+
cgroup: host
26+
volumes:
27+
- /sys/fs/cgroup:/sys/fs/cgroup:rw
728
ports:
829
- "${PORT:-1234}:1234"
930
environment:

setup/compose.yml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,28 @@
11
services:
22
builder:
33
image: ${BUILDCAGE_IMAGE}:${BUILDCAGE_VERSION:-1}
4-
privileged: true
4+
# Instead of privileged: true, grant only the minimum privileges required
5+
# to run BuildKit and iptables. This avoids granting full device access
6+
# and unrestricted /sys write permissions that privileged mode includes.
7+
#
8+
# BuildKit OCI worker requires SYS_ADMIN for mount, namespaces, and cgroups.
9+
# iptables and CNI networking require NET_ADMIN.
10+
# runc needs SYS_PTRACE to access /proc/PID/ns/mnt for mount namespace setup.
11+
cap_add:
12+
- SYS_ADMIN
13+
- NET_ADMIN
14+
- SYS_PTRACE
15+
# BuildKit/runc needs syscalls (mount, unshare, pivot_root) blocked by
16+
# default seccomp and AppArmor profiles.
17+
security_opt:
18+
- seccomp=unconfined
19+
- apparmor=unconfined
20+
# Share the host's cgroup namespace so BuildKit can manage cgroups for
21+
# build containers. The volume mount makes /sys/fs/cgroup writable
22+
# (read-only by default in non-privileged containers).
23+
cgroup: host
24+
volumes:
25+
- /sys/fs/cgroup:/sys/fs/cgroup:rw
526
ports:
627
- "${PORT:-1234}:1234"
728
environment:

0 commit comments

Comments
 (0)