-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix: bind Sigstore provenance to admitted workload #2847
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
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
cabc840
fix(release-service): bind provenance to workload identity
ascorbic c2125e1
fix(release-service): distinguish workflow and run refs
ascorbic 05140e9
test(release-service): clarify workflow identity fixtures
ascorbic 4d0faa4
merge main and consolidate workload identity fixture
ascorbic 0f84214
fix(release-service): preserve GitHub repository casing
ascorbic f7a9390
merge current delegated-release security fixes
ascorbic 8e85dda
refactor(release-service): consolidate workload identity parsing
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
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": patch | ||
| --- | ||
|
|
||
| Fixes delegated-release provenance verification so verified GitHub attestations include the repository, workflow, commit, and run identity needed to enforce an exact authorized workload. |
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
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,146 @@ | ||
| import { digestWorkloadIdentity } from "./policy.js"; | ||
| import type { VerifiedWorkloadIdentity } from "./types.js"; | ||
|
|
||
| const DECIMAL_ID_PATTERN = /^[1-9][0-9]*$/; | ||
| const REPOSITORY_PATTERN = /^[a-z0-9_.-]+\/[a-z0-9_.-]+$/; | ||
| const LOGIN_PATTERN = /^[a-z0-9](?:[a-z0-9-]{0,38})$/; | ||
| const ACTOR_PATTERN = /^(?:[A-Za-z0-9](?:[A-Za-z0-9-]{0,38})|[A-Za-z0-9-]{1,39}\[bot\])$/; | ||
| const SHA_PATTERN = /^[a-f0-9]{40}$/; | ||
| const REF_PATTERN = /^refs\/[A-Za-z0-9._/-]{1,507}$/; | ||
| const WORKFLOW_REF_PATTERN = | ||
| /^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+\/\.github\/workflows\/[A-Za-z0-9_./-]+\.ya?ml@refs\/[A-Za-z0-9._/-]+$/; | ||
|
|
||
| function isRecord(value: unknown): value is Record<string, unknown> { | ||
| return value !== null && typeof value === "object" && !Array.isArray(value); | ||
| } | ||
|
|
||
| function boundedString(value: unknown, maximum: number, pattern?: RegExp): string | null { | ||
| return typeof value === "string" && | ||
| value.length > 0 && | ||
| value.length <= maximum && | ||
| (!pattern || pattern.test(value)) | ||
| ? value | ||
| : null; | ||
| } | ||
|
|
||
| function nullableString( | ||
| value: unknown, | ||
| maximum: number, | ||
| pattern?: RegExp, | ||
| ): string | null | undefined { | ||
| return value === null ? null : (boundedString(value, maximum, pattern) ?? undefined); | ||
| } | ||
|
|
||
| function safeInteger(value: unknown, minimum = 0): number | null { | ||
| return Number.isSafeInteger(value) && Number(value) >= minimum ? Number(value) : null; | ||
| } | ||
|
|
||
| function parseIdentity(value: unknown): VerifiedWorkloadIdentity | null { | ||
| if ( | ||
| !isRecord(value) || | ||
| !isRecord(value["repository"]) || | ||
| !isRecord(value["workflow"]) || | ||
| !isRecord(value["run"]) | ||
| ) { | ||
| return null; | ||
| } | ||
| const repository = value["repository"]; | ||
| const workflow = value["workflow"]; | ||
| const run = value["run"]; | ||
| const subject = boundedString(value["subject"], 2048); | ||
| const tokenId = boundedString(value["tokenId"], 255); | ||
| const repositoryName = boundedString(repository["name"], 256, REPOSITORY_PATTERN); | ||
| const repositoryId = boundedString(repository["id"], 32, DECIMAL_ID_PATTERN); | ||
| const repositoryOwner = boundedString(repository["owner"], 64, LOGIN_PATTERN); | ||
| const repositoryOwnerId = boundedString(repository["ownerId"], 32, DECIMAL_ID_PATTERN); | ||
| const workflowRef = boundedString(workflow["ref"], 1024, WORKFLOW_REF_PATTERN); | ||
| const workflowSha = boundedString(workflow["sha"], 40, SHA_PATTERN); | ||
| const jobRef = nullableString(workflow["jobRef"], 1024, WORKFLOW_REF_PATTERN); | ||
| const jobSha = nullableString(workflow["jobSha"], 40, SHA_PATTERN); | ||
| const runId = boundedString(run["id"], 32, DECIMAL_ID_PATTERN); | ||
| const runAttempt = safeInteger(run["attempt"], 1); | ||
| const actor = boundedString(run["actor"], 64, ACTOR_PATTERN); | ||
| const actorId = boundedString(run["actorId"], 32, DECIMAL_ID_PATTERN); | ||
| const eventName = boundedString(run["eventName"], 128); | ||
| const ref = boundedString(run["ref"], 512, REF_PATTERN); | ||
| const commitSha = boundedString(run["commitSha"], 40, SHA_PATTERN); | ||
| const environment = nullableString(run["environment"], 255); | ||
| const issuedAt = safeInteger(value["issuedAt"]); | ||
| const expiresAt = safeInteger(value["expiresAt"]); | ||
| if ( | ||
| value["issuer"] !== "github-actions" || | ||
| !subject || | ||
| !tokenId || | ||
| !repositoryName || | ||
| !repositoryId || | ||
| !repositoryOwner || | ||
| !repositoryOwnerId || | ||
| (repository["visibility"] !== "public" && | ||
| repository["visibility"] !== "private" && | ||
| repository["visibility"] !== "internal") || | ||
| !workflowRef || | ||
| !workflowSha || | ||
| jobRef === undefined || | ||
| jobSha === undefined || | ||
| (jobRef === null) !== (jobSha === null) || | ||
| !runId || | ||
| runAttempt === null || | ||
| !actor || | ||
| !actorId || | ||
| !eventName || | ||
| !ref || | ||
| (run["refType"] !== "branch" && run["refType"] !== "tag") || | ||
| !commitSha || | ||
| environment === undefined || | ||
| (run["runnerEnvironment"] !== "github-hosted" && run["runnerEnvironment"] !== "self-hosted") || | ||
| issuedAt === null || | ||
| expiresAt === null || | ||
| issuedAt > expiresAt || | ||
| repositoryOwner !== repositoryName.split("/", 1)[0] || | ||
| !workflowRef.toLowerCase().startsWith(`${repositoryName}/.github/workflows/`) | ||
| ) { | ||
| return null; | ||
| } | ||
| return { | ||
| issuer: "github-actions", | ||
| subject, | ||
| tokenId, | ||
| repository: { | ||
| name: repositoryName, | ||
| id: repositoryId, | ||
| owner: repositoryOwner, | ||
| ownerId: repositoryOwnerId, | ||
| visibility: repository["visibility"], | ||
| }, | ||
| workflow: { ref: workflowRef, sha: workflowSha, jobRef, jobSha }, | ||
| run: { | ||
| id: runId, | ||
| attempt: runAttempt, | ||
| actor, | ||
| actorId, | ||
| eventName, | ||
| ref, | ||
| refType: run["refType"], | ||
| commitSha, | ||
| environment, | ||
| runnerEnvironment: run["runnerEnvironment"], | ||
| }, | ||
| issuedAt, | ||
| expiresAt, | ||
| }; | ||
| } | ||
|
|
||
| export async function parseStoredWorkloadIdentity( | ||
| json: string, | ||
| expectedDigest: string, | ||
| ): Promise<VerifiedWorkloadIdentity | null> { | ||
| let parsed: unknown; | ||
| try { | ||
| parsed = JSON.parse(json); | ||
| } catch { | ||
| return null; | ||
| } | ||
| const identity = parseIdentity(parsed); | ||
| if (!identity || JSON.stringify(identity) !== json) return null; | ||
| return (await digestWorkloadIdentity(identity)) === expectedDigest ? identity : null; | ||
| } |
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.
[needs fixing]
sourceRepositoryis built fromidentity.repository.name, whichgithub-oidc.tslowercases when normalizing the OIDC token. The Sigstore-attestedbuilderIdand OID 21invocationId, however, preserve the original casing from the GitHubworkflow_refclaim. Repositories with uppercase letters therefore pass admission-time policy matching (which normalizes case) but fail here withATTESTED_WORKFLOW_MISMATCHorATTESTED_INVOCATION_MISMATCHbecauseexpectedBuilderIdandinvocationIduse a lowercased prefix.Derive the repo prefix from
identity.workflow.ref— the parser already validates that the ref starts with the repository — and compare source repositories case-insensitively. Add a regression test that upper-cases the provenancebuilderId/invocationId(or the stored workflow ref).