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

update_repositories() failed #16

Closed
Lncn opened this issue Feb 18, 2012 · 11 comments
Closed

update_repositories() failed #16

Lncn opened this issue Feb 18, 2012 · 11 comments

Comments

@Lncn
Copy link

Lncn commented Feb 18, 2012

I discovered a problem today with my installation when a user who was trying to register and clone a Git repo. It's hard to say how long this may have not worked as this is probably the first person to register in a week or so (we just use this on our internal network at work... maybe a 20 person or so operation)

Anyways, she was complaining that her git clone was getting rejected because she didn't have permissions. I checked her sshkey and it was loaded in the Redmine database, but when I checked the gitolite-admin repo, I didn't see the public key. I tried it myself and it didn't work again.

It looks like the plugin is having trouble with accessing the gitolite-admin repository and updating the keys. I checked the redmine production.log and saw that the access just suddenly stopped working last night at 3:34 am. I have the fetch_changesets running every minute on the crontab:

$ cat /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root

* * * * * apache cd /var/www/redmine && /usr/bin/ruby script/runner "Repository.fetch_changesets" -e production 2&>1 | tee -a /var/www/redmine/log/repository.log

In the middle of the night, I just started getting this error:

Executing RESYNC_ALL operation on gitolite configuration
Fetching changes from gitolite-admin repository to /tmp/redmine_git_hosting/git/gitolite-admin
***> Command failed (return 128): env GIT_SSH=/var/www/redmine/vendor/plugins/redmine_git_hosting/bin/gitolite_admin_ssh git --git-dir='/tmp/redmine_git_hosting/git/gitolite-admin/.git' --work-tree='/tmp/redmine_git_hosting/git/gitolite-admin' merge FETCH_HEAD
***> error: Could not read 65cd0537d541169a217dd6831f7a7d62c89bc733
***> error: Could not read 65cd0537d541169a217dd6831f7a7d62c89bc733
***> fatal: unable to read tree 8fb3e85c975a610a84cc8c66cb17aad7f862a467
***> Failure to access gitolite-admin repository.  Attempting to fix...
 Reestablishing gitolite key
***> Command failed (return 1): /var/www/redmine/vendor/plugins/redmine_git_hosting/bin/run_as_git_user 'gl-setup ~/id_rsa.pub'
***> gl-setup: Command not found.
***> Failure again.  Probably requires human intervention
***> git_hosting: update_repositories() failed

This may not be specifically related to the original problem, but I honestly don't really know where to begin debugging this. The "Could not read" and "unable to read tree" just looks like a problem with Git, but I can't seem to find much information on it. Any ideas on what could be going on here?

I'm using Redmine 1.3 (stable)

@kubitron
Copy link
Owner

Sorry about the delay. Not sure what the problem was that caused the "could not read" errors. Very weird. Note that you got a 128 error return from git. Often this is caused by a permissions problem on the keys (REDMINE_ROOT/.ssh). Did that change recently?

At any rate, where is your gitolite installation? This version of the plugin attempts to reesatablish the gitolite key, which it is currently failing to do. If you see, it tries to run "gl-setup" and doesn't find it...

Incidentally, running "fetch_changesets" every minute is probably asking for a synchronization problem. Why not run it more like every 15 minutes?

@Lncn
Copy link
Author

Lncn commented Feb 22, 2012

Yeah, it was pretty weird. I haven't really had a chance to look into this at work as I have been busy with other things. Nothing has changed lately with permissions to my knowledge. I did notice that the 128 error fixed itself in the middle of the night, on Saturday morning (~24 hours later). I'm kind of beginning to think that this was probably completely unrelated to this plugin. I checked the server's VLM and the only odd thing is that around the same time, both nights (when it broke, and when it worked) Fedora had run pcscd the Smart Card reader at the exact same time. Var logs were clear other than that. That seems unlikely to have caused this problem, but who knows...

I still get the gl-setup Command not found error, and I guess this is just because the path to gl-setup is not in the apache user's PATH.

Also, the fetch_changesets cronjob I guess runs fine since our operation is pretty small, but you're saying once our repositories get adequately large and the operation takes longer, I may start running into problems?

Basically, once I get time, I'll fix the gl-setup not found problem and my problems may be fixed, in which case we can just close this as not a bug or something...

@kubitron
Copy link
Owner

OK. Keep me informed as to whether the problems go away --- I would like to close the bug when possible. I'm going to mark this as a configuration problem, since it appears that it may be something like that...

@Lncn
Copy link
Author

Lncn commented Mar 2, 2012

Sorry it's taking me so long. As I mentioned only 20 or so people use our installation and gitolite + update repositories works so it's not a problem most of the time, and I've been super busy with other things.

That being said, a user tried to create a new project and push the initial commit today and failed. When I get less busy I can probably figure this out pretty easy as it does look like a simple configuration problem, but I am still unsure of how it got in this state. On first glance, this seems like the sshkey I used under <redmine_install_dir>/.ssh/id_rsa.pub doesn't have RW+ access to the gitolite-admin repo.

I checked and it appears to be there... How do I verify that everything is as it should be?

Executing RESYNC_ALL operation on gitolite configuration
Cloning gitolite-admin repository to /tmp/redmine_git_hosting/git/gitolite-admin
***> Command failed (return 128): env GIT_SSH=/var/www/redmine/vendor/plugins/redmine_git_hosting/bin/gitolite_admin_ssh git clone git@tmsmine:gitolite-admin.git /tmp/redmine_git_hosting/git/gitolite-admin
***> Cloning into /tmp/redmine_git_hosting/git/gitolite-admin...
***> Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
***> fatal: The remote end hung up unexpectedly
***> Failure to access gitolite-admin repository.  Attempting to fix...
 Reestablishing gitolite key
 Deleting and recloning gitolite-admin to /tmp/redmine_git_hosting/git/gitolite-admin
***> Command failed (return 128): env GIT_SSH=/var/www/redmine/vendor/plugins/redmine_git_hosting/bin/gitolite_admin_ssh git clone git@tmsmine:gitolite-admin.git /tmp/redmine_git_hosting/git/gitolite-admin
***> Cloning into /tmp/redmine_git_hosting/git/gitolite-admin...
***> Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
***> fatal: The remote end hung up unexpectedly
***> Failure again.  Probably requires human intervention
***> git_hosting: update_repositories() failed

Sorry, this is turning out to be more of a support issue. This is just easier for now that I don't have much time to devote to it.

@kubitron
Copy link
Owner

kubitron commented Mar 4, 2012

No worries.

Did I ask you whether your keys directory has the right permissions? (i.e. RAILS_ROOT/.ssh) should be 700, and RAILS_ROOT/.ssh/gitolite_admin_rsa_id => 400, and RAILS_ROOT/.ssh/gitolite_admin_rsa_id.pub should be 444.

If things are more permissive, this can cause ssh to refuse to use the keys....

@Lncn
Copy link
Author

Lncn commented Mar 5, 2012

I did check this, but was making sure it was still how I set it up as described in the readme:

cd [redmine_rails_root]
mkdir .ssh
cp [somewhere-or-other]/gitolite_admin_id_rsa     .ssh/gitolite_admin_id_rsa
cp [somewhere-or-other]/gitolite_admin_id_rsa.pub .ssh/gitolite_admin_id_rsa.pub

chown www-data -R .ssh
chmod 700 .ssh
chmod 600 .ssh/gitolite_admin_id_rsa
chmod 644 .ssh/gitolite_admin_id_rsa.pub

I'd assume setting the owner write permission wouldn't matter... Just to clarify, because maybe my assumption is wrong, but the id_rsa keypair don't need to be of any particular user, right? When I set up the server which is hosting our installation, I made a local linux user named "redmine", who I used to create the ssh keypairs. Other than this, this user isn't used for anything. Is this typically how one would do this?

@kubitron
Copy link
Owner

kubitron commented Mar 5, 2012

Well, it seems correct.

What is "tmsmine"? Is that the machine with a gitolite repo (and with the redmine server)? Perhaps you need a fully-resolved host name (I'm wondering if your git requests are being forwarded to the wrong machine)? I'm assuming that you have gitServer set to "tmsmine"?

Also, su to root and cd to your git user homedirectory (~git) and make sure that the same thing is true about the directory and keys there... (i.e. ~git/.ssh should be 700, ~git/.ssh/authorized_keys => 400 (or 600), etc. The important part here is that it must not be possible for anyone other than the given user to read or write the keys. Otherwise, ssh will ignore them.

@kubitron
Copy link
Owner

kubitron commented Mar 5, 2012

Oh -- one last thing. Look in:

vendor/plugins/redmine_git_hosting/bin/gitolite_admin_ssh 

to see which key it is attempting to use (there is a "-i" argument which should point at your private key under REDMINE_ROOT).

@Lncn
Copy link
Author

Lncn commented Mar 9, 2012

So I finally broke down and took the time to fix this today. I'm not exactly sure how this happened but somehow the private key Redmine uses to authenticate with the git user got renamed within the gitolite config. I have a feeling this was messed up because I had originally made a new key pair when I first set up Redmine to use as the new gitolite-admin authentication (and not a pre-existing one), and copied the wrong one or something because I left it the default "id_rsa.pub" filename.

The mess up seemed to happen "on it's own", but maybe it simply happened the first time this plugin had to push a change to the gitolite-admin repo, and the subsequent gitolite compile removed access for the old key which was mistakenly the one I gave to Redmine to use to authenticate. Again, that's just speculation. I'm not sure, but yeah, this was definitely just a configuration issue.

On a more useful note, the sshkeys-lint utility is very helpful in debugging this sort of thing. It pointed me exactly to the problem!

@Lncn Lncn closed this as completed Mar 9, 2012
@kubitron
Copy link
Owner

kubitron commented Mar 9, 2012

Actually, the id_rsa.pub is probably my fault -- the current version of the plugin attempts to reestablish the key when there is a problem. It calls it "id_rsa.pub" and reruns gl-setup to set it up as the key. I know that gl-setup was not originally in your path, so perhaps this was part of the problem.

The reason this code is in there, is that the original plugin had a failure condition that completely removed the access key from the gitolite.conf file. Thus, fetch_changesets tries to fix this circumstances (and seems to under a lot of situations). I'm kinda curious what was actually wrong with your configuration. Do you think that the id_rsa.pub key was in the conf file but not in the keydir directory?

@Lncn
Copy link
Author

Lncn commented Mar 10, 2012

Hmm... intereseting. My original key that I used was called "id_rsa" as well. Again, perhaps the problem was that I set this up before I understood how the whole machine worked together... If I remember correctly, when I setup Gitolite, the gitolite user I gave access to the gitolite-admin repo was "redmine" (public key was "redmine.pub"), with the expectation of redmine getting the access. But when I went to set up this plugin, I think I might have renamed it to "id_rsa_", or I might have remade one and *thought_ I gave access, and then when the plugin went to fix it, it got the keys confused or something. I'll let you know if this happens again.

BUT, I have another problem now! I think this is a problem with the plugin (having to do with the caching), so I think I'll open another issue...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants