Skip to content

Commit b8f2caa

Browse files
committed
pkg/containerfs: deprecate ResolveScopedPath
If was a very shallow wrapper around symlink.FollowSymlinkInScope, so inline that code instead. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 90f37f4 commit b8f2caa

5 files changed

Lines changed: 12 additions & 8 deletions

File tree

builder/dockerfile/copy.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ import (
1717
"github.com/docker/docker/builder/remotecontext"
1818
"github.com/docker/docker/builder/remotecontext/urlutil"
1919
"github.com/docker/docker/pkg/archive"
20-
"github.com/docker/docker/pkg/containerfs"
2120
"github.com/docker/docker/pkg/idtools"
2221
"github.com/docker/docker/pkg/longpath"
2322
"github.com/docker/docker/pkg/progress"
2423
"github.com/docker/docker/pkg/streamformatter"
2524
"github.com/docker/docker/pkg/system"
2625
"github.com/moby/buildkit/frontend/dockerfile/instructions"
26+
"github.com/moby/sys/symlink"
2727
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
2828
"github.com/pkg/errors"
2929
)
@@ -45,7 +45,7 @@ type copyInfo struct {
4545
}
4646

4747
func (c copyInfo) fullPath() (string, error) {
48-
return containerfs.ResolveScopedPath(c.root, c.path)
48+
return symlink.FollowSymlinkInScope(filepath.Join(c.root, c.path), c.root)
4949
}
5050

5151
func newCopyInfoFromSource(source builder.Source, path string, hash string) copyInfo {

builder/remotecontext/archive.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import (
88
"github.com/docker/docker/builder"
99
"github.com/docker/docker/pkg/archive"
1010
"github.com/docker/docker/pkg/chrootarchive"
11-
"github.com/docker/docker/pkg/containerfs"
1211
"github.com/docker/docker/pkg/longpath"
1312
"github.com/docker/docker/pkg/tarsum"
13+
"github.com/moby/sys/symlink"
1414
"github.com/pkg/errors"
1515
)
1616

@@ -117,7 +117,7 @@ func (c *archiveContext) Hash(path string) (string, error) {
117117

118118
func normalize(path string, root string) (cleanPath, fullPath string, err error) {
119119
cleanPath = filepath.Clean(string(filepath.Separator) + path)[1:]
120-
fullPath, err = containerfs.ResolveScopedPath(root, path)
120+
fullPath, err = symlink.FollowSymlinkInScope(filepath.Join(root, path), root)
121121
if err != nil {
122122
return "", "", errors.Wrapf(err, "forbidden path outside the build context: %s (%s)", path, cleanPath)
123123
}

builder/remotecontext/detect.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"io"
88
"os"
9+
"path/filepath"
910
"runtime"
1011
"strings"
1112

@@ -15,10 +16,10 @@ import (
1516
"github.com/docker/docker/builder"
1617
"github.com/docker/docker/builder/remotecontext/urlutil"
1718
"github.com/docker/docker/errdefs"
18-
"github.com/docker/docker/pkg/containerfs"
1919
"github.com/moby/buildkit/frontend/dockerfile/parser"
2020
"github.com/moby/patternmatcher"
2121
"github.com/moby/patternmatcher/ignorefile"
22+
"github.com/moby/sys/symlink"
2223
"github.com/pkg/errors"
2324
)
2425

@@ -177,7 +178,8 @@ func StatAt(remote builder.Source, path string) (os.FileInfo, error) {
177178

178179
// FullPath is a helper for getting a full path for a path from a source
179180
func FullPath(remote builder.Source, path string) (string, error) {
180-
fullPath, err := containerfs.ResolveScopedPath(remote.Root(), path)
181+
remoteRoot := remote.Root()
182+
fullPath, err := symlink.FollowSymlinkInScope(filepath.Join(remoteRoot, path), remoteRoot)
181183
if err != nil {
182184
if runtime.GOOS == "windows" {
183185
return "", fmt.Errorf("failed to resolve scoped path %s (%s): %s. Possible cause is a forbidden path outside the build context", path, fullPath, err)

container/container.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,8 @@ func (container *Container) GetResourcePath(path string) (string, error) {
310310
return "", errors.New("GetResourcePath: BaseFS of container " + container.ID + " is unexpectedly empty")
311311
}
312312
// IMPORTANT - These are paths on the OS where the daemon is running, hence
313-
// any filepath operations must be done in an OS agnostic way.
314-
r, e := containerfs.ResolveScopedPath(container.BaseFS, containerfs.CleanScopedPath(path))
313+
// any filepath operations must be done in an OS-agnostic way.
314+
r, e := symlink.FollowSymlinkInScope(filepath.Join(container.BaseFS, containerfs.CleanScopedPath(path)), container.BaseFS)
315315

316316
// Log this here on the daemon side as there's otherwise no indication apart
317317
// from the error being propagated all the way back to the client. This makes

pkg/containerfs/containerfs.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ func CleanScopedPath(path string) string {
2020

2121
// ResolveScopedPath evaluates the given path scoped to the root.
2222
// For example, if root=/a, and path=/b/c, then this function would return /a/b/c.
23+
//
24+
// Deprecated: use [symlink.FollowSymlinkInScope].
2325
func ResolveScopedPath(root, path string) (string, error) {
2426
return symlink.FollowSymlinkInScope(filepath.Join(root, path), root)
2527
}

0 commit comments

Comments
 (0)