Domain 2: Configure and Use Secret Scanning (15%) โ
โ Domain 1 ยท Next Domain โ
Exam Tip
Know the difference between secret scanning (reactive โ detects secrets already committed) and push protection (proactive โ blocks secrets before commit). The exam loves asking which feature handles which scenario.
What Secret Scanning Does โ
Secret scanning automatically scans the full repository history (all branches, all commits) for patterns matching known secrets and credentials:
- AWS Access Keys
- GitHub Personal Access Tokens
- Stripe API Keys
- Azure Storage Account keys
- Private SSH keys
- And 200+ other partner patterns
When a match is found, GitHub creates a secret scanning alert and notifies repository administrators and security managers.
Enabling Secret Scanning โ
Repository Level โ
Settings โ Code security โ Secret scanning โ Enable
Organization Level โ
Org Settings โ Code security โ GitHub Advanced Security โ Secret scanning
- Can enable for all current repositories, all future repositories, or both
- Requires GHAS license for private/internal repositories
Enterprise Level โ
Enterprise Settings โ Code security โ GitHub Advanced Security โ Secret scanning
- Applies a default policy across all organizations in the enterprise
- Org owners can still override at the org level (unless locked by enterprise policy)
Push Protection โ
Push protection blocks a git push if the diff contains a recognized secret pattern.
How Push Protection Works โ
- Developer runs
git push - GitHub scans the diff for secret patterns
- If a secret is detected: the push fails with an error message naming the secret type
- Developer must either:
- Remove the secret and re-push
- Bypass the block by providing a reason (if allowed by policy)
Bypass Reasons (If Allowed) โ
| Reason | When to use |
|---|---|
| Used in tests | The secret is a fake/test credential |
| False positive | GitHub incorrectly identified this as a secret |
| Fix later | Acknowledged but not removing now (creates an alert) |
Enabling Push Protection โ
- Repository: Settings โ Code security โ Push protection
- Organization: Org Settings โ Code security โ Push protection
- Enterprise: Enterprise policy level
Exam Trap
Push protection does not prevent all secret leaks. It blocks secrets at push time, but:
- It only applies to patterns GitHub recognizes
- Secrets in environment variables, CI logs, or manually pasted into chat are not caught
- Bypass is possible โ the exam may ask about this as a limitation
Secret Scanning Patterns โ
Partner Patterns โ
- GitHub maintains 200+ patterns in partnership with service providers (AWS, Azure, Stripe, GitHub, etc.)
- Partner patterns are automatically updated when providers submit new patterns
- When a partner pattern match is found, GitHub can notify the service provider (automatic revocation for some providers)
Custom Patterns โ
Organizations and enterprises can define their own secret patterns using regular expressions.
Repository-level: Settings โ Code security โ Custom patterns Organization-level: Org Settings โ Code security โ Custom patterns
Custom pattern syntax:
Name: Internal API Key
Pattern (regex): CORP-[A-Z0-9]{32}
Secret group: 1
Test string (optional): CORP-ABC123DEF456GHI789JKL012MNO345TIP
Custom patterns can also be configured at the enterprise level and applied across all organizations.
Validity Checking โ
For some partner patterns, GitHub can query the service provider's API to check if a detected token is still active (valid):
- Shows alert status as: Active, Inactive, or Unknown
- Helps prioritize which alerts require immediate action
- Not available for all providers
Managing Secret Scanning Alerts โ
Alert States โ
| State | Meaning |
|---|---|
| Open | Secret is active; needs remediation |
| Resolved โ Revoked | Secret has been revoked/deleted at the provider |
| Resolved โ False positive | Not actually a secret |
| Resolved โ Used in tests | Known test credential |
| Resolved โ Won't fix | Acknowledged; accepted risk |
Remediation Steps (Correct Order) โ
Always revoke first
- Revoke the secret at the service provider (e.g., delete the GitHub PAT, rotate the AWS key)
- Remove the secret from the codebase and commit history
- Audit access logs at the provider to check for unauthorized use
- Resolve the alert in GitHub with the appropriate reason
Removing Secrets from History โ
After revoking a secret, if it's in commit history, you must also clean it up:
- Use
git filter-repo(recommended) or BFG Repo-Cleaner - Force-push the cleaned history
- Contact GitHub Support to remove cached/cached views
Notifications and Webhooks โ
- Email notifications: Sent to repository admins and security managers by default
- GitHub Security tab: Alerts visible under Security โ Secret scanning
- Webhooks: Organizations can receive
secret_scanning_alertwebhook events for automation
Domain 2 Quick Quiz
What is the key difference between secret scanning and push protection?
(Click to reveal)