
GitHub Actionsの侵害・サプライチェーンリスクを軽減:pinactを使ってアクションをバージョンではなくハッシュ値で指定
GitHub Actionsでファイルの差分などを得るサードパーティーアクション tj-actions/changed-files が侵害され、バックドアが仕込まれ、Gitタグも書き換えられました。
azu on X: "GitHub Actionsでファイルの差分とかを得る - uses: tj-actions/changed-files の全部のバージョンにマルウェアが入ってる問題 。 全部のタグが書き換えられているので、SHAで指定する以外は現状対応方法がない。 - https://t.co/mr7T3yl6gw - https://t.co/lIiKzApAis - https://t.co/fIBRBWh2mk" / X
- Semgrep | 🚨 Popular GitHub Action tj-actions/changed-files is compromised
- Harden-Runner detection: tj-actions/changed-files action is compromised - StepSecurity
結果的に、 tj-actions/changed-files をタグのバージョン指定で呼び出していた場合、この侵害の影響を受けたことになります。
GitHubの公式ドキュメント"Security hardening for GitHub Actions"に従い、アクションを可変なタグではなく不変(immutable)なコミットSHAでピン留めしておくと、このリポジトリの侵害リスクを防げました。
本記事では、@szkdash 作による pinact という OSS ツールを用い、コミットSHA でアクションをピン留めしつつ、タグ(バージョン)指定の利便性も維持する方法を紹介します。
pinact を使ってアクションをコミットSHAで固定
リポジトリのGitHub ワークフローファイルのアクションバージョンをコミットSHAで固定するには、 pinact をインストールし、 $ pinact run
を実行するだけです。
$ brew install pinact
$ pinact run
$ git diff
diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml
index 7ec30ad..b930934 100644
--- a/.github/workflows/deploy.yml
+++ b/.github/workflows/deploy.yml
@@ -23,21 +23,21 @@ jobs:
steps:
- name: Checkout
- uses: actions/checkout@v4
+ uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Configure AWS Credentials
- uses: aws-actions/configure-aws-credentials@v4
+ uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4.0.2
with:
role-to-assume: ${{ env.ROLE_ARN }}
aws-region: ${{ env.AWS_REGION }}
...
タグに対応するコミットSHAでピン留めしてセキュリティレベルを上げ、同時に、タグ情報をコメントに残すことで、人間が管理しやすくしています。
pinact の各種環境へのインストール方法は、次のドキュメントを参照ください
GitHubランナーの侵害リスク
GitHub公式ドキュメントにあるように、侵害されたランナーは以下のような潜在的影響があります
- シークレットへのアクセス
- ランナーからのデータ流出
GITHUB_TOKEN
の盗難- リポジトリコンテンツの改ざん
サードパーティーアクションのリスク軽減
GitHubの公式ドキュメントでは、アクションのリスクを軽減するために、以下の様なアプローチが推奨されています
- アクションをコミットSHAで固定
- ソースコードを監査
- 利用可能なアクションを制限
3つ目について補足します。
組織・リポジトリの Actions → General から利用可能なアクションを制限できます。
より具体的には、 "Allow enterprise, and select non-enterprise, actions and reusable workflows" をチェックし
- Allow actions created by GitHub
- Allow actions by Marketplace verified creators
をチェックした上で、サードパーティーについては、コード監査を経たサードパーティーアクションを "Allow specified actions and reusable workflows" で許可すると、セキュリティリスクを軽減できます。
本機能は公開リポジトリやプライベートリポジトリの場合は特定のプランに限定されることにご留意ください。
利用可能なサードパーティーアクションを許可制にすると、開発者は自分たちの使いたい・試したいアクションをすぐに評価できず、開発効率の軽減にも繋がり、許可対応のために、GitHub管理者の運用負荷も上がります。
サンドボックス環境の提供や利用申請フローの整備も併せて検討しましょう
参考
- https://docs.github.com/enterprise-cloud@latest/actions/security-for-github-actions/security-guides/security-hardening-for-github-actions#using-third-party-actions
- https://docs.github.com/organizations/managing-organization-settings/disabling-or-limiting-github-actions-for-your-organization
最後に
GitHubのサードパーティーアクションのセキュリティリスクを軽減する方法として、以下があります
- アクションをタグではなくコミットSHAで固定
- ソースコードを監査
- サードパーティーアクションを許可制にする
2025年3月 に発生した tj-actions/changed-files の侵害インシデントでは、バックドアが仕掛けられ、タグも書き換えられました。
本件では、1つ目のコミットSHA方式で回避できました。
pinact を利用すると、コミットSHA運用を簡単に実現できます。
参考
- https://docs.github.com/enterprise-cloud@latest/actions/security-for-github-actions/security-guides/security-hardening-for-github-actions#using-third-party-actions
- https://docs.github.com/organizations/managing-organization-settings/disabling-or-limiting-github-actions-for-your-organization
- https://github.com/suzuki-shunsuke/pinact
- https://zenn.dev/shunsuke_suzuki/articles/pinact-pin-github-actions-version
- Semgrep | 🚨 Popular GitHub Action tj-actions/changed-files is compromised
- Harden-Runner detection: tj-actions/changed-files action is compromised - StepSecurity