Skip to content

Commit 6d0e17c

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

File tree

2 files changed

+96
-0
lines changed

2 files changed

+96
-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
728+
729+
Args:
730+
container_name (str): The name of the container to look for
731+
732+
Returns:
733+
dict: 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,74 @@
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+
13+
14+
@tier1
15+
@green_squad
16+
class TestCSIAddonPodSecurity:
17+
def test_csi_addon_pod_security(self):
18+
"""
19+
Validate that the CSI Addon pods are compliant with the Pod Security Standards.
20+
21+
Test Steps:
22+
1. Fetch a pod with label 'app=openshift-storage.rbd.csi.ceph.com-nodeplugin' (CSI RBD Nodeplugin).
23+
2. Retrieve container information for the container named 'csi-addons'.
24+
3. Assert that the 'csi-addons' container exists in the pod.
25+
4. Extract the port used by the 'csi-addons' container.
26+
5. Execute a HTTPS (secure) curl command inside the 'csi-addons' container on localhost:{port}/healthz.
27+
- Verify that the pod responds correctly over HTTPS (secure connection should succeed).
28+
6. Execute a HTTP (insecure) curl command inside the 'csi-addons' container on localhost:{port}/healthz.
29+
- Verify that the insecure connection fails as expected (CommandFailed exception raised).
30+
7. Assert that the CSI Addon pod does not allow connections without TLS (insecure HTTP).
31+
32+
Expected Result:
33+
- The pod should be reachable securely over HTTPS.
34+
- The pod should reject insecure HTTP (non-TLS) connections.
35+
"""
36+
37+
logging.info("Validating CSI Addon pod security standards")
38+
39+
pod_obj = Pod(**get_pods_having_label(CSI_RBDPLUGIN_LABEL_419)[0])
40+
41+
csi_addon_container = pod_obj.get_container_data("csi-addons")
42+
43+
assert csi_addon_container, "No CSI Addon container found in the pod"
44+
45+
port_used_by_csi_addon = csi_addon_container[0]["ports"][0]["containerPort"]
46+
47+
# Querying to the container port with HTTPS
48+
try:
49+
pod_obj.exec_cmd_on_pod(
50+
command=f"curl -k -s https://localhost:{port_used_by_csi_addon}/healthz",
51+
container_name="csi-addons",
52+
out_yaml_format=False,
53+
)
54+
logging.info(
55+
f"CSI Addon pod is reachable securely on port {port_used_by_csi_addon}"
56+
)
57+
except CommandFailed as e:
58+
logging.error(
59+
f"CSI Addon pod is not reachable securely on port {port_used_by_csi_addon}: {str(e)}"
60+
)
61+
pytest.fail(f"CSI Addon pod HTTPS connection failed: {str(e)}")
62+
63+
# Now check if the pod is rejecting insecure HTTP (without TLS)
64+
with pytest.raises(CommandFailed) as exc_info:
65+
pod_obj.exec_cmd_on_pod(
66+
command=f"curl -s http://localhost:{port_used_by_csi_addon}/healthz",
67+
container_name="csi-addons",
68+
out_yaml_format=False,
69+
)
70+
71+
assert "command terminated" in str(
72+
exc_info.value
73+
), "CSI Addon pod should not allow connection without TLS"
74+
logging.info("CSI Addon pod correctly refused HTTP (insecure) connection")

0 commit comments

Comments
 (0)