Enforce SHA pinning の検証
検証用リポジトリ: https://github.com/szksh-lab-2/test-enforce-sha
Org と Repo それぞれで有効化できる
Repo で有効化してみる。
予想に反してマージできそう
できてしまった。
ちゃんとドキュメントを読み直す。
Enforce SHA pinning
To proactively limit the impact of a compromised dependency, GitHub recommends that workflows pin dependency versions to a specific commit SHA.
This will prevent malicious code added to a new or updated branch or tag from being automatically used.
Administrators can now enforce the use of SHA pinning through the allowed actions policy.
A new checkbox appears under each radio selection, except when actions are disabled at the enterprise, organization, or repository level.
The policy will check for a full commit SHA, and any workflow that attempts to use an action that isn’t pinned will fail.
あぁ push できないのではなくて、 action の実行に失敗するのか。
実行したら失敗した。
Error: The action actions/checkout@v4.2.2 is not allowed in szksh-lab-2/test-enforce-sha because all actions must be pinned to a full-length commit SHA.
実行時エラーなので、実行前に静的に check する pinact のようなツールとは違う。
Pros.
- action 1 が別の action 2 を実行している場合、 action 1 だけではなく、 action 2 もチェックできるのでは
- セキュリティ的にはかなり有効であるものの、 pinning してない action に依存する action も多くあるため、多くの action, workflow が動かなくなって厳しいのでは
Cons.
- 実行前に問題を検出できない
やはり依存している action が pinning されていない場合でも失敗した。
Error: The action actions/setup-node@v4 is not allowed in szksh-lab-2/test-enforce-sha because all actions must be pinned to a full-length commit SHA.
まとめ
- Enforce SHA Pinning を検証した
- Workflow 実行時に失敗するので、静的な linter とは異なる
- 正確には
Set up job
の段階で失敗するので、 Job が中途半端に実行されたりはしないし、 Check は failure になる
- 正確には
- Organization または Repository レベルで設定できる
- Organization レベルで有効化すると、 Repository レベルで無効化できない
- 特定の action を除外するということはできない
- まず、実行前に問題を検出できないという問題がある
- Pinning してないコードを含む PR であっても、そのコードが実行されなければ問題が検出されず、 PR をマージできてしまう
- また、実行時にチェックするので action の依存を遡って Pinning を強制することになる
- Pros. セキュリティ的にはかなり強力
- Cons. 例えあなたが適切に Pinning してたとしても、 Pinning してない Action を使ってる場合、 workflow が動かなくなる
- 何も考えずに会社の Org 全体で有効化すると至るところで Workflow が動かなくなって混乱が生じる可能性が高い
例:
szksh-lab-2/test-action-2@9e2a72fb2ec7ffe46e18ab4782a7742955839c85 が actions/setup-node@v4 を実行している。
この場合、 szksh-lab-2/test-action-2@9e2a72fb2ec7ffe46e18ab4782a7742955839c85 を実行すると actions/setup-node@v4 が Pinning されていないので実行に失敗する。
これは action の依存を遡って Pinning を強制するのでセキュリティ的にはかなり有効ではある。
しかし、 action を Pinning せずに依存している action も少なくなく、例えあなたが action を Pinning してたとしても workflow が動かなくなるケースも多く考えられる。