Skip to main content

Defining custom patterns for secret scanning

You can define your own custom patterns to extend the capabilities of secret scanning by generating one or more regular expressions.

누가 이 기능을 사용할 수 있나요?

리포지토리 소유자, 조직 소유자, 보안 관리자, 엔터프라이즈 관리자, 관리자 역할이 있는 사용자

secret scanning을 위한 사용자 지정 패턴은 다음 리포지토리 유형에서 사용할 수 있습니다.

About custom patterns for secret scanning

You can define custom patterns to identify secrets that are not detected by the default patterns supported by secret scanning. For example, you might have a secret pattern that is internal to your organization. For details of the supported secrets and service providers, see 지원되는 비밀 검사 패턴.

You can define custom patterns for your enterprise, organization, or repository. Secret scanning supports up to 500 custom patterns for each organization or enterprise account, and up to 100 custom patterns per repository.

You can also enable push protection for custom patterns. For more information about push protection, see 푸시 보호 정보.

About using regular expressions for custom patterns

You can specify custom patterns for secret scanning as one or more regular expressions.

Secret scanning uses the Hyperscan library and only supports Hyperscan regex constructs, which are a subset of PCRE syntax. Hyperscan option modifiers are not supported. For more information on Hyperscan pattern constructs, see Pattern support in the Hyperscan documentation.

Regular expressions can be entered manually or generated using Copilot 비밀 검색's 정규식 생성기.

Regular expression syntax for manually defining custom patterns

The More options section in the UI helps you write regular expressions manually.

  • Secret format: an expression that describes the format of the secret itself.
  • Before secret: an expression that describes the characters that come before the secret. By default, this is set to \A|[^0-9A-Za-z] which means that the secret must be at the start of a line or be preceded by a non-alphanumeric character.
  • After secret: an expression that describes the characters that come after the secret. By default, this is set to \z|[^0-9A-Za-z] which means that the secret must be followed by a new line or a non-alphanumeric character.
  • Additional match requirements: one or more optional expressions that the secret itself must or must not match.

For simple tokens you will usually only need to specify a secret format. The other fields provide flexibility so that you can specify more complex secrets without creating complex regular expressions. For an example of a custom pattern, see Example of a custom pattern specified using additional requirements below.

Using Copilot 비밀 검색's 정규식 생성기

Copilot 비밀 검색의 정규식 생성기는 감지해야 하는 선택적 예제 문자열을 포함하여 감지하려는 패턴 유형에 대한 텍스트 설명을 입력하는 생성 AI 모델을 사용합니다. 이 모델은 검토를 위해 최대 3개의 정규식을 반환합니다. For more information, see Responsible generation of regular expressions with Copilot secret scanning and Generating regular expressions for custom patterns with Copilot secret scanning.

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. "패턴 이름" 필드에 패턴 이름을 입력합니다.
    2. "비밀 형식" 필드에 비밀 패턴 형식의 정규식을 입력합니다. 또는 생성기를 사용하여 정규식을 생성할 수 있습니다. 자세한 내용은 Generating regular expressions for custom patterns with Copilot secret scanning을(를) 참조하세요.
    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. 시험 실행이 완료되면 결과 샘플(최대 1,000개)이 표시됩니다. 결과를 검토하고 가양성 결과를 식별합니다.

    시험 실행의 결과를 보여 주는 스크린샷

  8. 새 사용자 지정 패턴을 편집하여 결과와 관련한 문제를 해결합니다. 변경 내용을 테스트하려면 저장 및 시험 실행을 클릭합니다.

  9. 새 사용자 지정 패턴에 만족하면 게시 패턴을 클릭합니다.

  10. Optionally, to enable push protection for your custom pattern, click Enable.

    참고 항목

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

    For more information about push protection, see 푸시 보호 정보.

After your pattern is created, secret scanning은 GitHub 리포지토리에 있는 모든 분기에서 전체 Git 기록의 비밀을 검색합니다. For more information on viewing 비밀 검사 경고, see 비밀 검사에서 경고 관리.

Example of a custom pattern specified using additional requirements

A company has an internal token with five characteristics. They use the different fields to specify how to identify tokens as follows:

CharacteristicField and regular expression
Length between 5 and 10 charactersSecret format: [$#%@AA-Za-z0-9]{5,10}
Does not end in a .After secret: [^\.]
Contains numbers and uppercase lettersAdditional requirements: secret must match [A-Z] and [0-9]
Does not include more than one lowercase letter in a rowAdditional requirements: secret must not match [a-z]{2,}
Contains one of $%@!Additional requirements: secret must match [$%@!]

These tokens would match the custom pattern described above:

a9@AAfT!         # Secret string match: a9@AAfT
ee95GG@ZA942@aa  # Secret string match: @ZA942@a
a9@AA!ee9        # Secret string match: a9@AA

These strings would not match the custom pattern described above:

a9@AA.!
a@AAAAA
aa9@AA!ee9
aAAAe9

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 보안 기능의 대규모 사용 정보.

  1. GitHub의 오른쪽 위 모서리에서 프로필 사진을 클릭한 다음, Your organizations를 클릭합니다.

  2. 조직 옆에 있는 설정을 클릭합니다.

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

  4. "사용자 지정 패턴"에서 새 패턴을 클릭합니다.

  5. 새 사용자 지정 패턴에 대한 세부 정보를 입력합니다. 적어도 패턴의 이름과 비밀 패턴 형식에 대한 정규식을 제공해야 합니다.

    1. "패턴 이름" 필드에 패턴 이름을 입력합니다.
    2. "비밀 형식" 필드에 비밀 패턴 형식의 정규식을 입력합니다. 또는 생성기를 사용하여 정규식을 생성할 수 있습니다. 자세한 내용은 Generating regular expressions for custom patterns with Copilot secret scanning을(를) 참조하세요.
    3. 기타 옵션 을 클릭하여 다른 주변 콘텐츠나 비밀 형식에 대한 추가 일치 요구 사항을 제공할 수 있습니다.
    4. 구성이 예상하는 패턴과 일치하는지 확인하는 샘플 테스트 문자열을 제공합니다.

    채워진 사용자 지정 secret scanning 패턴 양식의 스크린샷

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

  7. 시험 실행을 수행할 리포지토리를 선택합니다.

    • 조직 전체에 대한 시험 실행을 수행하려면 조직의 모든 리포지토리를 선택합니다.
    • 시험 실행을 수행할 리포지토리를 지정하려면 선택한 리포지토리를 선택한 다음 최대 10개의 리포지토리를 검색하여 선택합니다.
  8. 새 사용자 지정 패턴을 테스트할 준비가 되면 실행을 클릭합니다.

  9. 시험 실행이 완료되면 결과 샘플(최대 1,000개)이 표시됩니다. 결과를 검토하고 가양성 결과를 식별합니다.

    시험 실행의 결과를 보여 주는 스크린샷

  10. 새 사용자 지정 패턴을 편집하여 결과와 관련한 문제를 해결합니다. 변경 내용을 테스트하려면 저장 및 시험 실행을 클릭합니다.

  11. 새 사용자 지정 패턴에 만족하면 게시 패턴을 클릭합니다.

  12. Optionally, to enable push protection for your custom pattern, click Enable. For more information, see 푸시 보호 정보.

    참고 항목

    • 푸시 보호를 사용하는 옵션은 게시된 패턴에 대해서만 표시됩니다.
    • 사용자 지정 패턴에 대한 푸시 보호는 푸시 보호가 사용하도록 설정된 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의 오른쪽 위 모서리에서 프로필 사진을 클릭합니다.

  2. 환경에 따라 Enterprise를 클릭하거나 Enterprise를 클릭한 다음 보려는 엔터프라이즈를 클릭합니다.

  3. 페이지 상단에서 정책을 클릭합니다.{ %else %}페이지의 왼쪽에 있는 엔터프라이즈 계정 사이드바에서 정책을 클릭합니다.

  4. "정책"에서 Advanced Security 를 클릭합니다.

  5. Under "Advanced Security", click Security features.

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

  7. 새 사용자 지정 패턴에 대한 세부 정보를 입력합니다. 적어도 패턴의 이름과 비밀 패턴 형식에 대한 정규식을 제공해야 합니다.

    1. "패턴 이름" 필드에 패턴 이름을 입력합니다.
    2. "비밀 형식" 필드에 비밀 패턴 형식의 정규식을 입력합니다. 또는 생성기를 사용하여 정규식을 생성할 수 있습니다. 자세한 내용은 Generating regular expressions for custom patterns with Copilot secret scanning을(를) 참조하세요.
    3. 기타 옵션 을 클릭하여 다른 주변 콘텐츠나 비밀 형식에 대한 추가 일치 요구 사항을 제공할 수 있습니다.
    4. 구성이 예상하는 패턴과 일치하는지 확인하는 샘플 테스트 문자열을 제공합니다.

    채워진 사용자 지정 secret scanning 패턴 양식의 스크린샷

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

  9. 시험 실행을 수행할 리포지토리를 최대 10개까지 검색하여 선택합니다.

  10. 새 사용자 지정 패턴을 테스트할 준비가 되면 실행을 클릭합니다.

  11. 시험 실행이 완료되면 결과 샘플(최대 1,000개)이 표시됩니다. 결과를 검토하고 가양성 결과를 식별합니다.

    시험 실행의 결과를 보여 주는 스크린샷

  12. 새 사용자 지정 패턴을 편집하여 결과와 관련한 문제를 해결합니다. 변경 내용을 테스트하려면 저장 및 시험 실행을 클릭합니다.

  13. 새 사용자 지정 패턴에 만족하면 게시 패턴을 클릭합니다.

  14. Optionally, to enable push protection for your custom pattern, click Enable. For more information, see 푸시 보호 정보.

    참고 항목

    • 사용자 지정 패턴에 푸시 보호를 사용하도록 설정하려면 엔터프라이즈 수준에서 푸시 보호로 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 비밀 검사에서 경고 관리.

Further reading