瀏覽代碼

Merge pull request #42072 from AkihiroSuda/prohibit-rootless-as-root-2010

[20.10 backport] dockerd-rootless.sh: prohibit running as root
Sebastiaan van Stijn 4 年之前
父節點
當前提交
122ef5ce94
共有 1 個文件被更改,包括 4 次插入0 次删除
  1. 4 0
      contrib/dockerd-rootless.sh

+ 4 - 0
contrib/dockerd-rootless.sh

@@ -80,6 +80,10 @@ fi
 if [ -z $_DOCKERD_ROOTLESS_CHILD ]; then
 if [ -z $_DOCKERD_ROOTLESS_CHILD ]; then
 	_DOCKERD_ROOTLESS_CHILD=1
 	_DOCKERD_ROOTLESS_CHILD=1
 	export _DOCKERD_ROOTLESS_CHILD
 	export _DOCKERD_ROOTLESS_CHILD
+	if [ "$(id -u)" = "0" ]; then
+		echo "This script must be executed as a non-privileged user"
+		exit 1
+	fi
 	# Re-exec the script via RootlessKit, so as to create unprivileged {user,mount,network} namespaces.
 	# Re-exec the script via RootlessKit, so as to create unprivileged {user,mount,network} namespaces.
 	#
 	#
 	# --copy-up allows removing/creating files in the directories by creating tmpfs and symlinks
 	# --copy-up allows removing/creating files in the directories by creating tmpfs and symlinks