GitHubで `git://` が使えなくなったので `https://` などに置き換える必要があった

tl;dr

  • git://GitHubで使えなくなった
  • git:// の変わりに https:// を使うようにした
  • パブリックなリポジトリ以外に対しての変更の可能性もある

The unauthenticated git protocol on port 9418 is no longer supported.

今朝からRubyのアプリをビルドするジョブが以下のようなエラーを吐くようになった。

Fetching git://github.com/sinatra/sinatra.git
fatal: remote error: 
  The unauthenticated git protocol on port 9418 is no longer supported.
Please see https://github.blog/2021-09-01-improving-git-protocol-security-github/ for more information.

既に趣旨を伝えるエラーの文言が見えるが、念の為に手元のマシンでも試してみる。

$ git clone git://github.com/sinatra/sinatra.git
Cloning into 'sinatra'...
fatal: remote error:
  The unauthenticated git protocol on port 9418 is no longer supported.
Please see https://github.blog/2021-09-01-improving-git-protocol-security-github/ for more information.

同じ結果だった。

原因としては GitHub が git プロトコルを明示的に使えないようにしたため。

github.blog

No more unauthenticated Git

On the Git protocol side, unencrypted git:// offers no integrity or authentication, making it subject to tampering. We expect very few people are still using this protocol, especially given that you can’t push (it’s read-only on GitHub). We’ll be disabling support for this protocol.

まだ使っていてすまん…使うのやめます…

ということで、置き換えることにした。

https:// に置き換える

まず、現状の手順で最小の変更手数になりそうな「ジョブランナー側を変更する」を検討した。unencrypted な git プロトコルと記述があったので、もしかして暗号化される git プロトコルも存在するのでは?と軽く調査したが、見る限りでは見当たらなかった。そのため、各個別の git:// を使用している箇所について対応をする方針で進める。

今回はpublicなリポジトリに対してのcloneの操作だったので、特に考えることもなく https:// に置き換えることで対応完了とした。

今回の場合、gitプロトコル経由でリポジトリを取得しているのはGemfile経由のbundle installだったので、Gemfileの先頭あたりに以下の行を追加した。

git_source(:github) { |repo| "https://github.com/#{repo}.git" }

その他にも

先程のgithubのblog曰く、sshプロトコルかつ鍵経由でやり取りをしている場合であっても古いタイプの鍵を使っている場合は影響を受けるらしい。

今回の削除方向の変更は具体的には以下の通り。

もし上記に当てはまる場合は以下の項目を参考にしたほうが良さそう。

https://github.blog/2021-09-01-improving-git-protocol-security-github/#how-do-i-prepare