2

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

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

我们当前的配置文件,我将拥有 .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
4

2 回答 2

2

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

正如 booyaa 所建议的,env 变量也可以工作。

于 2012-05-04T02:24:47.123 回答
1

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

于 2012-04-24T08:08:53.190 回答