diff --git a/base/redhat-8/Dockerfile b/base/redhat-8/Dockerfile index 2f71cb49..d839e582 100644 --- a/base/redhat-8/Dockerfile +++ b/base/redhat-8/Dockerfile @@ -28,8 +28,8 @@ LABEL name="splunk" \ ARG BUSYBOX_URL ENV BUSYBOX_URL=${BUSYBOX_URL} \ - PYTHON_VERSION=3.7.16 \ - PYTHON_GPG_KEY_ID=0D96DF4D4110E5C43FBFB17F2D347EA6AA65421D + PYTHON_VERSION=3.9.19 \ + PYTHON_GPG_KEY_ID=E3FF2839C048B25C084DEBE9B26995E310250568 COPY install.sh /install.sh diff --git a/base/redhat-8/install.sh b/base/redhat-8/install.sh index 63e7950c..2763a84a 100755 --- a/base/redhat-8/install.sh +++ b/base/redhat-8/install.sh @@ -17,7 +17,8 @@ set -e # Generate UTF-8 char map and locale # Reinstalling local English def for now, removed in minimal image: https://bugzilla.redhat.com/show_bug.cgi?id=1665251 -microdnf -y --nodocs install glibc-langpack-en +# Comment below install until glibc update is available in minimal image: https://access.redhat.com/errata/RHSA-2024:2722 +#microdnf -y --nodocs install glibc-langpack-en # Currently there is no access to the UTF-8 char map. The following command is commented out until # the base container can generate the locale. @@ -74,9 +75,12 @@ ln -sf /usr/bin/pip${PY_SHORT} /usr/bin/pip # Install splunk-ansible dependencies cd / -/usr/bin/python3.7 -m pip install --upgrade pip +/usr/bin/python3.9 -m pip install --upgrade pip pip -q --no-cache-dir install --upgrade "requests_unixsocket<2.29" "requests<2.29" six wheel Mako "urllib3<2.0.0" certifi jmespath future avro cryptography lxml protobuf setuptools ansible +# Avoid vulnerability on old pip version +/usr/libexec/platform-python -m pip install --upgrade pip + # Remove tests packaged in python libs find /usr/lib/ -depth \( -type d -a -not -wholename '*/ansible/plugins/test' -a \( -name test -o -name tests -o -name idle_test \) \) -exec rm -rf '{}' \; find /usr/lib/ -depth \( -type f -a -name '*.pyc' -o -name '*.pyo' -o -name '*.a' \) -exec rm -rf '{}' \; diff --git a/py23-image/redhat-8/Dockerfile b/py23-image/redhat-8/Dockerfile index 89676579..c2dd5471 100644 --- a/py23-image/redhat-8/Dockerfile +++ b/py23-image/redhat-8/Dockerfile @@ -3,10 +3,12 @@ FROM ${SPLUNK_PRODUCT}-redhat-8:latest USER root RUN microdnf -y --nodocs update \ - && microdnf -y --nodocs install python2-pip python2-devel \ + && microdnf -y --nodocs install python2 \ + && pip2 install --upgrade pip \ && pip2 --no-cache-dir install requests pyyaml jmespath \ - && ln -sf /usr/bin/python3.7 /usr/bin/python3 \ - && ln -sf /usr/bin/pip3.7 /usr/bin/pip3 \ - && ln -sf /usr/bin/python3.7 /usr/bin/python \ - && ln -sf /usr/bin/pip3.7 /usr/bin/pip \ - && pip3 install --upgrade ansible==3.4.0 requests==2.25.1 pyyaml==5.4.1 jmespath==0.10.0 + && ln -sf /usr/bin/python3.9 /usr/bin/python3 \ + && ln -sf /usr/bin/pip3.9 /usr/bin/pip3 \ + && ln -sf /usr/bin/python3.9 /usr/bin/python \ + && ln -sf /usr/bin/pip3.9 /usr/bin/pip \ + && pip3 install --upgrade requests==2.25.1 pyyaml==5.4.1 jmespath==0.10.0 \ + && sed -i '/^\[defaults\]/a\interpreter_python = /usr/bin/python3' /opt/ansible/ansible.cfg diff --git a/tests/executor.py b/tests/executor.py index c6026adc..a34ee162 100644 --- a/tests/executor.py +++ b/tests/executor.py @@ -101,9 +101,11 @@ def get_container_logs(self, container_id): stream = self.client.logs(container_id, stream=True) output = "" for char in stream: - if "Ansible playbook complete" in char: - break + if type(char) is bytes: + char = char.decode("utf-8") output += char + if "Ansible playbook complete" in output: + break return output def cleanup_files(self, files): @@ -148,6 +150,8 @@ def wait_for_containers(self, count, label=None, name=None, timeout=500): # The healthcheck on our Splunk image is not reliable - resorting to checking logs if container.get("Labels", {}).get("maintainer") == "support@splunk.com": output = self.client.logs(container["Id"], tail=5) + if type(output) is bytes: + output = output.decode("utf-8") if "unable to" in output or "denied" in output or "splunkd.pid file is unreadable" in output: self.logger.error("Container {} did not start properly, last log line: {}".format(container["Names"][0], output)) elif "Ansible playbook complete" in output: @@ -231,7 +235,9 @@ def extract_json(self, container_name): retries = 15 for i in range(retries): exec_command = self.client.exec_create(container_name, "cat /opt/container_artifact/ansible_inventory.json") - json_data = self.client.exec_start(exec_command) + json_data = self.client.exec_start(exec_command["Id"]) + if type(json_data) is bytes: + json_data = json_data.decode("utf-8") if "No such file or directory" in json_data: time.sleep(5) else: @@ -380,3 +386,9 @@ def check_dmc_groups(self, splunkd_port, num_idx, num_sh, num_cm, num_lm): assert status == 200 output = json.loads(content) assert len(output["entry"][0]["content"]["member"]) == num_sh + + def check_uds_socket_file(self, container_name): + # Check for cli.socket file + exec_command = self.client.exec_create(container_name, "ls /opt/splunkforwarder/var/run/splunk", user="splunk") + file_output = self.client.exec_start(exec_command) + return "cli.socket" in file_output.decode("utf-8") diff --git a/tests/requirements.txt b/tests/requirements.txt index 0fff1856..6b5520e7 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -1,6 +1,6 @@ pytest==4.4.0 pyrsistent==0.16.1 -requests +requests==2.31.0 docker PyYAML docker-compose diff --git a/tests/test_single_splunk_image.py b/tests/test_single_splunk_image.py index 0743fe1f..48e788dd 100644 --- a/tests/test_single_splunk_image.py +++ b/tests/test_single_splunk_image.py @@ -2778,3 +2778,33 @@ def test_compose_1hf_splunk_add(self): assert self.check_splunkd("admin", self.password) # Check Splunkd using the new users assert self.check_splunkd("jerry", "seinfeld") + + def test_compose_1uf_uds(self): + container_name = self.generate_random_string() + self.DIR = os.path.join(self.FIXTURES_DIR, container_name) + cid = None + try: + cid = self.client.create_container(self.UF_IMAGE_NAME, tty=True, command="start", + volumes=["/tmp/defaults/"], name=container_name, + environment={"DEBUG": "true", "SPLUNK_START_ARGS": "--accept-license", + "SPLUNK_PASSWORD": "Changeme", "ENABLE_TCP_MODE": "false"}, + host_config=self.client.create_host_config(binds=[ + os.path.join(self.FIXTURES_DIR, container_name) + ":/tmp/defaults/"]) + ) + cid = cid.get("Id") + self.client.start(cid) + assert self.wait_for_containers(1, name=container_name) + output = self.get_container_logs(cid) + assert "Allows UDS" in output + assert self.check_uds_socket_file(container_name) + except Exception as e: + self.logger.error(e) + raise e + finally: + if cid: + self.client.remove_container(cid, v=True, force=True) + try: + os.remove(os.path.join(self.DIR, "default.yml")) + os.rmdir(self.DIR) + except OSError: + pass