mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-31 03:45:17 +00:00
updated policies
updated policies according to new policy structure for testing
This commit is contained in:
parent
e200cdc2a4
commit
2997a5139b
16 changed files with 466 additions and 0 deletions
14
test/ConfigMap/CM.yaml
Normal file
14
test/ConfigMap/CM.yaml
Normal file
|
@ -0,0 +1,14 @@
|
|||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: game-config
|
||||
namespace: default
|
||||
data:
|
||||
secretData: "very sensitive data"
|
||||
secretDatatoreplace: "data is not changed"
|
||||
game.properties: |
|
||||
enemies=aliens
|
||||
lives=3
|
||||
ui.properties: |
|
||||
color.good=purple
|
||||
color.bad=yellow
|
49
test/ConfigMap/policy-CM.yaml
Normal file
49
test/ConfigMap/policy-CM.yaml
Normal file
|
@ -0,0 +1,49 @@
|
|||
apiVersion : kubepolicy.nirmata.io/v1alpha1
|
||||
kind : Policy
|
||||
metadata :
|
||||
name : policy-cm
|
||||
spec :
|
||||
rules:
|
||||
- name: pCM1
|
||||
resource:
|
||||
kind : ConfigMap
|
||||
name: "game-config"
|
||||
mutate:
|
||||
patches:
|
||||
- path : "/data/newKey"
|
||||
op : add
|
||||
value : newValue
|
||||
- name: pCM2
|
||||
resource:
|
||||
kind : ConfigMap
|
||||
name: "game-config"
|
||||
mutate:
|
||||
patches:
|
||||
- path : "/data/secretData"
|
||||
op : remove
|
||||
- path : "/data/secretDatatoreplace"
|
||||
op : replace
|
||||
value : "data is replaced"
|
||||
- name: pCM3
|
||||
resource:
|
||||
kind : ConfigMap
|
||||
name: "game-config"
|
||||
mutate:
|
||||
patches:
|
||||
- path : "/data/secretData"
|
||||
op : add
|
||||
value : newData
|
||||
validate:
|
||||
message: "There is only one enemy"
|
||||
pattern:
|
||||
data:
|
||||
game.properties: "*enemies=aliens*"
|
||||
- name: pCM4
|
||||
resource:
|
||||
kind : ConfigMap
|
||||
name: "game-config"
|
||||
validate:
|
||||
message: "This CM data is broken because it does not have ui.properties"
|
||||
pattern:
|
||||
data:
|
||||
ui.properties: "*"
|
62
test/CronJob/cronjobs.yaml
Normal file
62
test/CronJob/cronjobs.yaml
Normal file
|
@ -0,0 +1,62 @@
|
|||
apiVersion: batch/v1beta1
|
||||
kind: CronJob
|
||||
metadata:
|
||||
name: hello
|
||||
labels :
|
||||
label : "original"
|
||||
spec:
|
||||
schedule: "*/1 * * * *"
|
||||
jobTemplate:
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- name: hello
|
||||
image: busybox
|
||||
args:
|
||||
- /bin/sh
|
||||
- -c
|
||||
- date; echo Hello from the Kubernetes cluster
|
||||
restartPolicy: OnFailure
|
||||
---
|
||||
apiVersion: batch/v1beta1
|
||||
kind: CronJob
|
||||
metadata:
|
||||
name: hellow
|
||||
labels :
|
||||
label : "original"
|
||||
spec:
|
||||
schedule: "*/1 * * * *"
|
||||
jobTemplate:
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- name: 12hello
|
||||
image: busybox
|
||||
args:
|
||||
- /bin/sh
|
||||
- -c
|
||||
- date; echo Hello from the Kubernetes cluster
|
||||
restartPolicy: OnFailure
|
||||
---
|
||||
apiVersion: batch/v1beta1
|
||||
kind: CronJob
|
||||
metadata:
|
||||
name: hello23
|
||||
labels:
|
||||
label: "original"
|
||||
spec:
|
||||
schedule: "*/1 * * * *"
|
||||
jobTemplate:
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- name: hel32lo
|
||||
image: busybox
|
||||
args:
|
||||
- /bin/sh
|
||||
- -c
|
||||
- date; echo Hello from the Kubernetes cluster
|
||||
restartPolicy: OnFailure
|
37
test/CronJob/policy-cronjob-wldcrd.yaml
Normal file
37
test/CronJob/policy-cronjob-wldcrd.yaml
Normal file
|
@ -0,0 +1,37 @@
|
|||
apiVersion: kubepolicy.nirmata.io/v1alpha1
|
||||
kind: Policy
|
||||
metadata:
|
||||
name: policy-cronjob
|
||||
spec:
|
||||
rules:
|
||||
- name:
|
||||
resource:
|
||||
kind : CronJob
|
||||
name: "?ell*"
|
||||
mutate:
|
||||
patches:
|
||||
- path: "/metadata/labels/isMutated"
|
||||
op: add
|
||||
value: "true"
|
||||
- path : "/spec/schedule"
|
||||
op : replace
|
||||
value : "* */1 * * *"
|
||||
- path: "/metadata/labels/label"
|
||||
op: add
|
||||
value: "not_original"
|
||||
- path: "/metadata/labels/label234e3"
|
||||
op: remove
|
||||
validate:
|
||||
message: "This resource is broken"
|
||||
pattern:
|
||||
metadata:
|
||||
labels:
|
||||
label: "not_original"
|
||||
spec:
|
||||
jobTemplate:
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- name: "h*"
|
||||
image: busybox
|
27
test/DaemonSet/policy-daemonset.yaml
Normal file
27
test/DaemonSet/policy-daemonset.yaml
Normal file
|
@ -0,0 +1,27 @@
|
|||
apiVersion: kubepolicy.nirmata.io/v1alpha1
|
||||
kind: Policy
|
||||
metadata:
|
||||
name: policy-daemonset
|
||||
spec:
|
||||
rules:
|
||||
- name: "Patch and Volume validation"
|
||||
resource:
|
||||
kind: DaemonSet
|
||||
name: fluentd-elasticsearch
|
||||
mutate:
|
||||
patches:
|
||||
- path: "/metadata/labels/isMutated"
|
||||
op: add
|
||||
value: "true"
|
||||
- path: "/metadata/labels/originalLabel"
|
||||
op: remove
|
||||
validate:
|
||||
message: "This daemonset is broken"
|
||||
pattern:
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
volumeMounts:
|
||||
- name: varlibdockercontainers
|
||||
readOnly: false
|
25
test/Deployment/policy-deployment-any.yaml
Normal file
25
test/Deployment/policy-deployment-any.yaml
Normal file
|
@ -0,0 +1,25 @@
|
|||
apiVersion : kubepolicy.nirmata.io/v1alpha1
|
||||
kind : Policy
|
||||
metadata :
|
||||
name : policy-deployment
|
||||
spec :
|
||||
rules:
|
||||
- name: "First policy v2"
|
||||
resource:
|
||||
kind : Deployment
|
||||
name: nginx-*
|
||||
mutate:
|
||||
patches:
|
||||
- path: /metadata/labels/isMutated
|
||||
op: add
|
||||
value: "true"
|
||||
- path: /metadata/labels/app
|
||||
op: replace
|
||||
value: "nginx_is_mutated"
|
||||
|
||||
validate:
|
||||
message: "Because I like only mutated resources"
|
||||
pattern:
|
||||
metadata:
|
||||
labels:
|
||||
app: "*mutated"
|
13
test/Endpoint/endpoints.yaml
Normal file
13
test/Endpoint/endpoints.yaml
Normal file
|
@ -0,0 +1,13 @@
|
|||
apiVersion: v1
|
||||
kind: Endpoints
|
||||
metadata:
|
||||
name: test-endpoint
|
||||
labels:
|
||||
label : test
|
||||
subsets:
|
||||
- addresses:
|
||||
- ip: 192.168.10.171
|
||||
ports:
|
||||
- name: secure-connection
|
||||
port: 443
|
||||
protocol: TCP
|
32
test/Endpoint/policy-endpoints.yaml
Normal file
32
test/Endpoint/policy-endpoints.yaml
Normal file
|
@ -0,0 +1,32 @@
|
|||
apiVersion : kubepolicy.nirmata.io/v1alpha1
|
||||
kind : Policy
|
||||
metadata :
|
||||
name : policy-endpoints
|
||||
spec :
|
||||
rules:
|
||||
- name:
|
||||
resource:
|
||||
kind : Endpoints
|
||||
selector:
|
||||
matchLabels:
|
||||
label : test
|
||||
mutate:
|
||||
patches:
|
||||
- path : "/subsets/0/ports/0/port"
|
||||
op : replace
|
||||
value: 9663
|
||||
- path : "/subsets/0"
|
||||
op: add
|
||||
value:
|
||||
addresses:
|
||||
- ip: "192.168.10.171"
|
||||
ports:
|
||||
- name: load-balancer-connection
|
||||
port: 80
|
||||
protocol: UDP
|
||||
validate:
|
||||
message: "This resource has wrong IP"
|
||||
pattern:
|
||||
subsets:
|
||||
- addresses:
|
||||
- ip: "192.168.10.171|192.168.10.172"
|
22
test/HorizontalPodAutoscaler/hpa.yaml
Normal file
22
test/HorizontalPodAutoscaler/hpa.yaml
Normal file
|
@ -0,0 +1,22 @@
|
|||
apiVersion: autoscaling/v2beta1
|
||||
kind: HorizontalPodAutoscaler
|
||||
metadata:
|
||||
name: wildfly-example
|
||||
labels:
|
||||
originalLabel: isHere
|
||||
spec:
|
||||
scaleTargetRef:
|
||||
apiVersion: extensions/v1beta1
|
||||
kind: Deployment
|
||||
name: wildfly-example
|
||||
minReplicas: 1
|
||||
maxReplicas: 5
|
||||
metrics:
|
||||
- type: Resource
|
||||
resource:
|
||||
name: cpu
|
||||
targetAverageUtilization: 80
|
||||
- type: Resource
|
||||
resource:
|
||||
name: memory
|
||||
targetAverageValue: 1000Mi
|
30
test/Ingress/policy-ingress.yaml
Normal file
30
test/Ingress/policy-ingress.yaml
Normal file
|
@ -0,0 +1,30 @@
|
|||
apiVersion: kubepolicy.nirmata.io/v1alpha1
|
||||
kind: Policy
|
||||
metadata :
|
||||
name : policy-ingress
|
||||
spec :
|
||||
rules:
|
||||
- name: ingress1
|
||||
resource:
|
||||
kind : Ingress
|
||||
selector:
|
||||
matchLabels:
|
||||
originalLabel: isHere
|
||||
mutate:
|
||||
patches:
|
||||
- path: "/metadata/labels/isMutated"
|
||||
op: add
|
||||
value: "true"
|
||||
- path : "/spec/rules/0/http/paths/0/path"
|
||||
op : replace
|
||||
value: "/mutatedpath"
|
||||
validate:
|
||||
message: "Ingress allowed only for prod services"
|
||||
pattern:
|
||||
spec:
|
||||
rules:
|
||||
- http:
|
||||
paths:
|
||||
- path: "*"
|
||||
backend:
|
||||
serviceName: "*prod"
|
29
test/NetworkPolicy/policy-network-policy.yaml
Normal file
29
test/NetworkPolicy/policy-network-policy.yaml
Normal file
|
@ -0,0 +1,29 @@
|
|||
apiVersion: kubepolicy.nirmata.io/v1alpha1
|
||||
kind: Policy
|
||||
metadata:
|
||||
name: policy-network-policy
|
||||
spec:
|
||||
rules:
|
||||
- name: np1
|
||||
resource:
|
||||
kind : NetworkPolicy
|
||||
selector:
|
||||
matchLabels:
|
||||
originalLabel: isHere
|
||||
mutate:
|
||||
patches:
|
||||
- path: "/metadata/labels/isMutated"
|
||||
op: add
|
||||
value: "true"
|
||||
- path : "/spec/ingress/0/from/0/ipBlock/cidr"
|
||||
op : replace
|
||||
value: "172.17.128.0/17"
|
||||
validate:
|
||||
message: "This network policy does not meet security criteria"
|
||||
pattern:
|
||||
spec:
|
||||
ingress:
|
||||
- from:
|
||||
- ipBlock:
|
||||
except:
|
||||
- 172.17.129.0/24
|
42
test/ResourceQuota/policy-quota-validation.yaml
Normal file
42
test/ResourceQuota/policy-quota-validation.yaml
Normal file
|
@ -0,0 +1,42 @@
|
|||
apiVersion : kubepolicy.nirmata.io/v1alpha1
|
||||
kind : Policy
|
||||
metadata :
|
||||
name : policy-quota-low-test-validation
|
||||
spec :
|
||||
rules:
|
||||
- name:
|
||||
resource:
|
||||
kind : ResourceQuota
|
||||
selector:
|
||||
matchLabels:
|
||||
quota: low
|
||||
validate:
|
||||
message: "This RQ requests too many RAM"
|
||||
pattern:
|
||||
spec:
|
||||
hard:
|
||||
memory: "8Gi|12Gi"
|
||||
- name:
|
||||
resource:
|
||||
kind : ResourceQuota
|
||||
selector:
|
||||
matchLabels:
|
||||
quota: low
|
||||
validate:
|
||||
message: "This RQ requests too many CPUs"
|
||||
pattern:
|
||||
spec:
|
||||
hard:
|
||||
cpu: <3
|
||||
- name:
|
||||
resource:
|
||||
kind : ResourceQuota
|
||||
selector:
|
||||
matchLabels:
|
||||
quota: low
|
||||
validate:
|
||||
message: "This RQ requests too many PODs"
|
||||
pattern:
|
||||
spec:
|
||||
hard:
|
||||
pods: 1|2|3|4
|
27
test/Secret/policy-secret.yaml
Normal file
27
test/Secret/policy-secret.yaml
Normal file
|
@ -0,0 +1,27 @@
|
|||
apiVersion: kubepolicy.nirmata.io/v1alpha1
|
||||
kind: Policy
|
||||
metadata:
|
||||
name: policy-secrets
|
||||
spec:
|
||||
rules:
|
||||
- name: secret1
|
||||
resource:
|
||||
kind : Secret
|
||||
name: "mysecret"
|
||||
mutate:
|
||||
patches:
|
||||
- path: "/metadata/labels/isMutated"
|
||||
op: add
|
||||
value: "true"
|
||||
- path: "/metadata/labels/originalLabel"
|
||||
op: remove
|
||||
- path : "/data/newPass"
|
||||
op : add
|
||||
value : "bmV3UmFuZG9tUGFzcwo="
|
||||
- path : "/data/password"
|
||||
op : replace
|
||||
value : "Y29tcHJvbWlzZWQK"
|
||||
validate:
|
||||
message: "This type of secrets does not meet security criteria"
|
||||
pattern:
|
||||
type: "Opaque"
|
11
test/Secret/secret.yaml
Normal file
11
test/Secret/secret.yaml
Normal file
|
@ -0,0 +1,11 @@
|
|||
apiVersion: v1
|
||||
kind: Secret
|
||||
metadata:
|
||||
name: mysecret
|
||||
labels:
|
||||
originalLabel : isHere
|
||||
|
||||
type: Opaque
|
||||
data:
|
||||
username: TmlybWF0YQ==
|
||||
password: aXNDb29s
|
31
test/Service/policy-service.yaml
Normal file
31
test/Service/policy-service.yaml
Normal file
|
@ -0,0 +1,31 @@
|
|||
apiVersion : kubepolicy.nirmata.io/v1alpha1
|
||||
kind : Policy
|
||||
metadata :
|
||||
name : policy-service
|
||||
spec :
|
||||
rules:
|
||||
- name: ps1
|
||||
resource:
|
||||
kind: Service
|
||||
name: "game-service*"
|
||||
mutate:
|
||||
patches:
|
||||
- path: "/metadata/labels/isMutated"
|
||||
op: add
|
||||
value: "true"
|
||||
- path : "/metadata/labels/secretLabel"
|
||||
op : replace
|
||||
value : "weKnow"
|
||||
- path : "/metadata/labels/originalLabel"
|
||||
op : remove
|
||||
- path: "/spec/selector/app"
|
||||
op: replace
|
||||
value: "mutedApp"
|
||||
validate:
|
||||
message: "This service has wrong port"
|
||||
pattern:
|
||||
spec:
|
||||
ports:
|
||||
- name: "http"
|
||||
protocol: TCP
|
||||
port: 80|8080
|
15
test/Service/service.yaml
Normal file
15
test/Service/service.yaml
Normal file
|
@ -0,0 +1,15 @@
|
|||
kind: Service
|
||||
apiVersion: v1
|
||||
metadata:
|
||||
name: game-service
|
||||
labels:
|
||||
originalLabel : isHere
|
||||
secretLabel : thisIsMySecret
|
||||
spec:
|
||||
selector:
|
||||
app: MyApp
|
||||
ports:
|
||||
- name: http
|
||||
protocol: TCP
|
||||
port: 80
|
||||
targetPort: 9376
|
Loading…
Add table
Reference in a new issue