Skip to main content
Five Steps for Cloud Compliance Readiness·A practical playbook for security teamsDownload
CIS Google Cloud Platform Foundation v5.0.0 · 1.14

API keys should only work from the websites, servers or apps that need them

  • Level 2
  • Identity and Access Management

This check looks at every API key in your Google Cloud projects and whether it has an application restriction (allowed websites, IP addresses, Android apps or iOS apps). The safe setting is that no key can be used from anywhere except the specific hosts or apps you named.

Why it matters

An API key is a plain string. Anyone who copies it from a web page, a mobile app package or a code repository can send requests that Google bills to your project and that count against your quotas. An application restriction limits where a key is accepted, so a leaked key is far less useful to whoever finds it.

Google documents four kinds of application restriction: HTTP referrers for browser keys, IP addresses for server keys, Android app package and signing certificate, and iOS bundle IDs. Google's own guidance on API keys recommends adding both an application restriction and an API restriction to every key. See the sources below.

How to check it yourself

In the Google Cloud console open APIs & Services → Credentials, pick the project, and look at the API keys list. A key whose Application restrictions column reads None is open to any caller.

The command line equivalent is read-only. It lists keys in one project and prints their restrictions block; a key with nothing under the restriction fields has no application restriction:

gcloud services api-keys list --project=my-project-id \
  --format="table(displayName,name.basename(),restrictions)"

To walk every project you can see:

for p in $(gcloud projects list --format="value(projectId)"); do
  echo "== $p"
  gcloud services api-keys list --project="$p" --format="table(displayName,restrictions)"
done

Run it from an account with viewer-level access first, ideally in a test project. These commands only read.

How to fix it

Decide first where each key is really used. Then, in APIs & Services → Credentials, open the key, choose Application restrictions, pick the matching type and enter the allowed values, then save.

With gcloud, pick the flag that matches the key's use:

# Browser key: only these websites
gcloud services api-keys update KEY_ID --project=my-project-id \
  --allowed-referrers="https://www.example.com/*"

# Server key: only these addresses
gcloud services api-keys update KEY_ID --project=my-project-id \
  --allowed-ips="203.0.113.10,203.0.113.11"

# iOS app
gcloud services api-keys update KEY_ID --project=my-project-id \
  --allowed-bundle-ids="com.example.app"

You run these yourself with an account that may edit keys. ConfigCobra only reads your environment and shows the finding and a suggested fix; it never changes your Google Cloud projects. If a key has no clear owner, create a new restricted key for the real user, switch the application over, and delete the old one once traffic stops.

What changes when you fix it

Any caller that does not match the restriction starts receiving permission-denied errors for that key. That is the intended effect, but it also catches legitimate clients you forgot about: a staging site on another domain, a partner who was given the key, a scheduled job running from a new IP address, or a mobile app build with a different signing certificate.

Before you enforce it, look at the key's usage metrics in APIs & Services → Metrics to see which services call it, and talk to the application owners. Roll out one key at a time and keep the previous values noted so you can widen the restriction quickly if something breaks. Users of your websites and apps see no change when the restriction matches how they already connect.

Included in

BenchmarkCIS IDProfile
CIS Google Cloud Platform Foundation v5.0.01.14Level 2

Check this on your Google Cloud

ConfigCobra runs this check with every other control of the CIS Google Cloud Platform Foundation Benchmark, read-only.

Get in touch

Let's talk.

Whether you're evaluating ConfigCobra, running an audit, or managing a client fleet — we respond within one business day.

Free trial