-
Notifications
You must be signed in to change notification settings - Fork 1k
feat(release-service): isolate verification egress #1988
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ascorbic
merged 5 commits into
feat/delegated-release-service
from
feat/delegated-release-service-16-verifier-worker
Jul 13, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c494fc0
feat(release-service): isolate verification egress
ascorbic 67ba3c9
fix(release-service): bound verifier RPC responses
ascorbic 5559194
Merge remote-tracking branch 'origin/feat/delegated-release-service' …
ascorbic 97afb8c
fix(release-service): preserve verifier error codes
ascorbic 638f9df
chore(release-service): remove unused dependency
ascorbic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@emdash-cms/registry-verification": minor | ||
| --- | ||
|
|
||
| Adds a Worker-safe safe-fetch entry point for isolated resource verification. |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| type VerifierMethod = "fetchArtifact" | "fetchProvenance"; | ||
|
|
||
| export type ReleaseVerifierResult = | ||
| | { success: true; value: Uint8Array } | ||
| | { success: false; error: { code: string; message: string } }; | ||
|
|
||
| export interface ReleaseVerifierBinding { | ||
| fetchArtifact(url: string): Promise<unknown>; | ||
| fetchProvenance(url: string): Promise<unknown>; | ||
| } | ||
|
|
||
| export class VerifierUnavailableError extends Error { | ||
| readonly retryable = true; | ||
|
|
||
| constructor(options?: ErrorOptions) { | ||
| super("Release verifier is unavailable", options); | ||
| this.name = "VerifierUnavailableError"; | ||
| } | ||
| } | ||
|
|
||
| export async function fetchArtifact( | ||
| binding: ReleaseVerifierBinding, | ||
| url: string, | ||
| ): Promise<ReleaseVerifierResult> { | ||
| return callVerifier(binding, "fetchArtifact", url); | ||
| } | ||
|
|
||
| export async function fetchProvenance( | ||
| binding: ReleaseVerifierBinding, | ||
| url: string, | ||
| ): Promise<ReleaseVerifierResult> { | ||
| return callVerifier(binding, "fetchProvenance", url); | ||
| } | ||
|
|
||
| async function callVerifier( | ||
| binding: ReleaseVerifierBinding, | ||
| method: VerifierMethod, | ||
| url: string, | ||
| ): Promise<ReleaseVerifierResult> { | ||
| try { | ||
| const result = await binding[method](url); | ||
| if (!isVerificationResult(result)) { | ||
| throw new TypeError("Release verifier returned an invalid response"); | ||
| } | ||
| return result; | ||
| } catch (error) { | ||
| if (error instanceof VerifierUnavailableError) throw error; | ||
| throw new VerifierUnavailableError({ cause: error }); | ||
| } | ||
| } | ||
|
|
||
| function isVerificationResult(value: unknown): value is ReleaseVerifierResult { | ||
| if (!isRecord(value) || typeof value["success"] !== "boolean") return false; | ||
| if (value["success"] === true) return value["value"] instanceof Uint8Array; | ||
| return isVerificationError(value["error"]); | ||
| } | ||
|
|
||
| function isVerificationError(value: unknown): value is { code: string; message: string } { | ||
| return ( | ||
| isRecord(value) && typeof value["code"] === "string" && typeof value["message"] === "string" | ||
| ); | ||
| } | ||
|
|
||
| function isRecord(value: unknown): value is Record<string, unknown> { | ||
| return value !== null && typeof value === "object" && !Array.isArray(value); | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import { WorkerEntrypoint } from "cloudflare:workers"; | ||
|
|
||
| export default class TestReleaseVerifier extends WorkerEntrypoint { | ||
| fetchArtifact(url) { | ||
| if (url.endsWith("/unavailable")) throw new Error("internal service address"); | ||
| return { success: true, value: new Uint8Array([7]) }; | ||
| } | ||
|
|
||
| fetchProvenance() { | ||
| return { success: true, value: "not bytes" }; | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| import { env } from "cloudflare:workers"; | ||
| import { describe, expect, it, vi } from "vitest"; | ||
|
|
||
| import { | ||
| fetchArtifact, | ||
| fetchProvenance, | ||
| type ReleaseVerifierBinding, | ||
| VerifierUnavailableError, | ||
| } from "../src/verifier.js"; | ||
|
|
||
| function verifierBinding(overrides: Partial<ReleaseVerifierBinding> = {}): ReleaseVerifierBinding { | ||
| return { | ||
| fetchArtifact: async () => ({ success: true, value: new Uint8Array([1]) }), | ||
| fetchProvenance: async () => ({ success: true, value: new Uint8Array([2]) }), | ||
| ...overrides, | ||
| }; | ||
| } | ||
|
|
||
| describe("release verifier binding adapter", () => { | ||
| it("validates results across the configured RPC service binding", async () => { | ||
| await expect( | ||
| fetchArtifact(env.RELEASE_VERIFIER, "https://example.test/plugin.tgz"), | ||
| ).resolves.toEqual({ success: true, value: new Uint8Array([7]) }); | ||
| await expect( | ||
| fetchProvenance(env.RELEASE_VERIFIER, "https://example.test/provenance.json"), | ||
| ).rejects.toBeInstanceOf(VerifierUnavailableError); | ||
| }); | ||
|
|
||
| it("normalizes configured service-binding failures", async () => { | ||
| await expect( | ||
| fetchArtifact(env.RELEASE_VERIFIER, "https://example.test/unavailable"), | ||
| ).rejects.toMatchObject({ | ||
| message: "Release verifier is unavailable", | ||
| retryable: true, | ||
| }); | ||
| }); | ||
|
|
||
| it("returns successful bytes and stable verification failures", async () => { | ||
| await expect( | ||
| fetchArtifact(verifierBinding(), "https://example.test/plugin.tgz"), | ||
| ).resolves.toEqual({ | ||
| success: true, | ||
| value: new Uint8Array([1]), | ||
| }); | ||
| const failure = { | ||
| success: false, | ||
| error: { code: "RESOURCE_STATUS_ERROR", message: "The resource returned HTTP 404." }, | ||
| }; | ||
| await expect( | ||
| fetchProvenance( | ||
| verifierBinding({ fetchProvenance: async () => failure }), | ||
| "https://example.test/provenance.json", | ||
| ), | ||
| ).resolves.toEqual(failure); | ||
| }); | ||
|
|
||
| it("preserves definitive failures from a newer verifier", async () => { | ||
| const failure = { | ||
| success: false as const, | ||
| error: { code: "NEW_VERSION_CODE", message: "new definitive failure" }, | ||
| }; | ||
|
|
||
| await expect( | ||
| fetchArtifact( | ||
| verifierBinding({ fetchArtifact: async () => failure }), | ||
| "https://example.test/plugin.tgz", | ||
| ), | ||
| ).resolves.toEqual(failure); | ||
| }); | ||
|
|
||
| it("fails closed with a retryable generic error when the binding rejects", async () => { | ||
| const cause = new Error("internal service address"); | ||
| const binding = verifierBinding({ | ||
| fetchArtifact: vi.fn().mockRejectedValue(cause), | ||
| }); | ||
| const result = fetchArtifact(binding, "https://example.test/plugin.tgz"); | ||
| await expect(result).rejects.toBeInstanceOf(VerifierUnavailableError); | ||
| await expect(result).rejects.toMatchObject({ | ||
| message: "Release verifier is unavailable", | ||
| retryable: true, | ||
| cause, | ||
| }); | ||
| }); | ||
|
|
||
| it("preserves malformed response details as a diagnostic cause", async () => { | ||
| const binding = verifierBinding({ fetchArtifact: async () => null }); | ||
|
|
||
| await expect(fetchArtifact(binding, "https://example.test/plugin.tgz")).rejects.toMatchObject({ | ||
| name: "VerifierUnavailableError", | ||
| cause: expect.objectContaining({ | ||
| name: "TypeError", | ||
| message: "Release verifier returned an invalid response", | ||
| }), | ||
| }); | ||
| }); | ||
|
|
||
| it.each([ | ||
| null, | ||
| { success: true, value: "not bytes" }, | ||
| { success: false, error: { code: "FETCH_FAILED" } }, | ||
| ])("rejects malformed RPC result %#", async (rpcResult) => { | ||
| const binding = verifierBinding({ fetchArtifact: async () => rpcResult }); | ||
| await expect(fetchArtifact(binding, "https://example.test/plugin.tgz")).rejects.toMatchObject({ | ||
| name: "VerifierUnavailableError", | ||
| retryable: true, | ||
| }); | ||
| }); | ||
| }); |
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| { | ||
| "name": "@emdash-cms/release-verifier", | ||
| "version": "0.0.0", | ||
| "private": true, | ||
| "description": "Isolated egress Worker for delegated release verification.", | ||
| "type": "module", | ||
| "scripts": { | ||
| "build": "wrangler deploy --dry-run --outdir dist", | ||
| "deploy": "wrangler deploy", | ||
| "typecheck": "tsgo --noEmit", | ||
| "test": "vitest run", | ||
| "types": "wrangler types" | ||
| }, | ||
| "dependencies": { | ||
| "@emdash-cms/registry-verification": "workspace:*" | ||
| }, | ||
| "devDependencies": { | ||
| "@cloudflare/vitest-pool-workers": "catalog:", | ||
| "@types/node": "catalog:", | ||
| "typescript": "catalog:", | ||
| "vite": "catalog:", | ||
| "vitest": "catalog:", | ||
| "wrangler": "catalog:" | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[suggestion] The catch in
callVerifierreplaces every binding/validation failure with a freshVerifierUnavailableError, throwing away the original cause. That matches the "fail closed" design, but when this bubbles up in production logs there will be no trace of why the verifier was considered unavailable — RPC transport error, malformed response, version-skewed error code, etc.Consider stashing the original error as
cause:and then rethrowing
new VerifierUnavailableError(error). This keeps the client response unchanged while giving operators something actionable in the logs.