Skip to content

Commit

Permalink
move rest of pod checks over to schema
Browse files Browse the repository at this point in the history
  • Loading branch information
rbren committed Dec 23, 2019
1 parent d80d326 commit 3304285
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 31 deletions.
15 changes: 15 additions & 0 deletions checks/hostIPC.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: HostIPCSet
id: hostIPCSet
successMessage: Host IPC is not configured
failureMessage: Host IPC should not be configured
category: Security
controllers:
exclude: []
target: Pod
schema:
'$schema': http://json-schema.org/draft-07/schema
type: object
properties:
hostIPC:
not:
const: true
3 changes: 1 addition & 2 deletions checks/host_network.yaml → checks/hostNetwork.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@ schema:
properties:
hostNetwork:
not:
enum:
- true
const: true
15 changes: 15 additions & 0 deletions checks/hostPID.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: HostPIDSet
id: hostPIDSet
successMessage: Host PID is not configured
failureMessage: Host PID should not be configured
category: Security
controllers:
exclude: []
target: Pod
schema:
'$schema': http://json-schema.org/draft-07/schema
type: object
properties:
hostPID:
not:
const: true
26 changes: 0 additions & 26 deletions pkg/validator/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package validator

import (
"github.com/fairwindsops/polaris/pkg/config"
"github.com/fairwindsops/polaris/pkg/validator/messages"
corev1 "k8s.io/api/core/v1"
)

Expand All @@ -33,7 +32,6 @@ func ValidatePod(conf config.Configuration, pod *corev1.PodSpec, controllerName
ResourceValidation: &ResourceValidation{},
}

pv.validateSecurity(&conf, controllerName)
applyPodSchemaChecks(&conf, pod, controllerName, &pv)

pRes := PodResult{
Expand All @@ -59,27 +57,3 @@ func (pv *PodValidation) validateContainers(containers []corev1.Container, pRes
pRes.ContainerResults = append(pRes.ContainerResults, cRes)
}
}

func (pv *PodValidation) validateSecurity(conf *config.Configuration, controllerName string) {
category := messages.CategorySecurity

name := "HostIPCSet"
if conf.IsActionable(conf.Security, name, controllerName) {
id := config.GetIDFromField(conf.Security, name)
if pv.Pod.HostIPC {
pv.addFailure(messages.HostIPCFailure, conf.Security.HostIPCSet, category, id)
} else {
pv.addSuccess(messages.HostIPCSuccess, category, id)
}
}

name = "HostPIDSet"
if conf.IsActionable(conf.Security, name, controllerName) {
id := config.GetIDFromField(conf.Security, name)
if pv.Pod.HostPID {
pv.addFailure(messages.HostPIDFailure, conf.Security.HostPIDSet, category, id)
} else {
pv.addSuccess(messages.HostPIDSuccess, category, id)
}
}
}
10 changes: 7 additions & 3 deletions pkg/validator/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,17 @@ var (
TargetContainer: []SchemaCheck{},
TargetPod: []SchemaCheck{},
}
checkOrder = []string{
"hostIPC",
"hostPID",
"hostNetwork",
}
)

func init() {
schemaBox = packr.New("Schemas", "../../checks")
files := schemaBox.List()
for _, file := range files {
contents, err := schemaBox.Find(file)
for _, file := range checkOrder {
contents, err := schemaBox.Find(file + ".yaml")
if err != nil {
panic(err)
}
Expand Down

0 comments on commit 3304285

Please sign in to comment.