Skip to content

Commit a036507

Browse files
singulierewxiaoguangzeripath
authored
gitconfig: set safe.directory = * (#19870)
Allow git push to work when networked file systems with mixed ownership are used with Gitea docker images >= 1.16.6 or Gitea binaries running alongside git versions published after 04/2022. There are circumstances independent of Gitea (networked file systems with various permission systems) by which the git repositories managed by Gitea may have mixed owners. It is not a behavior that Gitea have control over nor is it a problem as long as the permissions for Gitea to operate are correct. Gitea instances have been operating under these conditions for a number of years. It is detected as a potential security risk ( see GHSA-vw2c-22j4-2fh2 ) by the most recent git versions. However, Gitea always runs git commands with a current directory matching the repository on which it operates. That makes Gitea immune from this security problem and it is safe to ignore the mixed owner permission check. This gitconfig modification is done on a file dedicated to the user exclusively used by Gitea. Fixes: #19455 Co-authored-by: wxiaoguang <[email protected]> Co-authored-by: zeripath <[email protected]>
1 parent bdde56c commit a036507

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

modules/git/git.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,19 @@ func syncGitConfig() (err error) {
251251
}
252252
}
253253

254+
// Due to CVE-2022-24765, git now denies access to git directories which are not owned by current user
255+
// however, some docker users and samba users find it difficult to configure their systems so that Gitea's git repositories are owned by the Gitea user. (Possibly Windows Service users - but ownership in this case should really be set correctly on the filesystem.)
256+
// see issue: https://github.com/go-gitea/gitea/issues/19455
257+
// Fundamentally the problem lies with the uid-gid-mapping mechanism for filesystems in docker on windows (and to a lesser extent samba).
258+
// Docker's configuration mechanism for local filesystems provides no way of setting this mapping and although there is a mechanism for setting this uid through using cifs mounting it is complicated and essentially undocumented
259+
// Thus the owner uid/gid for files on these filesystems will be marked as root.
260+
// As Gitea now always use its internal git config file, and access to the git repositories is managed through Gitea,
261+
// it is now safe to set "safe.directory=*" for internal usage only.
262+
// Please note: the wildcard "*" is only supported by Git 2.30.4/2.31.3/2.32.2/2.33.3/2.34.3/2.35.3/2.36 and later
263+
// Although only supported by Git 2.30.4/2.31.3/2.32.2/2.33.3/2.34.3/2.35.3/2.36 and later - this setting is tolerated by earlier versions
264+
if err := configAddNonExist("safe.directory", "*"); err != nil {
265+
return err
266+
}
254267
if runtime.GOOS == "windows" {
255268
if err := configSet("core.longpaths", "true"); err != nil {
256269
return err

0 commit comments

Comments
 (0)