Skip to main content

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

  1. Use Application Default Credentials (ADC): This should be the default for all GCP services.
  2. Implement Workload Identity: Use this for GKE to map Kubernetes Service Accounts to GCP Service Accounts securely.
  3. Avoid Service Account Keys: Do not create or download service account keys. Use IAM roles to grant permissions to services directly.
  4. Store Secrets in Secret Manager: For any secrets you must use (like third-party API keys), store them in GCP Secret Manager.
  5. Enable API Key Restrictions: Restrict API keys to specific IP addresses, HTTP referrers, or services.
  6. Implement VPC Service Controls: Create perimeters to prevent data exfiltration.
  7. Use Short-Lived Access Tokens: Use the IAM Credentials API to mint short-lived tokens instead of using static keys.
  8. Audit Key Usage: Regularly audit all service account keys and disable/delete any that are not necessary.
  9. Enable Org Policies: Use Organization Policies to block the creation of service account keys (iam.disableServiceAccountKeyCreation).