简体   繁体   English

如何隐藏敏感的 Twilio 账户信息(account_sid & auth_token)

[英]How to hide sensitive Twilio account information (account_sid & auth_token)

I am getting introduced the wonderful world of Twilio + RoR and have so far had a pleasant experience.我正在介绍 Twilio + RoR 的精彩世界,到目前为止有一个愉快的体验。

However, I've noticed that if I were to make my projects public, I would exposing sensitive Twilio account information:但是,我注意到如果我要公开我的项目,我会暴露敏感的 Twilio 帐户信息:

  • Account_sid Account_sid
  • Auth_token Auth_token
  • Twilio phone number Twilio 电话号码

My question is, how can I hide these three pieces of information in a Rails application so that when pushed to GitHub, they remain unaccessible to others?我的问题是,如何在 Rails 应用程序中隐藏这三条信息,以便在推送到 GitHub 时,其他人无法访问它们?

Here is some sample code below:下面是一些示例代码:

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

The answer is to not publish that information to GitHub in the first place. 答案是不首先将该信息发布到GitHub。

When I worked with Twilio applications, I used a localsettings.py (Python, but should be the same for Ruby) file holding the sensitive information that I downloaded and distributed out-of-band. 当我使用Twilio应用程序时,我使用了localsettings.py (Python,但对于Ruby应该是相同的)文件,其中包含我下载并在带外分发的敏感信息。

A user-friendly interface could be a setup script to download this file from a server credentials. 用户友好的界面可以是从服务器凭证下载此文件的安装脚本。

Alternatively, if you must check it into github, encrypt it symmetrically with something like gnupg and decrypt it on your host machine. 或者,如果必须将其检入github,则使用gnupg等对称加密,并在主机上对其进行解密。

In all these cases, you have to be careful not to accidentally check it in to git. 在所有这些情况下,你必须小心,不要意外地检查它到git。 Adding localsettings.rb to your .gitignore file is a great idea. localsettings.rb添加到.gitignore文件是个好主意。

(If you've already pushed it to github, see here for how to undo that.) (如果你已经将它推送到github,请参阅此处了解如何撤消它。)

a bit late my answer but you should use environment variables instead hardcoded strings.我的回答有点晚了,但你应该使用环境变量而不是硬编码的字符串。

in production you can use some tools like Vault to store it safely.在生产中,您可以使用 Vault 等工具安全地存储它。 here is a nice article about it https://medium.com/adessoturkey/getting-started-with-hashicorp-vault-658a3e523949这是一篇关于它的好文章https://medium.com/adessoturkey/getting-started-with-hashicorp-vault-658a3e523949

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM