仓库一致性检查

极狐GitLab 运行仓库一致性检查:

  • 当触发仓库检查时。
  • 当从镜像仓库中获取更改时。
  • 当用户将更改推送到仓库时。

这些一致性检查验证一个仓库是否拥有所有必需的对象,并且这些对象是否是有效的对象。它们可以分类为:

  • 基本检查,确保仓库不会损坏。这包括连通性检查和对象可解析性检查。
  • 安全检查,识别适合利用 Git 过去安全相关漏洞的对象。
  • 外观检查,验证所有对象的元数据是否有效。较旧的 Git 版本和其他 Git 实现可能生成了元数据无效的对象,但较新版本可以解释这些格式错误的对象。

移除一致性检查失败的格式错误对象需要重写仓库的历史,通常无法做到。因此,极狐GitLab 默认禁用一系列不会负面影响仓库一致性的外观问题的检查

默认情况下,极狐GitLab 不会禁用基本或安全相关检查,以防止分发可能触发 Git 客户端已知漏洞的对象。这也限制了导入包含此类对象的仓库的能力,即使项目没有恶意意图。

覆盖仓库一致性检查

实例管理员可以覆盖一致性检查,如果他们必须处理未通过一致性检查的仓库。

对于 Linux 软件包安装,编辑 /etc/gitlab/gitlab.rb 并设置以下键(在此示例中,禁用 hasDotgit 一致性检查):

  • 在 极狐GitLab 15.10 及之后版本:

    ignored_blobs = "/etc/gitlab/instance_wide_ignored_git_blobs.txt"
    
    gitaly['configuration'] = {
      # ...
      git: {
        # ...
        config: [
          # Populate a file with one unabbreviated SHA-1 per line.
          # See https://git-scm.com/docs/git-config#Documentation/git-config.txt-fsckskipList
          { key: "fsck.skipList", value: ignored_blobs },
          { key: "fetch.fsck.skipList", value: ignored_blobs },
          { key: "receive.fsck.skipList", value: ignored_blobs },
    
          { key: "fsck.hasDotgit", value: "ignore" },
          { key: "fetch.fsck.hasDotgit", value: "ignore" },
          { key: "receive.fsck.hasDotgit", value: "ignore" },
          { key: "fsck.missingSpaceBeforeEmail", value: "ignore" },
        ],
      },
    }
    
  • 在 极狐GitLab 15.3 到 极狐GitLab 15.9:

    ignored_blobs = "/etc/gitlab/instance_wide_ignored_git_blobs.txt"
    
    gitaly['gitconfig'] = [
    
     # Populate a file with one unabbreviated SHA-1 per line.
     # See https://git-scm.com/docs/git-config#Documentation/git-config.txt-fsckskipList
     { key: "fsck.skipList", value: ignored_blobs },
     { key: "fetch.fsck.skipList", value: ignored_blobs },
     { key: "receive.fsck.skipList", value: ignored_blobs },
    
     { key: "fsck.hasDotgit", value: "ignore" },
     { key: "fetch.fsck.hasDotgit", value: "ignore" },
     { key: "receive.fsck.hasDotgit", value: "ignore" },
     { key: "fsck.missingSpaceBeforeEmail", value: "ignore" },
    ]
    
  • 在 极狐GitLab 15.2 及更早版本(传统方法):

    ignored_git_errors = [
      "hasDotgit = ignore",
      "missingSpaceBeforeEmail = ignore",
    ]
    omnibus_gitconfig['system'] = {
    
     # Populate a file with one unabbreviated SHA-1 per line.
     # See https://git-scm.com/docs/git-config#Documentation/git-config.txt-fsckskipList
      "fsck.skipList" => ignored_blobs
      "fetch.fsck.skipList" => ignored_blobs,
      "receive.fsck.skipList" => ignored_blobs,
    
      "fsck" => ignored_git_errors,
      "fetch.fsck" => ignored_git_errors,
      "receive.fsck" => ignored_git_errors,
    }
    

对于自编译安装,编辑极狐GitLab 配置文件(gitaly.toml)做等效操作:

[[git.config]]
key = "fsck.hasDotgit"
value = "ignore"

[[git.config]]
key = "fetch.fsck.hasDotgit"
value = "ignore"

[[git.config]]
key = "receive.fsck.hasDotgit"
value = "ignore"

[[git.config]]
key = "fsck.missingSpaceBeforeEmail"
value = "ignore"

[[git.config]]
key = "fetch.fsck.missingSpaceBeforeEmail"
value = "ignore"

[[git.config]]
key = "receive.fsck.missingSpaceBeforeEmail"
value = "ignore"

[[git.config]]
key = "fsck.skipList"
value = "/etc/gitlab/instance_wide_ignored_git_blobs.txt"

[[git.config]]
key = "fetch.fsck.skipList"
value = "/etc/gitlab/instance_wide_ignored_git_blobs.txt"

[[git.config]]
key = "receive.fsck.skipList"
value = "/etc/gitlab/instance_wide_ignored_git_blobs.txt"

禁用检查

为了使极狐GitLab 能够处理具有某些格式错误特征的仓库,这些特征不会影响安全性或极狐GitLab 客户端,极狐GitLab 默认禁用了一部分外观检查

有关完整的一致性检查列表,请参阅 Git 文档

badTimezone

禁用 badTimezone 检查是因为 Git 中存在一个错误,导致用户创建带有无效时区的提交。结果,一些 Git 日志包含不符合规范的提交。因为极狐GitLab 默认运行 fsck 来检查接收到的 packfiles,任何包含此类提交的推送都会被拒绝。

missingSpaceBeforeDate

禁用 missingSpaceBeforeDate 检查是因为 git-fsck(1) 在签名没有邮件与日期之间的空格或日期完全丢失时会失败。这可能由各种问题引起,包括 Git 客户端行为异常。

zeroPaddedFilemode

禁用 zeroPaddedFilemode 检查是因为较旧的 Git 版本曾经对一些文件模式进行零填充。例如,树对象将文件模式 40000 编码为 040000