LoginSignup
6
1

More than 3 years have passed since last update.

【解決済み】GitLab 13.4.4から13.5.0にアップグレードしてgit pullがSSH鍵認証でエラーになった件

Last updated at Posted at 2020-10-23

毎度、ググっても出てこない小ネタを取り扱っております。
本記事は個人的な見解であり、筆者の所属するいかなる団体にも関係ございません。

0. GitLab サーバーへ git pull でエラーが出る。

ある朝のことだった、社内のメッセージでこんな問い合わせが来た

今回のGitLabバージョンアップの影響かどうかがわからないのですが、
TortoiseGitを使ってpullすると、添付のエラーが出ます。。。
同じ事象が出ているのは私とK君のみで、他のメンバーはSourceTreeを使っている影響から、正常にpullできているようです。
また、エラーをもとに調べても、これといった明確な原因が出てこず。。。

恐れ入りますが、こちら、ご確認をお願いします

確かに朝早くにGitLab 13.5へのバージョンアップがかかっていたはずだ。
このバージョンアップの影響の可能性が高い。私は調査を開始した。

1. 現象確認

まず、私もgitコマンドを試してみることにした。というのも先日、GitLabに連携しているLDAPサーバーが障害となって、git pullできなかったからだ。もしかしたら、またLDAPサーバーの不具合かも知れない。

$ git pull
remote:
remote: ========================================================================
remote:
remote: Internal API unreachable
remote:
remote: ========================================================================
remote:
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

変なエラーだった。
SSH鍵証明書を使ってpullした場合でのエラーなので、ID/PWを使ってhttps://でつないだ場合も確認してみた。

$ git pull
Username for 'https://gitlab.example.co.jp': hogehogehoge
Password for 'https://hogehogehoge@gitlab.example.co.jp':
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 4 (delta 1), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (4/4), done.
From https://gitlab.example.co.jp/foobar/bazbazbaz
   9d604c2..f3a86a8  master     -> origin/master
Updating 9d604c2..f3a86a8
Fast-forward

問題なく通るようだ。。

2. GitLabのログの確認

GitLabはRailsでできているので、Railsのproduction.logを確認する
# less /var/log/gitlab/gitlab-rails/production_json.log
一見問題なさそうに見えるが、以下のエラーがチラチラあるようだ。

/var/log/gitlab/gitlab-rails/production_json.log
Filter chain halted as :authenticate_user rendered or redirected
Completed 401 Unauthorized in 15ms (Views: 0.6ms | ActiveRecord: 2.4ms | Elasticsearch: 0.0ms | Allocations: 3263)

3. GitLab 13.5のリリースを見てみる

GitLab 13.5 released with Mobile App Sec, Group Wikis, and more! | GitLab
https://about.gitlab.com/releases/2020/10/22/gitlab-13-5-released/

下の方に以下のようなメッセージが書いてあった。
image.png

1つは、/var/opt/gitlab/git-data/repositoriesのパーミッションの話で、もう一つはworkhoseのソケットファイルの場所が変わったようだ。もし、workhorseのSocketがエラーだとしたらパスワード認証でもエラーになるはず。となると、ディレクトリのパーミッションの問題かも?

4. アップデート時のログを見てみる

自動アップデートのログはメールで飛んできているので見てみる

[0m    * link[Link /opt/gitlab/embedded/service/gitlab-shell/config.yml to /var/opt/gitlab/gitlab-shell/config.yml] action create (up to date)
  
[0m  * link[/opt/gitlab/embedded/service/gitlab-shell/.gitlab_shell_secret] action create (up to date)
  * file[/var/opt/gitlab/.ssh/authorized_keys] action create_if_missing (up to date)
Recipe: gitlab::gitlab-rails[0m
  * storage_directory[/var/opt/gitlab/git-data] action create
    * ruby_block[directory resource: /var/opt/gitlab/git-data] action run (skipped due to not_if)
     (up to date)
  * storage_directory[/var/opt/gitlab/git-data/repositories] action create
    * ruby_block[directory resource: /var/opt/gitlab/git-data/repositories] action run
      [0m
      ================================================================================[0m
      [31mError executing action `run` on resource 'ruby_block[directory resource: /var/opt/gitlab/git-data/repositories]'[0m
      ================================================================================[0m

[0m      Mixlib::ShellOut::ShellCommandFailed[0m
      ------------------------------------[0m
      Failed asserting that mode permissions on "/var/opt/gitlab/git-data/repositories" is 2770
[0m      ---- Begin output of set -x && [ "$(stat --printf='%04a' $(readlink -f /var/opt/gitlab/git-data/repositories) | grep -o '....$')" = '2770' ] ----

/var/opt/gitlab/git-data/repositoriesのパーミッションの話の方が正解のようである。

5. 推測

つまり、GitLabを13.4.4からGitlab 13.5へバージョンアップするときに
sudo gitlab-ctl reconfigure
したけれど、/var/opt/gitlab/git-data/repositoriesのパーミッションを変更できず中途半端にアップグレードされているのではないか?

確かに /var/opt/gitlab/git-data/repositoriesディレクトリが02770 ではないようだ。

root@gitlab:/var/opt/gitlab/git-data# ls -la
合計 8
drwx------  3 git  root   26  3月 27  2017 .
drwxr-xr-x 24 root root 4096 10月 23 02:53 ..
drwxrwx--- 89 git  git  4096 10月 23 04:19 repositories

6. 修正

パーミッションを修正する

chmod 02770 /var/opt/gitlab/git-data/repositories
ls -la /var/opt/gitlab/git-data/

修正を確認
image.png
スティッキービットが立った

よさそうなので、reconfigureする

sudo gitlab-ctl reconfigure

reconfigureが通ったのを確認して、再度アップデートしてGitLab 13.5.1にする

7. git pullが通るのを確認

問題なし

8. まとめ

管理しているGitLabの2台の内1台だけこの問題になったので、全てのサーバーで起こるわけではなさそう。
omnibusインストールのバージョンによるのかも。

6
1
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
1