Skip to content

Commit 4775621

Browse files
ereslibrethaJeztah
authored andcommitted
Dockerd rootless: make {/etc,/var/run}/cdi available
When dockerd is executed with the `dockerd-rootless.sh` script, make /etc/cdi and /var/run/cdi available to the daemon if they exist. This makes it possible to enable the CDI integration in rootless mode. Fixes: #47676 Signed-off-by: Rafael Fernández López <ereslibre@ereslibre.es> (cherry picked from commit 4e30acb) Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent a92d4c5 commit 4775621

File tree

1 file changed

+44
-4
lines changed

1 file changed

+44
-4
lines changed

contrib/dockerd-rootless.sh

+44-4
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,30 @@ if ! [ -d "$HOME" ]; then
5454
exit 1
5555
fi
5656

57+
mount_directory() {
58+
if [ -z "$_DOCKERD_ROOTLESS_CHILD" ]; then
59+
echo "mount_directory should be called from the child context. Otherwise data loss is at risk" >&2
60+
exit 1
61+
fi
62+
63+
DIRECTORY="$1"
64+
if [ ! -d "$DIRECTORY" ]; then
65+
return
66+
fi
67+
68+
# Bind mount directory: this makes this directory visible to
69+
# Dockerd, even if it is originally a symlink, given Dockerd does
70+
# not always follow symlinks. Some directories might also be
71+
# "copied-up", meaning that they will also be writable on the child
72+
# namespace; this will be the case only if they are provided as
73+
# --copy-up to the rootlesskit.
74+
DIRECTORY_REALPATH=$(realpath "$DIRECTORY")
75+
MOUNT_OPTIONS="${2:---bind}"
76+
rm -rf "$DIRECTORY"
77+
mkdir -p "$DIRECTORY"
78+
mount $MOUNT_OPTIONS "$DIRECTORY_REALPATH" "$DIRECTORY"
79+
}
80+
5781
rootlesskit=""
5882
for f in docker-rootlesskit rootlesskit; do
5983
if command -v $f > /dev/null 2>&1; then
@@ -139,6 +163,25 @@ if [ -z "$_DOCKERD_ROOTLESS_CHILD" ]; then
139163
"$0" "$@"
140164
else
141165
[ "$_DOCKERD_ROOTLESS_CHILD" = 1 ]
166+
167+
# The Container Device Interface (CDI) specs can be found by default
168+
# under {/etc,/var/run}/cdi. More information at:
169+
# https://github.com/cncf-tags/container-device-interface
170+
#
171+
# In order to use the Container Device Interface (CDI) integration,
172+
# the CDI paths need to exist before the Docker daemon is started in
173+
# order for it to read the CDI specification files. Otherwise, a
174+
# Docker daemon restart will be required for the daemon to discover
175+
# them.
176+
#
177+
# If another set of CDI paths (other than the default /etc/cdi and
178+
# /var/run/cdi) are configured through the Docker configuration file
179+
# (using "cdi-spec-dirs"), they need to be bind mounted in rootless
180+
# mode; otherwise the Docker daemon won't have access to the CDI
181+
# specification files.
182+
mount_directory /etc/cdi
183+
mount_directory /var/run/cdi
184+
142185
# remove the symlinks for the existing files in the parent namespace if any,
143186
# so that we can create our own files in our mount namespace.
144187
rm -f /run/docker /run/containerd /run/xtables.lock
@@ -153,10 +196,7 @@ else
153196
if [ "$(stat -c %T -f /etc)" = "tmpfs" ] && [ -L "/etc/ssl" ]; then
154197
# Workaround for "x509: certificate signed by unknown authority" on openSUSE Tumbleweed.
155198
# https://github.com/rootless-containers/rootlesskit/issues/225
156-
realpath_etc_ssl=$(realpath /etc/ssl)
157-
rm -f /etc/ssl
158-
mkdir /etc/ssl
159-
mount --rbind ${realpath_etc_ssl} /etc/ssl
199+
mount_directory /etc/ssl "--rbind"
160200
fi
161201

162202
exec "$dockerd" "$@"

0 commit comments

Comments
 (0)