@@ -292,19 +292,41 @@ func (s *simpleProvider) ValidateContainerSecurityContext(pod *api.Pod, containe
292
292
293
293
allErrs = append (allErrs , s .capabilitiesStrategy .Validate (pod , container )... )
294
294
295
- if len (pod .Spec .Volumes ) > 0 && ! sccutil .SCCAllowsAllVolumes (s .scc ) {
296
- allowedVolumes := sccutil .FSTypeToStringSet (s .scc .Volumes )
297
- for i , v := range pod .Spec .Volumes {
298
- fsType , err := sccutil .GetVolumeFSType (v )
299
- if err != nil {
300
- allErrs = append (allErrs , field .Invalid (fldPath .Child ("volumes" ).Index (i ), string (fsType ), err .Error ()))
301
- continue
295
+ if len (pod .Spec .Volumes ) > 0 {
296
+ if ! sccutil .SCCAllowsAllVolumes (s .scc ) {
297
+ allowedVolumes := sccutil .FSTypeToStringSet (s .scc .Volumes )
298
+ for i , v := range pod .Spec .Volumes {
299
+ fsType , err := sccutil .GetVolumeFSType (v )
300
+ if err != nil {
301
+ allErrs = append (allErrs , field .Invalid (fldPath .Child ("volumes" ).Index (i ), string (fsType ), err .Error ()))
302
+ continue
303
+ }
304
+
305
+ if ! allowedVolumes .Has (string (fsType )) {
306
+ allErrs = append (allErrs , field .Invalid (
307
+ fldPath .Child ("volumes" ).Index (i ), string (fsType ),
308
+ fmt .Sprintf ("%s volumes are not allowed to be used" , string (fsType ))))
309
+ }
302
310
}
311
+ }
303
312
304
- if ! allowedVolumes .Has (string (fsType )) {
305
- allErrs = append (allErrs , field .Invalid (
306
- fldPath .Child ("volumes" ).Index (i ), string (fsType ),
307
- fmt .Sprintf ("%s volumes are not allowed to be used" , string (fsType ))))
313
+ if len (s .scc .AllowedFlexDrivers ) > 0 && sccutil .SCCAllowsFSType (s .scc , securityapi .FSTypeFlexVolume ) {
314
+ for i , v := range pod .Spec .Volumes {
315
+ if v .FlexVolume == nil {
316
+ continue
317
+ }
318
+
319
+ found := false
320
+ driver := v .FlexVolume .Driver
321
+ for _ , allowedDriver := range s .scc .AllowedFlexDrivers {
322
+ if driver == allowedDriver {
323
+ found = true
324
+ break
325
+ }
326
+ }
327
+ if ! found {
328
+ allErrs = append (allErrs , field .Invalid (fldPath .Child ("volumes" ).Index (i ), driver , "Flexvolume driver is not allowed to be used" ))
329
+ }
308
330
}
309
331
}
310
332
}
0 commit comments