Skip to content

Commit a3328d3

Browse files
Fix mount layers on host
Unless we're extracting an image to a layer, we should never return it directly. We must always interact with it via a mount point, as Windows layers hold a number of metadata files which should never be mutated directly. When reading/manipulating the contents of a layer we should always pass through a mount. Allow the containerd mount.Mount() to properly mount the layer before we interact with it. Signed-off-by: Gabriel Adrian Samfira <[email protected]>
1 parent 13cca5a commit a3328d3

File tree

1 file changed

+7
-17
lines changed

1 file changed

+7
-17
lines changed

snapshot/localmounter_windows.go

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package snapshot
22

33
import (
4+
"os"
5+
46
"github.com/containerd/containerd/errdefs"
57
"github.com/containerd/containerd/mount"
68
"github.com/pkg/errors"
@@ -26,26 +28,13 @@ func (lm *localMounter) Mount() (string, error) {
2628
}
2729

2830
m := lm.mounts[0]
29-
30-
if m.Type == "bind" || m.Type == "rbind" {
31-
ro := false
32-
for _, opt := range m.Options {
33-
if opt == "ro" {
34-
ro = true
35-
break
36-
}
37-
}
38-
if !ro {
39-
return m.Source, nil
40-
}
31+
dir, err := os.MkdirTemp("", "buildkit-mount")
32+
if err != nil {
33+
return "", errors.Wrap(err, "failed to create temp dir")
4134
}
4235

43-
// Windows mounts always activate in-place, so the target of the mount must be the source directory.
44-
// See https://github.com/containerd/containerd/pull/2366
45-
dir := m.Source
46-
4736
if err := m.Mount(dir); err != nil {
48-
return "", errors.Wrapf(err, "failed to mount in-place: %v", m)
37+
return "", errors.Wrapf(err, "failed to mount %v: %+v", m, err)
4938
}
5039
lm.target = dir
5140
return lm.target, nil
@@ -59,6 +48,7 @@ func (lm *localMounter) Unmount() error {
5948
if err := mount.Unmount(lm.target, 0); err != nil {
6049
return err
6150
}
51+
os.RemoveAll(lm.target)
6252
lm.target = ""
6353
}
6454

0 commit comments

Comments
 (0)