Skip to content

Dockerfile: upgrade to git >= 2.36 and set safe.directory = * #19707

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,21 @@ RUN apk --no-cache add \
ca-certificates \
curl \
gettext \
git \
linux-pam \
openssh \
s6 \
sqlite \
su-exec \
gnupg

#
# Only required until git > 2.36 is released in alpine because Gitea needs
# support for *
#
# https://git-scm.com/docs/git-config#Documentation/git-config.txt-safedirectory
#
RUN apk add git --repository=http://dl-cdn.alpinelinux.org/alpine/edge/main

RUN addgroup \
-S -g 1000 \
git && \
Expand Down
2 changes: 2 additions & 0 deletions docs/content/doc/installation/from-binary.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ adduser \
git
```

**NOTE:** If such a dedicated Gitea user is not created and Gitea is run from an already existing user instead, it may modify the global git configuration file. It is possible to use an altnerate global git configuration file by setting the [GIT_CONFIG_GLOBAL](https://git-scm.com/docs/git#Documentation/git.txt-codeGITCONFIGGLOBALcode) if [git version 2.32 or above](https://github.com/git/git/blob/master/Documentation/RelNotes/2.32.0.txt#L92-L93) is installed.

### Create required directory structure

```sh
Expand Down
10 changes: 10 additions & 0 deletions modules/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,16 @@ func Init(ctx context.Context) error {
SupportProcReceive = false
}

if CheckGitVersionAtLeast("2.36") == nil {
//
// Disable the security check because Gitea runs the git CLI from within the
// repository. See https://github.com/go-gitea/gitea/issues/19455 for the full discussion.
//
if err := checkAndSetConfig("safe.directory", "*", true); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should have a comment here, explaining why this is chosen and the rationale of it being safe.

Otherwise I would already see the comments/issues/questions pouring in. of why we're doing this and why we're deliberately making Gitea insecure.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like a windows only issue - so can we only set this on windows?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is described for windows but is not windows specific:

/tmp/a/b$ strace -e stat git log
stat("/usr/share/locale", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
stat("/tmp/a/b", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0
stat("/tmp/a/b/.git", 0x7ffe70098e60)   = -1 ENOENT (No such file or directory)
stat("/tmp/a", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0
stat("/tmp/a/.git", 0x7ffe70098e60)     = -1 ENOENT (No such file or directory)
stat("/tmp", {st_mode=S_IFDIR|S_ISVTX|0777, st_size=139264, ...}) = 0
stat("/tmp/.git", 0x7ffe70098e60)       = -1 ENOENT (No such file or directory)
stat("/", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
stat("/.git", 0x7ffe70098e60)           = -1 ENOENT (No such file or directory)
fatal: not a git repository (or any of the parent directories): .git
+++ exited with 128 +++

return err
}
}

if runtime.GOOS == "windows" {
if err := checkAndSetConfig("core.longpaths", "true", true); err != nil {
return err
Expand Down