Skip to content

Commit 9a47a29

Browse files
committed
Removal and exchange duplicate test for privileged containers
This change removes the Kubescape implementation of test for privileged containers. The reason behind this decision is the absence of functionality to exclude containers from the test. Instead, it has been replaced with an in-house implementation of this test, which has been renamed from "privileged" to "privileged_containers". Implements: #2115 Signed-off-by: horecoli <oliver.horecny@tietoevry.com>
1 parent 73b1d44 commit 9a47a29

5 files changed

Lines changed: 9 additions & 46 deletions

File tree

‎CNF_TESTSUITE_YML_USAGE.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
The cnf-testsuite.yml is used by `cnf_setup` in order to install the CNF to be tested onto an existing K8s cluster.
55

66

7-
The information in the cnf-testsuite.yml is also used for additional configuration of some tests e.g. `allowlist_helm_chart_container_names` is used for exculding containers from the [privileged](https://github.com/cnti-testcatalog/testsuite/blob/main/src/tasks/workload/security.cr#L196) container test.
7+
The information in the cnf-testsuite.yml is also used for additional configuration of some tests e.g. `allowlist_helm_chart_container_names` is used for exculding containers from the [privileged_containers](https://github.com/cnti-testcatalog/testsuite/blob/main/src/tasks/workload/security.cr#L138) container test.
88

99

1010
### Table of Contents

‎embedded_files/points.yml‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,6 @@
5353
#- name: check_reaped
5454
# tags: state, dynamic, configuration
5555

56-
- name: privileged
57-
emoji: "🔓🔑"
58-
tags: [security, dynamic, workload]
59-
# required: true
6056
- name: privilege_escalation
6157
emoji: "🔓🔑"
6258
tags: [security, dynamic, workload, cert, normal]

‎spec/utils/cnf_manager_spec.cr‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ describe "SampleUtils" do
128128

129129
it "'CNFManager::Points.all_task_test_names' should return all tasks names", tags: ["points"] do
130130
CNFManager::Points.clean_results_yml
131-
tags = ["alpha_k8s_apis", "application_credentials", "cni_compatible", "container_sock_mounts", "database_persistence", "default_namespace", "disk_fill", "elastic_volumes", "external_ips", "hardcoded_ip_addresses_in_k8s_runtime_configuration", "helm_chart_published", "helm_chart_valid", "helm_deploy", "host_network", "host_pid_ipc_privileges", "hostpath_mounts", "hostport_not_used", "immutable_configmap", "immutable_file_systems", "increase_decrease_capacity", "ingress_egress_blocked", "insecure_capabilities", "ip_addresses", "latest_tag", "linux_hardening", "liveness", "log_output", "no_local_volume_configuration", "node_drain", "nodeport_not_used", "non_root_containers", "open_metrics", "operator_installed", "oran_e2_connection", "pod_delete", "pod_dns_error", "pod_io_stress", "pod_memory_hog", "pod_network_corruption", "pod_network_duplication", "pod_network_latency", "privilege_escalation", "privileged", "privileged_containers", "prometheus_traffic", "readiness", "reasonable_image_size", "reasonable_startup_time", "require_labels", "cpu_limits", "memory_limits", "rollback", "rolling_downgrade", "rolling_update", "rolling_version_change", "routed_logs", "secrets_used", "selinux_options", "service_account_mapping", "service_discovery", "shared_database", "sig_term_handled", "single_process_type", "smf_upf_heartbeat", "specialized_init_system", "suci_enabled", "symlink_file_system", "sysctls", "tracing", "versioned_tag", "zombie_handled"]
131+
tags = ["alpha_k8s_apis", "application_credentials", "cni_compatible", "container_sock_mounts", "database_persistence", "default_namespace", "disk_fill", "elastic_volumes", "external_ips", "hardcoded_ip_addresses_in_k8s_runtime_configuration", "helm_chart_published", "helm_chart_valid", "helm_deploy", "host_network", "host_pid_ipc_privileges", "hostpath_mounts", "hostport_not_used", "immutable_configmap", "immutable_file_systems", "increase_decrease_capacity", "ingress_egress_blocked", "insecure_capabilities", "ip_addresses", "latest_tag", "linux_hardening", "liveness", "log_output", "no_local_volume_configuration", "node_drain", "nodeport_not_used", "non_root_containers", "open_metrics", "operator_installed", "oran_e2_connection", "pod_delete", "pod_dns_error", "pod_io_stress", "pod_memory_hog", "pod_network_corruption", "pod_network_duplication", "pod_network_latency", "privilege_escalation", "privileged_containers", "prometheus_traffic", "readiness", "reasonable_image_size", "reasonable_startup_time", "require_labels", "cpu_limits", "memory_limits", "rollback", "rolling_downgrade", "rolling_update", "rolling_version_change", "routed_logs", "secrets_used", "selinux_options", "service_account_mapping", "service_discovery", "shared_database", "sig_term_handled", "single_process_type", "smf_upf_heartbeat", "specialized_init_system", "suci_enabled", "symlink_file_system", "sysctls", "tracing", "versioned_tag", "zombie_handled"]
132132
(CNFManager::Points.all_task_test_names()).sort.should eq(tags.sort)
133133
end
134134

‎spec/workload/security_spec.cr‎

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,35 @@ require "../../src/tasks/utils/utils.cr"
44

55
describe "Security" do
66

7-
it "'privileged' should pass with a non-privileged cnf", tags: ["privileged"] do
7+
it "'privileged_containers' should pass with a non-privileged cnf", tags: ["privileged"] do
88
begin
99
result = ShellCmd.run_testsuite("cnf_setup cnf-config=sample-cnfs/sample-statefulset-cnf/cnf-testsuite.yml")
1010
Log.debug { result[:output] }
11-
result = ShellCmd.run_testsuite("privileged verbose")
11+
result = ShellCmd.run_testsuite("privileged_containers verbose")
1212
result[:status].success?.should be_true
1313
(/Found.*privileged containers.*coredns/ =~ result[:output]).should be_nil
1414
ensure
1515
result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=sample-cnfs/sample-statefulset-cnf/cnf-testsuite.yml")
1616
Log.debug { result[:output] }
1717
end
1818
end
19-
it "'privileged' should fail on a non-whitelisted, privileged cnf", tags: ["privileged"] do
19+
it "'privileged_containers' should fail on a non-whitelisted, privileged cnf", tags: ["privileged"] do
2020
begin
2121
result = ShellCmd.run_testsuite("cnf_setup cnf-config=./sample-cnfs/sample_privileged_cnf/cnf-testsuite.yml verbose wait_count=0")
2222
result[:status].success?.should be_true
23-
result = ShellCmd.run_testsuite("privileged verbose")
23+
result = ShellCmd.run_testsuite("privileged_containers verbose")
2424
result[:status].success?.should be_true
2525
(/Found.*privileged containers.*/ =~ result[:output]).should_not be_nil
2626
(/Privileged container (privileged-coredns) in.*/ =~ result[:output]).should_not be_nil
2727
ensure
2828
result = ShellCmd.run_testsuite("sample_privileged_cnf_non_whitelisted_cleanup")
2929
end
3030
end
31-
it "'privileged' should pass on a whitelisted, privileged cnf", tags: ["privileged"] do
31+
it "'privileged_containers' should pass on a whitelisted, privileged cnf", tags: ["privileged"] do
3232
begin
3333
result = ShellCmd.run_testsuite("cnf_setup cnf-config=./sample-cnfs/sample_whitelisted_privileged_cnf/cnf-testsuite.yml verbose wait_count=0")
3434
result[:status].success?.should be_true
35-
result = ShellCmd.run_testsuite("privileged cnf-config=sample-cnfs/sample_whitelisted_privileged_cnf verbose")
35+
result = ShellCmd.run_testsuite("privileged_containers cnf-config=sample-cnfs/sample_whitelisted_privileged_cnf verbose")
3636
result[:status].success?.should be_true
3737
(/Found.*privileged containers.*/ =~ result[:output]).should be_nil
3838
ensure
@@ -219,18 +219,6 @@ describe "Security" do
219219
end
220220
end
221221

222-
it "'privileged_containers' should pass when the cnf has no privileged containers", tags: ["privileged"] do
223-
begin
224-
result = ShellCmd.run_testsuite("cnf_setup cnf-config=./sample-cnfs/sample-coredns-cnf")
225-
result[:status].success?.should be_true
226-
result = ShellCmd.run_testsuite("privileged_containers")
227-
result[:status].success?.should be_true
228-
(/(FAILED).*(Found privileged containers)/ =~ result[:output]).should be_nil
229-
ensure
230-
result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=./sample-cnfs/sample-coredns-cnf")
231-
end
232-
end
233-
234222
it "'immutable_file_systems' should fail when the cnf containers with mutable file systems", tags: ["security"] do
235223
begin
236224
result = ShellCmd.run_testsuite("cnf_setup cnf-config=./sample-cnfs/sample-coredns-cnf")

‎src/tasks/workload/security.cr‎

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ require "../utils/utils.cr"
77

88
desc "CNF containers should be isolated from one another and the host. The CNF Test suite uses tools like Sysdig Inspect and gVisor"
99
task "security", [
10-
"privileged",
1110
"symlink_file_system",
1211
"privilege_escalation",
1312
"insecure_capabilities",
@@ -137,7 +136,7 @@ task "container_sock_mounts" do |t, args|
137136
end
138137

139138
desc "Check if any containers are running in privileged mode"
140-
task "privileged" do |t, args|
139+
task "privileged_containers" do |t, args|
141140
CNFManager::Task.task_runner(args, task: t) do |args, config|
142141
white_list_container_names = config.cnf_config[:white_list_container_names]
143142
VERBOSE_LOGGING.info "white_list_container_names #{white_list_container_names.inspect}" if check_verbose(args)
@@ -397,26 +396,6 @@ task "non_root_containers", ["kubescape_scan"] do |t, args|
397396
end
398397
end
399398

400-
desc "Check that privileged containers are not used"
401-
task "privileged_containers", ["kubescape_scan" ] do |t, args|
402-
CNFManager::Task.task_runner(args, task: t) do |args, config|
403-
results_json = Kubescape.parse
404-
test_json = Kubescape.test_by_test_name(results_json, "Privileged container")
405-
test_report = Kubescape.parse_test_report(test_json)
406-
resource_keys = CNFManager.workload_resource_keys(args, config)
407-
test_report = Kubescape.filter_cnf_resources(test_report, resource_keys)
408-
409-
#todo whitelist
410-
if test_report.failed_resources.size == 0
411-
CNFManager::TestcaseResult.new(CNFManager::ResultStatus::Passed, "No privileged containers were found")
412-
else
413-
test_report.failed_resources.map {|r| stdout_failure(r.alert_message) }
414-
stdout_failure("Remediation: #{test_report.remediation}")
415-
CNFManager::TestcaseResult.new(CNFManager::ResultStatus::Failed, "Found privileged containers")
416-
end
417-
end
418-
end
419-
420399
desc "Check if containers have immutable file systems"
421400
task "immutable_file_systems", ["kubescape_scan"] do |t, args|
422401
CNFManager::Task.task_runner(args, task: t) do |args, config|

0 commit comments

Comments
 (0)