Skip to content

chore(security): 🔒 CIワークフローの権限 (Permissions) 最小化の強化 - #350

Merged
genzouw merged 8 commits into
mainfrom
security-permissions-minimization-1256602521592217066
Jul 7, 2026
Merged

genzouw merged 8 commits into
mainfrom
security-permissions-minimization-1256602521592217066

Conversation

@genzouw

@genzouw genzouw commented Jul 6, 2026

Copy link
Copy Markdown
Owner

背景

対象リポジトリには gitleakstrivy など多数のセキュリティスキャンが既に導入されており、多層防御が確立されています。
しかし、CI ワークフローの権限設定において、一部で permissions: read-all が使われたり、トップレベルで security-events: write が付与されていたりする権限の過剰付与(最小権限の原則への違反)が見受けられました。

現状認識(事前調査結果のサマリー)

  • 既存防御策: gitleaks, trivy, trufflehog, codeql, actionlint など多層的なスキャンと、permissions の監査ワークフローが導入済み
  • 未カバー領域: codeql.yml におけるトップレベルの書き込み権限の付与、scorecard.ymlread-all 権限、および監査ワークフローでの過剰権限の検知漏れ
  • 直近の漏洩リスク兆候: リポジトリのソースコード上には .env や秘密情報が含まれていないことを確認済み

このPRで導入・強化するもの

  • 対象: .github/workflows/scorecard.yml, .github/workflows/codeql.yml, .github/workflows/permissions-audit.yml, docs/security/leak-prevention.md
  • ツール名とバージョン: 既存 GitHub Actions 設定の見直しと監査スクリプトの強化
  • 期待される効果: 予期せぬスクリプト実行や悪意あるActionによるリポジトリの改ざん・二次被害リスクを低減し、トップレベル権限を contents: read に厳格化することで最小権限の原則を強制

検知漏れリスクと補完策

  • 検知できないケース: ワークフロー内の個別ジョブに付与された権限が悪用された場合
  • 補完策: 既に設定されている zizmor によるワークフロー自体のインジェクション・権限解析で補完

マージ前に必要な手動作業(チェックリスト)

レビュアーは PR をマージする前に必ず以下を実施してください。
本 PR の CI は手動作業完了を前提に通る設計です。

  • GitHub リポジトリの Settings -> Actions -> General の "Workflow permissions" が "Read repository contents and packages permissions" になっていることを確認

マージ後の確認手順

  • 次の push / PR で permissions-audit.yml が green になり、トップレベル権限のテストにパスすることを確認
  • codeql.ymlscorecard.yml が正常に実行されることを確認

ロールバック手順

設定ミスで CI が動かなくなった場合は、本 PR を revert してください。

参考情報


PR created automatically by Jules for task 1256602521592217066 started by @genzouw

- `codeql.yml` と `scorecard.yml` のトップレベル権限を `contents: read` に最小化
- 必要に応じてジョブ単位で `security-events: write` と `id-token: write` を付与
- `permissions-audit.yml` にてトップレベルの権限過剰付与 (`write`, `read-all`) を自動検知するルールを追加
- `docs/security/leak-prevention.md` に CI 権限最小化に関するドキュメントを追記

Co-authored-by: genzouw <29957+genzouw@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@github-actions github-actions Bot added github-actions Pull requests that update GitHub Actions code docs labels Jul 6, 2026
@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@genzouw, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 36 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 1ca43682-cd1f-465e-bb3f-e76a7d2a8129

📥 Commits

Reviewing files that changed from the base of the PR and between 16c51e7 and 9778892.

📒 Files selected for processing (8)
  • .github/workflows/ai-doc-generator.yml
  • .github/workflows/codeql.yml
  • .github/workflows/gitleaks.yml
  • .github/workflows/permissions-audit.yml
  • .github/workflows/scorecard.yml
  • .github/workflows/trivy.yml
  • .github/workflows/zizmor.yml
  • docs/security/leak-prevention.md
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch security-permissions-minimization-1256602521592217066

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@gemini-code-assist

Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

genzouw added 4 commits July 7, 2026 13:16
トップレベルの permissions ブロックから write 権限を削除し、
必要なジョブレベルに移動することで最小権限の原則を適用する。

- ai-doc-generator: contents:write をジョブレベルへ移動
- gitleaks/trivy/zizmor: security-events:write をジョブレベルへ移動

@genzouw genzouw left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request レビューサマリー

✅ 全体評価

全7ワークフローを「トップレベルは読み取り専用 + 書き込みはジョブ単位」へ一貫して移行する方針は最小権限の原則に忠実で、方向性はとても良いと考えています。ジョブレベルの permissions はトップレベルを完全に上書きするため、各ワークフローの実効権限は従来と等価であることも確認しました。一方で、新設された過剰権限の監査ロジック(awk)に検知漏れがあり、監査自体の信頼性に関わるため、マージ前の修正を推奨します(自分のPRのため変更依頼は投稿できず、コメントとして残します)。

🔍 発見した問題

重要度 観点 件数
🟠 High 監査ロジックの検知漏れ(false negative) 1件
🟡 Medium 監査対象の網羅性(.yaml バイパス) 1件
🟢 Low 可読性(ステップ名の乖離) 1件

合計: 3件(いずれも .github/workflows/permissions-audit.yml。詳細は該当箇所のインラインコメントを参照してください)

High Priority Issues(優先対応が必要)

  • .github/workflows/permissions-audit.yml:39 - permissions: write-all とインラインマップ形式(permissions: { contents: write })が検知をすり抜け、「✅ least privilege」と誤判定される

💡 推奨事項

  1. awk パターンへの write-all / インラインマップ検知の追加(インラインコメントに検証済みの修正案を記載しました)
  2. 監査対象への .yaml 拡張子の追加
  3. マージ前に pending の CodeQL チェック(Analyze (javascript-typescript))が green になることの確認(security-events: write のジョブ限定化後、SARIF アップロードが正常に通ることの実地確認になります)

✨ 良かった点

  • scorecard.ymlread-all 廃止、codeql.yml / gitleaks.yml / trivy.yml / zizmor.ymlsecurity-events: write のジョブ限定化など、7ファイルすべてで一貫したパターンが適用されており、レビューしやすい変更になっています
  • 設定値の修正だけで終わらせず、監査スクリプト側も同時に強化して回帰を防ぐアプローチは、このリポジトリの多層防御の方針とよく整合しています
  • reusable workflow 呼び出しジョブ(gitleaks / trivy / zizmor)への明示的な permissions 付与も、呼び出し先の SARIF アップロードに必要な権限を過不足なく維持できています
  • docs/security/leak-prevention.md への方針の明文化により、今後のワークフロー追加時の判断基準が残るのも良い点です

🎯 次のステップ

  1. High(awk の検知漏れ)の修正
  2. 修正後、permissions-audit.yml が green のままであることを確認してからマージしてください

権限最小化の本体部分は完成度が高く、残るは監査スクリプトの精度だけという状態です。指摘した検知漏れは修正案をそのまま適用すれば解消できる見込みなので、もう一息だと思います。

Comment thread .github/workflows/permissions-audit.yml Outdated
Comment thread .github/workflows/permissions-audit.yml Outdated
Comment thread .github/workflows/permissions-audit.yml Outdated
genzouw added 3 commits July 7, 2026 13:38
チェック対象が「missing」のみから「missing / excessive」に拡張されたことを
反映し、CI失敗時のデバッグを容易にするためステップ名を更新。

セルフレビューコメント: #350 (comment)
優先度: low
GitHub Actionsは.yaml拡張子も有効なため、*.ymlのみを対象としていると
監査をバイパスできる抜け道が生じる。findコマンドで両拡張子を対象とし、
また-rオプションを除いてgrepの呼び出しを整理した。

セルフレビューコメント: #350 (comment)
優先度: medium
現行のawkスクリプトはpermissions: write-all(write-allがパターン未包含)と
permissions: { contents: write }(インラインマップ形式)を検知できず、
監査が機能しない状態だった。

また複数ファイルをawkに渡す際にファイル境界でin_perms状態がリークする
問題をFNR==1で修正し、対象を$WORKFLOWSから読み込むよう変更した。

セルフレビューコメント: #350 (comment)
優先度: high
@genzouw
genzouw merged commit 505304f into main Jul 7, 2026
30 checks passed
@genzouw
genzouw deleted the security-permissions-minimization-1256602521592217066 branch July 7, 2026 04:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs github-actions Pull requests that update GitHub Actions code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant