@@ -273,47 +273,70 @@ func (v *Validator) CheckProcess() (msgs []string) {
273273 }
274274 }
275275
276- var caps []string
276+ msgs = append (msgs , v .CheckCapablities ()... )
277+ msgs = append (msgs , v .CheckRlimits ()... )
277278
278- for _ , cap := range process .Capabilities .Bounding {
279- caps = append (caps , cap )
280- }
281- for _ , cap := range process .Capabilities .Effective {
282- caps = append (caps , cap )
283- }
284- for _ , cap := range process .Capabilities .Inheritable {
285- caps = append (caps , cap )
286- }
287- for _ , cap := range process .Capabilities .Permitted {
288- caps = append (caps , cap )
289- }
290- for _ , cap := range process .Capabilities .Ambient {
291- caps = append (caps , cap )
292- }
279+ if v .spec .Platform .OS == "linux" {
293280
294- for _ , capability := range caps {
295- if err := CapValid (capability , v .HostSpecific ); err != nil {
296- msgs = append (msgs , fmt .Sprintf ("capability %q is not valid, man capabilities(7)" , capability ))
281+ if len (process .ApparmorProfile ) > 0 {
282+ profilePath := filepath .Join (v .bundlePath , v .spec .Root .Path , "/etc/apparmor.d" , process .ApparmorProfile )
283+ _ , err := os .Stat (profilePath )
284+ if err != nil {
285+ msgs = append (msgs , err .Error ())
286+ }
297287 }
298288 }
299289
300- for index , rlimit := range process .Rlimits {
301- if err := rlimitValid (rlimit ); err != nil {
302- msgs = append (msgs , err .Error ())
290+ return
291+ }
292+
293+ func (v * Validator ) CheckCapablities () (msgs []string ) {
294+ if v .spec .Platform .OS == "linux" {
295+ var caps []string
296+
297+ for _ , cap := range process .Capabilities .Bounding {
298+ caps = append (caps , cap )
299+ }
300+ for _ , cap := range process .Capabilities .Effective {
301+ caps = append (caps , cap )
302+ }
303+ for _ , cap := range process .Capabilities .Inheritable {
304+ caps = append (caps , cap )
303305 }
304- for i := index + 1 ; i < len (process .Rlimits ); i ++ {
305- if process .Rlimits [index ].Type == process .Rlimits [i ].Type {
306- msgs = append (msgs , fmt .Sprintf ("rlimit can not contain the same type %q." , process .Rlimits [index ].Type ))
306+ for _ , cap := range process .Capabilities .Permitted {
307+ caps = append (caps , cap )
308+ }
309+ for _ , cap := range process .Capabilities .Ambient {
310+ caps = append (caps , cap )
311+ }
312+
313+ for _ , capability := range caps {
314+ if err := CapValid (capability , v .HostSpecific ); err != nil {
315+ msgs = append (msgs , fmt .Sprintf ("capability %q is not valid, man capabilities(7)" , capability ))
307316 }
308317 }
318+ } else {
319+ logrus .Warnf ("process.capabilities validation not yet implemented for OS %q" , v .spec .Platform .OS )
309320 }
310321
311- if len (process .ApparmorProfile ) > 0 {
312- profilePath := filepath .Join (v .bundlePath , v .spec .Root .Path , "/etc/apparmor.d" , process .ApparmorProfile )
313- _ , err := os .Stat (profilePath )
314- if err != nil {
315- msgs = append (msgs , err .Error ())
322+ return
323+ }
324+
325+ func (v * Validator ) CheckRlimits () (msgs []string ) {
326+ process := v .spec .Process
327+ if v .spec .Platform .OS == "linux" {
328+ for index , rlimit := range process .Rlimits {
329+ if err := rlimitValid (rlimit ); err != nil {
330+ msgs = append (msgs , err .Error ())
331+ }
332+ for i := index + 1 ; i < len (process .Rlimits ); i ++ {
333+ if process .Rlimits [index ].Type == process .Rlimits [i ].Type {
334+ msgs = append (msgs , fmt .Sprintf ("rlimit can not contain the same type %q." , process .Rlimits [index ].Type ))
335+ }
336+ }
316337 }
338+ } else {
339+ logrus .Warnf ("process.rlimits validation not yet implemented for OS %q" , v .spec .Platform .OS )
317340 }
318341
319342 return
0 commit comments