python - Django, Fabric: What is the best way to manage secret keys to deploy Django projects? -
for i'm trying store secret_key in environment variable:
# settings/base.py def get_env_variable(var_name): """ environment variable or return exception """ try: return os.environ[var_name] except keyerror: error_msg = 'set {} environment variable'.format(var_name) raise improperlyconfigured(error_msg) secret_key = get_env_variable('secret_key')
and cant realize how should deploy project fabric:
@task def deploy(): syncdb() collectstatic() @task def collectstatic(): dj('collectstatic') cd('{django_root}/static'.format(**env)): fix_permissions() @task def syncdb(): dj('syncdb') @task def dj(command): run('{virtualenv_dir}/bin/python {django_root}/manage.py {dj_command}'.format(dj_command=command, **env))
which method setting env vars best in situation? i'm want make automatically , use fabscript many times. @ same time dont want store secret information in fabfile or in settings because push them public repo.
it pointless set secret key automatically part of deployment because secret key can know looking @ deployment files. (you source files may in less secure location, e.g. source control, , point of separating out secret key in first place access source cannot see is).
you have set secret manually once on deployment system first.
(in case set environment variable can done adding line /etc/enviroment
e.g. my_django_app_secret_key=mysecretkeyvalue
)
Comments
Post a Comment