Skip to content

Commit

Permalink
Merge pull request #1564 from giuseppe/fix-ownership-diff-dir
Browse files Browse the repository at this point in the history
drivers: chown root mount to root in the userns
  • Loading branch information
flouthoc committed Apr 12, 2023
2 parents b2ea3a8 + 7113c3d commit 4cc5edf
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion drivers/overlay/overlay.go
Original file line number Diff line number Diff line change
Expand Up @@ -1478,7 +1478,7 @@ func (d *Driver) get(id string, disableShifting bool, options graphdriver.MountO
absLowers = append(absLowers, path.Join(dir, "empty"))
}
// user namespace requires this to move a directory from lower to upper.
rootUID, rootGID, err := idtools.GetRootUIDGID(d.uidMaps, d.gidMaps)
rootUID, rootGID, err := idtools.GetRootUIDGID(options.UidMaps, options.GidMaps)
if err != nil {
return "", err
}
Expand Down
11 changes: 10 additions & 1 deletion drivers/vfs/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,16 @@ func (d *Driver) SupportsShifting() bool {
// UpdateLayerIDMap updates ID mappings in a from matching the ones specified
// by toContainer to those specified by toHost.
func (d *Driver) UpdateLayerIDMap(id string, toContainer, toHost *idtools.IDMappings, mountLabel string) error {
return d.updater.UpdateLayerIDMap(id, toContainer, toHost, mountLabel)
if err := d.updater.UpdateLayerIDMap(id, toContainer, toHost, mountLabel); err != nil {
return err
}
dir := d.dir(id)
rootIDs, err := toHost.ToHost(idtools.IDPair{UID: 0, GID: 0})
if err != nil {
return err
}
return os.Chown(dir, rootIDs.UID, rootIDs.GID)

}

// Changes produces a list of changes between the specified layer
Expand Down
4 changes: 4 additions & 0 deletions tests/idmaps.bats
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,10 @@ load helpers
[ "$output" != "" ]
mount="$output"

uid=$(stat -c %u ${mount})
gid=$(stat -c %g ${mount})
test ${uid}:${gid} = ${uidrange[$i]}:${gidrange[$i]}

for j in $(seq $n) ; do
ownerids=$(stat -c %u:%g ${mount}/file$j)
echo on-disk IDs: "$ownerids"
Expand Down

0 comments on commit 4cc5edf

Please sign in to comment.