Incident response for a leaked secret: rotate first, assess access through logs, purge history correctly, decide on NDB notification under the Privacy Act, and prevent recurrence with push protection, managed identity and rotation runbooks.
I treat the credential as compromised the moment it's pushed, so the first move is rotation, not deleting the commit: issue a new SQL password (or better, switch to managed identity), regenerate the storage key, update the app, then revoke the old ones. Next I investigate access: Azure SQL auditing, Storage resource logs and Entra sign-in logs for the exposure window, plus who could see the repo. Then I purge the history with git filter-repo, force-push and have collaborators re-clone. In parallel I run the Notifiable Data Breaches assessment: if personal information was accessed or is likely to have been, and serious harm is likely, we notify the OAIC and affected people; the assessment must finish within 30 days. Finally, prevention: push protection, gitleaks in CI, and removing those secrets entirely with managed identity. Rotate first, because history cleanup is cosmetic once a secret is out.
"The first thing I say is that the secret is already compromised. Deleting the commit doesn't help: anyone who fetched in the meantime has it, forks and caches have it, and for public repos automated scanners find keys within minutes. So containment means rotating, and in the right order so we don't cause an outage: create the new credential, update the app's configuration, confirm it's healthy, then revoke the old one. For the storage account that means regenerating whichever key leaked, after moving the app to the other key, and invalidating any SAS tokens signed with it. For SQL I'd rather not just change the password - this is the moment to move the app to managed identity and disable the SQL login.
For example, at [company] a developer pushed [a storage account key] in a config file to [a private repo with ~40 people with access]. I [was the on-call senior], so I opened an incident, rotated the key within [25 minutes], and then pulled the Storage logs from Log Analytics for the exposure window, filtering on requests authenticated with the account key from unexpected IPs. There were none. That evidence is what let our privacy officer conclude it wasn't an eligible data breach under the NDB scheme. Then I cleaned the history with
git filter-repo, force-pushed, asked everyone to re-clone, and we turned on push protection for the organisation. [Since then push protection has blocked N similar pushes.]The mistake I see is teams spending the first hour rewriting history and never checking whether the key was used. The NDB scheme cares about whether personal information was accessed or disclosed and whether serious harm is likely; you can only answer that with logs. So I'm careful to preserve evidence before rotating anything that would destroy it. Rotate first, prove what happened second, tidy up Git third."
| Step | Action | Why this order |
|---|---|---|
| 1. Declare | Open an incident, name an incident lead, start a timeline | Decisions and timestamps are evidence for the NDB assessment |
| 2. Preserve | Make sure SQL auditing, Storage logs and sign-in logs for the window are retained/exported | Rotation and cleanup must not destroy evidence |
| 3. Rotate | New credential -> update app -> verify -> revoke old | Removes attacker access without an outage |
| 4. Investigate | Who could see the repo, was the secret used, what data could it reach | Drives the breach assessment |
| 5. Assess (NDB) | Privacy officer + legal decide if it's an eligible data breach | 30-day limit for a reasonable assessment |
| 6. Purge | git filter-repo, force-push, GitHub Support for cached views, re-clone |
Stops future exposure, but doesn't undo past exposure |
| 7. Prevent | Push protection, CI scanning, managed identity, runbook | So it doesn't happen again |
| 8. Review | Blameless post-incident review | Fixes the system, not the person |
| Question | Evidence |
|---|---|
| Did the leaked credential give access to personal information? | What the SQL login and storage account could reach |
| Was there unauthorised access or disclosure, or loss likely to lead to it? | Repo visibility, forks, logs of credential use |
| Is serious harm likely to a reasonable person? | Data sensitivity (health, financial, identity documents), volume |
| Can remedial action prevent serious harm? | Fast rotation with no evidence of use often means no eligible breach |
If eligible, notify the OAIC with the statement and the affected individuals as soon as practicable. Keep the assessment record either way.
After the incident above, the post-incident review produced four actions: organisation-wide push protection, gitleaks in every pipeline, managed identity for [all 12] services that still used SQL logins, and allowSharedKeyAccess=false on storage accounts. Within [six months], long-lived secrets across the estate dropped from [~60 to 9].
Checks calm, correctly ordered incident response and awareness of Australian breach obligations, not just Git commands.
Green flags
git filter-repo, knows forks and clones can't be cleaned.Red flags
A Git push copies objects to the server. From there they reach:
developer push
|
v
GitHub repo ---> every collaborator's next fetch (full history)
| ---> forks (separate repos, separate history)
| ---> CI runners' checkout caches, artefacts
| ---> PR views, "compare" pages cached by GitHub
| ---> (public repos) secret-harvesting bots within minutes
v
rewriting history removes it from future clones only
History rewriting is hygiene; rotation is containment.
Storage accounts have two keys precisely for this:
key1 leaked and the app uses it, switch the app to key2 (or, better, to managed identity with Storage Blob Data Contributor).key1. Any SAS signed with key1 (service or account SAS) becomes invalid. User-delegation SAS tokens are signed with Entra keys and are unaffected.allowSharedKeyAccess to false so keys can't be used at all.ALTER LOGIN ... WITH PASSWORD = '...' (or for the server admin, reset in the portal), update the app, restart if it caches the connection string.Authentication=Active Directory Default, then DROP LOGIN / disable the SQL login. Consider "Microsoft Entra-only authentication" on the server.| Source | Query for |
|---|---|
| Azure SQL auditing (Log Analytics / storage) | Logins by that principal from unknown client IPs or applications during the window |
StorageBlobLogs (resource logs) |
AuthenticationType == "AccountKey" from unexpected CallerIpAddress |
| Azure Activity Log | listKeys operations, key regenerations, firewall changes |
| Microsoft Defender for Cloud / Defender for Storage | Alerts for unusual access, access from Tor or known-bad IPs |
| GitHub audit log | Repo visibility, clones (Enterprise), forks, who had access |
| GitHub secret scanning alerts | When the secret was first detected; partner programme notifications |
Example KQL for storage:
StorageBlobLogs
| where TimeGenerated between (datetime(2026-11-03T09:12) .. datetime(2026-11-03T10:05))
| where AuthenticationType == "AccountKey"
| summarize count() by CallerIpAddress, OperationName, UserAgentHeader
If diagnostic logging wasn't enabled before the leak, you can't prove a negative. That shifts the NDB assessment towards "likely accessed" for sensitive data, and is itself a finding.
Part IIIC of the Privacy Act 1988 applies to APP entities (most businesses over A$3 million turnover, plus health providers, credit reporting bodies, Australian Government agencies and others).
Engineers don't make the legal call, but they provide the evidence, and the speed of rotation is often the "remedial action" that prevents serious harm.
git filter-repo (recommended by Git) or BFG Repo-Cleaner; git filter-branch is slow and error-prone. developer machine -> pre-commit hook (gitleaks) cheap, bypassable
push -> GitHub push protection blocks known patterns
CI -> gitleaks / secret scanning on PRs catches what slipped through
platform -> managed identity, shared key disabled nothing left to leak
operations -> rotation runbook, expiry alerts leaks become boring
The strongest layer is the last-but-one: if the SQL server only accepts Entra authentication, a leaked password is worthless.
Blameless format: timeline, what went well (detection, rotation time), what didn't (logs missing, no runbook), contributing factors (secret in an example config file, no push protection), and actions with owners and dates. Track time-to-rotate as a metric.
git filter-repo --replace-text and confirm with git log -p that it's gone from every branch.The rotation and cleanup commands an incident lead would run, in order:
# 1. Storage: move the app to the other key (or managed identity), then regenerate the leaked key.
az storage account keys renew -g rg-claims-prod -n stclaimsprod --key primary
# Long-term: stop shared-key auth entirely.
az storage account update -g rg-claims-prod -n stclaimsprod --allow-shared-key-access false
# 2. SQL: prefer Entra-only auth so a leaked SQL password is useless.
az sql server ad-only-auth enable -g rg-claims-prod -n sql-claims-prod
# 3. History: rewrite every ref, then force-push. Collaborators must re-clone.
pip install git-filter-repo
echo 'AccountKey=***REMOVED***' > /tmp/replacements.txt # pattern==>replacement lines also supported
git filter-repo --replace-text /tmp/replacements.txt --force
git push --force --all && git push --force --tags
-- The app now authenticates with its managed identity instead of a password.
CREATE USER [app-claims-prod] FROM EXTERNAL PROVIDER;
ALTER ROLE db_datareader ADD MEMBER [app-claims-prod];
ALTER ROLE db_datawriter ADD MEMBER [app-claims-prod];
A CI gate so a leaked secret fails the PR even if push protection is bypassed:
# .github/workflows/secret-scan.yml
name: secret-scan
on: [pull_request]
jobs:
gitleaks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with: { fetch-depth: 0 } # scan the PR's full history, not just the tip
- uses: gitleaks/gitleaks-action@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
And the code change that removes the secret for good:
using Azure.Identity;
using Azure.Storage.Blobs;
var builder = WebApplication.CreateBuilder(args);
// Before: new BlobServiceClient("DefaultEndpointsProtocol=https;AccountName=...;AccountKey=...")
// After: the managed identity plus RBAC (Storage Blob Data Contributor). Nothing to leak.
builder.Services.AddSingleton(_ => new BlobServiceClient(
new Uri(builder.Configuration["Storage:BlobEndpoint"]!),
new ManagedIdentityCredential(ManagedIdentityId.SystemAssigned)));
var app = builder.Build();
app.Run();
git filter-branch or only rewriting main. Why it is wrong: It's slow, error-prone, and other branches and tags still contain the secret. Instead: Use git filter-repo on all refs, force-push, and have everyone re-clone.The senior instinct is contain, evidence, tidy, prevent, in that order, with the privacy decision running in parallel and owned by the right people. The best long-term fix isn't better scanning; it's having nothing worth leaking. A server that only accepts Entra authentication and a storage account with shared-key access disabled make the whole class of incident disappear.
On SAS tokens, be precise: regenerating key1 immediately invalidates every account SAS and service SAS signed with key1, including ones issued legitimately to partners, so check what you issued and re-issue those with the new key or, better, as user-delegation SAS (signed with an Entra-derived key and revocable by revoking user delegation keys). Then verify: a request using an old SAS should now return 403 AuthenticationFailed, and the Storage logs should show no further successful SAS authentications with the old signature. Stored access policies let you revoke service SAS individually in future without a key rotation.
Track time to rotate (target: under an hour for any production secret) and long-lived secrets per service as metrics. If you can't rotate a secret in an hour, you don't have a runbook, you have a hope.
| Action | When it fits | Cost | When not to rely on it alone |
|---|---|---|---|
| Rotate / revoke | Every leak, immediately | Possible outage if done in the wrong order | Never optional |
| History rewrite | Secret in any reachable commit | Force-push disruption, re-clones | It doesn't contain the leak |
| Push protection + CI scanning | Every repo | Occasional false positives | Unknown or custom secret formats |
| Managed identity / Entra-only auth | Azure-hosted targets | Migration effort | Third-party APIs |
First I read the exact error. NU1301 means a source couldn't be reached, 401 or 403 means authentication, and NU1101 means the package isn't on any configured source. It works on my machine because I have cached packages and stored credentials, while CI starts clean. Then I check which nuget.config CI actually uses, since config files are merged from the repo upwards. I make the repo's config explicit with <clear />, and I authenticate CI the supported way, for example the Azure Artifacts credential provider or a token from the pipeline's secret store, never a committed password. I also add package source mapping and lock files so restores are reproducible and protected against dependency confusion.
Treat logs as a data store that attackers and too many staff can read. Never log secrets (passwords, tokens, Authorization headers, connection strings, card numbers) and keep personal information out: log identifiers like CustomerId, not names, emails or request bodies.
Enforce it in code rather than by memory: Microsoft.Extensions.Compliance.Redaction lets you classify fields with attributes, map classifications to redactors (erase, or HMAC for a stable pseudonym) with AddRedaction, and apply them to logs with EnableRedaction. Use header allowlists in HTTP logging.
In Australia, APP 11 requires reasonable steps to protect personal information and APP 11.2 requires destroying or de-identifying it when no longer needed, so retention matters, and a leaked log store can be a notifiable data breach. The trade-off: less detail in logs versus a smaller breach surface.
I'd need a timeline (pushed, detected, rotated), who could access the secret (collaborators, forks, visibility), and resource logs for the exposure window showing every use of the credential came from our own workloads: SQL audit logins by principal and client IP, Storage logs filtered on account-key authentication, Activity Log for key listing. Alongside that, an assessment of what data the credential could reach and how sensitive it is, because that drives the serious-harm test. All of this should be captured through the organisation's data breach response plan, which defines who assesses, who decides and who talks to the OAIC. Without logs, we can't positively show there was no access, so the privacy officer has to weigh the likelihood of access against the data's sensitivity, often more conservatively. The fix is SQL auditing and Storage diagnostic logs everywhere with retention well beyond the 30-day assessment window, and removing the credential type altogether.
How to tell it (STAR)
**S:** A developer pushed a production storage key and SQL password to our [private] repo; the storage held [customer documents]. **T:** As [on-call senior], I had to contain it, find out if it had been used, and give our privacy officer what they needed for the NDB assessment. **A:** I rotated the storage key using the second key so there was no outage, changed the SQL password, and then queried Storage and SQL audit logs for the exposure window: every access came from our own app. Then I cleaned history with git filter-repo and led the review, where we moved both to managed identity and turned on push protection. **R:** The key was rotated within [25 minutes], the privacy officer recorded it as not notifiable based on the logs, and push protection has since blocked [N] similar pushes.
Last updated 23 Nov 2026.