Skip to content

Commit 190a06f

Browse files
committed
nvmeof: validate unknown parameters in ControllerModifyVolume
Add validation to reject unknown mutable parameters in the NVMe-oF ControllerModifyVolume implementation. Previously, unknown parameters were silently ignored, which could lead to confusion when users specify incorrect parameter names. The validation now checks that only known parameters (QoS parameters: rwIosPerSecond, rwMbytesPerSecond, rMbytesPerSecond, wMbytesPerSecond, and host parameter: allowHostNQNs) are provided, returning an InvalidArgument error for any unknown parameters. Assisted-by: AskBob <askbob@ibm.com> Signed-off-by: Niels de Vos <ndevos@ibm.com>
1 parent 23f9dda commit 190a06f

1 file changed

Lines changed: 33 additions & 1 deletion

File tree

internal/nvmeof/controller/controllerserver.go

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"fmt"
2424
"maps"
2525
"net"
26+
"slices"
2627
"strconv"
2728

2829
"github.com/container-storage-interface/spec/lib/go/csi"
@@ -370,7 +371,23 @@ func (cs *Server) ControllerModifyVolume(
370371
}
371372
defer cs.volumeLocks.Release(volumeID)
372373

373-
// Step 2: Parse QoS parameters from mutable_parameters
374+
// Step 2: Validate that only known parameters are provided
375+
knownParams := []string{
376+
nvmeof.RwIosPerSecond,
377+
nvmeof.RwMbytesPerSecond,
378+
nvmeof.RMbytesPerSecond,
379+
nvmeof.WMbytesPerSecond,
380+
nvmeof.AllowHostNQNs,
381+
}
382+
383+
for param := range params {
384+
if !slices.Contains(knownParams, param) {
385+
return nil, status.Errorf(codes.InvalidArgument,
386+
"unknown mutable parameter: %s", param)
387+
}
388+
}
389+
390+
// Step 3: Parse QoS parameters from mutable_parameters
374391
hasRBDQoS := rbd.HasQoSParams(params)
375392
if hasRBDQoS {
376393
log.ErrorLog(ctx, "Cannot set RBD QoS parameters on NVMe-oF volumes")
@@ -491,6 +508,21 @@ func validateCreateVolumeRequest(req *csi.CreateVolumeRequest) error {
491508
// Validate QoS parameters - cannot mix RBD and NVMe-oF QoS
492509
mutableParams := req.GetMutableParameters()
493510

511+
// Validate that only known mutable parameters are provided
512+
knownMutableParams := []string{
513+
nvmeof.RwIosPerSecond,
514+
nvmeof.RwMbytesPerSecond,
515+
nvmeof.RMbytesPerSecond,
516+
nvmeof.WMbytesPerSecond,
517+
nvmeof.AllowHostNQNs,
518+
}
519+
520+
for param := range mutableParams {
521+
if !slices.Contains(knownMutableParams, param) {
522+
return fmt.Errorf("unknown mutable parameter: %s", param)
523+
}
524+
}
525+
494526
// check for RBD QoS parameters in both params and mutableParams
495527
if hasRBDQoS := rbd.HasQoSParams(params); hasRBDQoS {
496528
return errors.New("setting RBD QoS parameters on NVMe-oF volumes is not supported")

0 commit comments

Comments
 (0)