mirror of
https://github.com/go-gitea/gitea.git
synced 2026-03-10 13:56:06 -05:00
'git push' over SSH does not close issues, but does over HTTP(S). #2417
Closed
opened 2025-11-02 04:35:19 -06:00 by GiteaMirror
·
30 comments
No Branch/Tag Specified
main
release/v1.25
release/v1.24
release/v1.23
release/v1.22
release/v1.21
release/v1.20
release/v1.19
release/v1.18
release/v1.17
release/v1.16
release/v1.15
release/v1.14
release/v1.13
release/v1.12
release/v1.11
release/v1.10
release/v1.9
release/v1.8
v1.25.3
v1.25.2
v1.25.1
v1.25.0
v1.24.7
v1.25.0-rc0
v1.26.0-dev
v1.24.6
v1.24.5
v1.24.4
v1.24.3
v1.24.2
v1.24.1
v1.24.0
v1.23.8
v1.24.0-rc0
v1.25.0-dev
v1.23.7
v1.23.6
v1.23.5
v1.23.4
v1.23.3
v1.23.2
v1.23.1
v1.23.0
v1.23.0-rc0
v1.24.0-dev
v1.22.6
v1.22.5
v1.22.4
v1.22.3
v1.22.2
v1.22.1
v1.22.0
v1.23.0-dev
v1.22.0-rc1
v1.21.11
v1.22.0-rc0
v1.21.10
v1.21.9
v1.21.8
v1.21.7
v1.21.6
v1.21.5
v1.21.4
v1.21.3
v1.21.2
v1.20.6
v1.21.1
v1.21.0
v1.21.0-rc2
v1.21.0-rc1
v1.20.5
v1.22.0-dev
v1.21.0-rc0
v1.20.4
v1.20.3
v1.20.2
v1.20.1
v1.20.0
v1.19.4
v1.21.0-dev
v1.20.0-rc2
v1.20.0-rc1
v1.20.0-rc0
v1.19.3
v1.19.2
v1.19.1
v1.19.0
v1.19.0-rc1
v1.20.0-dev
v1.19.0-rc0
v1.18.5
v1.18.4
v1.18.3
v1.18.2
v1.18.1
v1.18.0
v1.17.4
v1.18.0-rc1
v1.19.0-dev
v1.18.0-rc0
v1.17.3
v1.17.2
v1.17.1
v1.17.0
v1.17.0-rc2
v1.16.9
v1.17.0-rc1
v1.18.0-dev
v1.16.8
v1.16.7
v1.16.6
v1.16.5
v1.16.4
v1.16.3
v1.16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3
v1.4.0-rc1
v1.3.2
v1.3.1
v1.3.0
v1.3.0-rc2
v1.3.0-rc1
v1.2.3
v1.2.2
v1.2.1
v1.2.0
v1.2.0-rc3
v1.2.0-rc2
v1.1.4
v1.2.0-rc1
v1.1.3
v1.1.2
v1.1.1
v1.1.0
v1.0.2
v1.0.1
v1.0.0
v0.9.99
Labels
Clear labels
$20
$250
$50
$500
backport/done
💎 Bounty
docs-update-needed
good first issue
hacktoberfest
issue/bounty
issue/confirmed
issue/critical
issue/duplicate
issue/needs-feedback
issue/not-a-bug
issue/regression
issue/stale
issue/workaround
lgtm/need 2
modifies/api
modifies/translation
outdated/backport/v1.18
outdated/theme/markdown
outdated/theme/timetracker
performance/bigrepo
performance/cpu
performance/memory
performance/speed
pr/breaking
proposal/accepted
proposal/rejected
pr/wip
pull-request
reviewed/wontfix
💰 Rewarded
skip-changelog
status/blocked
topic/accessibility
topic/api
topic/authentication
topic/build
topic/code-linting
topic/commit-signing
topic/content-rendering
topic/deployment
topic/distribution
topic/federation
topic/gitea-actions
topic/issues
topic/lfs
topic/mobile
topic/moderation
topic/packages
topic/pr
topic/projects
topic/repo
topic/repo-migration
topic/security
topic/theme
topic/ui
topic/ui-interaction
topic/ux
topic/webhooks
topic/wiki
type/bug
type/deprecation
type/docs
type/enhancement
type/feature
type/miscellaneous
type/proposal
type/question
type/refactoring
type/summary
type/testing
type/upstream
Mirrored from GitHub Pull Request
Milestone
No items
No Milestone
Projects
Clear projects
No project
No Assignees
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: github-starred/gitea#2417
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @pcopissa on GitHub (Oct 18, 2018).
[x]):Description
0a) On on Centos 7.5 server, installed Gitea 1.5.2, git 2.18 (Followed steps at https://docs.gitea.io/en-us/install-from-binary/). Started Gitea web server as a service.
0b) On Windows 10 client, installed MSYS2 git 2.15 + Putty. Substituted
sshwith Putty'sPLINK.EXEby setting theGIT_SSHenvironment variable. Also startPAGEANT.EXEand insert the ppk file for Centos logingitwho is runninggiteaservice.p.copissavia web UI, and setup the server with a few custom values (as shown in the Site administration > Configuration web page):Also register a Gitea user named
gitwith the same password as the Centosgitlogin.In the web UI, log in as
p.copissa, create a repositorytest, (be sure to tick the check box Initialize Repository to avoid issue #2898), create two issues (#1 and #2).On the client, clone repository
testvia HTTP (or HTTPS) usinggit.execommand:git clone http://git.lan:3000/p.copissa/test.git test-httpOn the client, create a new file, commit and push it:
git commit -a -m "this fixes issue #1"git push(specify user
p.copissaand give its Gitea password when asked)In the web UI, refresh the issues: Issue #1 is now closed, as expected. Look at the file: the new file has shown up with the expected commit message.
On the client, redo step 3 but this time use SSH:
git clone git@git.lan:p.copissa/test.git test-sshRedo step 4 but with issue 2:
git commit -a -m "this fixes issue #2"git pushNote that no username nor password is asked. Also note that the Gitea user
githas the same password as Centosgitlogin.In the web UI, refresh the issue: Issue 2 is still opened. Click on the Code tab: The commit of step 7 is there with the user name
git. In fact you can choose whatever user name on the client (viagit config user.name whateverand mail as well) and the commit is there bearing that name. But closing the issue always fails even when user name is the owner or a collaborator.Expected behavior:
At step 8, issue #2 should be closed, like it was at step 2. In general, closing issues should not depend on the protocol used. If the remote server trusted the user to commit, then it should trust him to close the issue as well.
See also https://discourse.gitea.io/t/how-to-close-an-issue-with-a-commit-push/604/23 for more context.
Screenshots
@OvermindDL1 commented on GitHub (Oct 18, 2018):
Ah, this explains why commits don't close issues! I see this same issue.
@Etzelia commented on GitHub (Oct 22, 2018):
For what it's worth, I don't have this issue and I do all my operations via SSH.
Differences in settings:
For a client I use TortoiseGit on Windows 10
My server is running Ubuntu 16.04 with a Git version of 2.7.4
@zeripath commented on GitHub (Oct 24, 2018):
Hmm. You don't mention setting a key for p.copissa - how do you login through SSH?
Are you just using the generic git username and password?
If so that explains your problem. If you look at the way the authorized_keys file is created for gitea - on login with the appropriate key with id <id> the command: "gitea serv key-<id>" is run, and this sets up the appropriate environment variables for the post-commit hooks that will close issues.
If you don't login with a key that gitea knows about and manages, you will need to set those environment variables yourself.
@pcopissa commented on GitHub (Oct 24, 2018):
@zeripath: I don't have a key for p.copissa. I do for git (which is also a Centos login), as I wrote above.
But the point is that
git pushover an HTTP URL doesn't need a key for p.copissa. It happily closes the bug without any (instead git asks for user name and password). No so for SSH: The push does happen but not the close. And to me that looks like a bug:As I said, if the system trusts me enough to modify the remote repo, why should it not trust me for closing the issue ? Even more so when the same system DOES trust me closing when I have no key !! (i.e. when pushing over HTTP)
@pcopissa commented on GitHub (Oct 24, 2018):
@Etzelia: I think I will eventually switch to TortoiseGit : It seems to work with both HTTP and SSH, whereas I have trouble with HTTP on GitExtension. (That may be down to how I installed the bits and pieces on that system. MSYS2 came first via a Ruby environment, and the GUI came later but apparently relies on its own subset of MSYS2. Not sure what happens here. And that's off topic here anyway. There is a bit more context on here )
@Etzelia commented on GitHub (Oct 24, 2018):
It has nothing to do with not trusting you (I think). The likely reason that it doesn't close the issue is because your SSH key is for git, a user not associated within Gitea itself.
When you push using HTTP, you are authenticating as p.copissa, which Gitea can associate with your Gitea user, which it uses to create logs, etc. "This issue was referenced by p.copissa..."
When you push using an SSH key for git, my guess is the commit works because git has access to that repo, as it is the Centos user that Gitea itself uses. However, the SSH key is not associated with a Gitea user, therefore Gitea has no way of knowing who is trying to do what.
If I am way off base, let me know and I'll remove this comment.
EDIT: Adding comment back for reference. I re-read too hastily.
There is a git user in Gitea, however the SSH key was not managed by Gitea. So the above explanation is still plausible.
@pcopissa commented on GitHub (Oct 24, 2018):
@Etzelia: That looks like a plausible mechanism.
But still... I can specify any user by setting some environment variables (as I wrote) and that user shows up as the committer (and the closer, IIRC. Will try tomorrow in the office) when pushing over HTTP...
@zeripath commented on GitHub (Oct 24, 2018):
@Etzelia you were right. @pcopissa if the key is not managed by gitea then when you login with SSH, gitea will not do any permissions checks and it's hooks won't work unless you set the environment variables it needs.
@pcopissa commented on GitHub (Oct 24, 2018):
So what I take from that discussion is that I have to take the trouble to set keys for each Gitea user if I want to use SSH, while I can do the same by not bothering and using HTTP(S) ?
Interesting.
@zeripath commented on GitHub (Oct 24, 2018):
@pcopissa your findings of the setting environment variables meaning you're able to set yourself as any user is correct. It's why you shouldn't use non managed keys. You'll also find that apart from locked branches no permissions are checked.
Managed keys are sufficiently locked down in the authorized_keys file to prevent users from changing their environment like this (and running other commands).
@pcopissa commented on GitHub (Oct 24, 2018):
@Etzelia: I re-read your comment above:
Actually, I had suspected the issue was authentication or user related, so (as I wrote above) I also created a Gitea user named
gitand declared it as a contributor. I went as far as using the same password for Centos logingitand Gitea usergit. Still, that did not allow to close the issue either. So not sure what you mean by the sentence above ?@Etzelia commented on GitHub (Oct 24, 2018):
Does the Gitea user git have the SSH key installed?
@pcopissa commented on GitHub (Oct 24, 2018):
You mean if I sign in in Gitea web UI as (Gitea user)
git, then click on the top right user avatar, then click on Settings, then click on SSH / GPG keys and I should have something there ?If that's what you mean, then the answer is no, I never added keys there.
@Etzelia commented on GitHub (Oct 24, 2018):
I think that is the likeliest cause of the issue.
The way you are using SSH, you are authenticating as a system account, not a Gitea account. Therefore, Gitea cannot associate your user with a Gitea user and run it's actions.
If you were to add the SSH key to your Gitea git user, then make sure you clone using the SSH key associated with the Gitea user, my guess is it would work as expected.
This would normally not be an issue, as others wouldn't have access to a system account like you do.
@zeripath commented on GitHub (Oct 24, 2018):
@pcopissa yes, for SSH each user needs their own key. The key takes the place of the password and username. I don't think there's space within the git+ssh handshake to ask for an additional username and password following key authentication.
@pcopissa commented on GitHub (Oct 24, 2018):
When I'm back in the office, I'll try to add keys in the web UI for user
gitand see what happens. The likely conclusion of all this is that I will end up using HTTP(S)...@zeripath commented on GitHub (Oct 24, 2018):
@pcopissa Does Gitlab do arbitrary user username/password login on its SSH? I remember that Sourceforge provided this - I don't think Github do though. Using SSH keys for this is very common and allows federated login without Gitea ever seeing your password.
Anyway you could set up your SSHD to use a PAM module that would query login with Gitea, and do some permissions check.
A basic first step might be to change SSHD to check an LDAP, and change Gitea to use that LDAP. This might be the simplest way of getting things working - however, permissions checks wouldn't happen and I don't know if you can get SSHD to map arbitrary usernames to a single username (git) - I expect it's possible though.
You'd then have to look at some way of running a command on login which could query the passed in command to find out which repository you're trying to commit to, check permissions and set the correct environment variables, but you can't just leverage
gitea servfor this as it relies on key-<id> rather user-<username>. However, when you get down to doing all that you might find you're better off writing a proper PAM module yourself instead of just leveraging the LDAP module.(A difference between GitLab and Gitea is that GitLabs hooks are what checks whether a user can commit to a repository whereas on Gitea this is mostly done in the
gitea servcommand meaning that if you go down this path you'll have to recreate all of that work - however it can all be done with the API.)I'm not suggesting you actually do any of the above however.
@lunny commented on GitHub (Oct 25, 2018):
@zeripath Gitea has supported PAM if you build with
pamtag@zeripath commented on GitHub (Oct 25, 2018):
@lunny as far as I can see that's as a pam user not a pam provider?
@lunny commented on GitHub (Oct 25, 2018):
Yes.
pamproviders authentication just like LDAP.@pcopissa commented on GitHub (Oct 25, 2018):
I did this:
git,gitavatar (top right corner), then selected menu SettingsI get an error message (red text on pink background at top of page):
This SSH key is already added to your account.This was because
p.copissaGitea user had this key inserted as well. Signed in asp.copissa, Removed the key, rerun the above sequence:In Gitea web UI, under the Manage SSH Keys header, I now have one entry named git@git.lan
git clone git@git.lan:git/test.git test-sshgit commit -a -m "this fixes issue #2"git commit -a -m "this fixes #2"git pushSo it does not seem that adding
gitSSH public key changed anything...Note for completeness:
Prior to step 9, I ran part of steps 0b of top post, namely setup
GIT_SSH, startedPAGEANT.EXEand added to Pageant the very same ppk file used at step 4+5 above.I did try to remove Pageant from that sequence but that causes
git pushat step 10 to fail with a message:fatal: protocol error: bad line length character: git@I did try as well to run
git cloneat step 9 usinggit's CentOS password in the URL:git clone git:password@git.lan:git/test.git test-sshThat also fails with a similar message:
fatal: protocol error: bad line length character: Pass@zeripath commented on GitHub (Oct 25, 2018):
@pcopissa In step 9 are you being asked to provide a password (not a passphrase) to login?
If you're being asked for a password:
@zeripath commented on GitHub (Oct 25, 2018):
Hmm... I've just looked at trying this on docker.
The phrase "this fixes issue #n' doesn't close the issue for either HTTP or SSH.
It needs to be 'Fixes #n' or 'fixes #n'
@pcopissa commented on GitHub (Oct 26, 2018):
@zeripath:
I tried that too but the result is the same. Updated the sequence above.
@pcopissa commented on GitHub (Oct 26, 2018):
@zeripath:
Neither. As I wrote above, the only way I could get
gitto authenticate over SSH was to have the PuTTY Authentication Agent (PAGEANT.EXE) running. Specifying the key is done in Pageant GUI and at this point I am asked for the passphrase. Then never again.Well... As I wrote above, I copied the gibberish text from an edit box in PuTTY Key Generator that was labelled Public key for pasting into OpenSSH authorized_keys files. Is this unsuitable ?
The PPK file from which Putty Key Generator derived the Public key for pasting into OpenSSH authorized_keys files is also the one that specified in PuTTY (the SSH terminal) and PuTTY logs the CentOS user
gitsuccessful after I supply the passphrase, which is the same as the one asked by Pageant.exe. If I already have Pageant running, CentOS usergitget logged in straight away (nothing asked).@zeripath commented on GitHub (Oct 26, 2018):
Right, tell me, can you login to a shell with this key?
If you can it's not being managed by gitea and it's likely duplicated in the authorized_keys file. What are the contents of the git user's authorized_keys file? Please feel free to censor the keystring but tell me of there are duplicated keystrings in the file - that's very important.
Have you tried creating a new SSH key and putting in to gitea only? Do not add this new key into anything else to do with your centos box. If you're not able to commit/clone/pull with this new key then we know that there is something wrong with the way that your gitea installation is dealing with keys.
Edit: you should not be able to log in to a shell with a Gitea managed key.
@zeripath commented on GitHub (Oct 26, 2018):
I think it might be worth putting down some information about how gitea manages git over SSH.
Gitea is making several assumptions here:
a. SSHD is configured to allow authorized_keys files for users.
b. It's configured for the git user to have an authorized_keys.
c. The git user's authorized_keys file is supposed to be in the git's $HOME/.ssh/authorized_keys
d. The sshd server is configured to allow authorized_keys files to set the above options
e. If sshd has an AuthorizedKeysCommand set up for the git user then we are assuming that our key isn't matched by that command - otherwise Gitea's line will not be read.
f. If our key is in the authorized_key file multiple times, only the first line will be matched. If that is not Gitea's line then Gitea's command will not run.
g. Assuming we match a Gitea line the command option has to be able to run - if the command is not runnable we will not be able to log in. Further it has to be the correct command with the correct options, so if it is not run correctly the hooks won't run correctly.
There are therefore several things that can go wrong in the case of a non default install. Especially if some other software is trying to be helpful and manages SSH keys itself.
Assuming that none of those are the problem then we then have to consider the issue that the post-commit hooks aren't being run correctly - however this is a little odd as you tell me that they're running on http.
@pcopissa commented on GitHub (Oct 26, 2018):
Sorry but I got stuck with Windows 10 updates for the past 120mn :/
Yes. The key predates the Gitea experiments. It's purpose was password-less login. And this works. And worked before Gitea came into the picture. At that time, the CentOS machine had a DNS CNAME record
linux.lan. It now also has a CNAME recordgit.lan. They point to the same fully qualified name.It is duplicated on the server in
~git/.ssh/authorized_keys(this same key is present in that file, twice, see below)On my MSYS client, I copied the string mentionned at step 4 into a file called
pubkey-from-ppk.txtand ran:No
This will have to wait untli Monday.
@zeripath commented on GitHub (Oct 26, 2018):
Ok so the fact that the key is duplicated in the authorized_keys file explains your problem. When you log in with that key, the first line is matched and so you never get the gitea command called. That breaks the post-commit hook and you'll find that you get no permissions checked either.
You either have to get rid of that first line, meaning you can't log in to a shell with that key, or use a different key. (A third option is to write a bash script that checks if you're trying run a git command and then passes to the appropriate gitea serv command, or else just runs the command/shell and set that script as the command option on the first mention of your key... There are many issues with this option.)
@stale[bot] commented on GitHub (Jan 5, 2019):
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs during the next 2 weeks. Thank you for your contributions.