简体   繁体   English

Gitlab预先接收挂钩拒绝SSH推送

[英]Gitlab Pre-Receive Hook Rejecting SSH Push

Current Installation: 当前安装:
Server: Ubuntu Server 16.04 伺服器:Ubuntu Server 16.04
Gitlab Version: 10.7.3 Gitlab版本:10.7.3
Gitlab Workhorse: 4.1.0 Gitlab主力军:4.1.0
Gitlab App Directory: /opt/gitlab (application resides here) Gitlab应用程序目录:/ opt / gitlab(应用程序位于此处)
Gitlab Data Directory: /drive2/repositories (repos created and stored here) Gitlab数据目录:/ drive2 /存储库(在此处创建和存储存储库)

Context: 内容:
I slapped together a working Gitlab installation with the data-dir pointing to a separate partition for back-up purposes, because data continuity is a cool idea, right? 我将可正常运行的Gitlab安装拍打在一起,将数据目录指向一个单独的分区以进行备份,因为数据连续性是一个很不错的主意,对吗? Repositories that are created through the gitlab web-interface are stored in the data-dir as expected. 通过gitlab Web界面创建的存储库按预期存储在data-dir中。 SSL is fine and dandy so I can use HTTPS to CLONE out of these repos. SSL很好而且很花哨,所以我可以使用HTTPS从这些存储库中克隆。 Furthermore, I am able to PUSH to these repos using HTTPS without any errors. 此外,我能够使用HTTPS推送到这些存储库,而不会出现任何错误。
I have also established SSH keys and authorized the git user (created by the omnibus gitlab installation) to validate against these keys. 我还建立了SSH密钥并授权git用户(由omnibus gitlab安装创建)来验证这些密钥。 I have verified that I can successfully tunnel through SSH onto the server as the git user and have correct privileges to write and read the data-dir where repos are stored. 我已经验证过,我可以以git用户身份通过​​SSH成功​​地通过隧道传输到服务器上,并且具有正确的特权来读写存储repos的data-dir。 Here's where it gets weird: 这是奇怪的地方:

The Error: 错误:
I can successfully use SSH to clone a repo from the server with the following command: 我可以通过以下命令成功使用SSH从服务器克隆存储库:

git clone git@some_domain.com:user/repo_name.git

Cool. 凉。 I'm less disappointed in the server than my parents are in me up until this point. 到目前为止,我对服务器的失望程度不如父母对我的失望。 So I go ahead, make a new file to add to the repo, commit (unlike my girlfriend that always drags her feet), and finally PUSH to the remote origin. 因此,我继续进行操作,制作一个新文件以添加到存储库中,进行提交(与我的女友总是拖着脚走路),最后按PUSH到远程原点。 And here my world crumbles like my motivation on Monday morning before work: 在这里,我的世界像周一下班前的动力一样崩溃:

git push -u origin master
*** Edited Out: Push Stats
remote: GitLab: The project you were looking for could not be found.
To some_domain.com:user/repo_name.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 
'git@some_domain.com:user/repo_name.git'

I open the repo's directory on the gitlab server, navigate to the hooks folder which contains a symbolic link back to the gitlab app directory that houses the pre-receive hook file. 我在gitlab服务器上打开仓库的目录,导航到hooks文件夹,该文件夹包含一个指向gitlab应用程序目录的符号链接,该目录包含接收前的钩子文件。 The contents of the pre-receive hook file here: 预先接收挂钩文件的内容在这里:

#!/opt/gitlab/embedded/bin/ruby --disable-gems
# Fix the PATH so that gitlab-shell can find git-upload-pack and friends.
ENV['PATH'] = '/opt/gitlab/bin:/opt/gitlab/embedded/bin:' + ENV['PATH']
#!/usr/bin/env ruby
# This file was placed here by GitLab. It makes sure that your pushed commits
# will be processed properly.

refs = $stdin.read
key_id = ENV.delete('GL_ID')
protocol = ENV.delete('GL_PROTOCOL')
repo_path = Dir.pwd
gl_repository = ENV['GL_REPOSITORY']

def increase_reference_counter(gl_repository, repo_path)
  result = GitlabNet.new.pre_receive(gl_repository)

  result['reference_counter_increased']
end

require_relative '../lib/gitlab_custom_hook'
require_relative '../lib/gitlab_access'
require_relative '../lib/gitlab_net'

# It's important that on pre-receive `increase_reference_counter` gets executed
# last so that it only runs if everything else succeeded. On post-receive on the
# other hand, we run GitlabPostReceive first because the push is already done
# and we don't want to skip it if the custom hook fails.
if GitlabAccess.new(gl_repository, repo_path, key_id, refs, protocol).exec &&
    GitlabCustomHook.new(repo_path, key_id).pre_receive(refs) &&
    increase_reference_counter(gl_repository, repo_path)
  exit 0
else
  exit 1
end

Is the symbolic link back to the gitlab app folder causing issues to the dynamic directory being built by this file? 回到gitlab应用程序文件夹的符号链接是否导致该文件正在构建的动态目录出现问题?

I am at a complete loss of why SSH pushes are not working and am as desperate for help as I am desperate for some validation in my life. 我完全不知道为什么SSH推送不起作用,为什么急于寻求帮助,就像我急于进行一些验证一样。 Why does the CLONE command successfully find the directory, but the PUSH command not? 为什么CLONE命令成功找到目录,而PUSH命令找不到? Everything points me to the hook file, but I've never dealt with these and help would be more appreciated than a $5 gift-card three weeks after a birthday. 一切都指向我钩子文件,但我从未处理过这些问题,并且比生日后三周提供5美元的礼品卡更为感谢。

Thanks StackOverflow! 谢谢StackOverflow!

I have also established SSH keys and authorized the git user (created by the omnibus gitlab installation) to validate against these keys. 我还建立了SSH密钥并授权git用户(由omnibus gitlab安装创建)来验证这些密钥。

You need to be careful as to how you established those SSH keys. 您需要注意如何建立这些SSH密钥。

You should only copy the public key to a GitLab User setting SSH page (see " How to create your SSH Keys "). 您只能将公共密钥复制到GitLab用户设置SSH页面(请参阅“ 如何创建SSH密钥 ”)。
You should not add that public key yourself directly in the ~git/.ssh/authorized_keys file. 应该补充的是公众直接在关键的自己~git/.ssh/authorized_keys文件。

Also, a gitlab-rake gitlab:check on your GitLab server can help detecting such issues. 另外,您的GitLab服务器上的gitlab-rake gitlab:check可以帮助检测此类问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM