本文へスキップ
ecdsa.com
git over HTTPS with libcurl + OpenSSL (Git for Windows default, macOS Homebrew, Alpine, RHEL)Git

エラーメッセージ

fatal: unable to access 'https://git.example.com/team/app.git/': SSL certificate problem: self-signed certificate in certificate chain

別の表記

  • fatal: unable to access 'https://git.example.com/team/app.git/': SSL certificate OpenSSL verify result: self-signed certificate in certificate chain (19)
  • SSL certificate problem: self signed certificate in certificate chain

URL は使用しているリモートのものです。OpenSSL 1.1.1 ベースのビルドではハイフンなしの「self signed」が出力され、libcurl 8.22 では「SSL certificate OpenSSL verify result: self-signed certificate in certificate chain (19)」が出力されます。

このエラーの意味

Git サーバー(またはその前段にある何か)が、自己署名のルートで終わる完全なチェーンを送信しましたが、そのルートが git の libcurl が使う CA バンドルに含まれていません。github.com のような公開ホストでこれが起きる場合、ルートはほぼ必ずネットワーク上の TLS を検査するプロキシのものです。セルフホストのサーバーの場合は、社内 CA のものです。

発生する理由

修正方法

  1. 1.

    ルートを特定する

    公開ホストのチェーンを出力してください。最上位の証明書に自社名やセキュリティベンダーの名前が付いている場合、接続は検査されており、git が信頼すべきなのはそのルートです。まったく見覚えのない証明書であれば、信頼してはいけません。まず調査してください。

    bash
    openssl s_client -connect github.com:443 -servername github.com -showcerts </dev/null 2>/dev/null \
      | grep -E '^ *[0-9]+ s:|^ *i:'
    # A root named after your company or a security vendor = interception proxy
  2. 2.

    Windows:Windows の証明書ストアを使う

    http.sslBackend を schannel に設定した Git for Windows は、Windows が信頼するものをすべて信頼します。管理対象のマシンでは、そこにプロキシのルートがすでに含まれています。

    bash
    # Git for Windows: use the Windows certificate store, which already trusts the proxy root
    git config --global http.sslBackend schannel
  3. 3.

    git が使うバンドルにルートを追加する

    http.sslCAInfo はデフォルトのバンドルを置き換えるため、パブリックルートに加えて、プロキシのルートまたは社内のルートを含むファイルを作成してください。

    bash
    # Linux/macOS/WSL: append the proxy root to a bundle that keeps the public roots
    cat /etc/ssl/certs/ca-certificates.crt corp-proxy-root.pem > ~/.config/git/ca-bundle.pem
    git config --global http.sslCAInfo ~/.config/git/ca-bundle.pem
  4. 4.

    Linux でルートをシステム全体にインストールする

    update-ca-certificates を使うと、git、curl、wget、pip をはじめとするほとんどのツール向けに、ルート証明書が一度に追加されます。

    bash
    sudo cp corp-proxy-root.pem /usr/local/share/ca-certificates/corp-proxy-root.crt
    sudo update-ca-certificates
  5. 5.

    一時的な診断:1 つのコマンドに限って検証をスキップする

    診断の確認にのみ使ってください。実際の作業で検証を無効にすると、Git の認証情報とソースコードが、接続を終端する者の手に渡ります。

    bash
    # Diagnostic only, for one command
    git -c http.sslVerify=false ls-remote https://git.example.com/team/app.git

関連するエラー

署名エラーデータベースをすべて見る