Skip to content

Modern Docker Management, Designed for Everyone

fix: actionable error when the projects directory is unreadable by the runtime user

Kyle Mendell802ab8913930
diff --git a/backend/pkg/projects/discovery.go b/backend/pkg/projects/discovery.go
index 5b455b1f9..584713364 100644
--- a/backend/pkg/projects/discovery.go
+++ b/backend/pkg/projects/discovery.go
@@ -67,17 +67,23 @@ func DiscoverProjectDirectories(root string, followSymlinks bool, maxDepth int)
root = filepath.Clean(root)
isDir, err := IsProjectDirectoryPath(root, followSymlinks)
- if err != nil {
- return nil, err
- }
- if !isDir {
+ if err == nil && !isDir {
return nil, errors.Errorf("project root is not a directory: %s", root)
}
discovered := make([]DiscoveredProjectDir, 0)
ancestors := make(map[string]struct{})
- if err := walkProjectDirectoriesInternal(root, true, 0, maxDepth, followSymlinks, ancestors, &discovered); err != nil {
+ if err == nil {
+ err = walkProjectDirectoriesInternal(root, true, 0, maxDepth, followSymlinks, ancestors, &discovered)
+ }
+ if err != nil {
+ // The process runs as the PUID/PGID runtime user (default 65532) even
+ // when the container was started as root, so a root-only projects
+ // directory is genuinely unreadable (#3489).
+ if errors.Is(err, os.ErrPermission) {
+ return nil, errors.WrapIff(err, "projects directory is not readable by the runtime user (uid %d): fix its permissions or set PUID/PGID to an owner that can read it", os.Geteuid())
+ }
return nil, err
}
diff --git a/backend/pkg/projects/fs_util_unix_test.go b/backend/pkg/projects/fs_util_unix_test.go
index 005d9f8be..05e226eb2 100644
--- a/backend/pkg/projects/fs_util_unix_test.go
+++ b/backend/pkg/projects/fs_util_unix_test.go
@@ -157,3 +157,20 @@ func TestMirrorDirectoryContentsPreserving_ToleratesUnreadableDestSubdir(t *test
require.NoError(t, os.Chmod(locked, 0o755))
assert.FileExists(t, filepath.Join(locked, "config", "app.conf"))
}
+
+func TestDiscoverProjectDirectories_UnreadableRootErrorIsActionable(t *testing.T) {
+ if os.Geteuid() == 0 {
+ t.Skip("running as root; permission bits are not enforced")
+ }
+
+ root := t.TempDir()
+ require.NoError(t, os.Chmod(root, 0o000))
+ t.Cleanup(func() { _ = os.Chmod(root, 0o755) })
+
+ _, err := DiscoverProjectDirectories(root, false, 0)
+ require.Error(t, err)
+ // The bare "permission denied" must be wrapped with the runtime identity
+ // and remediation hints (#3489).
+ assert.Contains(t, err.Error(), "not readable by the runtime user")
+ assert.Contains(t, err.Error(), "PUID")
+}