【问题标题】:Keeping API keys and access details for the database secure确保数据库的 API 密钥和访问详细信息安全
【发布时间】:2012-05-04 10:24:47
【问题描述】:

保持数据库的 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

【问题讨论】:

    标签: git security node.js nodejitsu


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 2012-04-03
        • 1970-01-01
        • 2014-05-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-05-06
        • 2017-12-29
        相关资源
        最近更新 更多