diff --git a/pkg/volume/glusterfs/glusterfs.go b/pkg/volume/glusterfs/glusterfs.go index 1b46c4e7132..59ef612e3d5 100644 --- a/pkg/volume/glusterfs/glusterfs.go +++ b/pkg/volume/glusterfs/glusterfs.go @@ -74,7 +74,12 @@ const ( gciGlusterMountBinariesPath = "/sbin/mount.glusterfs" defaultGidMin = 2000 defaultGidMax = math.MaxInt32 - absoluteGidMax = math.MaxInt32 + // absoluteGidMin/Max are currently the same as the + // default values, but they play a different role and + // could take a different value. Only thing we need is: + // absGidMin <= defGidMin <= defGidMax <= absGidMax + absoluteGidMin = 2000 + absoluteGidMax = math.MaxInt32 ) func (plugin *glusterfsPlugin) Init(host volume.VolumeHost) error { @@ -850,6 +855,9 @@ func parseClassParameters(params map[string]string, kubeClient clientset.Interfa var cfg provisioningConfig var err error + cfg.gidMin = defaultGidMin + cfg.gidMax = defaultGidMax + authEnabled := true for k, v := range params { switch dstrings.ToLower(k) { @@ -874,12 +882,24 @@ func parseClassParameters(params map[string]string, kubeClient clientset.Interfa if err != nil { return nil, fmt.Errorf("glusterfs: invalid value %q for volume plugin %s", k, glusterfsPluginName) } + if parseGidMin < absoluteGidMin { + return nil, fmt.Errorf("glusterfs: gidMin must be >= %v", absoluteGidMin) + } + if parseGidMin > absoluteGidMax { + return nil, fmt.Errorf("glusterfs: gidMin must be <= %v", absoluteGidMax) + } cfg.gidMin = parseGidMin case "gidmax": parseGidMax, err := convertGid(v) if err != nil { return nil, fmt.Errorf("glusterfs: invalid value %q for volume plugin %s", k, glusterfsPluginName) } + if parseGidMax < absoluteGidMin { + return nil, fmt.Errorf("glusterfs: gidMax must be >= %v", absoluteGidMin) + } + if parseGidMax > absoluteGidMax { + return nil, fmt.Errorf("glusterfs: gidMax must be <= %v", absoluteGidMax) + } cfg.gidMax = parseGidMax default: return nil, fmt.Errorf("glusterfs: invalid option %q for volume plugin %s", k, glusterfsPluginName) @@ -912,14 +932,6 @@ func parseClassParameters(params map[string]string, kubeClient clientset.Interfa cfg.secretValue = cfg.userKey } - if cfg.gidMin == 0 { - cfg.gidMin = defaultGidMin - } - - if cfg.gidMax == 0 { - cfg.gidMax = defaultGidMax - } - if cfg.gidMin > cfg.gidMax { return nil, fmt.Errorf("StorageClass for provisioner %q must have gidMax value >= gidMin", glusterfsPluginName) } diff --git a/pkg/volume/glusterfs/glusterfs_test.go b/pkg/volume/glusterfs/glusterfs_test.go index e56c1a3a3ca..4ae94c7fe27 100644 --- a/pkg/volume/glusterfs/glusterfs_test.go +++ b/pkg/volume/glusterfs/glusterfs_test.go @@ -350,6 +350,130 @@ func TestParseClassParameters(t *testing.T) { true, // expect error nil, }, + { + "invalid gidMin #1", + map[string]string{ + "resturl": "https://localhost:8080", + "restauthenabled": "false", + "gidMin": "0", + }, + &secret, + true, // expect error + nil, + }, + { + "invalid gidMin #2", + map[string]string{ + "resturl": "https://localhost:8080", + "restauthenabled": "false", + "gidMin": "1999", + }, + &secret, + true, // expect error + nil, + }, + { + "invalid gidMin #3", + map[string]string{ + "resturl": "https://localhost:8080", + "restauthenabled": "false", + "gidMin": "1999", + }, + &secret, + true, // expect error + nil, + }, + { + "invalid gidMax #1", + map[string]string{ + "resturl": "https://localhost:8080", + "restauthenabled": "false", + "gidMax": "0", + }, + &secret, + true, // expect error + nil, + }, + { + "invalid gidMax #2", + map[string]string{ + "resturl": "https://localhost:8080", + "restauthenabled": "false", + "gidMax": "1999", + }, + &secret, + true, // expect error + nil, + }, + { + "invalid gidMax #3", + map[string]string{ + "resturl": "https://localhost:8080", + "restauthenabled": "false", + "gidMax": "1999", + }, + &secret, + true, // expect error + nil, + }, + { + "invalid gidMin:gidMax", + map[string]string{ + "resturl": "https://localhost:8080", + "restauthenabled": "false", + "gidMin": "5001", + "gidMax": "5000", + }, + &secret, + true, // expect error + nil, + }, + { + "valid gidMin", + map[string]string{ + "resturl": "https://localhost:8080", + "restauthenabled": "false", + "gidMin": "4000", + }, + &secret, + false, // expect error + &provisioningConfig{ + url: "https://localhost:8080", + gidMin: 4000, + gidMax: 2147483647, + }, + }, + { + "valid gidMax", + map[string]string{ + "resturl": "https://localhost:8080", + "restauthenabled": "false", + "gidMax": "5000", + }, + &secret, + false, // expect error + &provisioningConfig{ + url: "https://localhost:8080", + gidMin: 2000, + gidMax: 5000, + }, + }, + { + "valid gidMin:gidMax", + map[string]string{ + "resturl": "https://localhost:8080", + "restauthenabled": "false", + "gidMin": "4000", + "gidMax": "5000", + }, + &secret, + false, // expect error + &provisioningConfig{ + url: "https://localhost:8080", + gidMin: 4000, + gidMax: 5000, + }, + }, } for _, test := range tests {