Skip to content

Commit ff93519

Browse files
authored
Merge pull request #1243 from tonistiigi/1903-update
[19.03] bugfixes cherry-pick
2 parents ae10b29 + 2de5c31 commit ff93519

File tree

4 files changed

+50
-23
lines changed

4 files changed

+50
-23
lines changed

frontend/dockerfile/dockerfile2llb/convert.go

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,31 +1202,13 @@ func normalizeContextPaths(paths map[string]struct{}) []string {
12021202
if p == "/" {
12031203
return nil
12041204
}
1205-
pathSlice = append(pathSlice, p)
1205+
pathSlice = append(pathSlice, path.Join(".", p))
12061206
}
12071207

1208-
toDelete := map[string]struct{}{}
1209-
for i := range pathSlice {
1210-
for j := range pathSlice {
1211-
if i == j {
1212-
continue
1213-
}
1214-
if strings.HasPrefix(pathSlice[j], pathSlice[i]+"/") {
1215-
delete(paths, pathSlice[j])
1216-
}
1217-
}
1218-
}
1219-
1220-
toSort := make([]string, 0, len(paths))
1221-
for p := range paths {
1222-
if _, ok := toDelete[p]; !ok {
1223-
toSort = append(toSort, path.Join(".", p))
1224-
}
1225-
}
1226-
sort.Slice(toSort, func(i, j int) bool {
1227-
return toSort[i] < toSort[j]
1208+
sort.Slice(pathSlice, func(i, j int) bool {
1209+
return pathSlice[i] < pathSlice[j]
12281210
})
1229-
return toSort
1211+
return pathSlice
12301212
}
12311213

12321214
func proxyEnvFromBuildArgs(args map[string]string) *llb.ProxyEnv {

frontend/dockerfile/dockerfile_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ var fileOpTests = []integration.Test{
113113
testWorkdirUser,
114114
testWorkdirExists,
115115
testWorkdirCopyIgnoreRelative,
116+
testCopyFollowAllSymlinks,
116117
}
117118

118119
var securityTests = []integration.Test{}
@@ -1392,6 +1393,46 @@ COPY foo /
13921393
require.Equal(t, len(du), len(du2))
13931394
}
13941395

1396+
// #1197
1397+
func testCopyFollowAllSymlinks(t *testing.T, sb integration.Sandbox) {
1398+
f := getFrontend(t, sb)
1399+
isFileOp := getFileOp(t, sb)
1400+
1401+
dockerfile := []byte(`
1402+
FROM scratch
1403+
COPY foo /
1404+
COPY foo/sub bar
1405+
`)
1406+
1407+
dir, err := tmpdir(
1408+
fstest.CreateFile("Dockerfile", dockerfile, 0600),
1409+
fstest.CreateFile("bar", []byte(`bar-contents`), 0600),
1410+
fstest.CreateDir("foo", 0700),
1411+
fstest.Symlink("../bar", "foo/sub"),
1412+
)
1413+
require.NoError(t, err)
1414+
defer os.RemoveAll(dir)
1415+
1416+
c, err := client.New(context.TODO(), sb.Address())
1417+
require.NoError(t, err)
1418+
defer c.Close()
1419+
1420+
destDir, err := ioutil.TempDir("", "buildkit")
1421+
require.NoError(t, err)
1422+
defer os.RemoveAll(destDir)
1423+
1424+
_, err = f.Solve(context.TODO(), c, client.SolveOpt{
1425+
FrontendAttrs: map[string]string{
1426+
"build-arg:BUILDKIT_DISABLE_FILEOP": strconv.FormatBool(!isFileOp),
1427+
},
1428+
LocalDirs: map[string]string{
1429+
builder.DefaultLocalNameDockerfile: dir,
1430+
builder.DefaultLocalNameContext: dir,
1431+
},
1432+
}, nil)
1433+
require.NoError(t, err)
1434+
}
1435+
13951436
func testCopySymlinks(t *testing.T, sb integration.Sandbox) {
13961437
f := getFrontend(t, sb)
13971438
isFileOp := getFileOp(t, sb)

session/sshforward/ssh.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ func MountSSHSocket(ctx context.Context, c session.Caller, opt SocketOpt) (sockP
7575
}
7676
}()
7777

78+
if err := os.Chmod(dir, 0711); err != nil {
79+
return "", nil, errors.WithStack(err)
80+
}
81+
7882
sockPath = filepath.Join(dir, "ssh_auth_sock")
7983

8084
l, err := net.Listen("unix", sockPath)

solver/llbsolver/ops/exec.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ func (sm *secretMountInstance) Mount() ([]mount.Mount, func() error, error) {
525525
return []mount.Mount{{
526526
Type: "bind",
527527
Source: fp,
528-
Options: []string{"ro", "rbind"},
528+
Options: []string{"ro", "rbind", "nodev", "nosuid", "noexec"},
529529
}}, cleanup, nil
530530
}
531531

0 commit comments

Comments
 (0)