Skip to main content

Blocking pull request merges that contain secrets

Prevent exposed secrets from reaching protected branches by requiring contributors to resolve secret scanning alerts before merging.

この機能を使用できるユーザーについて

管理者 ロールを持つ組織の所有者、セキュリティ マネージャー、および組織メンバー, and enterprise owners

GitHub Secret Protection は、次のユーザーが使用できる GitHub Advanced Security 内の一連の機能です。

  • GitHub Team プランのユーザー
  • GitHub Enterprise Cloud と GitHub Enterprise Server 上の Enterprise の organization

メモ

The rule to require secret scanning alerts to be resolved before merging is in パブリック プレビュー and subject to change.

The Require secret scanning alerts are resolved rule is available for rulesets that target branches in repositories. You can use the rule to block a pull request from merging when either of these conditions applies:

  • A secret scanning scan has not completed for the head commit of the pull request.
  • A commit in the pull request introduced an open secret scanning alert that matches a secret type selected in the ruleset.

The rule supports provider, custom, and generic patterns. It does not support AI-detected secrets.

Prerequisites

The repositories that you want to protect must have:

Creating a merge protection ruleset for a repository

  1. GitHub で、リポジトリのメイン ページに移動します。

  2. リポジトリ名の下にある [Settings] をクリックします。 [設定] タブが表示されない場合は、 [] ドロップダウン メニューを選び、 [設定] をクリックします。

    タブを示すリポジトリ ヘッダーのスクリーンショット。 [設定] タブが濃いオレンジ色の枠線で強調表示されています。

  3. 左側のサイドバーの [コードと自動化] で、[ ルールセット] をクリックし、[ ルールセット] をクリックします。

  4. Click New ruleset.

  5. Click New branch ruleset.

  6. [ルールセット名] に、ルールセットの名前を入力します。

  7. 必要に応じて、既定の適用状態を変更するには、 [Disabled] をクリックして、新しい適用状態を選びます。 ブランチまたはタグをターゲットにするには、[ターゲット ブランチ] または [ターゲット タグ] セクションで、[ターゲットの追加] を選び、ブランチまたはタグを含めるまたは除外する方法を選びます。 fnmatch 構文を使って、パターンに基づいてブランチまたはタグを含めたり除外したりできます。 詳細については、「fnmatch 構文の使用」を参照してください。

複数のターゲット条件を同じルールセットに追加できます。 たとえば、既定のブランチを含め、*feature* のパターンに一致するブランチを含めてから、not-a-feature のパターンに一致する特定のブランチを除外することができます。

  1. Under "Branch protections", select Require secret scanning alerts are resolved.
  2. Under "Secret types", select one or more types of secrets that should block merging:
    • Provider patterns
    • Custom patterns
    • Generic patterns ルールセットの作成を完了するには、[作成] をクリックします。 ルールセットの適用ステータスが "アクティブ" に設定されている場合、ルールセットはすぐに有効になります。

ルールセットの分析情報を表示して、ルールが共同作成者にどのように影響しているかを確認できます。 適用ステータスが "評価" に設定されている場合、ルール セットがアクティブであった場合に合格または失敗したアクションを確認できます。 ルールセットの分析情報の詳細については、「リポジトリのルールセットの管理」を参照してください。

For information about configuring bypass permissions and other ruleset settings, see リポジトリのルールセットの作成.

Creating a merge protection ruleset for repositories in an organization or enterprise

You can create this ruleset for repositories in your organization, or create it for an enterprise to apply merge protection consistently across repositories in multiple organizations.

Accessing organization ruleset settings

  1. GitHub の右上隅にあるプロフィール画像をクリックしてから、[ Your organizations] をクリックします。

  2. 組織をクリックして選択します。

  3. Organization 名の下で、[ Settings] をクリックします。 [設定] タブが表示されない場合は、 [] ドロップダウン メニューを選び、 [設定] をクリックします。

    組織のプロファイルのタブのスクリーンショット。 [設定] タブが濃いオレンジ色の枠線で囲まれています。

  4. サイドバーの [Code, planning, and automation](コード、計画、自動化) の下で、[リポジトリ クリックし、[ルールセット] をクリックします。

Accessing enterprise ruleset settings

  1. 企業ページに移動してください。 たとえば、GitHub.com の [Enterprise] ページから。
  2. ページの上部にある [ポリシーの] をクリックします。
  3. Under "Policies", click Code.

Configuring the ruleset

  1. Click New ruleset.

  2. Click New branch ruleset.

  3. [ルールセット名] に、ルールセットの名前を入力します。

  4. 必要に応じて、既定の適用状態を変更するには、 [Disabled] をクリックして、新しい適用状態を選びます。

  5. If you are creating an enterprise-level ruleset, under "Target organizations", choose the organizations that the ruleset will apply to.

  6. Under "Target repositories", choose the repositories that the ruleset will apply to. ブランチまたはタグをターゲットにするには、[ターゲット ブランチ] または [ターゲット タグ] セクションで、[ターゲットの追加] を選び、ブランチまたはタグを含めるまたは除外する方法を選びます。 fnmatch 構文を使って、パターンに基づいてブランチまたはタグを含めたり除外したりできます。 詳細については、「fnmatch 構文の使用」を参照してください。

複数のターゲット条件を同じルールセットに追加できます。 たとえば、既定のブランチを含め、*feature* のパターンに一致するブランチを含めてから、not-a-feature のパターンに一致する特定のブランチを除外することができます。

  1. Under "Branch protections", select Require secret scanning alerts are resolved.
  2. Under "Secret types", select one or more types of secrets that should block merging:
    • Provider patterns
    • Custom patterns
    • Generic patterns ルールセットの作成を完了するには、[作成] をクリックします。 ルールセットの適用ステータスが "アクティブ" に設定されている場合、ルールセットはすぐに有効になります。

ルールセットの分析情報を表示して、ルールが共同作成者にどのように影響しているかを確認できます。 適用ステータスが "評価" に設定されている場合、ルール セットがアクティブであった場合に合格または失敗したアクションを確認できます。 ルールセットの分析情報の詳細については、「リポジトリのルールセットの管理」を参照してください。

For information about configuring bypass permissions and other ruleset settings, see 組織内のリポジトリのルールセットを作成する and Enterprise でルールセットを使ってコード ガバナンスを適用する.

Unblocking a pull request

When this rule blocks a pull request because of open alerts, you must resolve each alert that matches the secret types selected in the ruleset. See シークレット スキャンからのアラートの解決.