python - How to I hide my secret_key using virtualenv and Django? -
i using django, python, virtualenv, virtualenvwrapper, , vagrant.
so far have left secret_key inside of settings.py file. works file local files. have placed files in git. know not acceptable production(apache).
what correct way go hiding secret_key?
should use virtualenv hide it?
there's lot of different methods hide secrets.
use another, non-versioned file.
create new file
secrets.py
or have , put secrets in that. place alongside settings file , place secret in there; in settings file putfrom secrets import *
@ top. then, rahul said, add.gitignore
file , addsecrets.py
file won't committed.the disadvantage of approach there no source control @ on file; if lose you're sol.
use environment variables.
use apache
setenv
orpassenv
directives pass environment variables process, retrieve themos.environ()
in settings file. has advantage in in development, can set new variables (asvar1=whatever var2=whatever ... ./manage.py runserver ...
) or set them whatever mechanism use launch development project.the disadvantage same; if lose apache configs you're boned.
use second repository in combination method 1.
personally, idea of having dedicated
secrets
repository put secrets , keep repo under lock , key. part of deployment process, can usegit archive
or similar command extract proper keys place you're deploying to, , can keep secrets backed , under version control easily. can add appropriate files insecrets
repo.gitingore
file of site repository don't accidentally committed.the downside of have repository , deployment step. think that's worth it, personally, it's you.
in general, more secure want it, more inconvenient it's going to access secrets. that's rule in general, though.
Comments
Post a Comment