当您的项目中有密钥时,如何推送到 GitHub? [英] when you have secret key in your project, how can pushing to GitHub be possible?
问题描述
我正在尝试将一个全新的、空的 Rail 3.0.4 项目推送到 GitHub,但只是意识到 cookie 会话存储有一个密钥:
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:
在config/initializers/secret_token.rb
NewRuby192Rails304Proj::Application.config.secret_token = '22e8...'
那么我们怎样才能避免它被推送到 GitHub 上呢?我们可以忽略这个文件(使用 .gitignore
),但是没有这个文件,Rails 应用程序根本无法运行(也不是一个完整的 Rails 应用程序).或者一般来说,其他文件或框架也可能有包含密钥的文件.遇到这种情况,推送到GitHub时应该如何处理?
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?
推荐答案
添加到你的仓库:
- 它的一个模板(
secret_token.rb.template
), - 一个能够根据在服务器上找到的本地数据生成适当的配置文件
secret_token.rb
的脚本(例如一个加密文件,其秘密值准备好被解码并放入secret_token.rb
文件)
- a template of it (
secret_token.rb.template
), - a script able to generate a proper config file
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)
从那里,添加一个 git 属性自定义驱动程序:
From there, add a git attribute custom driver:
上面引用的脚本将是您的smudge
"脚本,它将在检出工作树时自动生成正确的文件.
The script referenced above will be your 'smudge
' script which will, on checkout of the working tree, generate automatically the right file.
这篇关于当您的项目中有密钥时,如何推送到 GitHub?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!