Skip to content

Commit d7d2826

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

File tree

2 files changed

+98
-0
lines changed

2 files changed

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

0 commit comments

Comments
 (0)