API keys should only work from the websites, servers or apps that need them
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)"
doneRun 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
| Benchmark | CIS ID | Profile |
|---|---|---|
| CIS Google Cloud Platform Foundation v5.0.0 | 1.14 | Level 2 |
More checks in Identity and Access Management
- Use corporate-managed login credentials instead of consumer accountsCIS 1.2
- Enforce multi-factor authentication for all non-service accountsCIS 1.3
- Enforce security-key two-factor authentication for all admin accountsCIS 1.4
- Use only GCP-managed keys for each service account (no user-managed keys)CIS 1.5
- Ensure service accounts hold no admin (owner/editor) privilegesCIS 1.6
Go further
- Identity and Access Management21 controls in this section
- CIS Google Cloud Platform Foundation v5.0.093 controls
- CIS Google Cloud Platform Foundation checklistEvery control in one list, as CSV
- RemediationSee what a fix changes in your tenant before you apply it, then use the generated script
- Monitoring & DriftScheduled scans, drift detection and email alerts when a control regresses
Check this on your Google Cloud
ConfigCobra runs this check with every other control of the CIS Google Cloud Platform Foundation Benchmark, read-only.