From f281eba4751a82ffd91d6a8459d6f76bdd6f227c Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Mon, 16 Dec 2019 15:20:29 +0530 Subject: [PATCH] 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 --- pkg/rbd/nodeserver.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/pkg/rbd/nodeserver.go b/pkg/rbd/nodeserver.go index d24316460..454660e1b 100644 --- a/pkg/rbd/nodeserver.go +++ b/pkg/rbd/nodeserver.go @@ -539,16 +539,19 @@ func (ns *NodeServer) NodeExpandVolume(ctx context.Context, req *csi.NodeExpandV } defer ns.VolumeLocks.Release(volumeID) - _, err := getVolumeName(volumeID) + volName, err := getVolumeName(volumeID) if err != nil { return nil, status.Error(codes.InvalidArgument, err.Error()) } - - diskMounter := &mount.SafeFormatAndMount{Interface: ns.mounter, Exec: mount.NewOsExec()} - devicePath, err := getDevicePath(ctx, volumePath) + imgInfo, devicePath, err := getDevicePathAndImageInfo(ctx, volumePath) if err != nil { 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 volumePath += "/" + volumeID resizer := resizefs.NewResizeFs(diskMounter) @@ -559,16 +562,16 @@ func (ns *NodeServer) NodeExpandVolume(ctx context.Context, req *csi.NodeExpandV 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) if err != nil { klog.Errorf(util.Log(ctx, "failed to find image metadata: %v"), err) } device, found := findDeviceMappingImage(ctx, imgInfo.Pool, imgInfo.ImageName, imgInfo.NbdAccess) 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