1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-06 16:06:56 +00:00

add examples_not_tested

This commit is contained in:
Shuting Zhao 2019-07-17 13:33:05 -07:00
parent 24b5acdc73
commit 27f893df53
4 changed files with 141 additions and 0 deletions

View file

@ -0,0 +1,22 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: psp-demo-unprivileged
labels:
app.type: prod
spec:
replicas: 1
selector:
matchLabels:
app: psp
template:
metadata:
labels:
app: psp
spec:
containers:
- name: sec-ctx-unprivileged
image: nginxinc/nginx-unprivileged
securityContext:
runAsNonRoot: true

View file

@ -0,0 +1,25 @@
apiVersion : kyverno.io/v1alpha1
kind: Policy
metadata:
name: container-security-context
spec:
rules:
- name: set-userID
resource:
kinds:
- Deployment
selector :
matchLabels:
app.type: prod
validate:
message: "validate container security contexts"
pattern:
spec:
template:
spec:
containers:
securityContext:
# privileged: false
# allowPrivilegeEscalation: false
# readOnlyRootFilesystem: true
runAsNonRoot: true

View file

@ -0,0 +1,24 @@
apiVersion : kyverno.io/v1alpha1
kind: Policy
metadata:
name: pod-security-context
spec:
rules:
- name: set-userID
resource:
kinds:
- Deployment
selector :
matchLabels:
app.type: prod
validate:
message: "secure pod"
pattern:
spec:
template:
spec:
hostNetwork: false
hostIPC: false
hostPID: false
securityContext:
runAsNonRoot: true

70
pkg/engine/overlay_new.go Executable file
View file

@ -0,0 +1,70 @@
package engine
import (
"reflect"
)
// func processoverlay(rule kubepolicy.Rule, rawResource []byte, gvk metav1.GroupVersionKind) ([][]byte, error) {
// var resource interface{}
// var appliedPatches [][]byte
// err := json.Unmarshal(rawResource, &resource)
// if err != nil {
// return nil, err
// }
// patches, err := mutateResourceWithOverlay(resource, *rule.Mutation.Overlay)
// if err != nil {
// return nil, err
// }
// appliedPatches = append(appliedPatches, patches...)
// return appliedPatches, err
// }
func applyoverlay(resource, overlay interface{}, path string) ([][]byte, error) {
var appliedPatches [][]byte
// resource item exists but has different type - replace
// all subtree within this path by overlay
if reflect.TypeOf(resource) != reflect.TypeOf(overlay) {
patch, err := replaceSubtree(overlay, path)
if err != nil {
return nil, err
}
appliedPatches = append(appliedPatches, patch)
}
return applyOverlayForSameTypes(resource, overlay, path)
}
func checkConditions(resource, overlay interface{}, path string) bool {
switch typedOverlay := overlay.(type) {
case map[string]interface{}:
typedResource := resource.(map[string]interface{})
if !checkConditionOnMap(typedResource, typedOverlay) {
return false
}
case []interface{}:
typedResource := resource.([]interface{})
if !checkConditionOnArray(typedResource, typedOverlay) {
return false
}
case string, float64, int64, bool:
default:
return false
}
return true
}
func checkConditionOnMap(resourceMap, overlayMap map[string]interface{}) bool {
// _ := getAnchorsFromMap(overlayMap)
return false
}
func checkConditionOnArray(resource, overlay []interface{}) bool {
return false
}