Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django SECRET_KEY in a distributed setup

Tags:

django

If I am setting up multiple django servers behind a load balancer, do I want the SECRET_KEY to be the same, different or does it matter at all? The docs are a little thin on exactly what this value is used for.

like image 297
ThatAintWorking Avatar asked May 31 '12 19:05

ThatAintWorking


People also ask

What does Django use SECRET_KEY for?

Summary: The Django secret key is used to provide cryptographic signing. This key is mostly used to sign session cookies. If one were to have this key, they would be able to modify the cookies sent by the application.

Which function is Django's SECRET_KEY not used for?

It's not used for passwords. Passwords use random generated salt for each account and PKGF hash by default. But it's used for other stuff, like generating password reset link, etc..

How do I generate a secret key in Django?

Generating a Django SECRET_KEY To generate a new key, we can use the get_random_secret_key() function present in django. core. management. utils .

What happens if you change Django secret key?

What happens if I change Django secret key? Once you change the SECRET_KEY on production, all the old sessions and cookies are invalidated, users are logged out and data in sessions are lost. This is good if your SECRET_KEY is compromised!


2 Answers

I guess it must be the same. Here is related question: Django SECRET_KEY.

Basically secret key is used to validate various things send to client or put in session. So if your nodes would have different secret keys you would have client's session cleared everytime it is routed to new node (which is bad).

like image 163
jb. Avatar answered Nov 09 '22 17:11

jb.


SECRET_KEY is used in various places such as the session middleware. If all nodes must have access to the session information then they must share the same key.

like image 5
Ignacio Vazquez-Abrams Avatar answered Nov 09 '22 15:11

Ignacio Vazquez-Abrams