move rest of pod checks over to schema

This commit is contained in:
Robert Brennan
2019-12-20 17:33:52 +00:00
parent d80d326f7c
commit 3304285b4e
5 changed files with 38 additions and 31 deletions

15
checks/hostIPC.yaml Normal file
View File

@@ -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

View File

@@ -12,5 +12,4 @@ schema:
properties:
hostNetwork:
not:
enum:
- true
const: true

15
checks/hostPID.yaml Normal file
View File

@@ -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

View File

@@ -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"
)
@@ -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{
@@ -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)
}
}
}

View File

@@ -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)
}