mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Merge pull request #111693 from kinvolk/rata/userns-support-2022
volume: FeatureGate access to GetHostIDsForPod()
This commit is contained in:
commit
11d4cb52f2
@ -669,17 +669,29 @@ func (og *operationGenerator) GenerateMountVolumeFunc(
|
|||||||
resizeOptions.DeviceStagePath = deviceMountPath
|
resizeOptions.DeviceStagePath = deviceMountPath
|
||||||
}
|
}
|
||||||
|
|
||||||
kvh, ok := og.GetVolumePluginMgr().Host.(volume.KubeletVolumeHost)
|
// No mapping is needed for hostUID/hostGID if userns is not used.
|
||||||
if !ok {
|
// Therefore, just assign the container users to host UID/GID.
|
||||||
eventErr, detailedErr := volumeToMount.GenerateError("MountVolume type assertion error", fmt.Errorf("volume host does not implement KubeletVolumeHost interface"))
|
hostUID := util.FsUserFrom(volumeToMount.Pod)
|
||||||
return volumetypes.NewOperationContext(eventErr, detailedErr, migrated)
|
hostGID := fsGroup
|
||||||
}
|
if utilfeature.DefaultFeatureGate.Enabled(features.UserNamespacesStatelessPodsSupport) {
|
||||||
uid := util.FsUserFrom(volumeToMount.Pod)
|
// Without userns hostUID/GID was the user inside the container too.
|
||||||
hostUID, hostGID, err := kvh.GetHostIDsForPod(volumeToMount.Pod, uid, fsGroup)
|
containerUID, containerGID := hostUID, hostGID
|
||||||
if err != nil {
|
|
||||||
msg := fmt.Sprintf("MountVolume.GetHostIDsForPod failed to find host ID in user namespace (UID: %v GID: %v)", uid, fsGroup)
|
kvh, ok := og.GetVolumePluginMgr().Host.(volume.KubeletVolumeHost)
|
||||||
eventErr, detailedErr := volumeToMount.GenerateError(msg, err)
|
if !ok {
|
||||||
return volumetypes.NewOperationContext(eventErr, detailedErr, migrated)
|
msg := fmt.Errorf("volume host does not implement KubeletVolumeHost interface")
|
||||||
|
eventErr, detailedErr := volumeToMount.GenerateError("MountVolume type assertion error", msg)
|
||||||
|
return volumetypes.NewOperationContext(eventErr, detailedErr, migrated)
|
||||||
|
}
|
||||||
|
|
||||||
|
// This pod _might_ use userns. GetHostIDsForPod() will give us the right
|
||||||
|
// UID/GID to use for this pod (no matter if the pod uses userns or not).
|
||||||
|
hostUID, hostGID, err = kvh.GetHostIDsForPod(volumeToMount.Pod, containerUID, containerGID)
|
||||||
|
if err != nil {
|
||||||
|
msg := fmt.Sprintf("MountVolume.GetHostIDsForPod failed to find host ID in user namespace (UID: %v GID: %v)", containerUID, containerGID)
|
||||||
|
eventErr, detailedErr := volumeToMount.GenerateError(msg, err)
|
||||||
|
return volumetypes.NewOperationContext(eventErr, detailedErr, migrated)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute mount
|
// Execute mount
|
||||||
|
Loading…
Reference in New Issue
Block a user