AZ-401: Sensitive Data Removal and Git History Coordination
When credentials appear in a repository, revoke or rotate them first. Then decide whether the remaining sensitive content warrants a coordinated history rewrite. Preserve authorized recovery evidence, define the affected paths and references, stop conflicting writes, inspect the cleaned history, and coordinate the repository update and other copies. Deleting the latest file is neither credential containment nor proof that every copy has disappeared.
This procedure separates immediate access containment from repository cleanup. Its worked removal uses an owner-approved file path in an authorized repository; it reports no token revocation, rewrite, push or other operation executed for this article. Complete AZ-401: Recovering Selected Git Data Safely first, particularly its preservation of unrelated work and staging state.
Contain the credential before editing history
Identify the credential's issuer, owner, affected resource and dependent consumers without copying its value into the incident record. Have the authorized owner revoke or rotate the exposed credential through the issuer's supported controls. Record the action and subsequent authentication observations; a clean repository cannot establish that the old credential is unusable.
| Credential | Containment and replacement boundary |
|---|---|
| GitHub personal access token (PAT) | Use the token owner's settings to delete the compromised token. Any replacement remains limited by that user's actual access, selected permissions and organization policy. Fine-grained and classic tokens are not interchangeable for every feature. |
| Azure DevOps PAT | In user settings, open Personal access tokens, select the compromised token, choose Revoke and confirm. Restore required consumers with an appropriately authorized replacement after containment. |
| Another password, key or secret | Use that issuer's supported revocation or rotation process with its owner; a repository command does not disable the credential. |
Treat emergency containment differently from routine pre-expiry rotation. Azure DevOps documents a planned replacement sequence for avoiding interruption, but an exposed PAT requires immediate revocation. Subsequent authentication with a revoked PAT is rejected; this does not guarantee termination of every connection already established.
For replacement automation, prefer supported Microsoft Entra authentication when available. If a tool still requires an Azure DevOps PAT, use an organization-scoped token with minimum permissions and a short practical lifetime. Existing global Azure DevOps Services PATs stop working on January 27, 2027; that announcement does not retire every organization-scoped PAT on that date. A PAT cannot exceed its owner's access.
GitHub user tokens also cannot grant authority their owner lacks. Fine-grained tokens can have repository and permission limits and organization approval requirements, but compatibility must fit the intended operation. Long-lived organization integrations should use the supported GitHub App approach rather than assuming a broad user token is necessary. Detailed authentication operations remain a separate task.
Agree on cleanup scope and preservation
After containment, ask whether history rewriting is still necessary. For an exposed credential, revocation or rotation may sufficiently mitigate access risk. Noncredential sensitive information needs its own disposition; there may be no token to revoke.
Use the following recommended incident record before authorizing a rewrite:
| Decision | Record without reproducing the sensitive value |
|---|---|
| Selected content | Repository, affected file paths and earlier names, introduction point and known affected references |
| Ownership | Incident owner, repository administrator and people who may authorize publication and restoration |
| Preservation | Restricted recovery location, necessary working/staged material and access-controlled evidence |
| Concurrent work | Branch owners, open pull requests and the agreed write-freeze window |
| Other copies | Known collaborators, forks, cached views, pull-request references and exposed automation logs |
| Acceptance | Intended removals, nonsecret work that must survive, required observations and unresolved-copy owners |
Keep recovery material restricted: an ordinary shared backup or ticket attachment can become another disclosure. Preserve only the evidence and work authorized for the incident. The point is recoverability and accountability, not distributing another copy of the secret.
Explain the rewrite's consequences before the owner decides. Commit identifiers can change, signatures can be removed, pull-request views can be damaged, and concurrent work can be lost. An old clone can later reintroduce the unwanted history. Agree how open pull requests and protection settings will be handled; do not silently weaken shared controls.
Prepare a dedicated cleanup clone
The documented GitHub procedure uses git-filter-repo. Use a current release with its sensitive-data-removal option, at least version 2.47, in a fresh owner-authorized clone. Keep incident recovery evidence outside the clone being transformed. Do not experiment in a collaborator's only working copy.
Confirm the actual repository identity, configured publication destination, selected paths and current references. Have collaborators preserve their work and honor the agreed freeze. The operator must know what a later repository update will replace; a familiar repository name is insufficient.
The illustrative path below is config/incident-fixture.env, a dedicated file selected for complete historical removal. Substitute the actual approved Git path only after inspecting it. This choice deletes that file's history, including any nonsensitive contents in it. It is unsuitable when the required outcome is merely to remove one value while retaining the rest of a shared file.
Rewrite only after the selected operation is understood
For the dedicated-file case, the supported command form is:
git-filter-repo --sensitive-data-removal --invert-paths --path config/incident-fixture.env
Account for every earlier path if the file moved or was renamed; the documented procedure allows additional path selections. A current filename alone does not cover its previous names. If sensitive text is scattered through otherwise retained files, stop and select the documented text-replacement route with the owner instead of pretending that one path filter covers it. Protect any replacement-rule input as incident material.
Inspect the actual result before publication. Review the changed-reference record produced by the tool, the reported first changed commits and the affected pull requests. Compare the selected paths across the intended history and references, and verify that unrelated required work remains. Record identifiers and redacted findings rather than pasting the sensitive content into a transcript.
If the changed-reference or pull-request impact exceeds the agreed scope, do not publish it. Preserve the diagnostic evidence and reassess the prepared clone and removal decision. A successful tool exit alone is not approval to overwrite the shared repository.
Publish under the repository owner's explicit control
Before updating GitHub, the owner must confirm the reviewed cleaned clone, its actual authenticated remote, the agreed reference changes and the continuing write freeze. Recheck the remote after transformation; if it is absent, changed or uncertain, stop and resolve it through the approved setup rather than guessing a destination.
GitHub's documented publication step is a forced mirror update:
git push --force --mirror origin
This replaces branches, tags and references in the selected remote repository and can discard other people's intervening updates. It is not a single-file upload. Use it only for the explicitly authorized incident repository after the preceding checks, never as routine cleanup or against a shared destination inferred from an example.
Protection changes, if required, belong to the administrator's approved temporary-change plan and must be restored and checked. GitHub's pull-request references are read-only and can produce expected reference-update failures in this procedure. Distinguish those from other failed updates; unresolved non-pull-request failures keep cleanup incomplete. Record actual published results and the resulting references.
Coordinate other copies and recontamination controls
Updating the central repository does not clean every clone, fork, cached view or pull-request reference. Ask known collaborators to preserve necessary work and follow the documented clone-cleanup route or obtain a clean clone. Simply pulling and pushing from an old copy can return the unwanted history.
Where branches retain work based on old history, GitHub's follow-up calls for rebasing rather than merging that history back. The owner and collaborator must validate the appropriate cleanup before resuming writes; do not invent a blanket reset that discards their local work.
Coordinate affected forks with their owners. GitHub Support may assist with sensitive cached views and pull-request references under its documented eligibility conditions, particularly where rotating credentials cannot mitigate the risk. Supply the requested repository, affected pull-request and first-changed-commit evidence through the approved support process. Support is not a general non-sensitive-history removal service or proof that every external copy was erased.
Maintain a recommended acknowledgement record: who has reconciled their copy, what work was preserved, and which copies remain unresolved. Resume ordinary collaboration only under the owner's agreed decision. If old history returns, keep containment in force, identify the reintroducing copy and reassess cleanup; do not silently mark the original operation successful.
Prevent recurrence without confusing storage with access
Keep credentials out of tracked source and plaintext workflow configuration. Use an appropriate secret-management mechanism, review what will be committed, and inspect how automation handles sensitive inputs. A local check can help prevent mistakes, but incident containment still requires action on the credential itself.
Azure Key Vault vaults support secrets, certificates and cryptographic keys. The hardware security module (HSM) offering, Managed HSM, supports only HSM-backed keys; it is not an interchangeable container for ordinary secret values. Consumers must authenticate and receive the permissions needed for their operations. Moving a value into a vault does not automatically grant the application access or configure a delivery integration.
Review exposed logs and automation consumers as separate surfaces. GitHub Actions masking is not guaranteed. Rotate exposed secrets and arrange removal of affected logs through their authorized owner; do not test masking by printing a live credential. Keep workflow permissions narrow and review untrusted code before it can reach secrets or a persistent self-hosted runner.
Close with separate evidence for each outcome
Use a proposed acceptance record, populated with actual observations rather than assumed success:
| Outcome | Evidence and remaining limit |
|---|---|
| Credential containment | Issuer action and authorized subsequent authentication result; existing connections may need separate investigation |
| Selected history cleanup | Intended affected references and paths inspected, nonsecret work compared and publication failures resolved |
| Collaborator coordination | Required acknowledgements and protected work reconciled; unresolved copies remain named limitations |
| Automation recovery | Approved consumers use the replacement identity or credential and their intended operations work |
| Prevention and restoration | Owned controls restored, sensitive logs handled and secret-storage permissions checked without exposing values |
Keep the original incident evidence under its retention and access decision. A clear latest commit, changed hash or quiet log is not proof of complete eradication. Ordinary accidental recovery remains a distinct operation; configuring secret delivery and secure-file integration belongs to the related sensitive-asset lesson.
Authoritative Sources
- Remove sensitive data from a repository — containment priority, documented rewrite/publish coordination and remaining-copy limitations.
- Manage GitHub personal access tokens — token owner, type, approval, compatibility and deletion boundaries.
- Use Azure DevOps personal access tokens — revocation, replacement, permission limits and global-token retirement.
- Azure Key Vault basic concepts — vault versus Managed HSM assets and authenticated consumer permissions.
- Secure use reference for GitHub Actions — secret exposure, logs, workflow privileges and untrusted-runner risks.
Related Reading
- AZ-401: Recovering Selected Git Data Safely — prerequisite.
- AZ-401: Secrets Keys Certificates and Sensitive Deployment Assets — related.

