Browse code

pkg/rootless: move to daemon/internal

This package is used internally by the daemon, and was only used out
side of the daemon by pkg/plugins (for which we still need to look
where it should be kept).

Making it internal because it's trivial to implement if needed by
anyone. The only reason it's a package is to keep it central, and
to make it easier to discover where we have rootlesskit-specific
codepaths in our codebase.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2025/07/29 03:56:42
Showing 8 changed files
... ...
@@ -29,6 +29,7 @@ import (
29 29
 	"github.com/docker/docker/daemon/internal/builder-next/exporter"
30 30
 	"github.com/docker/docker/daemon/internal/libcontainerd/supervisor"
31 31
 	"github.com/docker/docker/daemon/internal/otelutil"
32
+	"github.com/docker/docker/daemon/internal/rootless"
32 33
 	"github.com/docker/docker/daemon/listeners"
33 34
 	dopts "github.com/docker/docker/daemon/pkg/opts"
34 35
 	"github.com/docker/docker/daemon/pkg/plugin"
... ...
@@ -53,7 +54,6 @@ import (
53 53
 	"github.com/docker/docker/pkg/homedir"
54 54
 	"github.com/docker/docker/pkg/pidfile"
55 55
 	"github.com/docker/docker/pkg/plugingetter"
56
-	"github.com/docker/docker/pkg/rootless"
57 56
 	"github.com/docker/go-connections/tlsconfig"
58 57
 	"github.com/moby/buildkit/session"
59 58
 	"github.com/moby/buildkit/util/tracing/detect"
... ...
@@ -7,8 +7,8 @@ import (
7 7
 
8 8
 	"github.com/containerd/log"
9 9
 	"github.com/docker/docker/daemon/config"
10
+	"github.com/docker/docker/daemon/internal/rootless"
10 11
 	"github.com/docker/docker/dockerversion"
11
-	"github.com/docker/docker/pkg/rootless"
12 12
 	"github.com/moby/buildkit/util/apicaps"
13 13
 	"github.com/spf13/cobra"
14 14
 )
... ...
@@ -11,10 +11,10 @@ import (
11 11
 
12 12
 	"github.com/containerd/cgroups/v3"
13 13
 	"github.com/containerd/log"
14
+	"github.com/docker/docker/daemon/internal/rootless"
14 15
 	"github.com/docker/docker/daemon/libnetwork/drivers/bridge"
15 16
 	"github.com/docker/docker/daemon/pkg/opts"
16 17
 	"github.com/docker/docker/pkg/homedir"
17
-	"github.com/docker/docker/pkg/rootless"
18 18
 	"github.com/moby/moby/api/types/container"
19 19
 	"github.com/moby/moby/api/types/system"
20 20
 	"github.com/pkg/errors"
... ...
@@ -14,7 +14,7 @@ import (
14 14
 	runcoptions "github.com/containerd/containerd/api/types/runc/options"
15 15
 	"github.com/containerd/log"
16 16
 	"github.com/docker/docker/daemon/config"
17
-	"github.com/docker/docker/pkg/rootless"
17
+	"github.com/docker/docker/daemon/internal/rootless"
18 18
 	"github.com/docker/docker/pkg/sysinfo"
19 19
 	"github.com/moby/moby/api/types"
20 20
 	containertypes "github.com/moby/moby/api/types/container"
21 21
new file mode 100644
... ...
@@ -0,0 +1,8 @@
0
+package rootless
1
+
2
+import "os"
3
+
4
+// RunningWithRootlessKit returns true if running under RootlessKit namespaces.
5
+func RunningWithRootlessKit() bool {
6
+	return os.Getenv("ROOTLESSKIT_STATE_DIR") != ""
7
+}
... ...
@@ -16,7 +16,7 @@ import (
16 16
 	"time"
17 17
 
18 18
 	"github.com/containerd/log"
19
-	"github.com/docker/docker/pkg/rootless"
19
+	"github.com/docker/docker/daemon/internal/rootless"
20 20
 )
21 21
 
22 22
 // Action signifies the iptable action.
... ...
@@ -3,10 +3,10 @@
3 3
 package plugins
4 4
 
5 5
 import (
6
+	"os"
6 7
 	"path/filepath"
7 8
 
8 9
 	"github.com/docker/docker/pkg/homedir"
9
-	"github.com/docker/docker/pkg/rootless"
10 10
 )
11 11
 
12 12
 func rootlessConfigPluginsPath() string {
... ...
@@ -25,7 +25,8 @@ func rootlessLibPluginsPath() string {
25 25
 
26 26
 // specsPaths is the non-Windows implementation of [SpecsPaths].
27 27
 func specsPaths() []string {
28
-	if rootless.RunningWithRootlessKit() {
28
+	// TODO(thaJeztah): switch back to daemon/internal/rootless.RunningWithRootlessKit if this package moves internal to the daemon.
29
+	if os.Getenv("ROOTLESSKIT_STATE_DIR") != "" {
29 30
 		return []string{rootlessConfigPluginsPath(), rootlessLibPluginsPath()}
30 31
 	}
31 32
 	return []string{"/etc/docker/plugins", "/usr/lib/docker/plugins"}
32 33
deleted file mode 100644
... ...
@@ -1,8 +0,0 @@
1
-package rootless
2
-
3
-import "os"
4
-
5
-// RunningWithRootlessKit returns true if running under RootlessKit namespaces.
6
-func RunningWithRootlessKit() bool {
7
-	return os.Getenv("ROOTLESSKIT_STATE_DIR") != ""
8
-}