Skip to content

Sign workload tokens across a key creation or rotation race - #261

Merged
tnkuehne merged 1 commit into
mainfrom
fix/workload-key-boundary
Nov 21, 2026
Merged

tnkuehne merged 1 commit into
mainfrom
fix/workload-key-boundary

Conversation

@tnkuehne

@tnkuehne tnkuehne commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Problem

workloadKeys reads the clock once per call. If another call creates or rotates the key ring during the read, the first call can see a ring whose next key activates a second after its own clock:

  • On creation: the new ring's first key activates at the creating call's time, so the slower call finds no active key.
  • On rotation: the rotating call has already removed the old key's private key, so the slower call finds its active key unusable.

Either way the call fails with No active workload signing key (409). This can happen once on first use and then around every rotation (every 30 days). It is also why issues app and service tokens … including concurrent cold calls sometimes fails on main.

Fix

If no key with a private key is active yet for the call's clock, it signs with the earliest key that has one. That key has been in the JWKS since it was generated, so receivers verify the token.

Tests

  • New unit test for both cases. It fails without the fix.
  • pnpm check passes.

RetriggerView in GreptileConfidence Score: 5/5 Tier: plus

The PR appears safe to merge; no actionable issues were found.

Summary

Updates workloadKeys to select the earliest key with a private key when a concurrent call has created or rotated the ring ahead of the caller’s clock.

  • Workload tokens keep signing when a key-ring update races the clock.

Tests were reviewed, not run.

Reviews (1) · Last reviewed commit: "Sign workload tokens across a key creati..." · Reviewed by Greptile

A call that read the clock just before another call created or rotated
the key ring found no active signing key and failed with 409. It now
signs with the next key, which is already published.
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
widefleet-docs 3613913 Nov 21 2026, 01:18 PM

@tnkuehne
tnkuehne merged commit 53b995c into main Nov 21, 2026
16 checks passed
@tnkuehne
tnkuehne deleted the fix/workload-key-boundary branch November 21, 2026 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant