Skip to content

ops: main 直接 push 防止のための GitHub branch protection / ruleset hardening #359

Closed

Description

@squne121

Machine-Readable Contract

contract_schema_version: v1
issue_kind: implementation
parent_issue: "none"
goal_ref: "main ブランチへの直接 push を GitHub 側の branch protection / ruleset で防止する"
change_kind: workflow

親 Issue

なし

目的

2026-05-24 に発生した main 直接 push インシデントの再発を、GitHub 側の保護設定で技術的に防ぐ。

PR #358 で main の復旧は完了済みであり、PR #355 で #324 の正規修正も merge 済み。ただし、main branch への直接 push を GitHub remote 側で拒否する保護設定が未完了であるため、本 Issue で main の branch protection / ruleset を hardening する。

現在の検証済みスコープ

  • GitHub repository settings の main branch protection / ruleset 設定
  • docs/ops/branch-protection.md への検証手順・設定 snapshot の記録

残存する Parent Gap

なし

成果

main branch への直接 push が GitHub remote 側で拒否される。

git push origin HEAD:main、git push origin <branch>:main、force push などの local bypass 試行に対しても、GitHub 側の設定により main 更新が成立しない。

実装方針

優先順位:

  1. GitHub Ruleset で main を対象に active enforcement を設定する
  2. Ruleset が利用不可、または権限・プラン制約で困難な場合のみ Branch protection rule で代替する

In Scope

  • main branch を対象に以下を設定する:
    • Pull request before merge を必須化
    • Required status checks を必須化:
      • typecheck
      • lint
      • test
      • build
      • python-test
    • Conversation resolution を必須化
    • Force push を禁止
    • Deletion を禁止
    • Admin / bypass actor による bypass を禁止、または bypass actor を空にする
  • 設定後に git push origin HEAD:main が remote 側で拒否されることを確認する
  • 有効な設定・検証手順・確認結果を docs/ops/branch-protection.md に記録する

Out of Scope

Acceptance Criteria

  • AC1: main を対象にした active ruleset、または branch protection rule が存在する
  • AC2: main への commit は PR 経由必須で、直接 push では更新できない
  • AC3: required status checks に typecheck, lint, test, build, python-test が含まれる
  • AC4: PR conversation resolution が必須化されている
  • AC5: admin / bypass actor による bypass が許可されていない、または bypass actor が空である
  • AC6: git push origin HEAD:main が GitHub remote 側で拒否されることを実測している
  • AC7: docs/ops/branch-protection.md に設定 snapshot と検証手順が記録されている

Verification Commands

# Branch protection fallback を使った場合
gh api repos/squne121/loop-protocol/branches/main/protection \
  --jq '{
    required_pull_request_reviews,
    required_status_checks,
    required_conversation_resolution,
    enforce_admins,
    restrictions,
    allow_force_pushes,
    allow_deletions
  }'

# Ruleset を使った場合
gh api repos/squne121/loop-protocol/rules/branches/main --jq '.'

# 直接 push 拒否の実測
git checkout -b test-direct-push-main-protection
git commit --allow-empty -m "test: verify main direct push protection"
git push origin HEAD:main
# 期待: remote rejected / protected branch / ruleset violation / permission denied 系のエラーで失敗

# docs snapshot の存在確認
test -f docs/ops/branch-protection.md && echo "docs created"

Allowed Operations

  • GitHub repository settings:
    • Rulesets for main
    • Branch protection for main

Allowed Paths

  • docs/ops/branch-protection.md

Stop Conditions

  • GitHub UI / API で設定する権限が不足している
  • GitHub plan / repository type の制約により必要な保護設定が使えない
  • Required status check 名が GitHub UI/API 上で確定できない
  • main 直接 push の拒否を実測できない
  • feat: implementation-worker SubAgent に push destination guard hook を追加する #360 の SubAgent hook 実装と責務が混線し始めた
  • .github/workflows/ci.yml 変更が必要になった
  • 実装時間が手動 ops 作業として 2 時間を超過した

Required Skills

なし

Scope Delta

N/A


Background

2026-05-24 に implementation-worker SubAgent(Claude Haiku)が PR branch に push すべき修正 commit (abbc61a) を誤って main へ直接 push した。PR #358 で main の復旧は完了し、PR #355 で #324 の正規修正も merge 済み。ただし、main 直接 push を GitHub 側で技術的に拒否する設定は未完了であるため、本 Issue で branch protection / ruleset を hardening する。

根本原因の一つは、main branch に branch protection / ruleset が設定されておらず、GitHub API レベルで直接 push が成立していたこと。本 Issue は GitHub 側の hardening により、SubAgent / 人間のいずれの誤操作からも main 直接 push を技術的に不可能にすることを目的とする。

References

Activity

  1. added
    enhancement
    phase/implementation
    agent/implementer
    triage-required
    on May 24, 2026
  2. squne121 commented on May 24, 2026

    @squne121
    OwnerAuthor

    人間からの指摘です。
    Issue 本文は日本語にしてほしい。

  3. squne121 commented on May 24, 2026

    @squne121
    OwnerAuthor

    ([Gmail]1)([Gmail]2)([Gmail]3)([Gmail]4)([Gmail]5)

    判定: REQUEST_CHANGES

    #359 の方向性は正しいですが、現状のまま実装Issueとして流すのは危険です。最大の問題は、本文が英語主体で、読者・実行者が日本語運用しているリポジトリの実装契約として不適合な点です。人間コメントでも「Issue 本文は日本語にしてほしい」と明示されています。これは単なる文体修正ではなく、実行契約の読み違いを防ぐための blocker と扱うべきです。

    #359 は PR #358 の復旧後 follow-up として妥当です。PR #358 は abbc61a の main 直接pushを revert する復旧PRで、本文でも #359 と #360 を再発防止Issueとして分離しています。さらに PR #355 は既に merged で、#324 も completed なので、#359 の背景文にある “Recovery PR #358 is currently addressing the incident” は古くなっています。

    Blocker 1: Issue本文を日本語化する

    現在の #359 は見出し・Outcome・In Scope・Acceptance Criteria・Stop Conditions が英語主体です。loop-protocol の最近の Issue / PR は日本語運用の比重が高く、#324 のような契約Issueも日本語で詳細化されています。#359 は人間・SubAgent・reviewer が直接読む安全設定Issueなので、日本語で誤読余地を減らすべきです。

    修正要求: #359 本文を日本語契約に差し替え、英語は Machine-Readable Contract の値や必要な GitHub 設定名だけに限定してください。

    Blocker 2: 背景が stale

    #359 本文は「PR #358 is currently addressing the incident」と書いていますが、取得時点で PR #358 は closed / merged です。PR #355 も merged 済みです。したがって、背景は「復旧中」ではなく「復旧済み、ただし再発防止未完了」に更新する必要があります。

    修正要求: Background を次の意味に更新してください。

    2026-05-24 に implementation-worker SubAgent が PR branch に push すべき修正 commit を誤って main へ直接 push した。PR #358 で main の復旧は完了し、PR #355 で #324 の正規修正も merge 済み。ただし、main 直接 push を GitHub 側で技術的に拒否する設定は未完了であるため、本 Issue で branch protection / ruleset を hardening する。

    Blocker 3: #360 への参照が古い

    #359 の Out of Scope は「SubAgent-side push destination guard は別Issue、作成後にリンク」となっていますが、#360 は既に作成済みです。#360 は PreToolUse hook で git push の main/master 宛てを exit 2 で止める補完策なので、#359 から明示リンクすべきです。

    修正要求: #359 の Out of Scope / References に #360 を直接入れてください。

    Blocker 4: 「branch protection or ruleset」が曖昧すぎる

    GitHub の branch protection は「PR必須」「status checks必須」「conversation resolution必須」「bypass禁止」「push制限」を設定できます。特に admin / bypass 権限者には既定では保護が適用されないため、Do not allow bypassing the above settings 相当を明示するのは正しいです。([GitHub Docs]6)

    一方で、rulesets は branch protection と併用でき、複数 ruleset が同時適用されるため、今後の拡張性は rulesets の方が高いです。GitHub Docs でも rulesets は既存の branch protection と並行して動作し、複数 ruleset の rule は集約され、より厳しい方が適用されると説明されています。([GitHub Docs]7)

    修正要求: 「branch protection or ruleset」ではなく、優先実装を明示してください。推奨は ruleset 優先、branch protection は fallback です。

    優先順位:
    1. GitHub Ruleset で `main` を対象に保護する
    2. Ruleset が利用不可、または UI/API 権限上困難な場合のみ Branch protection rule で代替する

    Blocker 5: AC が不足している

    現在の AC は大枠としては良いですが、「何を設定できたら pass か」が弱いです。GitHub rulesets の REST API では、pull_request rule は「target branch 以外に commit し、PR 経由で merge すること」を要求でき、required_review_thread_resolution も pull request rule の parameter として表現できます。required_status_checks は ref 更新前に指定 status check が pass していることを要求します。([GitHub Docs]8) ([GitHub Docs]8)

    現在の CI job 名は typecheck, lint, test, build, python-test で一意です。GitHub Docs は required status checks を使う場合、workflow 間で job name が重複すると PR merge が block され得ると注意しているため、この5つを required checks として固定するのは妥当です。 ([GitHub Docs]6)

    修正要求: AC を次の水準まで具体化してください。

    - [ ] AC1: `main` を対象にした active ruleset、または branch protection rule が存在する
    - [ ] AC2: `main` への commit は PR 経由必須で、直接 push では更新できない
    - [ ] AC3: required status checks に `typecheck`, `lint`, `test`, `build`, `python-test` が含まれる
    - [ ] AC4: PR conversation resolution が必須化されている
    - [ ] AC5: admin / bypass actor による bypass が許可されていない、または bypass actor が空である
    - [ ] AC6: `git push origin HEAD:main` が GitHub remote 側で拒否されることを実測している
    - [ ] AC7: 現在有効な rules / protection の JSON snapshot を `docs/ops/branch-protection.md` に記録している

    Non-blocking: Allowed Paths が実態とズレている

    GitHub UI で ruleset / branch protection を設定する場合、通常は repository file path の変更ではありません。現在の Allowed Paths に .github/ が含まれていますが、今回の主成果物は GitHub repository setting であって .github/ ではありません。.github/ を許可すると、workflow や settings を無関係に触る逃げ道になります。

    修正案:

    ## Allowed Operations
    
    - GitHub repository settings:
      - Rulesets for `main`
      - Branch protection for `main`
    - Documentation:
      - `docs/ops/branch-protection.md`
    
    ## Allowed Paths
    
    - `docs/ops/branch-protection.md`

    差し替え用の日本語 Issue 本文案

    ## Machine-Readable Contract
    
    ```yaml
    contract_schema_version: v1
    issue_kind: implementation
    parent_issue: "none"
    goal_ref: "main ブランチへの直接 push を GitHub 側の branch protection / ruleset で防止する"
    change_kind: workflow

    親 Issue

    なし

    目的

    2026-05-24 に発生した main 直接 push インシデントの再発を、GitHub 側の保護設定で技術的に防ぐ。

    PR #358 で main の復旧は完了済みであり、PR #355 で #324 の正規修正も merge 済み。ただし、main branch への直接 push を GitHub remote 側で拒否する保護設定が未完了であるため、本 Issue で main の branch protection / ruleset を hardening する。

    現在の検証済みスコープ

    • GitHub repository settings の main branch protection / ruleset 設定
    • docs/ops/branch-protection.md への検証手順・設定 snapshot の記録

    成果

    main branch への直接 push が GitHub remote 側で拒否される。

    git push origin HEAD:main、git push origin <branch>:main、force push などの local bypass 試行に対しても、GitHub 側の設定により main 更新が成立しない。

    実装方針

    優先順位:

    1. GitHub Ruleset で main を対象に active enforcement を設定する
    2. Ruleset が利用不可、または権限・プラン制約で困難な場合のみ Branch protection rule で代替する

    In Scope

    • main branch を対象に以下を設定する:

      • Pull request before merge を必須化

      • Required status checks を必須化

        • typecheck
        • lint
        • test
        • build
        • python-test
      • Conversation resolution を必須化

      • Force push を禁止

      • Deletion を禁止

      • Admin / bypass actor による bypass を禁止、または bypass actor を空にする

    • 設定後に git push origin HEAD:main が remote 側で拒否されることを確認する

    • 有効な設定・検証手順・確認結果を docs/ops/branch-protection.md に記録する

    Out of Scope

    Acceptance Criteria

    • AC1: main を対象にした active ruleset、または branch protection rule が存在する
    • AC2: main への commit は PR 経由必須で、直接 push では更新できない
    • AC3: required status checks に typecheck, lint, test, build, python-test が含まれる
    • AC4: PR conversation resolution が必須化されている
    • AC5: admin / bypass actor による bypass が許可されていない、または bypass actor が空である
    • AC6: git push origin HEAD:main が GitHub remote 側で拒否されることを実測している
    • AC7: docs/ops/branch-protection.md に設定 snapshot と検証手順が記録されている

    Verification Commands

    # Branch protection fallback を使った場合
    gh api repos/squne121/loop-protocol/branches/main/protection \
      --jq '{
        required_pull_request_reviews,
        required_status_checks,
        required_conversation_resolution,
        enforce_admins,
        restrictions,
        allow_force_pushes,
        allow_deletions
      }'
    
    # Ruleset を使った場合
    gh api repos/squne121/loop-protocol/rules/branches/main \
      --jq '.'
    
    # 直接 push 拒否の実測
    git checkout -b test-direct-push-main-protection
    git commit --allow-empty -m "test: verify main direct push protection"
    git push origin HEAD:main
    # 期待: remote rejected / protected branch / ruleset violation / permission denied 系のエラーで失敗

    Allowed Operations

    • GitHub repository settings:

      • Rulesets for main
      • Branch protection for main

    Allowed Paths

    • docs/ops/branch-protection.md

    Stop Conditions

    • GitHub UI / API で設定する権限が不足している
    • GitHub plan / repository type の制約により必要な保護設定が使えない
    • Required status check 名が GitHub UI/API 上で確定できない
    • main 直接 push の拒否を実測できない
    • feat: implementation-worker SubAgent に push destination guard hook を追加する #360 の SubAgent hook 実装と責務が混線し始めた
    • .github/workflows/ci.yml 変更が必要になった

    Required Skills

    なし

    関連

    
    ## 最終提案
    
    #359 は **閉じずに修正継続**。まず本文を日本語化し、stale な復旧状況と #360 参照を更新してください。その後、実装者には「ruleset 優先、branch protection fallback」「required checks 5種固定」「direct push 拒否を実測」「docs/ops に snapshot 記録」の4点を必須条件として渡すのが妥当です。
    ::contentReference[oaicite:15]{index=15}
    
  4. removed
    triage-required
    on May 24, 2026
  5. changed the title [-]ops: main branch protection / ruleset hardening to prevent direct push[/-] [+]ops: main 直接 push 防止のための GitHub branch protection / ruleset hardening[/+] on May 24, 2026
  6. squne121 commented on May 24, 2026

    @squne121
    OwnerAuthor

    issue-refinement-loop: 完了 (2026-05-24)

    事実確認結果(codebase-investigator 経由・main thread 検証)

    Claim Verdict Evidence
    PR #358 は復旧済み supported MERGED 2026-05-24T08:04:31Z
    PR #355 は merge 済み supported MERGED 2026-05-24T08:25:19Z
    #324 は completed supported CLOSED/COMPLETED
    #360 は存在する supported OPEN (push destination guard hook)
    CI job 名 typecheck/lint/test/build/python-test supported .github/workflows/ci.yml jobs と完全一致

    外部仕様 claim(GitHub Docs: rulesets / branch protection)は非 critical(推奨方針の裏付け)として参照扱い。

    反映した修正(anchor comment の 5 blocker)

    • Blocker 1: Issue 本文を完全に日本語化(タイトル含む)
    • Blocker 2: Background を stale な「復旧中」→「復旧済み・再発防止未完了」に更新
    • Blocker 3: Out of Scope / References から feat: implementation-worker SubAgent に push destination guard hook を追加する #360 を明示参照
    • Blocker 4: 「branch protection or ruleset」を「Ruleset 優先、Branch protection は fallback」に明確化
    • Blocker 5: AC を 5 項目 → 7 項目に具体化(PR 経由必須、required checks 5 種固定、conversation resolution、bypass 禁止、直接 push 拒否実測、snapshot 記録)
    • Non-blocking: Allowed Paths から .github/ を除去し Allowed Operations に分離(GitHub UI 設定が主成果物のため)

    追加調整

    • タイトル: ops: main branch protection / ruleset hardening to prevent direct push → ops: main 直接 push 防止のための GitHub branch protection / ruleset hardening
    • triage-required ラベルを除去(refinement 完了により triage 不要)
    • Stop Conditions に「2 時間超過」を維持(元 Issue の運用ガード)

    次アクション

    issue-contract-review skill で baseline VC preflight を実行し、go 判定後に手動 ops 実装へ進む。

  7. squne121 commented on May 24, 2026

    @squne121
    OwnerAuthor

    impl-review-loop: 完了 (APPROVE, マージ判断待ち)

    モデル分担

    • Opus (main session): GitHub Ruleset (16796903) 作成 / Branch protection 更新 (enforce_admins: true, python-test 追加) / git push origin HEAD:main 拒否実測 / docs/ops/branch-protection.md 起草 / PR 起票 / PR 最終判定(Sonnet limit のため pr-reviewer SubAgent 不可、user 指示に従い Opus 直接判定)
    • Haiku SubAgent: pnpm typecheck/lint/test/build 実行 (test-runner) / PR review evidence 収集 (general-purpose)

    Out-of-band 変更(GitHub side、git diff には現れない)

    層 ID 状態
    Ruleset main-direct-push-protection 16796903 active, bypass_actors: [], current_user_can_bypass: never
    Branch protection /branches/main/protection — enforce_admins: true, required checks: typecheck/lint/test/build/python-test

    AC 充足

    AC1-AC7 すべて pass。詳細は PR #362 の APPROVE コメント参照。

    マージ判断待ち

    PR #362 は draft / CLEAN / MERGEABLE / CI 全 success。人間判断で ready-for-review に切り替えてマージするか、追加レビューを依頼するか決定してください。

  8. added 2 commits that reference this issue on May 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent/implementerenhancementphase/implementation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions