Join our Newsletter — 33% off our NHI Course
Home› Guides› How to find unrestricted Google Cloud API keys…
Guide Secrets Management

How to find unrestricted Google Cloud API keys and lock them to APIs and apps: inventory, restrict and verify

PDF for newsletter subscribers · free to read online

← All guides
By NHI Mgmt Group, under the editorial direction of Lalit Choda Updated 28 November 2026 12 min read
On this page

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_id label to see which APIs each key calls, then allowlist exactly those.
  • Updates replace, they do not append. gcloud services api-keys update --api-target replaces 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 restrictions object, 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 list shows 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

  1. 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.
  2. List keys per project with full detail: gcloud services api-keys list --project=PROJECT_ID --format=json. Each key record carries uid, displayName, createTime, updateTime, restrictions and, for authorization keys, serviceAccountEmail.
  3. Record enabled APIs per project with gcloud services list --enabled --project=PROJECT_ID. An unrestricted key can reach everything on that list.
  4. 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 showsClassificationRiskPriority
No restrictions object at allFully unrestrictedAny enabled API, from anywhereFix first, especially in projects with the Generative Language API enabled
apiTargets missing, client restriction presentAPI-unrestrictedCopied key can call any enabled API, within the client restriction (which may be spoofable)High
apiTargets present, no client restrictionApplication-unrestrictedCallable from anywhere, but only the listed APIsMedium; add an application restriction
Both presentRestrictedCheck the allowlist is minimalReview
serviceAccountEmail setAuthorization key bound to a service accountActs with the account's permissionsCheck 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.

Sample 1
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_count metric, then filter on the credential_id label 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.com on 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

  1. Confirm each API you will allowlist is enabled in the project; Google requires that before you can restrict to it.
  2. 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).
  3. Or in the console: APIs & Services > Credentials, open the key, choose Restrict key under API restrictions, select the APIs and save.
  4. For Firebase keys, keep only the Firebase services the app uses (for example identitytoolkit.googleapis.com for Authentication, firestore.googleapis.com for 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 usedRestrictiongcloud flagCaveat from Google's docs
Browser (web pages)Websites (HTTP referrers)--allowed-referrersWildcards only for subdomains or paths, as whole segments
Server or batch jobIP addresses--allowed-ipsIPv4, IPv6 or CIDR; internal addresses and localhost are not supported
Android appAndroid apps--allowed-application=sha1_fingerprint=...,package_name=...Easy to bypass; pair with API restrictions
iOS appiOS apps--allowed-bundle-idsRequests 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-key header 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 with gcloud services api-keys undelete KEY_ID (find it with list --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.disableServiceAccountApiKeyCreation enforced 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-target or a restrictions object.

Verify it worked

  1. Re-run the inventory and confirm no key lacks apiTargets and every client-facing key has one application restriction.
  2. 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.
  3. Watch the key's credential_id metrics for a rise in error responses after the change, which points to a missing API on the allowlist.
  4. 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 on CreateKey, UpdateKey, DeleteKey and UndeleteKey (Admin Activity), plus GetKeyString (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.
MetricSample targetWhy it matters
Keys with no API restriction0The core exposure
Client-facing keys with no application restriction0Limits casual reuse of copied keys
Keys with no successful traffic in 30 days still active0 after reviewDormant keys are unowned risk
Projects mixing public client keys and AI APIs0Prevents the Gemini pattern recurring
Keys with a named owner100%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-target with 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

FrameworkReferenceHow this runbook supports it
NIST SP 800-53 Rev 5CM-8 System Component Inventory; IA-5 Authenticator Management; AC-6 Least Privilege; AU-6 Audit Record ReviewKey inventory, rotation and deletion, minimal allowlists, audit alerts
NIST CSF 2.0PR.AA-01; PR.AA-05Credentials for services managed, permissions least privilege
ISO/IEC 27001:2022 Annex AA.5.17 Authentication information; A.8.9 Configuration managementKey handling and restriction baselines
MITRE ATT&CKT1552.001 Credentials In Files; T1078 Valid Accounts; T1496 Resource HijackingLimits 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_id metric 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.disableServiceAccountApiKeyCreation enforced and fix pipelines that create unrestricted keys.
  • Alert on key creation, updates, key string reads and new API enablement.

Standards and references

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

PDF for subscribers

Take this guide with you

Every section, table and checklist in one PDF, with links to the sources and related guides. Subscribe to our weekly NHI & AI Identity Journal and we’ll email you a download link.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

PDF Downloads for Newsletter Subscribers

Get the guide

Enter your details and we’ll email you a download link.

The full guide is free to read online. The PDF is a thank you for subscribing.

Fill in all fields marked * and tick both boxes to continue.