summaryrefslogtreecommitdiff
path: root/patchwork/settings
diff options
context:
space:
mode:
authorJeremy Cline <jcline@redhat.com>2019-10-09 15:03:45 -0400
committerStephen Finucane <stephen@that.guru>2019-10-17 14:07:55 +0100
commitbb7626b2f257852f426723de551418753e3dd692 (patch)
tree82fec46366fdaeec96b72c15ddf6ea636f918e55 /patchwork/settings
parentb4f4c8554c1168ffe177dc11ddf9ff1535c1ff31 (diff)
downloadpatchwork-bb7626b2f257852f426723de551418753e3dd692.tar
patchwork-bb7626b2f257852f426723de551418753e3dd692.tar.gz
Use secrets and fall back to random.SystemRandom for keys
The random module uses the Mersenne Twister pseudorandom number generator and is not a cryptographically secure random number generator[0]. The secrets[1] module is intended for generating cryptographically strong random numbers, so recommend using that to generate the secret key. It's new in Python 3, so if it's unavailable fall back to using the ``os.urandom()`` backed implementation of random. NOTE(stephenfin): Modified to include change to 'config.yaml'. Also renamed reno to just stick with hyphens for filenames. [0] https://docs.python.org/3/library/random.html [1] https://docs.python.org/3/library/secrets.html Signed-off-by: Jeremy Cline <jcline@redhat.com> Signed-off-by: Stephen Finucane <stephen@that.guru>
Diffstat (limited to 'patchwork/settings')
-rw-r--r--patchwork/settings/production.example.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/patchwork/settings/production.example.py b/patchwork/settings/production.example.py
index c6aa2f2..8058537 100644
--- a/patchwork/settings/production.example.py
+++ b/patchwork/settings/production.example.py
@@ -21,9 +21,15 @@ from .base import * # noqa
# You'll need to replace this to a random string. The following python code can
# be used to generate a secret key:
#
-# import string, random
-# chars = string.letters + string.digits + string.punctuation
-# print repr("".join([random.choice(chars) for i in range(0,50)]))
+# import string
+# try:
+# import secrets
+# except ImportError: # Python < 3.6
+# import random
+# secrets = random.SystemRandom()
+#
+# chars = string.ascii_letters + string.digits + string.punctuation
+# print("".join([secrets.choice(chars) for i in range(50)]))
SECRET_KEY = os.environ['DJANGO_SECRET_KEY']