diff --git a/bake/bake.go b/bake/bake.go index b3427c07..9a507cd6 100644 --- a/bake/bake.go +++ b/bake/bake.go @@ -1000,6 +1000,10 @@ func checkPath(p string) error { } return err } + p, err = filepath.Abs(p) + if err != nil { + return err + } wd, err := os.Getwd() if err != nil { return err @@ -1008,7 +1012,8 @@ func checkPath(p string) error { if err != nil { return err } - if strings.HasPrefix(rel, ".."+string(os.PathSeparator)) { + parts := strings.Split(rel, string(os.PathSeparator)) + if parts[0] == ".." { return errors.Errorf("path %s is outside of the working directory, please set BAKE_ALLOW_REMOTE_FS_ACCESS=1", p) } return nil diff --git a/tests/bake.go b/tests/bake.go new file mode 100644 index 00000000..130fb0bd --- /dev/null +++ b/tests/bake.go @@ -0,0 +1,265 @@ +package tests + +import ( + "path/filepath" + "testing" + + "github.com/containerd/continuity/fs/fstest" + "github.com/docker/buildx/util/gitutil" + "github.com/moby/buildkit/util/testutil/integration" + "github.com/stretchr/testify/require" +) + +func bakeCmd(sb integration.Sandbox, opts ...cmdOpt) (string, error) { + opts = append([]cmdOpt{withArgs("bake", "--progress=quiet")}, opts...) + cmd := buildxCmd(sb, opts...) + out, err := cmd.CombinedOutput() + return string(out), err +} + +var bakeTests = []func(t *testing.T, sb integration.Sandbox){ + testBakeRemote, + testBakeRemoteCmdContext, + testBakeRemoteCmdContextOverride, + testBakeRemoteContextSubdir, + testBakeRemoteCmdContextEscapeRoot, + testBakeRemoteCmdContextEscapeRelative, +} + +func testBakeRemote(t *testing.T, sb integration.Sandbox) { + bakefile := []byte(` +target "default" { + dockerfile-inline = <