You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## Running BuildKit in Rootless mode (containerd worker)
29
30
30
31
[RootlessKit](https://github.com/rootless-containers/rootlesskit/) needs to be installed.
31
32
32
33
Run containerd in rootless mode using rootlesskit following [containerd's document](https://github.com/containerd/containerd/blob/main/docs/rootless.md).
Adding `--device /dev/fuse` to the `docker run` arguments is required only if you want to use `fuse-overlayfs` snapshotter.
77
+
> [!TIP]
78
+
> If you don't mind using `--privileged` (almost safe for rootless), the `docker run` flags can be shorten as follows:
79
+
>
80
+
>```bash
81
+
> docker run --name buildkitd -d --privileged moby/buildkit:rootless
82
+
>```
70
83
71
-
#### About `--oci-worker-no-process-sandbox`
84
+
Justification of the `--security-opt` flags:
72
85
73
-
By adding `--oci-worker-no-process-sandbox` to the `buildkitd` arguments, BuildKit can be executed in a container without adding `--privileged` to `docker run` arguments.
74
-
However, you still need to pass `--security-opt seccomp=unconfined --security-opt apparmor=unconfined` to `docker run`.
86
+
*`seccomp=unconfined`: For allowing several syscalls such as `unshare` (used by runc) and `mount` (used by snapshotters, etc).
75
87
76
-
Note that `--oci-worker-no-process-sandbox` allows build executor containers to `kill` (and potentially `ptrace` depending on the seccomp configuration) an arbitrary process in the BuildKit daemon container.
88
+
*`apparmor=unconfined`: For allowing mounting filesystems, etc.
89
+
This flag is not needed when the host operating system does not use AppArmor.
77
90
78
-
To allow running rootless `buildkitd` without `--oci-worker-no-process-sandbox`, run `docker run` with `--security-opt systempaths=unconfined`. (For Kubernetes, set `securityContext.procMount` to `Unmasked`.)
91
+
*`systempaths=unconfined`: For disabling the masks forthe `/proc` mountin the container, so that each of `ExecOp`
92
+
(corresponds to a `RUN` instruction in Dockerfile) can have a dedicated `/proc` filesystem.
93
+
`systempaths=unconfined` potentially allows reading and writing dangerous kernel files from a container, but it is safe when you are running `buildkitd` as non-root.
79
94
80
-
The `--security-opt systempaths=unconfined` flag disables the masks for the `/proc` mount in the container and potentially allows reading and writing dangerous kernel files, but it is safe when you are running `buildkitd` as non-root.
95
+
> [!TIP]
96
+
> Instead of `--security-opt systempaths=unconfined`, `buildkitd` can be also executed with `--oci-worker-no-process-sandbox` (flag of `buildkitd`, not `docker`)
97
+
> to avoid creating a new PID namespace and mounting a new `/proc`for it.
98
+
>
99
+
> Using `--oci-worker-no-process-sandbox` is discouraged, as it cannot terminate processes that did not exit during an `ExecOp`.
100
+
> Also, `--oci-worker-no-process-sandbox` allows `ExecOp` containers to `kill` (and potentially `ptrace` depending on the seccomp configuration) an arbitrary process in the BuildKit daemon container.
101
+
>
102
+
> Despite these caveats, the [Kubernetes examples](../examples/kubernetes) uses `--oci-worker-no-process-sandbox`, as Kubernetes lacks the equivalent of `systempaths=unconfined`.
103
+
> (`securityContext.procMount=Unmasked` is similar, but different in the sense that it depends on `hostUsers: false`)
81
104
82
105
### Change UID/GID
83
106
@@ -90,7 +113,7 @@ Actual ID (shown in the host and the BuildKit daemon container)| Mapped ID (show
90
113
... | ...
91
114
165535 | 65536
92
115
93
-
```
116
+
```console
94
117
$ docker exec buildkitd id
95
118
uid=1000(user) gid=1000(user)
96
119
$ docker exec buildkitd ps aux
@@ -99,15 +122,16 @@ PID USER TIME COMMAND
99
122
13 user 0:00 /proc/self/exe buildkitd --addr tcp://0.0.0.0:1234
100
123
21 user 0:00 buildkitd --addr tcp://0.0.0.0:1234
101
124
29 user 0:00 ps aux
125
+
102
126
$ docker exec cat /etc/subuid
103
127
user:100000:65536
104
128
```
105
129
106
130
To change the UID/GID configuration, you need to modify and build the BuildKit image manually.
@@ -137,12 +163,19 @@ Run `sysctl -w user.max_user_namespaces=N` (N=positive integer, like 63359) on t
137
163
138
164
See [`../examples/kubernetes/sysctl-userns.privileged.yaml`](../examples/kubernetes/sysctl-userns.privileged.yaml).
139
165
166
+
### Error `fork/exec /proc/self/exe: permission denied` with `This error might have happened because /proc/sys/kernel/apparmor_restrict_unprivileged_userns is set to 1`
167
+
Add `kernel.apparmor_restrict_unprivileged_userns=0` to `/etc/sysctl.conf` (or `/etc/sysctl.d`) and run `sudo sysctl -p`.
Copy file name to clipboardExpand all lines: examples/kubernetes/README.md
+34-22
Original file line number
Diff line number
Diff line change
@@ -6,16 +6,26 @@ This directory contains Kubernetes manifests for `Pod`, `Deployment` (with `Serv
6
6
*`StateFulset`: good for client-side load balancing, without registry-side cache
7
7
*`Job`: good if you don't want to have daemon pods
8
8
9
-
Using Rootless mode (`*.rootless.yaml`) is recommended because Rootless mode image is executed as non-root user (UID 1000) and doesn't need `securityContext.privileged`.
10
-
See [`../../docs/rootless.md`](../../docs/rootless.md).
9
+
## Variants
11
10
12
-
See also ["Building Images Efficiently And Securely On Kubernetes With BuildKit" (KubeCon EU 2019)](https://kccnceu19.sched.com/event/MPX5).
11
+
-`*.privileged.yaml`: Launches the Pod as the fully privileged root user.
12
+
-`*.rootless.yaml`: Launches the Pod as a non-root user, whose UID is 1000.
13
+
-`*.userns.yaml`: Launches the Pod as a non-root user. The UID is determined by kubelet.
14
+
Needs kubelet and kube-apiserver to be reconfigured to enable the
0 commit comments