Skip to content
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

Explicitly disable Git credential helper #5367

Merged
merged 2 commits into from
Nov 28, 2018
Merged

Explicitly disable Git credential helper #5367

merged 2 commits into from
Nov 28, 2018

Conversation

michaelkuhn
Copy link
Contributor

If the user running Gitea has configured a credential helper, Git credentials might leak out of Gitea.

There are two problems with credential helpers when combined with Gitea:

  1. Credentials entered by a user when doing a migration or setting up a mirror will end up in the credential store. In the worst case, this is the plain text file ~/.git-credentials.
  2. Credentials in the credential store will be used for migrations and mirrors by all users. For example, if user A sets up a mirror, their credentials will be stored. If user B later sets up a mirror from the same host and does not enter any credentials, user A's credentials will be used.

This PR prepends -c credential.helper= to all Git commands to clear the list of helpers. This requires at least Git version 2.9, as previous versions will try to load an empty helper instead. For more details, see git/git@2432137

(Related to #3966)

@codecov-io
Copy link

codecov-io commented Nov 20, 2018

Codecov Report

Merging #5367 into master will decrease coverage by <.01%.
The diff coverage is 60%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5367      +/-   ##
==========================================
- Coverage   37.57%   37.57%   -0.01%     
==========================================
  Files         313      313              
  Lines       46617    46611       -6     
==========================================
- Hits        17515    17512       -3     
+ Misses      26607    26605       -2     
+ Partials     2495     2494       -1
Impacted Files Coverage Δ
modules/setting/setting.go 48.42% <60%> (+0.36%) ⬆️
modules/process/manager.go 76.81% <0%> (-4.35%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 08bf443...6f15705. Read the comment docs.

@bkcsoft bkcsoft added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Nov 20, 2018
@bkcsoft bkcsoft added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Nov 20, 2018
@lafriks lafriks added the type/enhancement An improvement of existing functionality label Nov 20, 2018
@lafriks lafriks modified the milestones: 1.x.x, 1.7.0 Nov 20, 2018
@bkcsoft bkcsoft added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Nov 20, 2018
@lafriks
Copy link
Member

lafriks commented Nov 25, 2018

Tests seem to be failing after this changes

@michaelkuhn
Copy link
Contributor Author

Tests seem to be failing after this changes

I am not sure why this is happening. With my initial PR, the tests ran fine but after rebasing, test-{sqlite,mysql,pgsql} keep failing randomly (sometimes they pass, sometimes they do not).

Moreover, the most recent failure in test-pgsql shows this:

[...ules/context/repo.go:364 func1()] [E] GetTags: exit status 129 - error: unknown option `sort=-v:refname'
usage: git show-ref [-q | --quiet] [--verify] [--head] [-d | --dereference] [-s | --hash[=<n>]] [--abbrev[=<n>]] [--tags] [--heads] [--] [<pattern>...]

but --sort=-v:refname is an option to be passed to tag -l, not to show-ref (see git/repo_tag.go:GetTags and git/repo_tag.go:GetTag).

@michaelkuhn
Copy link
Contributor Author

Sorry for the force-push spam, I had to play around a bit since I cannot reproduce the problem locally. I still have not been able to fix it, so any help is welcome.

@lunny
Copy link
Member

lunny commented Nov 27, 2018

CI failed.

@michaelkuhn
Copy link
Contributor Author

Seems I finally managed to fix the problem: It is a bug in the git module, which I have reported here: go-gitea/git#135

@techknowlogick
Copy link
Member

@michaelkuhn thank you for taking the time to trace this problem. It is much appreciated 😄

If the user running Gitea has configured a credential helper, Git
credentials might leak out of Gitea.

There are two problems with credential helpers when combined with Gitea:

1. Credentials entered by a user when doing a migration or setting up a
   mirror will end up in the credential store. In the worst case, this
   is the plain text file ~/.git-credentials.
2. Credentials in the credential store will be used for migrations and
   mirrors by all users. For example, if user A sets up a mirror, their
   credentials will be stored. If user B later sets up a mirror from the
   same host and does not enter any credentials, user A's credentials
   will be used.

This PR prepends -c credential.helper= to all Git commands to clear the
list of helpers. This requires at least Git version 2.9, as previous
versions will try to load an empty helper instead. For more details, see
git/git@2432137
@michaelkuhn
Copy link
Contributor Author

Now that go-gitea/git#135 has been merged (thanks!), I have rebased the PR to current master and included a commit to update the git module.

@lafriks
Copy link
Member

lafriks commented Nov 28, 2018

Great, thanks :)

@lafriks lafriks merged commit 0222623 into go-gitea:master Nov 28, 2018
@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/enhancement An improvement of existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants