有台 Gitea 私服最近要搬家,整個資料夾移到新主機,重新註冊成 Windows 服務,安裝好新版 Git for Windows 後,Gitea 順利啟動,但點進 Repository 爆炸噴出 HTTP 500,從 Log 看到錯誤訊息:

...ules/context/repo.go:853:func1() [E] GetCommitsCount: exit status 128 - fatal: unsafe repository 
   ('X:/Gitea/data/gitea-repositories/jeffrey/homework.git' is owned by someone else)
	To add an exception for this directory, call:
		git config --global --add safe.directory X:/Gitea/data/gitea-repositories/jeffrey/homework.git

訊息很明確,執行 Git 操作時出現 fatal: unsafe repository 錯誤,這是 git 2.35.2 新加入的安全修正,目的在修補 CVE-2022-24765 多人環境可能發生的安全漏洞, 限制 git 只能存取使用者所擁有的 Repository 目錄,其餘目錄除非透過 GIT_CEILING_DIRECTORIES 環境變數或在 config safe.directory 列舉,一律視為不安全禁止存取。

Gitea 是以 Windows 服務方式執行,執行身分是 Local System,若從頭到尾都用 Local System 建立與讀取 Repository 倒也相安無事(擁有者一致)。但很不幸我這台 Gitea 安裝目錄搬過家,Repository 資料夾擁有者變成複製檔案的使用者,從 Gitea 網頁開啟專案時,符合「git 存取非執行身分所擁有資料夾」前題,若使用舊版 git 也不會有事,換成 git 2.35.2+ 就爆炸了。

解決方法:

  1. 將 Gitea/data/gitea-repositories 目錄的擁有者改成 Local System 或 Administratots 群組。(選我正解)
  2. 修改 Local System 的 .gitconfig (位於 C:\Windows\System32\config\systemprofile.gitconfig)
    加入 safe.directory = * 設定
    (取消安全檢查,可能增加風險,若為管控嚴格的單純環境再納入考慮)


Comments

Be the first to post a comment

Post a comment