当你的项目有秘钥时,如何推送到 GitHub?
我正在尝试将一个全新的空 Rail 3.0.4 项目推送到 GitHub,但刚刚意识到 cookie 会话存储有一个密钥:
在 config/initializers/secret_token.rb 中
NewRuby192Rails304Proj::Application.config.secret_token = '22e8...'
那么我们如何才能避免将其推送到 GitHub?我们可以忽略这个文件(使用.gitignore
),但是如果没有这个文件,Rails 应用程序将根本无法运行(并且不是一个完整的 Rails 应用程序)。或者一般来说,其他文件或框架也可能具有包含密钥的文件。这种情况,推送到GitHub时应该如何处理?
I am trying to push a brand new, empty Rail 3.0.4 project to GitHub, but just realize that the cookie session store has a secret key:
In config/initializers/secret_token.rb
NewRuby192Rails304Proj::Application.config.secret_token = '22e8...'
So how can we avoid it being push to GitHub? We can ignore this file (using .gitignore
), but without this file, a Rails app won't run at all (and is not a complete Rails app). Or in general, other files or frameworks may have files containing secret keys too. In such case, how should it be handled when pushing to GitHub?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在您的存储库中添加:
secret_token.rb.template
),secret_token.rb
的脚本服务器(就像一个加密文件,其秘密值已准备好解码并放入secret_token.rb
文件中)从那里添加一个 git 属性自定义驱动程序:
上面引用的脚本将是您的 '
smudge
' 脚本,它将,在签出工作树时,自动生成正确的文件。Add in your repo:
secret_token.rb.template
),secret_token.rb
based on local data found on the server (like an encrypted file with the secret value ready to be decoded and put in thesecret_token.rb
file)From there, add a git attribute custom driver:
The script referenced above will be your '
smudge
' script which will, on checkout of the working tree, generate automatically the right file.将密钥放入某种外部配置文件中。这就是我们所做的。
Put the secret key in some sort of external config file. Thats what we do.
有几个外部工具可以做到这一点。基本上,这些工具使用您的私人数据加密文件并将其存储在 VCS 中,但忽略原始未加密的文件。
最知名和最值得信赖的之一是
blackbox
。它使用gpg
加密您的文件,并可与git
和hg
配合使用。顺便说一句,它是由 SO 团队创建的。看一下 alternatives 部分,它至少还有五个其他工具。我还可以向您推荐一个名为
git-secret
的工具,它也使用gpg
。但它仅适用于git
。主要优点是与其他工具相比,工作流程要容易得多。There are several external tools, which do exactly that. Basically, these tools encrypt the file with your private data and store it in the VCS, but ignore the original unencrypted file.
One of the most known and trusted is
blackbox
. It usesgpg
to encrypt your files and works with bothgit
andhg
. By the way, it is created by SO team. Have a look at the alternatives section, it has at least five other tools.I can also recommend you a tool called
git-secret
, it also usesgpg
. But it works only withgit
. The main advantage is that the workflow is much easier compared to other tools.如果它是私有存储库,您可能会冒险信任 Github 的安全/隐私......或者:
- 从服务器上的配置文件中提取数据。例如,如果您使用 Capistrano 进行部署,您可以添加一个步骤,从服务器上的某个位置复制配置文件。
- 使用环境变量。
You could risk trusting Github's security/privacy if it is a private repository .. or:
- Pull the data from a configuration file on the server. For example, if you use Capistrano for deployment, you can add a step that copies the configuration file from somewhere on the server.
- Use an environment variable.