Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add DeploymentConfig support #87

Merged
merged 1 commit into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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
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
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