Skip to content

Commit e24d562

Browse files
estespTibor Vass
authored and
Tibor Vass
committed
Fix ZFS permissions bug with user namespaces
Fix root directory of the mountpoint being owned by real root. This is unique to ZFS because of the way file mountpoints are created using the ZFS tooling, and the remapping that happens at layer unpack doesn't impact this root (already created) holding directory for the layer. Docker-DCO-1.1-Signed-off-by: Phil Estes <[email protected]> (github: estesp) (cherry picked from commit aef0995) From PR moby#20045
1 parent 33a8948 commit e24d562

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

daemon/graphdriver/zfs/zfs.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -308,10 +308,14 @@ func (d *Driver) Get(id, mountLabel string) (string, error) {
308308
return "", err
309309
}
310310

311-
err = mount.Mount(filesystem, mountpoint, "zfs", options)
312-
if err != nil {
311+
if err := mount.Mount(filesystem, mountpoint, "zfs", options); err != nil {
313312
return "", fmt.Errorf("error creating zfs mount of %s to %s: %v", filesystem, mountpoint, err)
314313
}
314+
// this could be our first mount after creation of the filesystem, and the root dir may still have root
315+
// permissions instead of the remapped root uid:gid (if user namespaces are enabled):
316+
if err := os.Chown(mountpoint, rootUID, rootGID); err != nil {
317+
return "", fmt.Errorf("error modifying zfs mountpoint (%s) directory ownership: %v", mountpoint, err)
318+
}
315319

316320
return mountpoint, nil
317321
}

0 commit comments

Comments
 (0)