Skip to content

Commit

Permalink
feat: add DeploymentConfig support
Browse files Browse the repository at this point in the history
Signed-off-by: szubersk <[email protected]>
  • Loading branch information
szubersk committed Mar 2, 2024
1 parent b3452f5 commit 5b45a1b
Show file tree
Hide file tree
Showing 43 changed files with 84 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# - kind: replicaset
# - kind: replicationcontroller
# - kind: deployment
# - kind: deploymentconfig
# - kind: statefulset
# - kind: daemonset
# - kind: cronjob
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# - kind: replicaset
# - kind: replicationcontroller
# - kind: deployment
# - kind: deploymentconfig
# - kind: statefulset
# - kind: daemonset
# - kind: cronjob
Expand Down
1 change: 1 addition & 0 deletions checks/kubernetes/advanced/optional/manages_etc_hosts.rego
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# - kind: replicaset
# - kind: replicationcontroller
# - kind: deployment
# - kind: deploymentconfig
# - kind: statefulset
# - kind: daemonset
# - kind: cronjob
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# - kind: replicaset
# - kind: replicationcontroller
# - kind: deployment
# - kind: deploymentconfig
# - kind: statefulset
# - kind: daemonset
# - kind: cronjob
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# - kind: replicaset
# - kind: replicationcontroller
# - kind: deployment
# - kind: deploymentconfig
# - kind: statefulset
# - kind: daemonset
# - kind: cronjob
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# - kind: replicaset
# - kind: replicationcontroller
# - kind: deployment
# - kind: deploymentconfig
# - kind: statefulset
# - kind: daemonset
# - kind: cronjob
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# - kind: replicaset
# - kind: replicationcontroller
# - kind: deployment
# - kind: deploymentconfig
# - kind: statefulset
# - kind: daemonset
# - kind: cronjob
Expand Down
1 change: 1 addition & 0 deletions checks/kubernetes/general/CPU_not_limited.rego
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# - kind: replicaset
# - kind: replicationcontroller
# - kind: deployment
# - kind: deploymentconfig
# - kind: statefulset
# - kind: daemonset
# - kind: cronjob
Expand Down
1 change: 1 addition & 0 deletions checks/kubernetes/general/CPU_requests_not_specified.rego
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# - kind: replicaset
# - kind: replicationcontroller
# - kind: deployment
# - kind: deploymentconfig
# - kind: statefulset
# - kind: daemonset
# - kind: cronjob
Expand Down
1 change: 1 addition & 0 deletions checks/kubernetes/general/SYS_ADMIN_capability.rego
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# - kind: replicaset
# - kind: replicationcontroller
# - kind: deployment
# - kind: deploymentconfig
# - kind: statefulset
# - kind: daemonset
# - kind: cronjob
Expand Down
1 change: 1 addition & 0 deletions checks/kubernetes/general/SYS_MODULE_capability.rego
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# - kind: replicaset
# - kind: replicationcontroller
# - kind: deployment
# - kind: deploymentconfig
# - kind: statefulset
# - kind: daemonset
# - kind: cronjob
Expand Down
1 change: 1 addition & 0 deletions checks/kubernetes/general/capabilities_no_drop_all.rego
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# - kind: replicaset
# - kind: replicationcontroller
# - kind: deployment
# - kind: deploymentconfig
# - kind: statefulset
# - kind: daemonset
# - kind: cronjob
Expand Down
1 change: 1 addition & 0 deletions checks/kubernetes/general/default_security_context.rego
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# - kind: replicaset
# - kind: replicationcontroller
# - kind: deployment
# - kind: deploymentconfig
# - kind: statefulset
# - kind: daemonset
# - kind: cronjob
Expand Down
1 change: 1 addition & 0 deletions checks/kubernetes/general/file_system_not_read_only.rego
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# - kind: replicaset
# - kind: replicationcontroller
# - kind: deployment
# - kind: deploymentconfig
# - kind: statefulset
# - kind: daemonset
# - kind: cronjob
Expand Down
1 change: 1 addition & 0 deletions checks/kubernetes/general/memory_not_limited.rego
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# - kind: replicaset
# - kind: replicationcontroller
# - kind: deployment
# - kind: deploymentconfig
# - kind: statefulset
# - kind: daemonset
# - kind: cronjob
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# - kind: replicaset
# - kind: replicationcontroller
# - kind: deployment
# - kind: deploymentconfig
# - kind: statefulset
# - kind: daemonset
# - kind: cronjob
Expand Down
1 change: 1 addition & 0 deletions checks/kubernetes/general/mounts_docker_socket.rego
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# - kind: replicaset
# - kind: replicationcontroller
# - kind: deployment
# - kind: deploymentconfig
# - kind: statefulset
# - kind: daemonset
# - kind: cronjob
Expand Down
1 change: 1 addition & 0 deletions checks/kubernetes/general/net_raw_capability.rego
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# - kind: replicaset
# - kind: replicationcontroller
# - kind: deployment
# - kind: deploymentconfig
# - kind: statefulset
# - kind: daemonset
# - kind: cronjob
Expand Down
1 change: 1 addition & 0 deletions checks/kubernetes/general/runs_with_GID_le_10000.rego
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# - kind: replicaset
# - kind: replicationcontroller
# - kind: deployment
# - kind: deploymentconfig
# - kind: statefulset
# - kind: daemonset
# - kind: cronjob
Expand Down
1 change: 1 addition & 0 deletions checks/kubernetes/general/runs_with_UID_le_10000.rego
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# - kind: replicaset
# - kind: replicationcontroller
# - kind: deployment
# - kind: deploymentconfig
# - kind: statefulset
# - kind: daemonset
# - kind: cronjob
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# - kind: replicaset
# - kind: replicationcontroller
# - kind: deployment
# - kind: deploymentconfig
# - kind: statefulset
# - kind: daemonset
# - kind: cronjob
Expand Down
1 change: 1 addition & 0 deletions checks/kubernetes/general/uses_image_tag_latest.rego
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# - kind: replicaset
# - kind: replicationcontroller
# - kind: deployment
# - kind: deploymentconfig
# - kind: statefulset
# - kind: daemonset
# - kind: cronjob
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# - kind: replicaset
# - kind: replicationcontroller
# - kind: deployment
# - kind: deploymentconfig
# - kind: statefulset
# - kind: daemonset
# - kind: cronjob
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# - kind: replicaset
# - kind: replicationcontroller
# - kind: deployment
# - kind: deploymentconfig
# - kind: statefulset
# - kind: daemonset
# - kind: cronjob
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# - kind: replicaset
# - kind: replicationcontroller
# - kind: deployment
# - kind: deploymentconfig
# - kind: statefulset
# - kind: daemonset
# - kind: cronjob
Expand Down
1 change: 1 addition & 0 deletions checks/kubernetes/pss/baseline/1_host_ipc.rego
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# - kind: replicaset
# - kind: replicationcontroller
# - kind: deployment
# - kind: deploymentconfig
# - kind: statefulset
# - kind: daemonset
# - kind: cronjob
Expand Down
1 change: 1 addition & 0 deletions checks/kubernetes/pss/baseline/1_host_network.rego
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# - kind: replicaset
# - kind: replicationcontroller
# - kind: deployment
# - kind: deploymentconfig
# - kind: statefulset
# - kind: daemonset
# - kind: cronjob
Expand Down
1 change: 1 addition & 0 deletions checks/kubernetes/pss/baseline/1_host_pid.rego
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# - kind: replicaset
# - kind: replicationcontroller
# - kind: deployment
# - kind: deploymentconfig
# - kind: statefulset
# - kind: daemonset
# - kind: cronjob
Expand Down
1 change: 1 addition & 0 deletions checks/kubernetes/pss/baseline/2_privileged.rego
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# - kind: replicaset
# - kind: replicationcontroller
# - kind: deployment
# - kind: deploymentconfig
# - kind: statefulset
# - kind: daemonset
# - kind: cronjob
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# - kind: replicaset
# - kind: replicationcontroller
# - kind: deployment
# - kind: deploymentconfig
# - kind: statefulset
# - kind: daemonset
# - kind: cronjob
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# - kind: replicaset
# - kind: replicationcontroller
# - kind: deployment
# - kind: deploymentconfig
# - kind: statefulset
# - kind: daemonset
# - kind: cronjob
Expand Down
1 change: 1 addition & 0 deletions checks/kubernetes/pss/baseline/5_access_to_host_ports.rego
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# - kind: replicaset
# - kind: replicationcontroller
# - kind: deployment
# - kind: deploymentconfig
# - kind: statefulset
# - kind: daemonset
# - kind: cronjob
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# - kind: replicaset
# - kind: replicationcontroller
# - kind: deployment
# - kind: deploymentconfig
# - kind: statefulset
# - kind: daemonset
# - kind: cronjob
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# - kind: replicaset
# - kind: replicationcontroller
# - kind: deployment
# - kind: deploymentconfig
# - kind: statefulset
# - kind: daemonset
# - kind: cronjob
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# - kind: replicaset
# - kind: replicationcontroller
# - kind: deployment
# - kind: deploymentconfig
# - kind: statefulset
# - kind: daemonset
# - kind: cronjob
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# - kind: replicaset
# - kind: replicationcontroller
# - kind: deployment
# - kind: deploymentconfig
# - kind: statefulset
# - kind: daemonset
# - kind: cronjob
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# - kind: replicaset
# - kind: replicationcontroller
# - kind: deployment
# - kind: deploymentconfig
# - kind: statefulset
# - kind: daemonset
# - kind: cronjob
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# - kind: replicaset
# - kind: replicationcontroller
# - kind: deployment
# - kind: deploymentconfig
# - kind: statefulset
# - kind: daemonset
# - kind: cronjob
Expand Down
1 change: 1 addition & 0 deletions checks/kubernetes/pss/restricted/3_runs_as_root.rego
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# - kind: replicaset
# - kind: replicationcontroller
# - kind: deployment
# - kind: deploymentconfig
# - kind: statefulset
# - kind: daemonset
# - kind: cronjob
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# - kind: replicaset
# - kind: replicationcontroller
# - kind: deployment
# - kind: deploymentconfig
# - kind: statefulset
# - kind: daemonset
# - kind: cronjob
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# - kind: replicaset
# - kind: replicationcontroller
# - kind: deployment
# - kind: deploymentconfig
# - kind: statefulset
# - kind: daemonset
# - kind: cronjob
Expand Down
7 changes: 7 additions & 0 deletions lib/kubernetes/kubernetes.rego
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,17 @@ is_cronjob {

default is_controller = false

api_version = object.apiVersion

is_controller {
kind = "Deployment"
}

is_controller {
api_version = "apps.openshift.io/v1"
kind = "DeploymentConfig"
}

is_controller {
kind = "StatefulSet"
}
Expand Down
36 changes: 36 additions & 0 deletions lib/kubernetes/kubernetes_test.rego
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,42 @@ test_deployment {
test_pods[_].spec.containers[_].name == "hello-deployment"
}

test_deploymentconfig {
# spec -> template
mock = {
"apiVersion": "apps.openshift.io/v1",
"kind": "DeploymentConfig",
"metadata": {"name": "hello"},
"spec": {"template": {"spec": {
"containers": [{
"command": [
"sh",
"-c",
"echo 'Hello !' && sleep 1h",
],
"image": "busybox",
"name": "hello-deploymentconfig-1",
}],
"volumes": [
{
"name": "hello-volume-1",
"emptyDir": {},
},
{
"name": "hello-volume-2",
"emptyDir": {},
},
],
}}},
}

test_containers := containers with input as mock
test_volumes := volumes with input as mock

test_containers[_].name == "hello-deploymentconfig-1"
test_volumes[_].name == "hello-volume-2"
}

test_stateful_set {
# spec -> template
test_pods := pods with input as {
Expand Down

0 comments on commit 5b45a1b

Please sign in to comment.