使用源代码管理时如何隐藏连接字符串、用户名、密码?
我正在开发一个小型副项目,并且使用连接字符串以及 api 键和值,这些键和值不应被其他人看到或使用。我使用公共 GitHub 帐户进行源代码控制。当这些值在 web.config 中为纯文本时,使用源代码管理的常用方法是什么?
在签入代码之前是否需要手动删除这些值?
I'm working on a small side-project and I'm using connection strings and also api keys and values that should not be seen or used by other people. I use a public GitHub account for source control. What is the usual method for using source control when these values are in plain text in web.config?
Do I need to remove the values manually before checking in code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我发现有效的方法是签入具有空白或虚拟值的文件版本,然后运行:
不必担心签入。
然后 Git 将停止监视该文件的更改,允许您将真实的配置信息放入其中,而 当您稍后进行需要签入的更改时,您可以运行:
What I find works is to check in a version of the file with blanked or dummy values and then to run:
Git will then stop monitoring changes to that file allowing you to put the real config info into it without fear of checking it in.
If you later make changes that you DO want to check in you can run:
我们将敏感和/或特定于计算机的配置保存在单独的配置文件中,然后使用 configSource 来包含它们,如下所示...
这样您就可以签入 Web.config 和 cstrings.config 文件,该文件具有可以使用的通用值在开发机器上。 (例如,(local),...MyAppNameDb...)
对于生产环境,将 cstrings.config 文件标记为只读并设置部署脚本,以便您不会尝试覆盖它。您的生产连接字符串受到该盒子上的任何安全措施的保护。这使您的敏感字符串不受版本控制。
cstrings.config:
We keep sensitive and/or machine-specific configuration in separate config files, then use configSource to include them like so...
This way you can check in Web.config and a cstrings.config file that has a generic value that can be used on a dev machine. (e.g., (local),...MyAppNameDb...)
For production environments, mark the cstrings.config file as read-only and set up your deployment script so that you don't attempt to write over it. Your production connection string is protected by whatever security you have on that box. This keeps your sensitive strings out of version control.
cstrings.config:
您可以签入包含虚拟值的文件(例如 config.sample)。然后,每个开发人员都会将该文件复制到配置并编辑自己的值。然后,您可以将此本地文件放入 .gitignore 中。
You can check in a file like config.sample that contains dummy values. Each developer would then copy that file to config and edit in their own values. You would then put this local file in .gitignore.