Skip to content

Commit

Permalink
Validate fs type before mounting
Browse files Browse the repository at this point in the history
Signed-off-by: Eddie Torres <torredil@amazon.com>
  • Loading branch information
torredil committed Jul 25, 2022
1 parent 6592290 commit c993dc2
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion pkg/driver/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"os"
"path/filepath"
"strings"

csi "github.com/container-storage-interface/spec/lib/go/csi"
"github.com/kubernetes-sigs/aws-ebs-csi-driver/pkg/cloud"
Expand Down Expand Up @@ -56,7 +57,12 @@ const (
)

var (
ValidFSTypes = []string{FSTypeExt2, FSTypeExt3, FSTypeExt4, FSTypeXfs}
ValidFSTypes = map[string]struct{}{
FSTypeExt2: {},
FSTypeExt3: {},
FSTypeExt4: {},
FSTypeXfs: {},
}
)

var (
Expand Down Expand Up @@ -142,6 +148,11 @@ func (d *nodeService) NodeStageVolume(ctx context.Context, req *csi.NodeStageVol
fsType = defaultFsType
}

_, ok := ValidFSTypes[strings.ToLower(fsType)]
if !ok {
return nil, status.Errorf(codes.InvalidArgument, "NodeStageVolume: invalid fstype %s", fsType)
}

mountOptions := collectMountOptions(fsType, mountVolume.MountFlags)

if ok := d.inFlight.Insert(volumeID); !ok {
Expand Down Expand Up @@ -679,6 +690,11 @@ func (d *nodeService) nodePublishVolumeForFileSystem(req *csi.NodePublishVolumeR
fsType = defaultFsType
}

_, ok := ValidFSTypes[strings.ToLower(fsType)]
if !ok {
return status.Errorf(codes.InvalidArgument, "NodePublishVolume: invalid fstype %s", fsType)
}

mountOptions = collectMountOptions(fsType, mountOptions)
klog.V(4).Infof("NodePublishVolume: mounting %s at %s with option %s as fstype %s", source, target, mountOptions, fsType)
if err := d.mounter.Mount(source, target, fsType, mountOptions); err != nil {
Expand Down

0 comments on commit c993dc2

Please sign in to comment.