Skip to content

Commit eefa9a7

Browse files
committed
Add CSI Addon Pod Security Validation Test
Signed-off-by: Parag Kamble <[email protected]>
1 parent 4c80d85 commit eefa9a7

File tree

2 files changed

+105
-0
lines changed

2 files changed

+105
-0
lines changed

ocs_ci/ocs/resources/pod.py

+22
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,28 @@ def get_csi_pod_log_details(self, logs_dir, log_file_name):
722722
current_log_file_size = file_details[4]
723723
return gz_logs_num, current_log_file_size
724724

725+
def get_container_data(self, container_name):
726+
"""
727+
Get the container data for a requested container.
728+
729+
Args:
730+
container_name (str): The name of the container to look for
731+
732+
Returns:
733+
list: The container data
734+
735+
"""
736+
pod_containers = self.pod_data.get("spec").get("containers")
737+
matched_containers = [
738+
c for c in pod_containers if c.get("name") == container_name
739+
]
740+
741+
if not matched_containers:
742+
logger.info(f"NO container found in the pod name: {container_name} ")
743+
return []
744+
745+
return matched_containers
746+
725747

726748
# Helper functions for Pods
727749

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import pytest
2+
import logging
3+
4+
from ocs_ci.ocs.resources.pod import get_pods_having_label
5+
from ocs_ci.ocs.resources.pod import Pod
6+
from ocs_ci.ocs.exceptions import CommandFailed
7+
from ocs_ci.ocs.constants import CSI_RBDPLUGIN_LABEL_419
8+
from ocs_ci.framework.pytest_customization.marks import (
9+
tier1,
10+
green_squad,
11+
)
12+
from ocs_ci.framework.pytest_customization.marks import polarion_id, skipif_ocs_version
13+
14+
log = logging
15+
16+
17+
@tier1
18+
@green_squad
19+
@polarion_id("OCS-6807")
20+
@skipif_ocs_version("<4.19")
21+
class TestCSIAddonPodSecurity:
22+
"""This class contains tests to Validate if CSI Addon pod enforces security
23+
by allowing HTTPS and rejecting HTTP connections.
24+
"""
25+
26+
def test_csi_addon_pod_security(self):
27+
"""
28+
Validate that the CSI Addon pods are compliant with the Pod Security Standards.
29+
30+
Test Steps:
31+
1. Fetch a pod with label 'app=openshift-storage.rbd.csi.ceph.com-nodeplugin' (CSI RBD Nodeplugin).
32+
2. Retrieve container information for the container named 'csi-addons'.
33+
3. Assert that the 'csi-addons' container exists in the pod.
34+
4. Extract the port used by the 'csi-addons' container.
35+
5. Execute a HTTPS (secure) curl command inside the 'csi-addons' container on localhost:{port}/healthz.
36+
- Verify that the pod responds correctly over HTTPS (secure connection should succeed).
37+
6. Execute a HTTP (insecure) curl command inside the 'csi-addons' container on localhost:{port}/healthz.
38+
- Verify that the insecure connection fails as expected (CommandFailed exception raised).
39+
7. Assert that the CSI Addon pod does not allow connections without TLS (insecure HTTP).
40+
41+
Expected Result:
42+
- The pod should be reachable securely over HTTPS.
43+
- The pod should reject insecure HTTP (non-TLS) connections.
44+
"""
45+
46+
log.info("Validating CSI Addon pod security standards")
47+
48+
pod_obj = Pod(**get_pods_having_label(CSI_RBDPLUGIN_LABEL_419)[0])
49+
50+
csi_addon_container = pod_obj.get_container_data("csi-addons")
51+
52+
assert csi_addon_container, "No CSI Addon container found in the pod"
53+
54+
port_used_by_csi_addon = csi_addon_container[0]["ports"][0]["containerPort"]
55+
56+
# Querying to the container port with HTTPS
57+
try:
58+
pod_obj.exec_cmd_on_pod(
59+
command=f"curl -k -s https://localhost:{port_used_by_csi_addon}/healthz",
60+
container_name="csi-addons",
61+
out_yaml_format=False,
62+
)
63+
log.info(
64+
f"CSI Addon pod is reachable securely on port {port_used_by_csi_addon}"
65+
)
66+
except CommandFailed as e:
67+
log.error(
68+
f"CSI Addon pod is not reachable securely on port {port_used_by_csi_addon}: {str(e)}"
69+
)
70+
pytest.fail(f"CSI Addon pod HTTPS connection failed: {str(e)}")
71+
72+
# Now check if the pod is rejecting insecure HTTP (without TLS)
73+
with pytest.raises(CommandFailed) as exc_info:
74+
pod_obj.exec_cmd_on_pod(
75+
command=f"curl -s http://localhost:{port_used_by_csi_addon}/healthz",
76+
container_name="csi-addons",
77+
out_yaml_format=False,
78+
)
79+
80+
assert "command terminated" in str(
81+
exc_info.value
82+
), "CSI Addon pod should not allow connection without TLS"
83+
log.info("CSI Addon pod correctly refused HTTP (insecure) connection")

0 commit comments

Comments
 (0)