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

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