Validate rbd image name in NodeExpand

Added one more validation in NodeExpand for
the volume name from the request and the image
name stored in the staging path metadata.

Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
Madhu Rajanna 2019-12-16 15:20:29 +05:30 committed by mergify[bot]
parent 166eaf700f
commit f281eba475

View File

@ -539,16 +539,19 @@ func (ns *NodeServer) NodeExpandVolume(ctx context.Context, req *csi.NodeExpandV
} }
defer ns.VolumeLocks.Release(volumeID) defer ns.VolumeLocks.Release(volumeID)
_, err := getVolumeName(volumeID) volName, err := getVolumeName(volumeID)
if err != nil { if err != nil {
return nil, status.Error(codes.InvalidArgument, err.Error()) return nil, status.Error(codes.InvalidArgument, err.Error())
} }
imgInfo, devicePath, err := getDevicePathAndImageInfo(ctx, volumePath)
diskMounter := &mount.SafeFormatAndMount{Interface: ns.mounter, Exec: mount.NewOsExec()}
devicePath, err := getDevicePath(ctx, volumePath)
if err != nil { if err != nil {
return nil, status.Error(codes.Internal, err.Error()) return nil, status.Error(codes.Internal, err.Error())
} }
if volName != imgInfo.ImageName {
return nil, status.Errorf(codes.InvalidArgument, "volume name missmatch between request (%s) and stored metadata (%s)", volName, imgInfo.ImageName)
}
diskMounter := &mount.SafeFormatAndMount{Interface: ns.mounter, Exec: mount.NewOsExec()}
// TODO check size and return success or error // TODO check size and return success or error
volumePath += "/" + volumeID volumePath += "/" + volumeID
resizer := resizefs.NewResizeFs(diskMounter) resizer := resizefs.NewResizeFs(diskMounter)
@ -559,16 +562,16 @@ func (ns *NodeServer) NodeExpandVolume(ctx context.Context, req *csi.NodeExpandV
return &csi.NodeExpandVolumeResponse{}, nil return &csi.NodeExpandVolumeResponse{}, nil
} }
func getDevicePath(ctx context.Context, volumePath string) (string, error) { func getDevicePathAndImageInfo(ctx context.Context, volumePath string) (rbdImageMetadataStash, string, error) {
imgInfo, err := lookupRBDImageMetadataStash(volumePath) imgInfo, err := lookupRBDImageMetadataStash(volumePath)
if err != nil { if err != nil {
klog.Errorf(util.Log(ctx, "failed to find image metadata: %v"), err) klog.Errorf(util.Log(ctx, "failed to find image metadata: %v"), err)
} }
device, found := findDeviceMappingImage(ctx, imgInfo.Pool, imgInfo.ImageName, imgInfo.NbdAccess) device, found := findDeviceMappingImage(ctx, imgInfo.Pool, imgInfo.ImageName, imgInfo.NbdAccess)
if found { if found {
return device, nil return imgInfo, device, nil
} }
return "", fmt.Errorf("failed to get device for stagingtarget path %v", volumePath) return rbdImageMetadataStash{}, "", fmt.Errorf("failed to get device for stagingtarget path %v", volumePath)
} }
// NodeGetCapabilities returns the supported capabilities of the node server // NodeGetCapabilities returns the supported capabilities of the node server