[Django] #32451: Management command to securely generate a secret key

28 views
Skip to first unread message

Django

unread,
Feb 16, 2021, 4:21:26 AM2/16/21
to django-...@googlegroups.com
#32451: Management command to securely generate a secret key
-----------------------------------------+------------------------
Reporter: RealOrangeOne | Owner: nobody
Type: New feature | Status: new
Component: Uncategorized | Version: 3.1
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
Django's `startproject` command does generate a secret key for you in a
secure way for your newly created Django project. But it's good practice
to have a different key for each environment, whether that be development,
staging or production. Therefore, there's a need to generate one after a
project has been setup, when you're creating a new environment or starting
a project from something other than `startproject`. The method used to
generate (`get_random_secret_key`) seems to be undocumented, and yet its
implementation details are rather important (the fact it's not just
`random.choice`).

I recently wrote (https://github.com/RealOrangeOne/django-secret-key-
generator) a web app to generate a `SECRET_KEY` in a similarly secure way
(more secure than the other ones out there), but it'd be great to have a
simple management command to securely generate a key (using the existing
`get_random_secret_key` util) so it could be easily set in a project, and
thus share the original implementation.

Does this (management command + documenting `get_random_secret_key`) sound
like a good idea? I'm happy to submit a patch myself.

--
Ticket URL: <https://code.djangoproject.com/ticket/32451>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Feb 16, 2021, 4:22:27 AM2/16/21
to django-...@googlegroups.com
#32451: Management command to securely generate a secret key
-------------------------------------+-------------------------------------
Reporter: Jake Howard | Owner: nobody

Type: New feature | Status: new
Component: Core (Management | Version: 3.1
commands) |
Severity: Normal | Resolution:

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jake Howard):

* component: Uncategorized => Core (Management commands)


--
Ticket URL: <https://code.djangoproject.com/ticket/32451#comment:1>

Django

unread,
Feb 16, 2021, 5:20:29 AM2/16/21
to django-...@googlegroups.com
#32451: Management command to securely generate a secret key
-------------------------------------+-------------------------------------
Reporter: Jake Howard | Owner: nobody
Type: New feature | Status: closed

Component: Core (Management | Version: 3.1
commands) |
Severity: Normal | Resolution: duplicate

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* status: new => closed
* resolution: => duplicate


Comment:

Duplicate of #24448.

--
Ticket URL: <https://code.djangoproject.com/ticket/32451#comment:2>

Reply all
Reply to author
Forward
0 new messages