Chapter 24Lesson 03~165 minutes

Secret Scanning, Push Protection, Custom Patterns, Bypass Controls, and Incident Response: Configuration, Design Choices, and Tradeoffs

Secret prevention becomes policy when a team decides which patterns to trust, when a false positive may be bypassed, who may approve an exception, where protection applies, and whether old Git objects need rewriting after a credential is already dead. This lesson turns those choices into an explicit operating model.

Custom patternsDelegated bypassEnforcementHistory rewritePolicy

Learning objectives

  • Choose built-in/provider, generic, or custom detection based on the secret format and false-positive economics.
  • Choose block, direct bypass, delegated approval, or exemption according to trust and separation-of-duties requirements.
  • Compare repository-level and organization-wide enforcement without assuming an enterprise entitlement.
  • Decide when revoked historical exposure justifies disruptive Git history rewriting.
  • Build a decision record that weighs maintainability, security, governance, reliability, compatibility, and cost.
No-paid path: public-repository secret scanning and push protection are sufficient for mandatory learning. Organization-wide custom patterns, delegated bypass, private/internal coverage, public monitoring, and centralized security configuration are production extensions whose availability depends on organization ownership, plan, product, and admin role.

1. Built-in pattern, generic detection, or custom pattern?

Start by asking whether GitHub already knows the credential format. Provider patterns receive the strongest platform integration because GitHub can attach provider metadata, partner notification, validity checks, or push-protection support when that specific pattern supports them. Adding a custom regex that duplicates a mature provider pattern creates a second rule with different identity and false-positive behavior.

Need Preferred control Why
Known provider token format Built-in supported provider pattern Least custom maintenance; provider-specific capabilities may exist.
Non-provider secret shape such as supported private-key/connection-string pattern Supported generic pattern Broader than a provider pattern without maintaining your own regex.
Internal company credential with stable syntax Custom pattern after dry run Encodes organization-specific format, but you own precision and rollout.
Unstructured password-like data AI/generic detection where available + secret manager policy Regex alone can be poor at semantic secrets; feature availability and precision need review.
Configuration that resembles a secret but is intentionally public Do not widen regex to “catch everything” Use data classification and narrow pattern/context boundaries to avoid bypass fatigue.

A custom pattern is internal security code. Give it test fixtures, an owner, change review, an expected false-positive rate, and a rollback plan. Current GitHub supports dry runs before publication; treat that as the observation phase of a policy rollout, not a cosmetic preview.

2. Block, direct bypass, delegated approval, or exemption?

Blocking is the default for real secrets because the cost of stopping a commit is usually far lower than rotating a production credential. A bypass exists for exceptional non-secrets and constrained workflows; it should not become the normal path for “the build is urgent.”

Mechanism Use when Governance risk
Remove secret and retry Detected value should not be stored Lowest risk and default choice.
Direct documented bypass Repository policy permits contributor self-service for a proven safe case Can normalize bypass if reasons are weak or unreviewed.
Delegated bypass Organization needs separation of duties for exceptions Better audit/review, but currently requires eligible Team organization + Secret Protection.
Exempt actor Trusted high-volume migration/service automation cannot practically stop for every detection Highest standing risk; exemption skips protection and must be narrowly scoped/reviewed.
Production principle: exception authority should be narrower than write authority. A contributor who can push code does not automatically need standing authority to override a credential-leak control.

3. Repository enforcement versus organization-wide enforcement

Repository-level controls are appropriate for learning, pilots, and repositories with unusual requirements. Organization-wide security configurations reduce drift and make ownership clearer, but an overly broad pattern or exemption can also cause organization-wide disruption. Centralization increases both consistency and blast radius.

Dimension Repository-level Organization/enterprise-level
Maintainability More per-repo drift Central policy, fewer copies
Security consistency Depends on each admin Stronger baseline when correctly scoped
Governance Local owners can experiment Central reviewers/security managers can own policy
Failure blast radius Usually one repository Bad pattern/exemption can affect many repositories
Availability/cost Public repository path free Private/internal and advanced organization features are plan/product dependent

4. History rewrite after revocation: security benefit versus operational damage

Once a credential is revoked, it cannot authenticate even if an old commit remains discoverable. That often removes the urgent security risk. Rewriting history may still be justified when the exposed material is not revocable, contains regulated/private data that must be removed, causes scanners/users to repeatedly rediscover sensitive content, or policy/legal requirements demand removal.

Situation Rewrite tendency Reason
Revocable API token, revoked promptly, no other sensitive data Often not necessary Access risk is removed; rewrite has coordination and recontamination costs.
Private key with all corresponding trust removed and no policy requiring purge Case-by-case Revocation/trust removal may be sufficient; verify all trust stores.
Password reused elsewhere and not fully rotated Do not start with rewrite First rotate everywhere; repository cleanup cannot compensate for live reuse.
Regulated personal data / non-revocable sensitive document More likely justified The content itself remains sensitive after access credentials are irrelevant.
Secret still present in forks/clones/comments Rewrite alone insufficient External copies/surfaces require separate coordination/remediation.
Destructive procedure: GitHub’s official sensitive-data removal process uses git-filter-repo and force-updates rewritten refs. It changes commit IDs, can invalidate signatures and PR diffs, can lose/reintroduce work, and may require GitHub Support for cached/internal references. This chapter explains the decision and coordination; the mandatory lab does not execute a history rewrite.

5. Detection policy is not secret-storage policy

Push protection reduces accidental commits; it does not authorize storing credentials in files that happen not to match a pattern. Production systems still need secret managers, short-lived identities, environment separation, least privilege, and rotation. Unknown formats, encoded values, transformed secrets, or unsupported token versions can evade pattern-based controls. The policy should therefore say “no secrets in source” rather than “anything push protection allows is safe.”

Likewise, validity checks are a prioritization tool. If a high-value credential is credibly exposed, rotate it even if validity metadata is unknown or stale. A prevention system should fail safe around uncertainty rather than wait for a perfect detector.

6. Worked scenario: choose a policy for Atlas Relay

Atlas Relay has 40 repositories, a proprietary deployment token formatted AR_DEPLOY_ plus 32 base32 characters, a migration bot, and a security team of three. Most repositories are private; one documentation repository is public. Evaluate the choices rather than copying a universal answer.

Criterion Decision Justification
Maintainability Central custom pattern with fixture tests and staged dry run One reviewed pattern avoids 40 divergent definitions.
Security Block proprietary token where Secret Protection is enabled; provider patterns remain enabled The internal token is high value and should not be source data.
Governance Delegated bypass reviewers = security team; developers request with evidence Separates code write permission from exception approval.
Reliability Migration bot gets time-bounded/narrow exemption only if redesign cannot remove need Avoids permanent human bypass while limiting standing hole.
Compatibility Public repo uses free protection; private repos require verified Team/Enterprise Secret Protection coverage Do not assume entitlements silently.
Cost Pilot one private repo + public docs before organization rollout Measure match quality and license/operational impact first.
Incident response Provider/issuer revocation SLA and consumer migration runbook independent of GitHub alert state GitHub detects; the issuer contains access.

Knowledge check

Why not create a custom regex for every provider token?

Why is delegated bypass stronger governance than broad self-bypass?

When can organization-wide enforcement be worse than repository-level policy?

After an API token is revoked, what question determines whether history rewrite is worth it?

Does a push that is not blocked prove the content contains no secret?

Summary

Secret policy balances detector coverage with developer friction. Prefer maintained built-in patterns, treat custom patterns as tested platform code, make bypass authority narrower than write authority, centralize only after a pilot, and rewrite history only when it adds real risk/compliance value after revocation.

Next you will diagnose the common ways teams defeat these controls through sequencing, noise, scope mistakes, and incomplete rotation.

Next lesson

Secret Scanning, Push Protection, Custom Patterns, Bypass Controls, and Incident Response: Diagnostics, Failure Modes, Security, and Performance

Official references

Keep the academy open

Support free, practical DevOps education.

Every lesson is designed to remain readable in a browser, downloadable from GitHub, and usable without a paid learning platform. Contributions help expand and maintain the curriculum.

Ethereum / ERC-20
0x716c4Ab160C4B66F31a28AE2448BfF68fc3a2ef0 Send only Ethereum/ERC-20 compatible assets to this address.