Skip to content

Commit

Permalink
Merge pull request #1319 from torredil/master
Browse files Browse the repository at this point in the history
Validate fs type before mounting
  • Loading branch information
k8s-ci-robot authored Jul 25, 2022
2 parents 6592290 + b5c548e commit dfa7430
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions 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 All @@ -38,8 +39,10 @@ const (
FSTypeExt3 = "ext3"
// FSTypeExt4 represents the ext4 filesystem type
FSTypeExt4 = "ext4"
// FSTypeXfs represents te xfs filesystem type
// FSTypeXfs represents the xfs filesystem type
FSTypeXfs = "xfs"
// FSTypeNtfs represents the ntfs filesystem type
FSTypeNtfs = "ntfs"

// default file system type to be used when it is not provided
defaultFsType = FSTypeExt4
Expand All @@ -56,7 +59,13 @@ const (
)

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

var (
Expand Down Expand Up @@ -142,6 +151,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 +693,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 dfa7430

Please sign in to comment.