Branch-planner authorized integration JWT rejected: token is malformed / access token does not exist #2

Closed
opened 2026-11-17 15:58:51 +00:00 by ginjiruu · 1 comment
Owner

Symptom

Since 2026-11-16 23:48Z, every Forgejo API call made with the branch-planner Authorized Integration auth is rejected. Observed in the automation namespace workflow pods (create-k8s-resources-in-repo*, add-deploykey + generate-manifests steps), which authenticate through our fork's forgejo provider using the tokenFile mechanism (internal/git/provider/options.go:152-162, reads the projected token per call).

Forgejo error responses:

authorized integration: parse JWT error: token is malformed: token contains an invalid number of segments
access token does not exist [sha: <redacted>]

Both signatures in the same response means Forgejo tried the authorized-integration JWT path (content is not a JWT at all, 0/2 segments) and the access-token path (sha no longer on the server).

Context

  • Forgejo upgraded to 17 with Authorized Integrations live on 2026-11-15; two integrations were provisioned: tofu and tofu-planner.
  • First failures land ~36h after the upgrade, right around the 2026-11-16 router cutover (which may be coincidence or may have triggered the first workflow runs after the upgrade).
  • The branch-planner pod itself (flux-system-tofu-controller-branch-planner) is running but has its own open comment-id bug; this issue is specifically the JWT being rejected, which currently also breaks the automation namespace workflows.

Suspects, in order

  1. The provider secret in use by the automation workflows carries a static non-JWT value in token (or an empty tokenFile target): projected SA token not mounted, mounted empty, or wrong path.
  2. The projected SA token audience no longer matches what the tofu-planner Authorized Integration expects after the Forgejo 17 migration (audience/token_endpoint re-saved with different values).
  3. The integration token with sha was dropped server-side during the upgrade, and whatever still references it needs re-pointing.

Repro / verify checklist

  • Identify which secret the failing workflows' provider config uses; inspect its keys (token vs tokenFile) without dumping values.
  • If tokenFile: exec into a workflow pod, check the file exists and head -c 20 starts with eyJ (a JWT).
  • On Forgejo: check the tofu-planner authorized integration's token audience and regenerate the integration token if needed.
  • Re-trigger one create-k8s-resources-in-repo workflow; the RBAC gap in the same pods (workflowtaskresults, fixed separately in flux-clusters) should be merged first so the workflow can report results.

Search keywords: authorized integration jwt token malformed segments branch planner automation workflows.

## Symptom Since 2026-11-16 23:48Z, every Forgejo API call made with the branch-planner Authorized Integration auth is rejected. Observed in the `automation` namespace workflow pods (`create-k8s-resources-in-repo*`, add-deploykey + generate-manifests steps), which authenticate through our fork's forgejo provider using the `tokenFile` mechanism (internal/git/provider/options.go:152-162, reads the projected token per call). Forgejo error responses: ``` authorized integration: parse JWT error: token is malformed: token contains an invalid number of segments access token does not exist [sha: <redacted>] ``` Both signatures in the same response means Forgejo tried the authorized-integration JWT path (content is not a JWT at all, 0/2 segments) and the access-token path (sha no longer on the server). ## Context - Forgejo upgraded to 17 with Authorized Integrations live on 2026-11-15; two integrations were provisioned: `tofu` and `tofu-planner`. - First failures land ~36h after the upgrade, right around the 2026-11-16 router cutover (which may be coincidence or may have triggered the first workflow runs after the upgrade). - The branch-planner pod itself (`flux-system-tofu-controller-branch-planner`) is running but has its own open comment-id bug; this issue is specifically the JWT being rejected, which currently also breaks the automation namespace workflows. ## Suspects, in order 1. The provider secret in use by the automation workflows carries a static non-JWT value in `token` (or an empty `tokenFile` target): projected SA token not mounted, mounted empty, or wrong path. 2. The projected SA token audience no longer matches what the `tofu-planner` Authorized Integration expects after the Forgejo 17 migration (audience/token_endpoint re-saved with different values). 3. The integration token with sha <redacted> was dropped server-side during the upgrade, and whatever still references it needs re-pointing. ## Repro / verify checklist - Identify which secret the failing workflows' provider config uses; inspect its keys (`token` vs `tokenFile`) without dumping values. - If tokenFile: exec into a workflow pod, check the file exists and `head -c 20` starts with `eyJ` (a JWT). - On Forgejo: check the `tofu-planner` authorized integration's token audience and regenerate the integration token if needed. - Re-trigger one `create-k8s-resources-in-repo` workflow; the RBAC gap in the same pods (workflowtaskresults, fixed separately in flux-clusters) should be merged first so the workflow can report results. Search keywords: authorized integration jwt token malformed segments <redacted> branch planner automation workflows.
Author
Owner

Root cause

This was not a tofu-controller bug. The tokenFile path in the fork works as designed.

  • The failing pods (create-k8s-resources-in-repo*, steps add-deploykey and create-pr) are plain curl containers. They sent a static PAT from automation/automation-workflow-merge-secret (key token). Forgejo no longer had that PAT. It tried every auth method on the string and rejected it, so the error listed the JWT parse failure next to "access token does not exist". The [sha: ...] in that message is the raw token the client sent, not a hash. It has been redacted from the handoff doc and should be treated as leaked.
  • That secret comes from ESO via ClusterSecretStore vault-backend (mini's in-cluster Vault). The Vault was sealed after the mini power cycle, so all 49 ExternalSecrets on that store were stale. It has been unsealed, the store revalidated, and 48 of 49 synced. forgejo/vault-example has an older, unrelated ownership conflict.
  • The branch planner was fine: projected SA token, audience u:263:..., no auth errors in its logs.

Fix

  • lab/iac #136, #137, #138 (forgejo-identity): new machine user argo-automation. It has write on lab/automation and lab/dev-apps-source, and an admin team argo-automation on dev-applications (adding deploy keys needs repo admin). Its Authorized Integration was created with the Forgejo CLI: issuer https://kubernetes.default.svc.cluster.local, sub = system:serviceaccount:automation:automation-kubetenantsetup, scope write:repository, audience u:264:5d9f72bb-b8ce-4542-9c3c-167de30002ad.
  • lab/automation #16: the create-k8s-repo-resources-in-repo WorkflowTemplate now mounts a projected SA token with that audience and calls curl --fail-with-body. The PAT is no longer used. Nothing syncs this repo to mini (the old Argo CD annotation is stale), so the template was applied with kubectl apply.

Verified

A workflow from the template with entrypoint add-deploykey against dev-applications/gofantasy authenticated through the integration and reached Forgejo's duplicate-key check (422 "This key has already been added"), which needs repo admin. The smoke workflow was deleted afterwards.

Follow-ups

  • Remove the dead token key from Vault path automation-workflow-merge-secret. The template no longer reads it.
  • Nothing deploys lab/automation to mini. That needs a Flux source or a decision to apply by hand.
  • mini's Vault needs a manual Shamir unseal after every reboot, and it took down ESO for every namespace on that store.
## Root cause This was not a tofu-controller bug. The `tokenFile` path in the fork works as designed. - The failing pods (`create-k8s-resources-in-repo*`, steps `add-deploykey` and `create-pr`) are plain `curl` containers. They sent a static PAT from `automation/automation-workflow-merge-secret` (key `token`). Forgejo no longer had that PAT. It tried every auth method on the string and rejected it, so the error listed the JWT parse failure next to "access token does not exist". The `[sha: ...]` in that message is the raw token the client sent, not a hash. It has been redacted from the handoff doc and should be treated as leaked. - That secret comes from ESO via ClusterSecretStore `vault-backend` (mini's in-cluster Vault). The Vault was sealed after the mini power cycle, so all 49 ExternalSecrets on that store were stale. It has been unsealed, the store revalidated, and 48 of 49 synced. `forgejo/vault-example` has an older, unrelated ownership conflict. - The branch planner was fine: projected SA token, audience `u:263:...`, no auth errors in its logs. ## Fix - lab/iac #136, #137, #138 (`forgejo-identity`): new machine user `argo-automation`. It has write on `lab/automation` and `lab/dev-apps-source`, and an admin team `argo-automation` on `dev-applications` (adding deploy keys needs repo admin). Its Authorized Integration was created with the Forgejo CLI: issuer `https://kubernetes.default.svc.cluster.local`, `sub` = `system:serviceaccount:automation:automation-kubetenantsetup`, scope `write:repository`, audience `u:264:5d9f72bb-b8ce-4542-9c3c-167de30002ad`. - lab/automation #16: the `create-k8s-repo-resources-in-repo` WorkflowTemplate now mounts a projected SA token with that audience and calls `curl --fail-with-body`. The PAT is no longer used. Nothing syncs this repo to mini (the old Argo CD annotation is stale), so the template was applied with `kubectl apply`. ## Verified A workflow from the template with entrypoint `add-deploykey` against `dev-applications/gofantasy` authenticated through the integration and reached Forgejo's duplicate-key check (422 "This key has already been added"), which needs repo admin. The smoke workflow was deleted afterwards. ## Follow-ups - Remove the dead `token` key from Vault path `automation-workflow-merge-secret`. The template no longer reads it. - Nothing deploys `lab/automation` to mini. That needs a Flux source or a decision to apply by hand. - mini's Vault needs a manual Shamir unseal after every reboot, and it took down ESO for every namespace on that store.
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
lab/tofu-controller#2
No description provided.