Tuesday 27 August 2013

gitlab - access denied issue (not able to push after installation)

[gitlab]
installation guide:
https://github.com/gitlabhq/gitlabhq/blob/master/doc/install/installation.md


- if you have the following issue with gitlab, that means your gitlab-shell not configured correctly

$ ssh git@server
Welcome to GitLab, Anonymous!
Connection to server closed.
$ git push -u origin master
Access denied.
fatal: Could not read from remote repository.
then you need update /home/git/gitlab-shell/config.yml
change default one("http://localhost/") to "http://<server>/"
refer to following info/explanation as well:
https://github.com/gitlabhq/gitlabhq/issues/3384#issuecomment-15457287
---- excerpted from above page ----
When invoking the internal api likehttp://server/api/v3/internal/allowed?key_id=2&action=git-upload-pack&ref=_any&project=user/projectfrom other machines, the nginx config will give gitlab as default web so it works.
However when actually doing clone, push and pull. The internal api is invoked by gitlab-shell on the same machine of the gitlab server. Now since the gitlab config for nginx /etc/nginx/sites-enabled/gitlab is set as:
server {
  listen YOUR_SERVER_IP:80 default_server;         # e.g., listen 192.168.1.1:80;
  server_name YOUR_SERVER_FQDN;     # e.g., server_name source.example.com;
  root /home/git/gitlab/public;
user git on the server invoked gitlab-shell to access web api at YOUR_SERVER_FQDN, but now the server IP to user git is 127.0.0.1. So gitlab is not valid website now. But the default nginx site listens to any IP at port 80 so the
<html>
<head>
<title>Welcome to nginx!</title>
</head>
<body bgcolor="white" text="black">
<center><h1>Welcome to nginx!</h1></center>
</body>
</html>
is given out. Because it is the index page of default nginx site.
Solution is to set the gitlab nginx config file /etc/nginx/sites-enabled/gitlab as:
server {
  listen *:80 default_server;         # e.g., listen 192.168.1.1:80;
  server_name YOUR_SERVER_FQDN;     # e.g., server_name source.example.com;
  root /home/git/gitlab/public;
Hope this solves problems.
If don't use FQDN only use IP, then the mentioned problem would not appear.
---------

- couple of config files to look at:
/home/git/gitlab/config/gitlab.yml
/home/git/gitlab-shell/config.yml
/etc/nginx/sites-enabled/gitlab

- restart service
sudo service gitlab stop/restart
sudo service nginx stop/restart
sudo /etc/init.d/gitlab restart

- turn on DEBUG log for gitlab-shell if still have trouble.
check /home/git/gitlab-shell/gitlab-shell.log

- if you meet following error:
fatal:bad default revision "HEAD"

most likely your repo has some issue, check ./git/refs, something must be missed there. and also use git branch --list --list -a to see whether correct branches listed.(should be no)  

you can re-clone the project, redo checkout, and then overwrite the original ".git" with the new one.

- check status:
sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production
sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production
/home/git/gitlab-shell/bin/check

- make sure the version of gitlab-shell is correct(with above check). and also hooks path is correct in /home/git/gitlab/config/gitlab.yml. 

  gitlab_shell:
    # REPOS_PATH MUST NOT BE A SYMLINK!!!
    repos_path: /home/git/repositories/

    hooks_path: /home/git/gitlab-shell/hooks/



No comments:

Post a Comment