# My Firebase Admin (service account) key leaked. What do I do?

**Short answer:** A Firebase Admin SDK service-account JSON file bypasses all Security Rules. Delete that key in Google Cloud console → IAM → Service accounts → Keys, create a replacement only if you can't use keyless credentials, and check Cloud Audit Logs and your data. The web `firebaseConfig` `apiKey` is public by design and is not this.

*Last updated 2026-11-25 · Reviewed by ProofForge*

## Is it this key?

**Format:** JSON file with `"type": "service_account"`, `private_key_id`, and a `-----BEGIN PRIVATE KEY-----` block

**Blast radius:** Admin access to Firestore, Realtime Database, Storage and Auth (Security Rules don't apply), plus any other Google Cloud roles the service account has.

## The first 10 minutes

| When | Do | How |
|---|---|---|
| 0–2 min | Delete key | Cloud console → IAM & Admin → Service accounts → the account → Keys → delete the leaked key ID. |
| 2–5 min | Replace | On Google Cloud hosts, use the attached service account (no key file). Elsewhere, create a new key and store it as a secret, never in the repo or frontend. |
| 5–8 min | Audit | Check Cloud Audit Logs for the key ID. Look at Auth users, Firestore and Storage for changes. |
| 8–10 min | Least privilege | Trim the service account's roles, and consider blocking key creation with an org policy. |

## Stop the next leak

- Keep the key in a server-side env var. Never use a `VITE_`, `NEXT_PUBLIC_` or `EXPO_PUBLIC_` variable or hard-code it in frontend code.
- Call the provider from your backend or an edge function, and add `.env*` to `.gitignore`.
- Re-scan the live site after every deploy. Keys also leak through JS bundles, source maps and exposed `.env` or `.git` paths.

> **Scan box (use the site's ScanBox component):** Check whether your live app has this problem. Paste your URL for a free outside-in scan covering exposed keys, open database rules, CORS and security headers. [Scan my app free →](https://proofforge.live/#scan)

## FAQ

### Is the apiKey in my firebaseConfig a leak?
No. It identifies the project. Security Rules protect data, so check them.

### Does deleting the key break my server?
Anything using that JSON fails until it gets the new credentials.

### Why does Admin bypass rules?
The Admin SDK runs with service-account privileges, by design, for trusted servers.

## Sources

- [Google Cloud: Create and delete service account keys](https://cloud.google.com/iam/docs/keys-create-delete)
- [Google Cloud: Best practices for managing service account keys](https://cloud.google.com/iam/docs/best-practices-for-managing-service-account-keys)
- [Firebase: Add the Admin SDK](https://firebase.google.com/docs/admin/setup)

## Related

- [Fix: open Firebase rules](/fix/firebase-open-rules)
- [Fix Firestore 'Missing or insufficient permissions'](/errors/firebase-missing-or-insufficient-permissions)
- [Firebase rules checker](/tools/firebase-rules-checker)
- [Exposed API key checker](/tools/exposed-api-key-checker)
- [Fix: source maps exposed](/fix/source-maps-exposed)
- [All leaked-key guides](/leaked-keys)
