【问题标题】:How to hide sensitive Twilio account information (account_sid & auth_token)如何隐藏敏感的 Twilio 帐户信息 (account_sid & auth_token)
【发布时间】:2013-10-22 16:37:18
【问题描述】:

我正在了解 Twilio + RoR 的精彩世界,到目前为止,我的体验很愉快。

但是,我注意到如果我要公开我的项目,我会暴露敏感的 Twilio 帐户信息:

  • Account_sid
  • Auth_token
  • Twilio 电话号码

我的问题是,如何在 Rails 应用程序中隐藏这三条信息,以便在推送到 GitHub 时,其他人无法访问它们?

下面是一些示例代码:

class SMS < ApplicationController
  def text
    message = params[:message]
    number = params[:number]
    account_sid = 'xxxxxxxxxxxxHIDExxxxxxxxxxxxxxxxx'
    auth_token = 'yyyyyyyyyyyyyHIDEyyyyyyyyyyyyyy'

    @client = Twilio::REST::Client.new account_sid, auth_token

    @message = @client.account.messages.create({:to => "+1"+"#{number}",
                                   :from => "zzzzHIDEzzzz",
                                   :body => "#{message}"})
    redirect_to '/index'
  end
end

【问题讨论】:

    标签: ruby-on-rails twilio


    【解决方案1】:

    答案是首先不要将该信息发布到 GitHub。

    当我使用 Twilio 应用程序时,我使用了一个 localsettings.py(Python,但对于 Ruby 应该是相同的)文件,其中包含我下载并带外分发的敏感信息。

    用户友好的界面可以是从服务器凭据下载此文件的设置脚本。

    或者,如果您必须将其签入 github,请使用 gnupg 之类的东西对其进行对称加密,然后在您的主机上解密。

    在所有这些情况下,您必须小心不要将其意外签入 git。将localsettings.rb 添加到您的.gitignore 文件中是个好主意。

    (如果您已经将其推送到 github,请参阅 here 了解如何撤消该操作。)

    【讨论】:

      猜你喜欢
      • 2020-11-24
      • 1970-01-01
      • 2018-01-31
      • 2012-01-01
      • 1970-01-01
      • 2010-11-30
      • 1970-01-01
      • 2022-11-02
      • 1970-01-01
      相关资源
      最近更新 更多