|
| 1 | +--- |
| 2 | +title: Blocking pull request merges that contain secrets |
| 3 | +shortTitle: Block merges with secrets |
| 4 | +intro: Prevent exposed secrets from reaching protected branches by requiring contributors to resolve {% data variables.product.prodname_secret_scanning %} alerts before merging. |
| 5 | +permissions: '{% data reusables.permissions.security-org-enable %}{% ifversion enterprise-code-rulesets %}, and enterprise owners{% endif %}' |
| 6 | +product: '{% data reusables.gated-features.secret-protection %}' |
| 7 | +versions: |
| 8 | + feature: secret-scanning-merge-protection |
| 9 | +contentType: how-tos |
| 10 | +category: |
| 11 | + - Protect your secrets |
| 12 | +redirect_from: |
| 13 | + - /code-security/how-tos/secure-your-secrets/prevent-future-leaks/block-pull-request-merges |
| 14 | +--- |
| 15 | + |
| 16 | +> [!NOTE] |
| 17 | +> {% data reusables.secret-scanning.merge-protection-public-preview %} |
| 18 | +
|
| 19 | +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: |
| 20 | + |
| 21 | +* A {% data variables.product.prodname_secret_scanning %} scan has not completed for the head commit of the pull request. |
| 22 | +* A commit in the pull request introduced an open {% data variables.product.prodname_secret_scanning %} alert that matches a secret type selected in the ruleset. |
| 23 | + |
| 24 | +The rule supports provider, custom, and generic patterns. It does not support AI-detected secrets. |
| 25 | + |
| 26 | +## Prerequisites |
| 27 | + |
| 28 | +The repositories that you want to protect must have: |
| 29 | + |
| 30 | +* Either {% data variables.product.prodname_GH_secret_protection %} or {% data variables.product.prodname_GHAS %} enabled |
| 31 | +* {% data variables.product.prodname_secret_scanning_caps %} enabled. See [AUTOTITLE](/code-security/how-tos/secure-your-secrets/detect-secret-leaks/enable-secret-scanning). |
| 32 | + |
| 33 | +## Creating a merge protection ruleset for a repository |
| 34 | + |
| 35 | +{% data reusables.repositories.navigate-to-repo %} |
| 36 | +{% data reusables.repositories.sidebar-settings %} |
| 37 | +{% data reusables.repositories.repo-rulesets-settings %} |
| 38 | +1. Click **New ruleset**. |
| 39 | +1. Click **New branch ruleset**. |
| 40 | +{% data reusables.repositories.rulesets-general-step %} |
| 41 | +{% data reusables.repositories.rulesets-target-branches %} |
| 42 | +{% data reusables.repositories.rulesets-require-secret-scanning-alerts-resolved %} |
| 43 | +{% data reusables.repositories.rulesets-create-and-insights-step %} |
| 44 | + |
| 45 | +For information about configuring bypass permissions and other ruleset settings, see [AUTOTITLE](/repositories/configuring-branches-and-merges-in-your-repository/managing-rulesets/creating-rulesets-for-a-repository). |
| 46 | + |
| 47 | +## Creating a merge protection ruleset for repositories in an organization{% ifversion enterprise-code-rulesets %} or enterprise{% endif %} |
| 48 | + |
| 49 | +{% ifversion enterprise-code-rulesets %}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. |
| 50 | + |
| 51 | +### Accessing organization ruleset settings{% endif %} |
| 52 | + |
| 53 | +{% data reusables.profile.access_org %} |
| 54 | +{% data reusables.profile.org_settings %} |
| 55 | +{% data reusables.organizations.access-ruleset-settings %} |
| 56 | + |
| 57 | +{% ifversion enterprise-code-rulesets %} |
| 58 | + |
| 59 | +### Accessing enterprise ruleset settings |
| 60 | + |
| 61 | +{% data reusables.enterprise-accounts.access-enterprise %} |
| 62 | +{% data reusables.enterprise-accounts.policies-tab %} |
| 63 | +1. Under "Policies", click **Code**. |
| 64 | + |
| 65 | +### Configuring the ruleset{% endif %} |
| 66 | + |
| 67 | +1. Click **New ruleset**. |
| 68 | +1. Click **New branch ruleset**. |
| 69 | +{% data reusables.repositories.rulesets-general-step %} |
| 70 | +{% ifversion enterprise-code-rulesets %} |
| 71 | +1. If you are creating an enterprise-level ruleset, under "Target organizations", choose the organizations that the ruleset will apply to. |
| 72 | +{% endif %} |
| 73 | +1. Under "Target repositories", choose the repositories that the ruleset will apply to. |
| 74 | +{% data reusables.repositories.rulesets-target-branches %} |
| 75 | +{% data reusables.repositories.rulesets-require-secret-scanning-alerts-resolved %} |
| 76 | +{% data reusables.repositories.rulesets-create-and-insights-step %} |
| 77 | + |
| 78 | +For information about configuring bypass permissions and other ruleset settings, see [AUTOTITLE](/organizations/managing-organization-settings/creating-rulesets-for-repositories-in-your-organization){% ifversion enterprise-code-rulesets %} and [AUTOTITLE](/admin/enforcing-policies/enforcing-policies-for-your-enterprise/enforcing-policies-for-code-governance){% endif %}. |
| 79 | + |
| 80 | +## Unblocking a pull request |
| 81 | + |
| 82 | +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 [AUTOTITLE](/code-security/how-tos/manage-security-alerts/manage-secret-scanning-alerts/resolving-alerts). |
0 commit comments