
GitHub Actions ワークフローでアクションを使うときにセキュリティ面を考慮すると「タグ指定」ではなく「コミットハッシュ指定(ピン留め)」が良いと言われている.たとえば GitHub Actions のドキュメントでも Pin actions to a full-length commit SHA(アクションを完全なコミット SHA にピン留めする) と書かれている📝
Pinning an action to a full-length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps mitigate the risk of a bad actor adding a backdoor to the action's repository, as they would need to generate a SHA-1 collision for a valid Git object payload. When selecting a SHA, you should verify it is from the action's repository and not a repository fork.
最近だと2026年3月19日の trivy-action の事例があったりする.過去を遡れば他にもある.
コミットハッシュ指定(ピン留め)
たとえば actions/checkout の v6.0.1 と actions/setup-python の v6.1.0 をコミットハッシュ指定(ピン留め)にすると以下のようになる.コミットハッシュだと具体的なバージョンがわからず利便性が下がってしまうけど「同じ行にコメントとしてバージョンを併記する」という記法が使える👌
name: Sandbox on: push: branches: - main permissions: contents: read jobs: lint: runs-on: ubuntu-latest steps: - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 - uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6.1.0 with: python-version: '3.14'
ピン留めするコミットハッシュは gh api コマンドで取得できる.
$ gh api repos/actions/checkout/git/ref/tags/v6.0.1 | jq -r .object.sha 8e8c483db84b4bee98b60c0593521ed34d9990e8 $ gh api repos/actions/setup-python/git/ref/tags/v6.1.0 | jq -r .object.sha 83679a892e2d95755f2dac6acb0bfd1e9ac5d548
もしくは pinact を使って自動的に GitHub Actions ワークフローを書き換えることもできる❗️便利〜
Dependabot で自動的に更新する
Dependabot は GitHub Actions ワークフローのアクションを自動更新することができて,さらに「同じ行にコメントとしてバージョンを併記する」という記法もサポートしている👌
Dependabot updates the version documentation of GitHub Actions when the comment is on the same line, such as actions/checkout@
# or actions/checkout@ # .
以下のように .github/dependabot.yml を実装しておく.
version: 2 updates: - package-ecosystem: github-actions directory: / schedule: interval: daily target-branch: main
すると2つのプルリクエストが自動的に作られた👌
- Bump actions/checkout from 6.0.1 to 6.0.2
- Bump actions/setup-python from 6.1.0 to 6.2.0

そしてプルリクエストを確認すると v6.0.1 というコメントも含めて更新された \( 'ω')/
- - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

まとめ
GitHub Actions ワークフローでアクションを「コミットハッシュ指定(ピン留め)」にしつつ,同じ行にコメントとしてバージョンを併記すれば Dependabot で自動的に更新できるので継続的に運用できる❗️