-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
'git push' over SSH does not close issues, but does over HTTP(S). #5107
Comments
Ah, this explains why commits don't close issues! I see this same issue. |
For what it's worth, I don't have this issue and I do all my operations via SSH. |
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. |
@zeripath: I don't have a key for p.copissa. I do for git (which is also a Centos login), as I wrote above. 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) |
@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 ) |
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. |
@Etzelia: That looks like a plausible mechanism. |
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) ? |
@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). |
@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 |
Does the Gitea user git have the SSH key installed? |
You mean if I sign in in Gitea web UI as (Gitea user) |
I think that is the likeliest cause of the issue.
This would normally not be an issue, as others wouldn't have access to a system account like you do. |
@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. |
When I'm back in the office, I'll try to add keys in the web UI for user |
@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 (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 I'm not suggesting you actually do any of the above however. |
@zeripath Gitea has supported PAM if you build with |
@lunny as far as I can see that's as a pam user not a pam provider? |
Yes. |
I did this:
So it does not seem that adding Note for completeness: |
@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:
|
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' |
I tried that too but the result is the same. Updated the sequence above. |
Neither. As I wrote above, the only way I could get
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 |
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. |
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. 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. |
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
It is duplicated on the server in
On my MSYS client, I copied the string mentionned at step 4 into a file called
No
This will have to wait untli Monday. |
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.) |
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. |
[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
ssh
with Putty'sPLINK.EXE
by setting theGIT_SSH
environment variable. Also startPAGEANT.EXE
and insert the ppk file for Centos logingit
who is runninggitea
service.p.copissa
via 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
git
with the same password as the Centosgit
login.In the web UI, log in as
p.copissa
, create a repositorytest
, (be sure to tick the check box Initialize Repository to avoid issue When creating repo without init it shows still howto #2898), create two issues (Rename import paths: "github.com/gogits/gogs" -> "github.com/go-gitea/gitea" #1 and Fix sender of issue notifications #2).On the client, clone repository
test
via HTTP (or HTTPS) usinggit.exe
command:git clone http://git.lan:3000/p.copissa/test.git test-http
On the client, create a new file, commit and push it:
git commit -a -m "this fixes issue #1"
git push
(specify user
p.copissa
and give its Gitea password when asked)In the web UI, refresh the issues: Issue Rename import paths: "github.com/gogits/gogs" -> "github.com/go-gitea/gitea" #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-ssh
Redo step 4 but with issue 2:
git commit -a -m "this fixes issue #2"
git push
Note that no username nor password is asked. Also note that the Gitea user
git
has the same password as Centosgit
login.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 whatever
and 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
The text was updated successfully, but these errors were encountered: