Skip to main content

Defining custom patterns for secret scanning

Protect your unique secret types by defining custom patterns with regular expressions.

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

リポジトリの所有者、organization の所有者、セキュリティ管理者、エンタープライズ管理者、および管理者ロールを持つユーザー

GitHub Team または GitHub Enterprise 上の組織所有リポジトリ (GitHub Secret Protection が有効)

Defining a custom pattern with Copilot

You can use Copilot シークレットスキャン to generate regular expressions based on a text description of the type of pattern you would like to detect, including optional example strings that should be detected. See Copilot シークレット スキャンを使用してカスタム パターンの正規表現を生成する.

Defining a custom pattern for a repository

Before defining a custom pattern, you must ensure that Secret Protection is enabled on your repository. For more information, see Enabling secret scanning for your repository.

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

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

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

  3. サイドバーの [Security] セクションで、[ Advanced Security] をクリックします。

  4. Under "Secret Protection", to the right of "Custom patterns", click New pattern.

  5. 新しいカスタム パターンの詳細を入力します。 少なくともパターンの名前と、シークレットパターンのフォーマットとして正規表現を提供しなければなりません。

    1. [Pattern name] (パターン名) フィールドにパターンの名前を入力します。
    2. [シークレット形式] フィールドに、シークレット パターンの形式の正規表現を入力します。
    3. 「その他のオプション をクリックして、秘密の形式に関するその他の周辺コンテンツや追加の一致要件を指定できます。 「カスタム パターン リファレンス」を参照してください。
    4. サンプルのテスト文字列を指定し、設定内容が期待するパターンにマッチすることを確認できます。

    記入したカスタム secret scanning パターン形式のスクリーンショット。

  6. When you're ready to test your new custom pattern, to identify matches in the repository without creating alerts, click Save and dry run.

  7. ドライ ランが完了すると、結果のサンプル (最大 1000 個) が表示されます。 結果をレビューし、誤検知の結果を特定します。

    ドライ ランの結果を示すスクリーンショット。

  8. 新しいカスタム パターンを編集して結果に関するすべての問題を修正してから、 [保存してドライ ラン] をクリックして変更をテストします。

  9. 新しいカスタム パターンに問題がなければ、 [パターンの発行] をクリックします。

  10. Optionally, to enable push protection for your custom pattern, click Enable. For more information, see Push protection.

    メモ

    The "Enable" button isn't available until after the dry run succeeds and you publish the pattern.

After your pattern is created, secret scanningはGitHubリポジトリ中に存在するすべてのブランチのGit履歴全体に対して、あらゆるシークレットをスキャンします。 For more information on viewing シークレット スキャンニング アラート, see シークレット スキャン アラートの管理.

Defining a custom pattern for an organization

Before defining a custom pattern, you must ensure that you enable secret scanning for the repositories that you want to scan in your organization. You can use security configurations to enable secret scanning on all repositories in your organization. For more information, see Enabling security features at scale.

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

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

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

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

  4. In the "Security" section of the sidebar, select the Advanced Security dropdown menu, then click Global settings.

  5. [カスタム パターン] で、[ 新しいパターン] をクリックします。

  6. 新しいカスタム パターンの詳細を入力します。 少なくともパターンの名前と、シークレットパターンのフォーマットとして正規表現を提供しなければなりません。

    1. [Pattern name] (パターン名) フィールドにパターンの名前を入力します。
    2. [シークレット形式] フィールドに、シークレット パターンの形式の正規表現を入力します。
    3. 「その他のオプション をクリックして、秘密の形式に関するその他の周辺コンテンツや追加の一致要件を指定できます。 「カスタム パターン リファレンス」を参照してください。
    4. サンプルのテスト文字列を指定し、設定内容が期待するパターンにマッチすることを確認できます。

    記入したカスタム secret scanning パターン形式のスクリーンショット。

  7. When you're ready to test your new custom pattern, to identify matches in select repositories without creating alerts, click Save and dry run.

  8. ドライ ランを実行するリポジトリを選びます。

    • 組織全体でドライ ランを実行するには、[組織内のすべてのリポジトリ] を選択します。
    • ドライ ランを実行するリポジトリを指定するには、 [選択済みリポジトリ] を選び、最大 10 個のリポジトリを検索して選びます。
  9. 新しいカスタム パターンをテストする準備ができたら、 [実行] をクリックします。

  10. ドライ ランが完了すると、結果のサンプル (最大 1000 個) が表示されます。 結果をレビューし、誤検知の結果を特定します。

    ドライ ランの結果を示すスクリーンショット。

  11. 新しいカスタム パターンを編集して結果に関するすべての問題を修正してから、 [保存してドライ ラン] をクリックして変更をテストします。

  12. 新しいカスタム パターンに問題がなければ、 [パターンの発行] をクリックします。

  13. Optionally, to enable push protection for your custom pattern, click Enable. For more information, see Push protection.

    メモ

    • プッシュ保護を有効にするオプションは、公開されたパターンでのみ表示されます。
    • カスタム パターンのプッシュ保護は、プッシュ保護として secret scanning が有効になっている組織のリポジトリにのみ適用されます。
    • 一般的なカスタム パターンに対してプッシュ保護を有効にすると、共同作成者が混乱する可能性があります。

After your pattern is created, secret scanning scans for any secrets in repositories in your organization, including their entire Git history on all branches. Organization owners and repository administrators will be alerted to any secrets found and can review the alert in the repository where the secret is found. For more information on viewing シークレット スキャンニング アラート, see シークレット スキャン アラートの管理.

Defining a custom pattern for an enterprise account

メモ

  • At the enterprise level, only the creator of a custom pattern can edit the pattern, and use it in a dry run.
  • ドライ ランは、自分が管理アクセス権を持つリポジトリでのみ実行できます。 エンタープライズ所有者が、組織内の任意のリポジトリでドライ ランを実行するためのアクセス権を必要とする場合は、組織所有者ロールが割り当てられている必要があります。 詳しくは、「あなたの企業が所有する組織での役割を管理する」をご覧ください。
  1. 企業ページに移動してください。 たとえば、GitHub.com の [Enterprise] ページから。

  2. ページの上部にある [ Policies] をクリックします。

  3. [Policies] で、[Advanced SecurityCode security] をクリックします。

  4. Under "Advanced SecurityCode security", click Security features.

  5. Under "Secret scanning custom patterns", click New pattern.

  6. 新しいカスタム パターンの詳細を入力します。 少なくともパターンの名前と、シークレットパターンのフォーマットとして正規表現を提供しなければなりません。

    1. [Pattern name] (パターン名) フィールドにパターンの名前を入力します。
    2. [シークレット形式] フィールドに、シークレット パターンの形式の正規表現を入力します。
    3. 「その他のオプション をクリックして、秘密の形式に関するその他の周辺コンテンツや追加の一致要件を指定できます。 「カスタム パターン リファレンス」を参照してください。
    4. サンプルのテスト文字列を指定し、設定内容が期待するパターンにマッチすることを確認できます。

    記入したカスタム secret scanning パターン形式のスクリーンショット。

  7. When you're ready to test your new custom pattern, to identify matches in the enterprise without creating alerts, click Save and dry run.

  8. ドライ ランを実行するリポジトリを最大 10 個検索して選択します。

  9. 新しいカスタム パターンをテストする準備ができたら、 [実行] をクリックします。

  10. ドライ ランが完了すると、結果のサンプル (最大 1000 個) が表示されます。 結果をレビューし、誤検知の結果を特定します。

    ドライ ランの結果を示すスクリーンショット。

  11. 新しいカスタム パターンを編集して結果に関するすべての問題を修正してから、 [保存してドライ ラン] をクリックして変更をテストします。

  12. 新しいカスタム パターンに問題がなければ、 [パターンの発行] をクリックします。

  13. Optionally, to enable push protection for your custom pattern, click Enable. For more information, see Push protection.

    メモ

    • カスタム パターンのプッシュ保護を有効にするには、エンタープライズ レベルでプッシュ保護として secret scanning を有効にする必要があります。
    • 一般的なカスタム パターンに対してプッシュ保護を有効にすると、共同作成者が混乱する可能性があります。

After your pattern is created, secret scanning scans for any secrets in repositories within your organizations with GitHub Secret Protection enabled, including their entire Git history on all branches. Organization owners and repository administrators will be alerted to any secrets found, and can review the alert in the repository where the secret is found. For more information on viewing シークレット スキャンニング アラート, see シークレット スキャン アラートの管理.