Blame SOURCES/rig-full-random-temp.patch

a15636
From 90c5505d82b288bbc0b2e8b01e85b78d18a0bd18 Mon Sep 17 00:00:00 2001
a15636
From: Jake Hunsaker <jhunsake@redhat.com>
a15636
Date: Thu, 9 Jun 2022 14:26:02 -0400
a15636
Subject: [PATCH] [rig] Use `tempfile` module for temp directory creation
a15636
a15636
Previously, a change was made to temp directory creation in an effort to
a15636
make it more secure. While that was largely handled, it left us with an
a15636
unhandled error in an edge case configuration. Rather than putting a
a15636
band-aid over that again, re-write the temp directory creation process
a15636
to leverage the `tempfile` module, so that we can safely and completely
a15636
ignore the id/name of a rig, and leave the use of that for the
a15636
communication socket.
a15636
a15636
Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
a15636
---
a15636
 rigging/rigs/__init__.py | 13 +++++++------
a15636
 1 file changed, 7 insertions(+), 6 deletions(-)
a15636
a15636
diff --git a/rigging/rigs/__init__.py b/rigging/rigs/__init__.py
a15636
index f14f312..29bb8b4 100644
a15636
--- a/rigging/rigs/__init__.py
a15636
+++ b/rigging/rigs/__init__.py
a15636
@@ -18,6 +18,7 @@ import string
a15636
 import socket
a15636
 import sys
a15636
 import tarfile
a15636
+import tempfile
a15636
 import time
a15636
 
a15636
 from argparse import Action
a15636
@@ -110,7 +111,7 @@ class BaseRig():
a15636
             self.log_debug("Initializing %s rig %s" %
a15636
                            (self.resource_name, self.id))
a15636
             self._sock, self._sock_address = self._create_rig_socket()
a15636
-            self._tmp_dir = self._create_temp_dir()
a15636
+            self._create_temp_dir()
a15636
             self.files = []
a15636
 
a15636
     def set_rig_id(self):
a15636
@@ -196,11 +197,11 @@ class BaseRig():
a15636
         Create a temp directory for rig to use for saving created files too
a15636
         """
a15636
         try:
a15636
-            _dir = "%s.%s/" % (RIG_TMP_DIR_PREFIX, self.id)
a15636
-            os.makedirs(_dir)
a15636
-            return _dir
a15636
-        except OSError:
a15636
-            raise CannotConfigureRigError('failed to create temp directory')
a15636
+            self._tmp_dir = tempfile.mkdtemp(prefix='rig.', dir='/var/tmp')
a15636
+        except Exception as err:
a15636
+            raise CannotConfigureRigError(
a15636
+                "failed to create temp directory: %s" % err
a15636
+            )
a15636
 
a15636
     def _load_args(self):
a15636
         """
a15636
-- 
a15636
2.35.3
a15636