github.com/khulnasoft-lab/defsec@v1.0.5-0.20230827010352-5e9f46893d95/rules/kubernetes/policies/cisbenchmarks/apiserver/always_admit_plugin_test.rego (about) 1 package builtin.kubernetes.KCV0011 2 3 test_always_admin_plugin_is_enabled { 4 r := deny with input as { 5 "apiVersion": "v1", 6 "kind": "Pod", 7 "metadata": { 8 "name": "apiserver", 9 "labels": { 10 "component": "kube-apiserver", 11 "tier": "control-plane", 12 }, 13 }, 14 "spec": {"containers": [{ 15 "command": ["kube-apiserver", "--enable-admission-plugins=AlwaysAdmit"], 16 "image": "busybox", 17 "name": "hello", 18 }]}, 19 } 20 21 count(r) == 1 22 r[_].msg == "Ensure that the admission control plugin AlwaysAdmit is not set" 23 } 24 25 test_always_admit_plugin_is_not_configured { 26 r := deny with input as { 27 "apiVersion": "v1", 28 "kind": "Pod", 29 "metadata": { 30 "name": "apiserver", 31 "labels": { 32 "component": "kube-apiserver", 33 "tier": "control-plane", 34 }, 35 }, 36 "spec": {"containers": [{ 37 "command": ["kube-apiserver", "--authorization-mode=Node,RBAC", "--anonymous-auth=false"], 38 "image": "busybox", 39 "name": "hello", 40 }]}, 41 } 42 43 count(r) == 0 44 } 45 46 test_always_admit_plugin_is_not_enabled { 47 r := deny with input as { 48 "apiVersion": "v1", 49 "kind": "Pod", 50 "metadata": { 51 "name": "apiserver", 52 "labels": { 53 "component": "kube-apiserver", 54 "tier": "control-plane", 55 }, 56 }, 57 "spec": {"containers": [{ 58 "command": ["kube-apiserver", "--enable-admission-plugins=NamespaceLifecycle,ServiceAccount"], 59 "image": "busybox", 60 "name": "hello", 61 }]}, 62 } 63 64 count(r) == 0 65 } 66 67 test_always_admit_plugin_is_enabled_with_others { 68 r := deny with input as { 69 "apiVersion": "v1", 70 "kind": "Pod", 71 "metadata": { 72 "name": "apiserver", 73 "labels": { 74 "component": "kube-apiserver", 75 "tier": "control-plane", 76 }, 77 }, 78 "spec": {"containers": [{ 79 "command": ["kube-apiserver", "--enable-admission-plugins=NamespaceLifecycle,AlwaysAdmit,ServiceAccount"], 80 "image": "busybox", 81 "name": "hello", 82 }]}, 83 } 84 85 count(r) == 1 86 r[_].msg == "Ensure that the admission control plugin AlwaysAdmit is not set" 87 }