fix(cypher): 改用 global_fetch_strictly_public flag 解 same-zone 1042(revert service binding)
richblack 拍板:service binding(前一 commit)靜態、加/改要重 deploy cypher,廢。
改用 global_fetch_strictly_public compatibility flag——cypher wrangler.toml 加一行,
讓 fetch() 走公網前門,self-hosted 的 same-zone fetch(cypher 與 auth 同在
{sub}.workers.dev zone)也能通。
- wrangler.toml:compatibility_flags 加 global_fetch_strictly_public(移除 SVC_AUTH_*)
- auth-dispatcher.ts / types.ts:還原到 service binding 之前(單純 fetch workers.dev)
- 安全(官方 docs):唯一副作用 self-loop 僅在 fetch 自己 hostname;cypher 不 self-loop
- 官方/self-host 共用同一份 toml:官方本就跨 zone 行為不變,self-host 被修好
- 規範還原:rule 02/03/CLAUDE.md/pre-bash-guard 的 service binding 禁令維持原狀
SDD: credential-primitives-wasm Phase 7(A→廢→B)。tsc exit 0。
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -20,23 +20,10 @@
|
||||
import type { Bindings } from '../types';
|
||||
import { resolveAuthRecipe, resolveRecipe } from '../routes/recipes';
|
||||
import { wasmWorkerUrl } from '../lib/component-loader';
|
||||
import type { ServiceBinding } from '../types';
|
||||
|
||||
/** 對應 Phase 1-4 會部署的 auth primitive Worker */
|
||||
const SUPPORTED_PRIMITIVES = new Set(['static_key', 'service_account', 'oauth2']);
|
||||
|
||||
/**
|
||||
* primitive 名 → service binding key(Phase 7,2026-06-06)。
|
||||
* 比照 component-loader 的邏輯零件:有 binding 走 CF 內部 RPC(繞開同 zone 522 + 同帳號 workers.dev 1042),
|
||||
* 無 binding(如 self-hosted 未綁、或 mtls 未部署)fallback 到 fetch(workers.dev)。
|
||||
*/
|
||||
const AUTH_BINDING_MAP: Record<string, keyof import('../types').Bindings> = {
|
||||
static_key: 'SVC_AUTH_STATIC_KEY',
|
||||
service_account: 'SVC_AUTH_SERVICE_ACCOUNT',
|
||||
oauth2: 'SVC_AUTH_OAUTH2',
|
||||
mtls: 'SVC_AUTH_MTLS',
|
||||
};
|
||||
|
||||
/** auth primitive 本身的 componentId(避免自引用) */
|
||||
const AUTH_PRIMITIVE_IDS = new Set([
|
||||
'auth_static_key',
|
||||
@@ -75,27 +62,18 @@ export async function tryAuthDispatch(
|
||||
if (!recipe) return null;
|
||||
if (!SUPPORTED_PRIMITIVES.has(recipe.primitive)) return null;
|
||||
|
||||
// 呼叫對應 auth primitive Worker(Phase 7,2026-06-06):
|
||||
// binding 優先(CF 內部 RPC,繞開同 zone 522 + 同帳號 workers.dev 子請求 1042,壓測階段 11),
|
||||
// 無 binding(self-hosted 未綁 / mtls 未部署)fallback 到 fetch(workers.dev)。比照 component-loader makeLogicRunner。
|
||||
const reqInit = {
|
||||
// 走新路徑:HTTP POST 到對應 auth primitive Worker
|
||||
// 走 workers.dev 避開同 zone 死鎖(P0 #9)
|
||||
const primitiveUrl = wasmWorkerUrl(`auth_${recipe.primitive}`, env.WORKER_SUBDOMAIN);
|
||||
const res = await fetch(primitiveUrl, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ action: 'authenticate', api_key: apiKey, service }),
|
||||
};
|
||||
|
||||
const bindingKey = AUTH_BINDING_MAP[recipe.primitive];
|
||||
const svc = bindingKey ? (env[bindingKey] as ServiceBinding | undefined) : undefined;
|
||||
|
||||
let res: Response;
|
||||
if (svc) {
|
||||
// service binding:用任意 URL,CF 內部 RPC 直送目標 Worker(不經公網)
|
||||
res = await svc.fetch(new Request('https://auth-primitive/', reqInit));
|
||||
} else {
|
||||
// fallback:公網 workers.dev(自架未綁 binding / 開發環境 / mtls)
|
||||
const primitiveUrl = wasmWorkerUrl(`auth_${recipe.primitive}`, env.WORKER_SUBDOMAIN);
|
||||
res = await fetch(primitiveUrl, reqInit);
|
||||
}
|
||||
body: JSON.stringify({
|
||||
action: 'authenticate',
|
||||
api_key: apiKey,
|
||||
service,
|
||||
}),
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
const text = await res.text().catch(() => '');
|
||||
|
||||
Reference in New Issue
Block a user