An unrestricted Google Cloud API key can call every API enabled in its project, so a key pasted into a web page for maps or Firebase quietly gains new reach each time someone enables another API, Gemini included. The Google API Keys Exposure 2026 analysis explains how that played out. This runbook is the hands-on part: list every key across your projects, find the ones with no API restriction or no application restriction, learn what each key really calls, and apply restrictions without breaking live apps. It is for cloud security, platform and mobile engineers. For key types, roles and the wider design, see the Google API Keys Security Guide; this page does not repeat it.
This is an independent guide from NHI Mgmt Group, based on Google Cloud's public documentation as of November 2026. It is not sponsored or reviewed by Google. Product features change, so confirm settings against Google's current documentation.
Key takeaways
- Two separate gaps. A key can lack API restrictions (which services it may call), application restrictions (where it may be used from), or both; check and fix each.
- API restrictions do the real work. Google notes that Android and iOS restrictions are easy to bypass, so the API allowlist is the control that limits what a copied key can do.
- Measure before you restrict. Filter Cloud Monitoring by the
credential_idlabel to see which APIs each key calls, then allowlist exactly those. - Updates replace, they do not append.
gcloud services api-keys update --api-targetreplaces the whole service list, so always pass every service the key needs. - Deletion is reversible for 30 days. Cut risk by deleting dormant keys, knowing you can undelete within that window if something breaks.
When you need this
- A new API was enabled: enabling a service changes what every unrestricted key in that project can call. Treat it as a permission change for those keys.
- Keys sit in client code: browser JavaScript, mobile app binaries and public repositories expose key strings by design for Maps and Firebase. Finding them in code is covered in Developer Secret Scanning Triage; this page fixes the keys themselves.
- Old or tool-created keys: Google documents that keys created through the REST API are unrestricted unless the request includes a
restrictionsobject, so automation and older tooling are common sources. - Audit or benchmark finding: cloud posture reviews routinely ask for keys restricted by API and by application.
Before you start
- Roles: to view and change standard keys you need API Keys Admin (
roles/serviceusage.apiKeysAdmin) and Service Usage Viewer (roles/serviceusage.serviceUsageViewer). Read-only inventory can be delegated more narrowly; restriction changes should stay with a platform team, because the same role can also widen restrictions. - Key IDs: a key has three identifiers: the ID (
uid), the display name and the key string. Commands use the ID;gcloud services api-keys listshows it. - Owners: for each project, know who owns the apps that use its keys. You will need them to confirm allowlists and to test.
- Test keys: Firebase and Google both advise testing restriction changes on a test key in a test app first, because a missing API on the allowlist causes errors in production.
Step 1: list every key
- Enumerate projects in scope with
gcloud projects list, or use Cloud Asset Inventory across the organisation:gcloud asset search-all-resources --scope=organizations/ORG_ID --asset-types=apikeys.googleapis.com/Key. See the Cloud Asset Inventory Guide. - List keys per project with full detail:
gcloud services api-keys list --project=PROJECT_ID --format=json. Each key record carriesuid,displayName,createTime,updateTime,restrictionsand, for authorization keys,serviceAccountEmail. - Record enabled APIs per project with
gcloud services list --enabled --project=PROJECT_ID. An unrestricted key can reach everything on that list. - Store the results in one sheet or table: project, key ID, display name, created, restrictions, enabled APIs, owner.
Listing keys and reading key metadata do not generate audit logs (Google documents that GetKey, ListKeys and LookupKey are not logged), so inventory runs leave no trail to alert on. Retrieving the key string does: GetKeyString is a Data Access log entry.
Step 2: classify what is unrestricted
The restrictions object has an apiTargets list and at most one client restriction field. Use that structure to classify each key.
| What the key record shows | Classification | Risk | Priority |
|---|---|---|---|
No restrictions object at all | Fully unrestricted | Any enabled API, from anywhere | Fix first, especially in projects with the Generative Language API enabled |
apiTargets missing, client restriction present | API-unrestricted | Copied key can call any enabled API, within the client restriction (which may be spoofable) | High |
apiTargets present, no client restriction | Application-unrestricted | Callable from anywhere, but only the listed APIs | Medium; add an application restriction |
| Both present | Restricted | Check the allowlist is minimal | Review |
serviceAccountEmail set | Authorization key bound to a service account | Acts with the account's permissions | Check the account holds no IAM roles beyond need |
A sample filter for a JSON export, run on your own workstation (adjust to your tooling):
1 Sample only. This step can disrupt services or delete data. It is based on the public documentation cited: assess it independently against the current official documentation, test outside production and back up first. Use at your own risk.
gcloud services api-keys list --project=PROJECT_ID --format=json \
| jq -r '.[] | select(.restrictions.apiTargets == null) | [.uid, .displayName, .createTime] | @tsv'Run a second pass for keys where none of browserKeyRestrictions, serverKeyRestrictions, androidKeyRestrictions or iosKeyRestrictions is set.
Step 3: learn what each key actually calls
- Metrics by credential: in Metrics Explorer, choose the Consumed API resource and the
serviceruntime.googleapis.com/api/request_countmetric, then filter on thecredential_idlabel for the key. Google's Maps Platform guidance uses this view to see which APIs a key calls and to spot unexpected use. - Window: look at a period long enough to include monthly and seasonal jobs; 30 days is a sensible sample minimum.
- Zero traffic: a key with no successful requests in the window is a deletion candidate, not a restriction candidate.
- Unexpected APIs: traffic to an API the owner did not expect, such as
generativelanguage.googleapis.comon a maps key, is a possible misuse signal: handle it as an exposure using How to work out what a leaked API key could access and what it actually did before restricting, so you keep the evidence.
Step 4: apply restrictions
API restrictions
- Confirm each API you will allowlist is enabled in the project; Google requires that before you can restrict to it.
- Apply the full list in one command, because the update replaces existing targets:
gcloud services api-keys update KEY_ID --api-target=service=maps-backend.googleapis.com --api-target=service=places.googleapis.com(sample services). - Or in the console: APIs & Services > Credentials, open the key, choose Restrict key under API restrictions, select the APIs and save.
- For Firebase keys, keep only the Firebase services the app uses (for example
identitytoolkit.googleapis.comfor Authentication,firestore.googleapis.comfor Cloud Firestore). Firebase states that the Generative Language API must never be on a public or shared key.
Application restrictions
Only one application restriction type can be set per key, so the key's platform decides the choice.
| Where the key is used | Restriction | gcloud flag | Caveat from Google's docs |
|---|---|---|---|
| Browser (web pages) | Websites (HTTP referrers) | --allowed-referrers | Wildcards only for subdomains or paths, as whole segments |
| Server or batch job | IP addresses | --allowed-ips | IPv4, IPv6 or CIDR; internal addresses and localhost are not supported |
| Android app | Android apps | --allowed-application=sha1_fingerprint=...,package_name=... | Easy to bypass; pair with API restrictions |
| iOS app | iOS apps | --allowed-bundle-ids | Requests send X-Ios-Bundle-Identifier; bypassing is straightforward |
- Split shared keys: one key used by a website and an Android app cannot carry both restrictions. Create one key per app and platform (Google's Maps guidance allows up to 300 keys per project), move each app, then delete the shared key.
- Server-side keys: if a server calls a Google API with a key, ask whether it should use a service account and short-lived credentials instead, which Google's best practices recommend where possible.
- Header, not URL: send keys in the
x-goog-api-keyheader rather than as a query parameter, which can end up in logs.
Step 5: delete, rotate and keep it fixed
- Delete dormant keys:
gcloud services api-keys delete KEY_ID. Google allows restore within 30 days withgcloud services api-keys undelete KEY_ID(find it withlist --show-deleted). - Rotate exposed keys: the console Rotate key action creates a new key with the same restrictions; after updating apps, select Delete the previous key. Restricting a leaked key reduces its reach but the string stays usable for the allowlisted APIs.
- Separate AI workloads: keep Gemini and other AI APIs in projects that hold no public client keys, and use server-side credentials for them. NHI Mgmt Group's breach analysis records that Google began rejecting unrestricted standard keys on the Gemini API from 19 June 2026; that protects Gemini only, not the other APIs in your projects.
- Keep the guardrail: leave the organisation policy constraint
constraints/iam.managed.disableServiceAccountApiKeyCreationenforced so keys cannot be bound to service accounts by default. See the Google Cloud Organization Policy Guide. - Fix creation paths: update Terraform modules, scripts and REST calls so every new key is created with
--api-targetor arestrictionsobject.
Verify it worked
- Re-run the inventory and confirm no key lacks
apiTargetsand every client-facing key has one application restriction. - From an allowed app, confirm normal calls succeed; from a disallowed context (for example a test request to an API not on the list), confirm Google rejects the call.
- Watch the key's
credential_idmetrics for a rise in error responses after the change, which points to a missing API on the allowlist. - Confirm the change appears in audit logs as
google.api.apikeys.v2.ApiKeys.UpdateKey.
Rollback
- Before each change, save the key's current restrictions from the JSON export.
- If an app breaks, re-apply the saved list for that key only; do not remove restrictions altogether.
- If a deleted key turns out to be in use, undelete it within 30 days, restrict it, and plan its replacement.
Detection and measurement
- Audit log alerts: filter on
protoPayload.serviceName="apikeys.googleapis.com"and alert onCreateKey,UpdateKey,DeleteKeyandUndeleteKey(Admin Activity), plusGetKeyString(Data Access, which must be enabled). See the Google Cloud Audit Logs and Log Sinks Guide. - API enablement: alert when a project with client-side keys enables a new service, especially AI APIs.
- Usage anomalies: per-key request volume against a baseline, and budget alerts per project.
| Metric | Sample target | Why it matters |
|---|---|---|
| Keys with no API restriction | 0 | The core exposure |
| Client-facing keys with no application restriction | 0 | Limits casual reuse of copied keys |
| Keys with no successful traffic in 30 days still active | 0 after review | Dormant keys are unowned risk |
| Projects mixing public client keys and AI APIs | 0 | Prevents the Gemini pattern recurring |
| Keys with a named owner | 100% | Every fix needs someone to test it |
Common failure patterns
- Restricting by platform only: a key limited to an Android package but with no API allowlist still calls every enabled API when the package and fingerprint headers are copied.
- Partial update: running
--api-targetwith only the new service wipes the existing list and breaks the app. - Enabling AI APIs in a public-key project: the pattern behind the Google API Keys Exposure 2026, where Truffle Security reported 2,863 live keys with Gemini access found in public web data.
- One key for everything: a shared key across web, mobile and server cannot be restricted properly and cannot be rotated without touching every app.
- Restricting a key that is already leaking: restriction reduces reach but the key stays valid; rotate exposed keys and investigate first.
- Fixing keys but not pipelines: automation keeps creating unrestricted keys through the REST API.
Framework mapping
| Framework | Reference | How this runbook supports it |
|---|---|---|
| NIST SP 800-53 Rev 5 | CM-8 System Component Inventory; IA-5 Authenticator Management; AC-6 Least Privilege; AU-6 Audit Record Review | Key inventory, rotation and deletion, minimal allowlists, audit alerts |
| NIST CSF 2.0 | PR.AA-01; PR.AA-05 | Credentials for services managed, permissions least privilege |
| ISO/IEC 27001:2022 Annex A | A.5.17 Authentication information; A.8.9 Configuration management | Key handling and restriction baselines |
| MITRE ATT&CK | T1552.001 Credentials In Files; T1078 Valid Accounts; T1496 Resource Hijacking | Limits what a key found in code can be used for, including billable compute abuse |
Practitioner checklist
- List every key in every project with restrictions, creation date and owner.
- List enabled APIs per project and flag projects with AI APIs and public client keys together.
- Classify keys as fully, API- or application-unrestricted, and authorization keys.
- Measure each key's real API use with the
credential_idmetric label before changing it. - Apply full API allowlists in one update, testing on a non-production key first.
- Add one application restriction per key, splitting shared keys by app and platform.
- Delete dormant keys, noting the 30-day undelete window; rotate any key that was exposed.
- Keep
iam.managed.disableServiceAccountApiKeyCreationenforced and fix pipelines that create unrestricted keys. - Alert on key creation, updates, key string reads and new API enablement.
Standards and references
- Google Cloud: Manage API keys
- Google Cloud: Best practices for managing API keys
- Google Cloud: API Keys API REST reference, projects.locations.keys
- Google Cloud: API Keys audit logging
- Google Cloud: Search resources with Cloud Asset Inventory
- Google Maps Platform: API security best practices
- Firebase: Learn about using and managing API keys for Firebase
- Google Cloud: Monitoring API usage
Related NHI Mgmt Group resources: Google API Keys Security Guide · Google API Keys Exposure 2026 · API Key Leak Response Playbook · Firebase Credentials Security Guide · API Key Management Guide