Charlie Roffe

Principal Architect & Engineering Director · Cloud & AI

Madrid, Spain · LinkedIn · GitHub

ADR-043: A Bootstrap Stack and Least-Privilege CI Identity

Context

The pipeline stands on resources that were created by hand and documented only as gcloud commands: the bucket holding every stack's Terraform state, the workload identity pool and GitHub provider, and the deployer service account with its twelve project roles. A review on 2026-10-30 found two problems.
* The state could not be rolled back: object versioning, uniform bucket-level access and public access prevention were all off.
* Any workflow run could become the deployer: its binding trusted every job in the repository, on any branch or event. The PR plan ran a pull request's own Terraform with rights to grant itself anything, and the drift check and the release preview used the same account for read-only work. The AI evals account had the same binding.

Decision

1. A separately applied bootstrap stack (terraform/bootstrap/) declares the state bucket, the pool and provider, the deployer and its roles, and a read-only planner. It adopts what exists with import blocks, keeps its state in the same bucket under its own prefix, and is applied by a human with owner credentials, never by CI. The bucket is versioned and keeps the 20 most recent earlier generations of each object.
2. Bindings by trigger, not by repository. The provider maps the ref, environment and event claims, plus "<event>:<ref>" with every v* tag collapsed to one value. The deployer accepts only pushes to main, manual runs on main, v* tag pushes and the production environment; the AI evals account only its schedule and manual runs on main.
3. A read-only planner, tf-planner, runs the PR plan, the drift check and the release preview: project viewer, IAM policy reads, state read, budget read, and access to only the placeholder version Terraform wrote for each runtime secret, never the real values.
4. Plans run without a state lock, because writing the lock would mean create and delete rights on the state bucket.

Amended 2026-10-31: the provider no longer trusts the repository name alone, which could be reclaimed by someone else if the account or repository were deleted or renamed. It also requires the immutable numeric repository and owner IDs that GitHub puts in every token (1247159083 and 122574).

Consequences

Benefits:
* A pull request's Terraform can read the project but change nothing; deploy credentials exist only for code on main, a release tag or the production environment.
* State can be restored from an earlier generation.
* A plan of the bootstrap stack shows any console edit to the foundation, and a test ties every job that authenticates to GCP to the binding that must accept it.

Trade-offs:
* A new deployer permission means applying the bootstrap stack by hand before the release that needs it.
* The planner can read all state, and an unlocked plan can show a stale diff during an apply.
* The deployer's own roles are still broad; this limits who becomes the deployer, not what it can do.

Amended 2026-11-01: the deployer's roles were narrowed. Project IAM admin is kept only under a condition that allows granting or revoking the five roles the stacks grant; service account admin now applies to the three runtime accounts only, so the deployer can no longer change who may act as itself; project-wide act-as is gone (each runner account grants it); Secret Manager admin became a custom role on the six runtime secrets with no access to their values, plus read of the placeholder version; and Storage admin became object read and write on the state bucket, which the deployer can no longer reconfigure or delete. Still open: the deployer can grant itself one of those five roles, and the state objects themselves are writable.

Alternatives considered

1. Letting the dev stack manage the deployer and the pool: Rejected — the deployer would apply its own grants and could revoke them mid-apply.
2. Binding on the token subject: Rejected — an environment replaces the ref in the subject, and tags would need one binding per version.
3. A pool-wide ref restriction: Rejected — it applies to every account, and pull request plans need a token too.
4. Lock access for the planner: Rejected for now — create and delete on the state bucket for any pull request, to avoid a harmless stale diff.
5. Full secret access for the planner: Rejected — it would read the real values; the condition reads only what Terraform wrote.

Architecture Decision Records