mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-29 10:55:05 +00:00
best practice: volume white list
This commit is contained in:
parent
16a851cd8b
commit
87d9cdd9dd
5 changed files with 77 additions and 1 deletions
|
@ -23,4 +23,5 @@
|
|||
| Require SELinux level of the container | [policy_validate_selinux_context.yaml](policy_validate_selinux_context.yaml) |
|
||||
| Allow default Proc Mount type | [policy_validate_default_proc_mount.yaml](policy_validate_default_proc_mount.yaml) |
|
||||
| Allow certain capability to be added | [policy_validate_container_capabilities.yaml](policy_validate_container_capabilities.yaml) |
|
||||
| Allow local tcp/udp port range | [policy_validate_sysctl_configs.yaml](policy_validate_sysctl_configs.yaml) |
|
||||
| Allow local tcp/udp port range | [policy_validate_sysctl_configs.yaml](policy_validate_sysctl_configs.yaml) |
|
||||
| Allowed volume plugins | [policy_validate_volume_whitelist.yaml](policy_validate_volume_whitelist.yaml) |
|
|
@ -0,0 +1,34 @@
|
|||
apiVersion : kyverno.io/v1alpha1
|
||||
kind: ClusterPolicy
|
||||
metadata:
|
||||
name: validate-volumes-whitelist
|
||||
spec:
|
||||
validationFailureAction: "audit"
|
||||
rules:
|
||||
- name: validate-volumes-whitelist
|
||||
match:
|
||||
resources:
|
||||
kinds:
|
||||
- Pod
|
||||
validate:
|
||||
message: "Volumes white list"
|
||||
anyPattern:
|
||||
- spec:
|
||||
volumes:
|
||||
- hostPath: "*"
|
||||
- spec:
|
||||
volumes:
|
||||
- emptyDir: "*"
|
||||
- spec:
|
||||
volumes:
|
||||
- configMap: "*"
|
||||
# pattern:
|
||||
# spec:
|
||||
# ^(volumes):
|
||||
# - hostPath: "*"
|
||||
# - emptyDir: "*"
|
||||
# - configMap: "*"
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: test-volumes
|
||||
spec:
|
||||
containers:
|
||||
- name: container-with-configmap
|
||||
image: busybox
|
||||
volumeMounts:
|
||||
- name: cache-vol
|
||||
mountPath: /cache
|
||||
volumes:
|
||||
- name: cache-vol
|
||||
configMap:
|
||||
name: log-config
|
||||
items:
|
||||
- key: log_level
|
||||
path: log_level
|
|
@ -131,3 +131,7 @@ func Test_validate_container_capabilities(t *testing.T) {
|
|||
func Test_validate_disallow_sysctl(t *testing.T) {
|
||||
testScenario(t, "test/scenarios/test/scenario_validate_sysctl_configs.yaml")
|
||||
}
|
||||
|
||||
func Test_validate_volume_whitelist(t *testing.T) {
|
||||
testScenario(t, "test/scenarios/test/scenario_validate_volume_whiltelist.yaml")
|
||||
}
|
||||
|
|
19
test/scenarios/test/scenario_validate_volume_whiltelist.yaml
Normal file
19
test/scenarios/test/scenario_validate_volume_whiltelist.yaml
Normal file
|
@ -0,0 +1,19 @@
|
|||
|
||||
# file path relative to project root
|
||||
input:
|
||||
policy: examples/best_practices/policy_validate_volume_whitelist.yaml
|
||||
resource: examples/best_practices/resources/resource_validate_volume_whitelist.yaml
|
||||
expected:
|
||||
validation:
|
||||
policyresponse:
|
||||
policy: validate-volumes-whitelist
|
||||
resource:
|
||||
kind: Pod
|
||||
apiVersion: v1
|
||||
namespace: ''
|
||||
name: test-volumes
|
||||
rules:
|
||||
- name: validate-volumes-whitelist
|
||||
type: Validation
|
||||
message: "Validation rule 'validate-volumes-whitelist' anyPattern[2] succesfully validated"
|
||||
success: true
|
Loading…
Add table
Reference in a new issue