API keys should be limited to the specific APIs the application calls
This check looks at each API key in your Google Cloud projects and whether it has an API restriction that names the services it may call. The safe setting is that every key can only reach the APIs its application actually needs.
Why it matters
By default a new API key can call every API that is enabled in its project. If such a key leaks, the person holding it can use any of those services, not just the one you meant to expose. An API restriction turns the key into a narrow credential: a map key can only load maps, a translation key can only translate.
Google's API key documentation lists API restrictions as one of the two kinds of restriction a key can carry, next to application restrictions, and its best-practices page recommends using both. Restricting the key also keeps the damage of a leak inside one service and one budget line.
How to check it yourself
In the console go to APIs & Services → Credentials, open a key and read API restrictions. Don't restrict key means the key can call any enabled API.
Read-only listing from the command line, showing the API targets per key (an empty column means unrestricted):
gcloud services api-keys list --project=my-project-id \
--format="table(displayName,name.basename(),restrictions.apiTargets[].service)"Across all projects 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.apiTargets[].service)"
doneBoth commands only read key metadata. Try them against a test project before a production one.
How to fix it
For each unrestricted key, work out which Google APIs the application really calls, open the key under APIs & Services → Credentials, choose Restrict key under API restrictions, tick only those APIs and save.
The same change with gcloud:
gcloud services api-keys update KEY_ID --project=my-project-id \
--api-target=service=translate.googleapis.com
# Several services: repeat the flag
gcloud services api-keys update KEY_ID --project=my-project-id \
--api-target=service=maps-backend.googleapis.com \
--api-target=service=geocoding-backend.googleapis.comYou apply the change yourself; ConfigCobra is read-only and never edits your projects, it only reports the finding and suggests the steps. Pair this with an application restriction on the same key so it is limited both by service and by where it is used.
What changes when you fix it
Requests from that key to any service outside the allowed list are rejected. An application that quietly relied on the key for a second API, for example a site that uses both a maps service and a places service, will break for that feature until you add the missing service to the list.
To avoid surprises, check the API usage metrics for the project and for the key before narrowing it, and confirm with the application team which services they call. Make the change in a quiet period, test the feature end to end, and keep a note of the previous setting. End users notice nothing if the list matches what the application already uses.
Included in
| Benchmark | CIS ID | Profile |
|---|---|---|
| CIS Google Cloud Platform Foundation v5.0.0 | 1.15 | 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.