diff --git a/sig/TC/content/doc/pics/github_clean_cached_view.png b/sig/TC/content/doc/pics/github_clean_cached_view.png new file mode 100644 index 0000000000000000000000000000000000000000..0e0138a00664549bbf360d122bbff978840e0cd5 Binary files /dev/null and b/sig/TC/content/doc/pics/github_clean_cached_view.png differ diff --git a/sig/TC/content/doc/projects/remove_sensitive_data.md b/sig/TC/content/doc/projects/remove_sensitive_data.md new file mode 100644 index 0000000000000000000000000000000000000000..9a073a311159a0cc8787cc312f6939f22d0ceb9e --- /dev/null +++ b/sig/TC/content/doc/projects/remove_sensitive_data.md @@ -0,0 +1,62 @@ +# 开源代码仓泄露敏感数据的预防与应急处理 + +在Git代码仓的设计机制中,一旦某个commit被上传至公开代码仓,即使后续通过强制修改 +分支等方式试图从历史记录中删除该commit,仍然可以通过commit hash检索到完整的提交 +内容。因此,应尽可能避免在公开代码仓中意外提交敏感数据;若已发生误提交情况,应立 +即更换密钥、删除令牌,并向公开代码仓的提供商申请删除相关敏感数据。 + +## 预防策略 + +建议使用Git `pre-hook`机制,在向公开代码仓上传本地数据前检查目标代码仓是否公开且 +待推送内容是否存在敏感数据。 + +[`pre-hook`](https://git-scm.com/book/ms/v2/Customizing-Git-Git-Hooks)是Git在向 +公开代码仓传输任何数据之前调用的脚本,该脚本可以通过返回非0值来阻止推送。Git的 +hook脚本不记入代码仓历史,因此无需担心这些脚本混入向上游代码仓提交的Pull +Request。 + +`pre-hook`的示例脚本可以在任一git仓库的`.git/hooks/pre-push.sample`下找到。 + +## 应急处理 + +如果敏感数据已经提交到公开代码仓,请立即采取以下措施: + +1. 对于凭据类的敏感信息(如密钥、密码、令牌等),强烈建议第一时间通过更换、删除 +的方式来撤销这些凭据的访问权限,以避免这些凭据被不正当地利用。 + +2. 对于商业机密类的敏感信息,建议联系公开代码仓的供应商,申请删除包含敏感信 +息的commit。 + +### 向GitHub申请删除敏感数据的步骤 + +1. 通过force push删除包含敏感信息的commit的提交历史; + +2. `git clone https://github.com/newren/git-filter-repo` + +3. 在本地代码仓的根目录,执行以下命令检查敏感信息文件是否仍被某个分支引用:`/path/to/git-filter-repo --sensitive-data-removal --invert-paths --path PATH-TO-YOUR-FILE-WITH-SENSITIVE-DATA` + +4. 确认无更多分支引用后,在[GitHub支持](https://support.github.com/request/remove-data)页面点击“清除缓存视图”。 + +![在GitHub支持页面申请清除缓存视图](../pics/github_clean_cached_view.png) + +5. 在工单描述中用**英文**明确表示(1)**the commit contains non-credential confidential data**,(2)**the commit has been removed from any existing branches according to the recommended steps in the 'Removing sensitive data from a repository' guide**,并提供以下信息: + + - GitHub代码仓的owner和代码仓名; + - 需要删除的commit hash; + - 第3步中`git-filter-repo`输出的影响PR数(如有)、First Changed Commit(s)和LFS object信息; + +`git-filter-repo`的输出示例: + +``` +NOTE: First Changed Commit(s) is/are: + +NOTE: LFS object orphaning not checked (LFS not in use) +``` + +GitHub工单需要代码仓的owner提交,如果涉及的代码仓是龙蜥社区GitHub组织下的AI训推 +框架仓库,在完成前3步后,请通过邮件联系茅俊杰(junjie.mao@linux.alibaba.com)并 +提供上述第5步中的信息。 + +## 参考文档 + +[Removing sensitive data from a repository - GitHub Docs](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/removing-sensitive-data-from-a-repository)