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