保持数据库的API密钥和访问详细信息安全

时间:2012-04-23 14:31:12

标签: git security node.js nodejitsu

保护数据库的API密钥和访问详细信息的最佳做法是什么?

我们将使用Nodejitsus jitsu deploy进行部署,所以我的想法是拥有一个不属于git的配置文件。

我们当前的配置文件,我将拥有.gitignore

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

2 个答案:

答案 0 :(得分:2)

通常我所做的是将我的配置存储在config.json中,将其添加到我的.gitignore,然后添加.npmignore,以便npm不使用.gitignore决定捆绑什么。这样,git不会添加config.json,但jitsu会在部署时捆绑它。

如博雅建议的那样,

env变量也会起作用。

答案 1 :(得分:1)

您可以使用jitsu env命令将API密钥(和其他机密)存储为环境变量。然后使用process.env在node.js应用程序中获取这些变量。