Common Misconfiguration
Exposed GCP service account keys grant full access to Google Cloud resources, potentially leading to data breaches, cryptocurrency mining, and massive cloud bills.Vulnerable Example
Secure Example
Detection Patterns
- GCP API Key:
`AIza[0-9A-Za-z\\-_]{35}` - GCP OAuth 2.0 Refresh Token:
`1//0[A-Za-z0-9-_]{60,}` - GCP Service Account (JSON):
`"private_key":\s*"-----BEGIN (RSA|EC) PRIVATE KEY-----"`
Prevention Best Practices
- Use Application Default Credentials (ADC): This should be the default for all GCP services.
- Implement Workload Identity: Use this for GKE to map Kubernetes Service Accounts to GCP Service Accounts securely.
- Avoid Service Account Keys: Do not create or download service account keys. Use IAM roles to grant permissions to services directly.
- Store Secrets in Secret Manager: For any secrets you must use (like third-party API keys), store them in GCP Secret Manager.
- Enable API Key Restrictions: Restrict API keys to specific IP addresses, HTTP referrers, or services.
- Implement VPC Service Controls: Create perimeters to prevent data exfiltration.
- Use Short-Lived Access Tokens: Use the IAM Credentials API to mint short-lived tokens instead of using static keys.
- Audit Key Usage: Regularly audit all service account keys and disable/delete any that are not necessary.
- Enable Org Policies: Use Organization Policies to block the creation of service account keys (
iam.disableServiceAccountKeyCreation).

