Most early cloud incidents come from two avoidable things: a leaked key and a public bucket. Both can be blocked centrally with Google Cloud organisation policies, managed in Terraform so the rule stays in place as the team grows.

Two Terraform Guardrails Every Startup Should Add on Day One Executive Briefing

Most early-stage cloud security breaches do not stem from sophisticated external exploits. They almost always result from two entirely preventable mistakes: a leaked service account JSON key accidentally committed to a public GitHub repository, or an object storage bucket inadvertently configured with public read permissions.

Rather than relying on developer discipline or manual code review, startups should enforce these boundaries centrally using Google Cloud Organisation Policies managed in Terraform. This guarantees that as new engineers join and new cloud projects are created, least-privilege guardrails remain permanently in place.


1. Disable Service Account Key Creation (iam.disableServiceAccountKeyCreation)

Exported service account JSON keys are long-lived administrative credentials that bypass multi-factor authentication (MFA) and conditional access rules. Once leaked, an attacker can maintain persistent access until the key is identified and manually revoked.

The Defensive Solution: Enforce the iam.disableServiceAccountKeyCreation constraint across your Google Cloud organisation or development projects. To authenticate CI/CD pipelines (such as GitHub Actions or GitLab CI), adopt Workload Identity Federation (WIF). WIF exchanges short-lived OIDC tokens directly with Google Cloud without storing static secrets anywhere in your repositories.

resource "google_org_policy_policy" "disable_sa_keys" {
  name   = "projects/${var.project_id}/policies/iam.disableServiceAccountKeyCreation"
  parent = "projects/${var.project_id}"

  spec {
    rules {
      enforce = "TRUE"
    }
  }
}

2. Enforce Public Access Prevention (storage.publicAccessPrevention)

Accidental data leakage via cloud storage remains one of the top findings in the CIS Google Cloud Foundations Benchmark. When developers create buckets for asset hosting or temporary backups, it is easy to inadvertently grant read access to allUsers or allAuthenticatedUsers.

The Defensive Solution: Apply the storage.publicAccessPrevention organisation policy. When enforced, this guardrail strictly blocks public ACLs or IAM bindings across all existing and newly created Cloud Storage buckets within the project.

resource "google_org_policy_policy" "enforce_storage_pap" {
  name   = "projects/${var.project_id}/policies/storage.publicAccessPrevention"
  parent = "projects/${var.project_id}"

  spec {
    rules {
      enforce = "TRUE"
    }
  }
}

Pragmatic Implementation Advice

Before applying these guardrails in production, enable the Organization Policy API (orgpolicy.googleapis.com) and verify existing pipelines in a staging project. If legacy deployment scripts still rely on downloaded JSON keys, migrate them to Workload Identity Federation first to avoid pipeline interruptions.

Want the complete foundation applied and hardened across your cloud estate?

Sachan & Partners helps growing startups, scale-ups and regulated suppliers implement production-grade cloud security baselines and automated Terraform guardrails.

Explore Cloud Security Guardrails
LIVE REFERENCEOpen the source article