#22310 closed Cleanup/optimization (fixed)
Document exact usage of and consequences of rotating SECRET_KEY
Reported by: | Sasha Romijn | Owned by: | Sasha Romijn |
---|---|---|---|
Component: | Documentation | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Occasionally, people have accidents with their secret keys. It is somehow leaked, or they discover that they haven't stored it as securely as they should have. The trivial fix is to rotate your secret key. However, the secret key is used in various places, and this may invalidate existing tokens, sessions, etc. For example, if I remember correctly, secret keys form part of signed cookies and password reset tokens - but not password hashes.
We should document where exactly secret keys are being used, and therefore which data will be invalidated as soon as you rotate your secret key. This helps people understand what's going to happen, and will make sure nobody keeps an unsafe secret key because they are afraid of rotating it.
This requires some digging: there are of course many direct references to settings.SECRET_KEY, but also some more generic utilities, like cookie signing, that use the secret key, but that various other parts of Django then depend upon.
Attachments (1)
Change History (14)
comment:1 by , 11 years ago
Triage Stage: | Unreviewed → Accepted |
---|---|
Type: | Uncategorized → Cleanup/optimization |
comment:2 by , 11 years ago
comment:3 by , 11 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
by , 11 years ago
Attachment: | secret_key_import_scheme.txt added |
---|
Draft of settings.SECRET_KEY importing
comment:5 by , 11 years ago
I think https://docs.djangoproject.com/en/dev/topics/signing/ might be the best place, as that's what SECRET_KEY is already described as being used for from the settings documentation.
comment:6 by , 11 years ago
Hello erikr,
My work is available at https://github.com/ZuluPro/django/commit/5f8e017c6d2378251d3a68a346b01b19a4293cf7
Tell if you want me to go more in depth.
Thanks
comment:7 by , 11 years ago
Has patch: | set |
---|---|
Patch needs improvement: | set |
Thanks for the patch, but I had something a bit more practical in mind. More like (contents all fictional):
The secret key is used for: * Password reset tokens * Session using the FooBarBackend * Signed cookies you may have set yourself using ..... * ... If you rotate your secret key, all of the above will be invalidated. Secret keys are not used, and rotation therefore will not affect: * Password stored for users * Sessions using other backends than FooBarBackend * ...
The second list would not be exhaustive, just some items where confusion is more likely.
comment:8 by , 11 years ago
Owner: | changed from | to
---|
I am currently working on this, but it'll have to wait on #22638.
comment:9 by , 10 years ago
Easy pickings: | unset |
---|
comment:10 by , 10 years ago
Patch needs improvement: | unset |
---|
comment:11 by , 10 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
comment:12 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Agreed this is a good idea.
A related issue is #20081, which would minimise the risk of a "leak to version control" of the
SECRET_KEY
.