📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

📚 Interview question

A developer pushed a commit containing a production Azure SQL connection string with a password, and an Azure Storage account key, to the team's GitHub repository. Walk me through what you do, in what order: containment, cleaning history, deciding whether it is a notifiable data breach, and making sure it can't happen again.

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.

Senior RealWorldScenario Advanced incident-response notifiable-data-breaches privacy-act secret-scanning secrets-management security

🎯 Key points

  • Rotate/revoke first: deleting the commit does not un-leak it (clones, forks, caches, scanners crawl public pushes in minutes)
  • Rotate in the right order: new credential, update app, then revoke old; regenerating a storage key invalidates every account and service SAS signed with it, but not user-delegation SAS
  • Prove use or non-use with queries, not opinions: StorageBlobLogs filtered on AuthenticationType == AccountKey grouped by CallerIpAddress, SQL audit logins by principal and client IP, Activity Log listKeys, Defender alerts
  • Purge history with git filter-repo or BFG across all refs, force-push, re-clone, GitHub Support for cached views; secondary to rotation
  • NDB scheme: eligible data breach = unauthorised access/disclosure likely to cause serious harm, not prevented by remedial action; reasonable assessment within 30 days; notify OAIC and individuals if eligible
  • The NDB record needs evidence: timeline (pushed, detected, rotated), who could access the repo, and log results for the window; no logs means you can't show no access
  • Prevent: GitHub push protection, gitleaks in CI, managed identity, Entra-only SQL auth, shared-key access disabled
  • Blameless post-incident review with timeline, time-to-rotate metric and owned actions

⏱ 30-second answer

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.

🗣 Full answer (senior)

How I would answer this in an interview

"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."


The order of operations

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

Is it a notifiable data breach?

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.

Production example

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].

🔍 What the interviewer is checking

Checks calm, correctly ordered incident response and awareness of Australian breach obligations, not just Git commands.

Green flags

  • Rotates first, in an order that avoids an outage.
  • Preserves and uses logs to determine whether the secret was used.
  • Knows the NDB test (likely serious harm, 30-day assessment) and involves the privacy officer.
  • Uses git filter-repo, knows forks and clones can't be cleaned.
  • Prevention removes the secret class (managed identity), plus push protection.

Red flags

  • "Delete the commit and force-push" as the main fix.
  • Doesn't mention checking whether the credential was used.
  • Thinks a private repo means it's not a breach.
  • Blames the individual.

📚 Learn in depth

1. Why rotation beats deletion

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.

2. Rotating without an outage

Storage account keys

Storage accounts have two keys precisely for this:

  1. If key1 leaked and the app uses it, switch the app to key2 (or, better, to managed identity with Storage Blob Data Contributor).
  2. Regenerate key1. Any SAS signed with key1 (service or account SAS) becomes invalid. User-delegation SAS tokens are signed with Entra keys and are unaffected.
  3. Long term: set allowSharedKeyAccess to false so keys can't be used at all.

Azure SQL credentials

  • Change the login's password with ALTER LOGIN ... WITH PASSWORD = '...' (or for the server admin, reset in the portal), update the app, restart if it caches the connection string.
  • Better: create a contained user for the app's managed identity, switch the connection string to Authentication=Active Directory Default, then DROP LOGIN / disable the SQL login. Consider "Microsoft Entra-only authentication" on the server.
  • Check firewall rules: was public network access open? That changes the likelihood that a leaked password was usable.

3. Investigating use

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.

4. The NDB scheme in practice (as of November 2026)

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).

  • Eligible data breach: unauthorised access to, or disclosure of, personal information (or loss likely to result in it), that a reasonable person would conclude is likely to result in serious harm, and the entity hasn't been able to prevent that harm with remedial action.
  • Suspected breach: you must take reasonable steps to complete an assessment within 30 days.
  • If eligible: prepare a statement for the OAIC and notify affected individuals (directly, or by publication if that's not practicable) as soon as practicable.
  • The 2024 amendments (Privacy and Other Legislation Amendment Act 2024) strengthened OAIC enforcement, with tiered civil penalties and infringement notices, and created a statutory tort for serious invasions of privacy. The draft Tranche 2 bill (exposure draft released August 2026, not yet law) proposes a 72-hour breach-reporting window, so check the current status before relying on the 30-day rule.
  • Also check sector rules: APRA CPS 234 requires notifying APRA within 72 hours of becoming aware of a material information security incident; critical infrastructure entities have SOCI Act reporting duties.

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.

5. Purging history correctly

  • Use git filter-repo (recommended by Git) or BFG Repo-Cleaner; git filter-branch is slow and error-prone.
  • Rewrite every branch and tag, force-push, then have every collaborator re-clone (old clones still hold the objects and can re-push them).
  • Open PRs referencing old commits keep them reachable on GitHub; contact GitHub Support to remove cached views and dangling objects.
  • Forks are separate repositories; you can't rewrite them.
  • Dismiss the secret scanning alert as "revoked" only once rotation is done.

6. Prevention, layered

  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.

7. The post-incident review

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.

Try it yourself

  1. In a throwaway repo, commit a fake key, then remove it with git filter-repo --replace-text and confirm with git log -p that it's gone from every branch.
  2. Enable push protection on a test repo and try to push a test token in a supported format; read the block message.
  3. Turn on Storage diagnostic logs and write the KQL query above for your own account.
  4. Write a one-page rotation runbook for one secret your team owns, then time a dry run.
  5. Read the OAIC's "Assessing a suspected data breach" guidance and map each step to evidence your systems can produce.

💻 Code

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();

⚠ Common mistakes

  • Mistake: Deleting the commit or making the repo private and considering it fixed. Why it is wrong: Clones, forks, caches and scanners already have the secret. Instead: Rotate or revoke the credential first, then clean history.
  • Mistake: Revoking the old credential before the app has the new one. Why it is wrong: You cause a production outage on top of the incident. Instead: Create the new credential, update and verify the app, then revoke; use the second storage key for zero-downtime swaps.
  • Mistake: Rotating and cleaning up before checking logs exist. Why it is wrong: You may lose the evidence you need to show the credential wasn't used, which pushes the NDB assessment towards notification. Instead: Preserve and export SQL audit, Storage and sign-in logs for the window before making changes that affect them.
  • Mistake: Assuming a private repo means no breach. Why it is wrong: Unauthorised access includes insiders and anyone with a compromised account; contractors and departed staff may still have access. Instead: List who could access the repo and check whether the secret was used.
  • Mistake: Engineers deciding alone that it isn't notifiable. Why it is wrong: The NDB assessment is a legal judgement about likely serious harm, with a 30-day limit and OAIC scrutiny. Instead: Give the privacy officer or legal the evidence and a timeline; let them decide and record it.
  • Mistake: Using 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.
  • Mistake: Forgetting SAS tokens signed with a leaked storage key. Why it is wrong: Anyone holding such a SAS keeps access until you regenerate the key. Instead: Regenerate the key and move to user-delegation SAS signed via Entra.
  • Mistake: Blaming the developer. Why it is wrong: People hide future mistakes and the systemic cause (no push protection, secrets that didn't need to exist) remains. Instead: Run a blameless review and fix the system.

🏛 Senior insight: trade-offs

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

🔗 Follow-ups the interviewer may ask

  1. When: Candidate mentions CI pipelines or tokens in config files. Why: Checks the same discipline applied to feed credentials in CI and nuget.config, a common source of leaked tokens.
    How to answer

    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.

  2. When: Candidate mentions logs as evidence or as a place secrets end up. Why: Checks the candidate also stops secrets and PII leaking through logs, the other common path.
    How to answer

    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.

  3. When: Candidate says the leak wasn't notifiable. Why: Checks the link between logging decisions made in advance and the ability to make a defensible breach assessment.
    How to answer

    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.

🛠 Real-world problems: how you handle them

Storage account key pushed to GitHub, rotated in 25 minutes
Situation
[A health-adjacent SaaS company] with [~40] engineers. A developer pushed `appsettings.Production.json` containing an Azure Storage account key and a SQL connection string with a password to a private GitHub repo. The storage account held [customer-uploaded documents with personal information].
Signals
GitHub secret scanning alert for an Azure Storage account key, followed by a teammate noticing the file in the PR diff [about 40 minutes after the push].
Investigation
Opened an incident and confirmed Storage diagnostic logs and SQL auditing had been streaming to Log Analytics. Queried `StorageBlobLogs` for `AuthenticationType == "AccountKey"` in the window, grouped by `CallerIpAddress`: only the app's outbound IPs. SQL audit showed logins for that principal only from the App Service. GitHub audit log: no forks, [N] collaborators, no departed staff with access.
Resolution
Immediate: switched the app to `key2`, regenerated `key1`, changed the SQL password and restarted; then moved both to managed identity within the week and disabled shared-key access and SQL authentication. Privacy officer assessed it as not an eligible data breach on the log evidence and recorded the assessment. History cleaned with `git filter-repo`, force-pushed, all collaborators re-cloned.
Prevention
Organisation-wide push protection, gitleaks in every pipeline, `allowSharedKeyAccess=false` enforced through Azure Policy, Entra-only auth on SQL servers, a rotation runbook per remaining secret, and a blameless review.

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.

↩ Usually asked after

More in Senior Security Topics

Last updated 23 Nov 2026.

🌐 Sangam's Webring

⏪ Previous 🏠 Main Next ⏩
💬 Chat with me