증상

push 할 경우 다음과 같은 에러 메시지가 발생하며 실패

remote: GitLab: You are not allowed to access master!
remote: error: hook declined to update refs/heads/master
To http://gitlab.example.com/lesstif/lib-hello.git
 ! [remote rejected] master -> master (hook declined)
CODE

 

원인

gitlab 의 서비스 URL 설정이 잘못 될 경우 발생함.

  1. gitlab.yml 의 기본 설정은 http(80) 를 사용하게 되어 있으나 아파치 http 용 gitlab 설정(/etc/httpd/conf.d/gitlab.conf) 은 mod_rewrite 를 사용하여 80 포트로 들어오면 443 으로 전환하도록 되어 있다.
  2. 이때문에 http(80 포트)로 API를 호출하면 HTTPS 로 강제 포워딩 하기 위해 HTTP 302 응답 코드를 전송하는데 git 클라이언트들은 이를 처리하지 않으므로 에러가 발생함.

  3. 위 설정때문에 발생하는 경우 gitlab-shell 의 로그 파일에 다음과 비슷한 로그가 남게 됨

    E, [2014-09-29T11:01:23.851271 #5078] ERROR -- : API call <GET http://gitlab.example.com//api/v3/internal/allowed?acti
    on=git-upload-pack&ref=_any&project=lesstif%2Fgitlab-spoon-knife&forced_push=false&key_id=2> failed: 302 => <<!DOCTYPE
    HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
    <html><head>
    <title>302 Found</title>
    </head><body>
    <h1>Found</h1>
    <p>The document has moved <a href="https://gitlab.example.com/api/v3/internal/allowed?action=git-upload-pack&amp;ref=_
    any&amp;project=lesstif%2Fgitlab-spoon-knife&amp;forced_push=false&amp;key_id=2">here</a>.</p>
    </body></html> 

해결

공통

gitlab-shell/config.yml 의 설정은 다음과 같이 로컬 호스트로 변경하는 게 좋다. FQDN 을 사용하면 Web 서버를 거치기 때문에 HTTP 302 문제도 발생할 수 있다.

 

gitlab_url: "http://localhost:8085/"
http_settings:
#  user: someone
#  password: somepass
#  ca_file: /etc/ssl/cert.pem
#  ca_path: /etc/pki/tls/certs
  self_signed_cert: false
CODE


서비스를 HTTP 로 제공(HTTP 로 들어와도 HTTP 302 응답이 발생하지 않음)

  • gitlab/gitlab.yml 의 설정을 다음과 같이 변경

    gitlab:
        ## Web server settings (note: host is the FQDN, do not include http://)
        host: gitlab.example.com
        port: 80
        https: false
    CODE
  • /etc/httpd/conf.d/gitlab.conf 의 80 으로 들어왔을 경우 redirect 하는 부분 수정(  RewriteEngine on -> off)

 RewriteEngine off
  RewriteCond %{HTTPS} !=on
  RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [NE,R,L]
CODE

서비스를 SSL(HTTPS) 로 제공

  • gitlab/gitlab.yml 의 설정을 다음과 같이 변경

    gitlab:
        ## Web server settings (note: host is the FQDN, do not include http://)
        host: gitlab.example.com
        port: 443
        https: true
    CODE
  • /etc/httpd/conf.d/gitlab.conf 의 RewriteEnginedirect 에 80 으로 들어왔을 경우 HTTPS 로 포워딩하도록 수정(  RewriteEngine off -> on)

     RewriteEngine off
     RewriteCond %{HTTPS} !=on
     RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [NE,R,L]
    CODE

설정이 완료되었으면 아파치와 gitlab 재시작

service httpd restart
service gitlab restart
CODE