Repository navigation
fix(ci): a job-level env: shadows $GITHUB_ENV, so the prod Cloudflare token never applied - #919
Merged
Merged
Conversation
… token never applied Two Cloudflare credential mechanisms landed within nine minutes of each other and collided. #912 set `CLOUDFLARE_API_TOKEN` as a job-level `env:` from the `infra-apply-core` Environment secret; #911 added a step exporting it from Secrets Manager for the prod leg. A job-level `env:` takes precedence over `$GITHUB_ENV`, so the value that is empty on the prod leg shadowed the token the step had just written — and `apply (prod)` failed with Cloudflare `9106`, no authorization header at all, on the line after the export step reported success. Precedence was the bug, not the fetch. Verified the fetch itself is sound: the step logged `exported CLOUDFLARE_API_TOKEN ... (53 chars)`, and the same token with an empty `provider "cloudflare" {}` block authenticates locally against provider 5.28.1 — the version CI locks — returning the zone name. #912's reasoning was correct when written. It says the value is "empty on dev and prod, which need no Cloudflare credential", and that stopped being true the moment envs/prod got DNS records. TWO TOKENS, NOT ONE, and this is the part worth keeping. core creates an R2 bucket and needs `Workers R2 Storage: Edit` on the ACCOUNT; prod writes DNS and needs `Zone DNS: Edit` on ONE zone. Measured: the zone-scoped token returns `9109` on `/accounts/<id>` and `10000` on `/accounts/<id>/r2/buckets`, so it cannot do core's work, and a shared token would have to carry both scopes and be strictly broader than either leg needs. So: one variable, one setter, source chosen per leg. The script takes the Environment secret when it is non-empty (core) and falls through to Secrets Manager otherwise (prod), and it is the only thing in the workflow that assigns `CLOUDFLARE_API_TOKEN`. Both branches are self-tested, including that the fall-through FAILS rather than silently exporting nothing, and that a token pasted with a trailing newline is trimmed — untrimmed it would ride into the Authorization header and fail exactly like an absent one. This does not fix `apply (core)`, which fails the same way for its own reason: its Environment secret exists and is populated, but the value does not authenticate. That is #910/#912's to resolve and it was already failing on its own merge, before this. No ticket: this reconciles two merged pull requests rather than adding scope. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
1 of 12 tasks
Contributor
terraform plan
Warning This plan DESTROYS resources in: core. Merging applies it unattended. core — 0 to add, 0 to change, 2 to DESTROYdata.aws_caller_identity.current: Reading...
data.aws_iam_policy_document.ci_tf_plan_state: Reading...
data.aws_iam_policy_document.ci_tf_plan_state: Read complete after 0s [id=2883378100]
data.aws_iam_policy_document.obs_pod_trust: Reading...
data.aws_iam_policy_document.obs_pod_trust: Read complete after 0s [id=819195744]
data.aws_iam_policy_document.ci_tf_apply_no_prod_state: Reading...
data.aws_iam_policy_document.ci_tf_apply_no_prod_state: Read complete after 0s [id=2395007408]
data.aws_iam_policy_document.ci_tf_drift_refresh: Reading...
data.aws_iam_policy_document.ci_tf_drift_refresh: Read complete after 0s [id=2350222434]
module.github_oidc.data.aws_iam_policy_document.trust: Reading...
module.identity_center.data.aws_ssoadmin_instances.this: Reading...
data.aws_caller_identity.current: Read complete after 0s [id=797781631727]
module.github_oidc.data.aws_iam_policy_document.trust: Read complete after 0s [id=4060172364]
data.aws_iam_policy_document.openobserve: Reading...
data.aws_iam_policy_document.openobserve: Read complete after 0s [id=2662704728]
data.aws_iam_policy_document.audit_bucket: Reading...
data.aws_iam_policy_document.audit_bucket: Read complete after 0s [id=3031279952]
data.aws_iam_policy_document.sccache_trust_write: Reading...
data.aws_iam_policy_document.cur_delivery: Reading...
data.aws_iam_policy_document.sccache_trust_write: Read complete after 0s [id=4060172364]
data.aws_iam_policy_document.ci_tf_drift_trust: Reading...
data.aws_iam_policy_document.ci_tf_apply_trust: Reading...
data.aws_iam_policy_document.sccache_trust_read: Reading...
data.aws_iam_policy_document.ci_tf_drift_trust: Read complete after 0s [id=2357770959]
data.aws_iam_policy_document.cur_delivery: Read complete after 0s [id=2207400467]
data.aws_iam_policy_document.ci_tf_apply_trust: Read complete after 0s [id=2538345208]
data.aws_iam_policy_document.sccache_trust_read: Read complete after 0s [id=1630650595]
data.aws_iam_policy_document.ci_tf_plan_trust: Reading...
data.aws_iam_policy_document.ci_tf_plan_trust: Read complete after 0s [id=1630650595]
data.aws_iam_policy_document.sccache_write: Reading...
data.aws_iam_policy_document.sccache_write: Read complete after 0s [id=786296009]
data.aws_iam_policy_document.sccache_read: Reading...
data.aws_iam_policy_document.sccache_read: Read complete after 0s [id=2701062528]
module.github_oidc.data.aws_iam_policy_document.push: Reading...
data.aws_iam_policy_document.config_bucket: Reading...
module.github_oidc.data.aws_iam_policy_document.push: Read complete after 0s [id=2177873069]
data.aws_iam_policy_document.config_bucket: Read complete after 0s [id=4067691321]
data.aws_iam_policy_document.ci_tf_apply_prod_trust: Reading...
data.aws_iam_policy_document.ci_tf_apply_prod_trust: Read complete after 0s [id=3513372776]
module.identity_center.data.aws_ssoadmin_instances.this: Read complete after 0s [id=us-east-2]
module.identity_center.data.aws_identitystore_user.admin: Reading...
module.identity_center.data.aws_identitystore_user.admin: Read complete after 1s [id=b17b2500-e0b1-7046-405b-23c088cf392b]
Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
- destroy
Terraform will perform the following actions:
# cloudflare_r2_bucket.sccache[0] will be destroyed
# (because index [0] is out of range for count)
- resource "cloudflare_r2_bucket" "sccache" {
- account_id = "9eefbe6bc92d11b2bb4e962494765a4c" -> null
- creation_date = "2026-11-08T20:59:18.644Z" -> null
- id = "er-ci-sccache" -> null
- jurisdiction = "default" -> null
- location = "enam" -> null
- name = "er-ci-sccache" -> null
- storage_class = "Standard" -> null
}
# cloudflare_r2_bucket_lifecycle.sccache[0] will be destroyed
# (because index [0] is out of range for count)
- resource "cloudflare_r2_bucket_lifecycle" "sccache" {
- account_id = "9eefbe6bc92d11b2bb4e962494765a4c" -> null
- bucket_name = "er-ci-sccache" -> null
- jurisdiction = "default" -> null
- rules = [
- {
- abort_multipart_uploads_transition = {
- condition = {
- max_age = 86400 -> null
- type = "Age" -> null
} -> null
} -> null
- conditions = {
# (1 unchanged attribute hidden)
} -> null
- delete_objects_transition = {
- condition = {
- max_age = 1209600 -> null
- type = "Age" -> null
} -> null
} -> null
- enabled = true -> null
- id = "expire-cache-objects" -> null
},
] -> null
}
Plan: 0 to add, 0 to change, 2 to destroy.
Changes to Outputs:
- r2_sccache_bucket = "er-ci-sccache" -> null
- r2_sccache_endpoint = "https://9eefbe6bc92d11b2bb4e962494765a4c.r2.cloudflarestorage.com" -> null
Warning: Resource Destruction Considerations
with cloudflare_r2_bucket_lifecycle.sccache[0],
on r2.tf line 96, in resource "cloudflare_r2_bucket_lifecycle" "sccache":
96: resource "cloudflare_r2_bucket_lifecycle" "sccache" {
Applying this resource destruction will remove the resource from the
Terraform state but will not change it in the API. If you would like to
destroy or reset this resource in the API, refer to the documentation for how
to do it manually.
|
This was referenced Nov 8, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Stop setting
CLOUDFLARE_API_TOKENas a job-levelenv:, and make one script the only thing that sets it — taking theinfra-apply-coreEnvironment secret on the core leg and falling through to Secrets Manager on the prod leg.Why
Two credential mechanisms landed nine minutes apart and collided. #912 set
CLOUDFLARE_API_TOKENas a job-levelenv:; #911 added a step exporting it from Secrets Manager for prod. A job-levelenv:takes precedence over$GITHUB_ENV, so the value that is empty on the prod leg shadowed the token the step had just written:Precedence was the bug, not the fetch. #912's reasoning was right when written — it says the value is "empty on dev and prod, which need no Cloudflare credential" — and that stopped being true the moment
envs/prodgot DNS records.Two tokens, not one, and that part is deliberate.
corecreates an R2 bucket and needsWorkers R2 Storage: Editon the account;prodwrites DNS and needsZone DNS: Editon one zone. Measured — the zone-scoped token returns9109on/accounts/<id>and10000on/accounts/<id>/r2/buckets— so it cannot do core's work, and a shared token would carry both scopes and be broader than either leg needs. So the fix is one variable with a per-leg source, not one token.Proof
python3 -c "yaml.safe_load(...)"parses;CLOUDFLARE_API_TOKENnow appears in noenv:block.workflow-shell-checkandscripts-home-checkclean.Self-tested both script branches, including the negative:
The trimming is not cosmetic: a token pasted into a secret with a trailing newline rides into the
Authorizationheader and fails exactly like an absent one.Risk & rollback
Risk: low, and it un-breaks
apply (prod). The core leg's source is unchanged. Rollback:git revert, which restores the shadowing.This does not fix
apply (core), which fails the same way for its own reason: its Environment secret exists and is populated (***in the log) but the value does not authenticate. That is #910/#912's, and it was already failing on its own merge before this.Post-merge ledger
Closed by: agent · session
a7f03c6d-206a-4ae3-a5c3-1c2f74052399onMac· 2026-11-08T21:20:00Zmainis green with this change on it — this ISmain's head,7cfeafc8.rustrun 42523297782 success, 23 jobs, zero failures;infra,frontend,devcontaineranddeployon the same SHA also success.images—n/a — a workflow file and a CI script; no image inputs changed.deploy—n/a — nothing to deploy from this change.deployis nonetheless green on this SHA, independently: feat(tags): reserved system tags, per-tag permission, tags in export (#805) #875's schema fixup landed, ending the run of red deploys that began at350cd213.infrarun 42523297838:apply (core),apply (dev)andapply (prod)all success, the first fully-green infra apply sincebe64c41e.n/a —no-ticket.This reconciles two merged pull requests rather than closing a card.env:-precedence rule is stated twice where it will be read: ininfra.ymlat the exact spot the shadowing value used to sit, and inscripts/ci/tf-cloudflare-token.sh's header as the reason the script must be called from a step. Plus thewaf-rate-rule-needs-warmupmemory from verifying the result.Specific to this change
apply (prod)succeeded, and the threecloudflare_dns_recordrefreshes that previously returned9106now pass. That is the direct evidence the shadowing is gone.list-web-acls→er-prod-edge;get-web-acl-for-resourceon the ALB →er-prod-edge. Blocking confirmed live: 60× 403 on/api/auth/loginagainst 5× 503 on/from the same address.apply (core)is still red for its own reason —n/a — it is not red any more, and this change is why.It went green in the same run. The predicted cause was right: that Environment secret's value carried trailing whitespace, and this change trims the token before exporting it, so core's token now authenticates without anyone re-setting the secret. Reported on infra(core): declare the R2 sccache bucket and its lifecycle rule #912 with the evidence.env:precedence is written down — see the box above. Deliberately in the workflow rather than only in memory: the next person to add a credential to this file will be editing thatenv:block, which is where the warning now sits.Context — plan, discoveries, measurements, files
Discoveries
env:silently beats$GITHUB_ENV. The export step succeeds, logs a plausible success line, and the variable the next step sees is the shadowing one. Nothing warns. The only way I found it was reading the failing step's ownenv:listing in the raw log and seeingCLOUDFLARE_API_TOKEN:with nothing after the colon.plansucceeding proves nothing about a credential when the resources are new.apply (core)'s plan passed and its apply failed on the first real API call, becauseplanmakes no provider call for a resource thatwill be created. So "plan was fine, apply broke" is not evidence of flakiness here.9106that theinfra-apply-coreEnvironment secret had never been created. It exists —gh api .../environments/infra-apply-core/secretslists it, and the log shows it resolving as***. The real state is that it is populated and does not authenticate, which is a different problem with a different owner.mainthree commits stale, which is why an earlier grep forcloudflareacrossinfra/missedenvs/core/r2.tfentirely and I initially believed prod was the only Cloudflare consumer.Measurements
Files
.github/workflows/infra.yml— the job-levelenv:removed with a note where it was, the step generalised to both legs, the header's one-credential claim corrected to twoscripts/ci/tf-cloudflare-token.sh— per-leg source selection, trimming, and the fail-closed fall-through