fix: support GCP metadata authentication in workerd - #1815
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed September 4, 2026, 9:09 AM ET / 13:09 UTC. ClawSweeper reviewWhat this changesThe PR changes GCP metadata token fetching to use workerd-supported manual redirects and explicitly rejects every redirect response before reading or using it. Merge readiness✅ Ready for maintainer review Keep open: current main still uses the unsupported workerd redirect mode, while this focused fix preserves the metadata-token trust boundary and includes sufficient native-runtime proof. Priority: P2 Review scores
Verification
How this fits togetherCrabbox’s Worker-side GCP client obtains a token from either a service-account key or the instance metadata service, then uses it for Compute API calls. Metadata responses must remain Google-marked and must never redirect token processing to another destination. flowchart LR
A[GCP credential settings] --> B[GCP client]
B --> C[Metadata token request]
C --> D{Redirect response?}
D -->|yes| E[Reject untrusted response]
D -->|no| F[Validate Google marker]
F --> G[Cache token]
G --> H[Compute API request]
Before mergeNone. Agent review detailsSecurityNone. Review metrics
Technical reviewBest possible solution: Land the narrow manual-redirect implementation and retain the explicit pre-body, non-retried rejection of all metadata 3xx responses. Do we have a high-confidence way to reproduce the issue? Yes. Current main’s metadata request uses Is this the best way to solve the issue? Yes. Manual redirect handling with an immediate fail-closed 3xx check restores workerd compatibility without accepting a redirected metadata response or changing token-cache and retry policy. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 9f1b19a89ffe. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Merged as 8165fa3; the landed tree matches the verified combined-main preview. The metadata loader previously requested Fetch redirect mode Native workerd A/B proof exercised the real GCPClient authentication path with synthetic metadata/Compute upstreams and no fetch override or preloaded cache: baseline failed after 59 seconds with zero requests; the candidate authenticated, rejected 302/307/308 without following them, rejected missing markers, and recovered from a transient 503. All runtimes were disposed. Full Worker tests and static/build/docs checks passed; all exact-head substantive checks passed without reruns. The final main readback contains the documented fix and changelog entry. This proof does not claim a production GCP account deployment. |
Summary
GCP metadata authentication passed
redirect: "error"to fetch. Node accepts that option, but workerd rejects it before sending a request; the existing transient-error handler then retried an unsupported option for almost a minute.Use workerd-supported manual redirect handling and reject every 300–399 response with the existing non-retried trust error before inspecting its marker or body. The endpoint, Google request/response markers, token cache, timeout, service-account path, and legitimate transient retry policy stay unchanged. Redirect destinations and token-looking bodies are never used.
Verification
The regression fails on unchanged main. Full Worker suite: 2,516 passed, 3 skipped. TypeScript, lint, formatting, Worker dry-run build, docs build, and diff checks passed. Tests cover 300/399 boundaries, common redirects, a body-unread 304 without a marker, repeated rejection without caching, and existing healthy/concurrent/transient/deadline behavior. Managed Codex review and independent semantic review found no accepted findings.
Real
GCPClientauthentication ran in native workerd 2026-08-26, without a fetcher override, preloaded token cache, or patched clock, against strictly synthetic metadata/Compute responses:Both runtimes were disposed. This proves the actual runtime transport and refusal behavior with synthetic upstreams; it is not live GCP IAM, attached-service-account, or cloud-lifecycle proof. No dependency, configuration, credentials, production deployment, or cloud resource changes are required. Changelog and provider documentation are updated.