Skip to content

GitHubでコミットの署名を強制する

コミットに署名をつけたくなったし、それを強制したくなったので調べた。

リポジトリ単位の設定で、ブランチ保護ルール(Branch protection rules)の Require signed commits オプションを有効にすればいい。

デフォルトブランチを保護するだけでは、元となった問題に対処できない。タグが参照するコミットはデフォルトにマージされていなくても向けることができるので、全部のブランチで有効にしたほうがいい。

  • Target branches: All
  • Branch rules: Require signed commits

この設定を入れておくと、署名のないコミットをpushしたとき以下のエラーで失敗する。

Terminal window
$ git push
remote: error: GH013: Repository rule violations found for refs/heads/main.
remote: Review all repository rules at https://github.com/lufia/plug/rules?ref=refs%2Fheads%2Fmain
remote:
remote: - Commits must have verified signatures.
remote: Found 1 violation:
remote:
remote: b254e04b07d138e4bfbe6a9743a7e1941d1be5bc
remote:
To https://github.com/lufia/plug.git
! [remote rejected] main -> main (push declined due to repository rule violations)

また、PRを作成したときも、保護されたブランチへマージしようとするとブロックされる。

[! Error] Merging is blocked Commits must have verified signatures.

これに関連して、警戒モード(Vigilant mode)という機能があるらしい。慎重な振る舞いが求められるときに、作者の合意を得たかそうでないかを識別するものなのか?いまいち分かっていない。