6f2509
From cdb5f116c3a43ff2a5943cdadd0562ec03054a5b Mon Sep 17 00:00:00 2001
6f2509
From: jmaloy <jmaloy@redhat.com>
6f2509
Date: Fri, 13 Mar 2020 18:55:18 +0100
6f2509
Subject: [PATCH 4/5] utils: use SystemRandom when generating random password.
6f2509
 (#204)
6f2509
6f2509
Message-id: <20200313185518.18544-2-jmaloy@redhat.com>
6f2509
Patchwork-id: 94296
6f2509
O-Subject: [RHEL-7.9 cloud-init PATCH 1/1] utils: use SystemRandom when generating random password. (#204)
6f2509
Bugzilla: 1812173
6f2509
RH-Acked-by: Mohammed Gamal <mgamal@redhat.com>
6f2509
RH-Acked-by: Vitaly Kuznetsov <vkuznets@redhat.com>
6f2509
RH-Acked-by: Eduardo Otubo <eterrell@redhat.com>
6f2509
6f2509
From: Dimitri John Ledkov <xnox@ubuntu.com>
6f2509
6f2509
As noticed by Seth Arnold, non-deterministic SystemRandom should be
6f2509
used when creating security sensitive random strings.
6f2509
6f2509
(cherry picked from commit 3e2f7356effc9e9cccc5ae945846279804eedc46)
6f2509
Signed-off-by: Jon Maloy <jmaloy@redhat.com>
6f2509
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
6f2509
---
6f2509
 cloudinit/util.py | 3 ++-
6f2509
 1 file changed, 2 insertions(+), 1 deletion(-)
6f2509
6f2509
diff --git a/cloudinit/util.py b/cloudinit/util.py
6f2509
index 9d9d5c7..5d51ba8 100644
6f2509
--- a/cloudinit/util.py
6f2509
+++ b/cloudinit/util.py
6f2509
@@ -401,9 +401,10 @@ def translate_bool(val, addons=None):
6f2509
 
6f2509
 
6f2509
 def rand_str(strlen=32, select_from=None):
6f2509
+    r = random.SystemRandom()
6f2509
     if not select_from:
6f2509
         select_from = string.ascii_letters + string.digits
6f2509
-    return "".join([random.choice(select_from) for _x in range(0, strlen)])
6f2509
+    return "".join([r.choice(select_from) for _x in range(0, strlen)])
6f2509
 
6f2509
 
6f2509
 def rand_dict_key(dictionary, postfix=None):
6f2509
-- 
6f2509
1.8.3.1
6f2509