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.

  1. 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 put from secrets import * @ top. then, rahul said, add .gitignore file , add secrets.py file won't committed.

    the disadvantage of approach there no source control @ on file; if lose you're sol.

  2. use environment variables.

    use apache setenv or passenv directives pass environment variables process, retrieve them os.environ() in settings file. has advantage in in development, can set new variables (as var1=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.

  3. 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 use git archive or similar command extract proper keys place you're deploying to, , can keep secrets backed , under version control easily. can add appropriate files in secrets 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

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

wso2esb - How to concatenate JSON array values in WSO2 ESB? -