Skip to content

Commit 9139208

Browse files
Properly mount base layers
As opposed to a writable layer derived from a base layer, the volume path of a base layer, once activated and prepared will not be a WCIFS volume, but the actual path on disk to the snapshot. We cannot directly mount this folder, as that would mean a client may gain access and potentially damage important metadata files that would render the layer unusabble. For base layers we need to mount the Files folder which must exist in any valid base windows-layer. Signed-off-by: Gabriel Adrian Samfira <[email protected]>
1 parent e61e7b3 commit 9139208

2 files changed

Lines changed: 9 additions & 11 deletions

File tree

mount/mount_windows.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,14 @@ func (m *Mount) mount(target string) (retErr error) {
9999
return fmt.Errorf("failed to get volume path for layer %s: %w", m.Source, err)
100100
}
101101

102+
if len(parentLayerPaths) == 0 {
103+
// this is a base layer. It gets mounted without going through WCIFS. We need to mount the Files
104+
// folder, not the actual source, or the client may inadvertently remove metadata files.
105+
volume = filepath.Join(volume, "Files")
106+
if _, err := os.Stat(volume); err != nil {
107+
return fmt.Errorf("no Files folder in layer %s", layerID)
108+
}
109+
}
102110
if err := bindfilter.ApplyFileBinding(target, volume, m.ReadOnly()); err != nil {
103111
return fmt.Errorf("failed to set volume mount path for layer %s: %w", m.Source, err)
104112
}

snapshots/windows/windows.go

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -319,24 +319,14 @@ func (s *snapshotter) mounts(sn storage.Snapshot, key string) []mount.Mount {
319319

320320
mountType := "windows-layer"
321321

322-
if len(sn.ParentIDs) == 0 {
323-
// A mount of a parentless snapshot is a bind-mount.
324-
mountType = "bind"
325-
// If not being extracted into, then the bind-target is the
326-
// "Files" subdirectory.
327-
if !strings.Contains(key, snapshots.UnpackKeyPrefix) {
328-
source = filepath.Join(source, "Files")
329-
}
330-
}
331-
332322
// error is not checked here, as a string array will never fail to Marshal
333323
parentLayersJSON, _ := json.Marshal(parentLayerPaths)
334324
parentLayersOption := mount.ParentLayerPathsFlag + string(parentLayersJSON)
335325

336326
options := []string{
337327
roFlag,
338328
}
339-
if mountType != "bind" {
329+
if len(sn.ParentIDs) != 0 {
340330
options = append(options, parentLayersOption)
341331
}
342332
mounts := []mount.Mount{

0 commit comments

Comments
 (0)