保持数据库安全的API密钥和访问细节
保持数据库安全的API密钥和访问细节的最佳做法是什么?
我们将部署Nodejitsus jitsu deploy
所以我的想法是有一个configuration文件不会是git的一部分。
我们目前的configuration文件,我将.gitignore'd
module.exports = (app) -> app.configure 'development', -> global.config = dbUrl: 'mongodb://username:password@host:port/closet' foursquare: client_id: 'xxx' client_secret: 'xxx' redirect_uri: 'http://127.0.0.1:3000/account/auth/foursquare/done' return app.configure 'production', -> global.config = dbUrl: 'mongodb://username:password@host:port/closet' foursquare: client_id: 'yyy' client_secret: 'yyy' redirect_uri: 'http://example.com/account/auth/foursquare/done' return return
通常,我所做的是将configuration存储在config.json
,将其添加到我的.gitignore
,然后包含一个.npmignore
以便npm不使用.gitignore
来决定捆绑什么。 这样,git不会添加config.json,但是jitsu会在部署时捆绑它。
环境variables,如booyaabuild议,也将工作。
您可以使用jitsu env
命令将API密钥(和其他秘密)存储为环境variables。 然后使用process.env来获取你的node.js应用程序中的这些variables。