Skip to content

Commit cdec1c6

Browse files
committed
storage: fix UID/GID map handling for shifting layers
when the driver supports shifting, set the rechown target to identity instead of the container's maps. Closes: https://redhat.atlassian.net/browse/RHEL-160859 Assisted-by: Claude Opus 4.6 Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
1 parent bdab57a commit cdec1c6

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

storage/layers.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1674,9 +1674,13 @@ func (r *layerStore) create(id string, parentLayer *Layer, names []string, mount
16741674
}
16751675
}
16761676

1677+
targetMappings := idMappings
1678+
if moreOptions.IDMappingOptions.HostUIDMapping && moreOptions.IDMappingOptions.HostGIDMapping {
1679+
targetMappings = &idtools.IDMappings{}
1680+
}
16771681
if oldMappings != nil &&
1678-
(!reflect.DeepEqual(oldMappings.UIDs(), idMappings.UIDs()) || !reflect.DeepEqual(oldMappings.GIDs(), idMappings.GIDs())) {
1679-
if err = r.driver.UpdateLayerIDMap(id, oldMappings, idMappings, mountLabel); err != nil {
1682+
(!reflect.DeepEqual(oldMappings.UIDs(), targetMappings.UIDs()) || !reflect.DeepEqual(oldMappings.GIDs(), targetMappings.GIDs())) {
1683+
if err = r.driver.UpdateLayerIDMap(id, oldMappings, targetMappings, mountLabel); err != nil {
16801684
cleanupFailureContext = "in UpdateLayerIDMap"
16811685
return nil, -1, err
16821686
}

storage/store.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2001,9 +2001,10 @@ func (s *store) CreateContainer(id string, names []string, image, layer, metadat
20012001
// But in transient store mode, all container layers are volatile.
20022002
Volatile: options.Volatile || s.transientStore,
20032003
}
2004+
useHostMapping := idMappingsOptions.HostUIDMapping || s.canUseShifting(uidMap, gidMap)
20042005
layerOptions.IDMappingOptions = LayerIDMappingOptions{
2005-
HostUIDMapping: idMappingsOptions.HostUIDMapping,
2006-
HostGIDMapping: idMappingsOptions.HostGIDMapping,
2006+
HostUIDMapping: useHostMapping,
2007+
HostGIDMapping: useHostMapping,
20072008
UIDMap: copySlicePreferringNil(uidMap),
20082009
GIDMap: copySlicePreferringNil(gidMap),
20092010
}

0 commit comments

Comments
 (0)