Modern Docker Management, Designed for Everyone
Go composecontainer-managementcontainersdockerdocker-composedocker-managementgoself-hostedsveltekittypescriptweb-ui
fix: skip symlinked external bind sources when preparing project updates (#4207)
Kyle Mendellbcaa9d447b5a
diff --git a/backend/internal/project/project_lifecycle.go b/backend/internal/project/project_lifecycle.goindex 198437842..473e58f36 100644--- a/backend/internal/project/project_lifecycle.go+++ b/backend/internal/project/project_lifecycle.go@@ -217,7 +217,8 @@ func (s *ProjectService) existingNamespaceDependentsInternal(ctx context.Context// considered (short syntax, or long syntax without create_host_path: false),// mirroring what the daemon would otherwise do. Existing files, directories,// and symlinks are left untouched, as are sources outside the project-// directory, and the root-confined acfs calls reject symlinks escaping it.+// directory or reached through a symlink escaping it (#4195); those are left+// to Docker.func prepareProjectBindDirectoriesInternal(projectPath string) projects.PrepareProjectFunc {return func(ctx context.Context, project *composetypes.Project) error {for _, serviceName := range slices.Sorted(maps.Keys(project.Services)) {@@ -238,7 +239,8 @@ func prepareProjectBindDirectoriesInternal(projectPath string) projects.PrepareP}// ensureProjectBindDirectoryInternal creates source (and missing parents)-// when it lies inside projectPath and nothing exists there yet.+// when it resolves inside projectPath and nothing exists there yet. Sources+// escaping the project, lexically or through a symlink, are skipped.func ensureProjectBindDirectoryInternal(ctx context.Context, projectPath, source string) error {logicalPath, err := acfs.LogicalPath(projectPath, source)if err != nil {@@ -252,11 +254,17 @@ func ensureProjectBindDirectoryInternal(ctx context.Context, projectPath, source}exists, err := acfs.Exists(ctx, projectPath, logicalPath)- if err != nil || exists {+ if errors.Is(err, acfs.ErrOutsideRoot) || exists {+ return nil+ }+ if err != nil {return err}if err := acfs.MkdirAll(ctx, projectPath, logicalPath, utils.DirPerm); err != nil {+ if errors.Is(err, acfs.ErrOutsideRoot) {+ return nil+ }return err}slog.InfoContext(ctx, "created missing bind directory for project deployment", "projectPath", projectPath, "source", source)diff --git a/backend/internal/project/service_test.go b/backend/internal/project/service_test.goindex 99793e653..6549a512f 100644--- a/backend/internal/project/service_test.go+++ b/backend/internal/project/service_test.go@@ -52,6 +52,7 @@ import ("github.com/samber/mo""github.com/stretchr/testify/assert""github.com/stretchr/testify/require"+ "go.getarcane.app/acfs"buildtypes "go.getarcane.app/builds/types""go.getarcane.app/updater/labels""go.uber.org/fx/fxtest"@@ -7914,15 +7915,48 @@ func TestPrepareProjectBindDirectoriesInternal(t *testing.T) {assert.NoDirExists(t, filepath.Join(projectPath, "named"))})- t.Run("rejects symlink escaping the project", func(t *testing.T) {+ t.Run("skips sources reached through symlinks escaping the project", func(t *testing.T) {+ t.Parallel()+ parent := t.TempDir()+ projectPath := filepath.Join(parent, "project")+ require.NoError(t, os.Mkdir(projectPath, 0o755))+ outside := filepath.Join(parent, "appdata")+ existingExternal := filepath.Join(outside, "jellyfin", "data")+ require.NoError(t, os.MkdirAll(existingExternal, 0o700))+ require.NoError(t, os.Symlink(outside, filepath.Join(projectPath, "abs")))+ require.NoError(t, os.Symlink(filepath.Join("..", "appdata"), filepath.Join(projectPath, "rel")))++ project := newProject(+ bind(filepath.Join(projectPath, "abs", "jellyfin", "data")),+ bind(filepath.Join(projectPath, "abs", "missing")),+ bind(filepath.Join(projectPath, "rel", "jellyfin", "data")),+ bind(filepath.Join(projectPath, "rel", "other")),+ bind(filepath.Join(projectPath, "local", "conf")),+ )++ require.NoError(t, prepareProjectBindDirectoriesInternal(projectPath)(context.Background(), project))++ info, err := os.Stat(existingExternal)+ require.NoError(t, err)+ assert.Equal(t, os.FileMode(0o700), info.Mode().Perm(), "external directory permissions preserved")+ assert.NoDirExists(t, filepath.Join(outside, "missing"))+ assert.NoDirExists(t, filepath.Join(outside, "other"))+ assert.DirExists(t, filepath.Join(projectPath, "local", "conf"))+ })++ t.Run("reports symlink loops and canceled contexts", func(t *testing.T) {t.Parallel()projectPath := t.TempDir()- outside := t.TempDir()- require.NoError(t, os.Symlink(outside, filepath.Join(projectPath, "link")))+ require.NoError(t, os.Symlink("loop", filepath.Join(projectPath, "loop")))- err := prepareProjectBindDirectoriesInternal(projectPath)(context.Background(), newProject(bind(filepath.Join(projectPath, "link", "conf"))))- require.Error(t, err)+ err := prepareProjectBindDirectoriesInternal(projectPath)(context.Background(), newProject(bind(filepath.Join(projectPath, "loop", "conf"))))+ require.ErrorIs(t, err, acfs.ErrSymlinkLoop)assert.Contains(t, err.Error(), "service app")- assert.NoDirExists(t, filepath.Join(outside, "conf"))++ ctx, cancel := context.WithCancel(context.Background())+ cancel()+ err = prepareProjectBindDirectoriesInternal(projectPath)(ctx, newProject(bind(filepath.Join(projectPath, "conf"))))+ require.ErrorIs(t, err, context.Canceled)+ assert.NoDirExists(t, filepath.Join(projectPath, "conf"))})}