How can I save my secret keys and password securely in my version control system?

前端 未结 17 1788
生来不讨喜
生来不讨喜 2020-11-29 14:49

I keep important settings like the hostnames and ports of development and production servers in my version control system. But I know that it\'s bad practice to kee

17条回答
  •  我在风中等你
    2020-11-29 15:27

    Heroku pushes the use of environment variables for settings and secret keys:

    The traditional approach for handling such config vars is to put them under source - in a properties file of some sort. This is an error-prone process, and is especially complicated for open source apps which often have to maintain separate (and private) branches with app-specific configurations.

    A better solution is to use environment variables, and keep the keys out of the code. On a traditional host or working locally you can set environment vars in your bashrc. On Heroku, you use config vars.

    With Foreman and .env files Heroku provide an enviable toolchain to export, import and synchronise environment variables.


    Personally, I believe it's wrong to save secret keys alongside code. It's fundamentally inconsistent with source control, because the keys are for services extrinsic to the the code. The one boon would be that a developer can clone HEAD and run the application without any setup. However, suppose a developer checks out a historic revision of the code. Their copy will include last year's database password, so the application will fail against today's database.

    With the Heroku method above, a developer can checkout last year's app, configure it with today's keys, and run it successfully against today's database.

提交回复
热议问题