Repository navigation
[KB-05] Prepare verified KB release artifacts and recovery #6
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
4 commits
Select commit
Hold shift + click to select a range
4a87719
Prepare KB-05 exact-artifact release and recovery gates
FlyOverCoderKY b52cd60
Encode complete package URL components in provenance checks
FlyOverCoderKY 256d1bc
Harden release authority and verify real npm audit output
FlyOverCoderKY c8ef14a
Require canonical npm paths in publication and verification
FlyOverCoderKY 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,26 @@ | ||
| name: Set up reviewed release npm | ||
| description: Verify and extract the pinned npm CLI without installing project dependencies. | ||
| runs: | ||
| using: composite | ||
| steps: | ||
| - name: Verify and extract pinned npm | ||
| shell: bash | ||
| env: | ||
| NPM_VERSION: 11.18.0 | ||
| NPM_TARBALL_SHA256: 73f6155215ebabf4ed96dca1f567c2372cc713c33af2e5b9b62fde4e92373e2e | ||
| run: | | ||
| set -euo pipefail | ||
| tarball="${RUNNER_TEMP}/npm-${NPM_VERSION}.tgz" | ||
| npm_root="${RUNNER_TEMP}/release-npm-${NPM_VERSION}" | ||
| curl --fail --silent --show-error --location --retry 3 \ | ||
| "https://registry.npmjs.org/npm/-/npm-${NPM_VERSION}.tgz" \ | ||
| --output "${tarball}" | ||
| echo "${NPM_TARBALL_SHA256} ${tarball}" | sha256sum --check --strict --quiet | ||
| mkdir "${npm_root}" | ||
| tar --extract --gzip --file "${tarball}" --directory "${npm_root}" | ||
| npm_cli="${npm_root}/package/bin/npm-cli.js" | ||
| if [[ "$(node "${npm_cli}" --version)" != "${NPM_VERSION}" ]]; then | ||
| echo "::error::The reviewed npm version is not active" | ||
| exit 1 | ||
| fi | ||
| printf 'RELEASE_NPM_CLI=%s\nRELEASE_NPM_VERSION=%s\n' "${npm_cli}" "${NPM_VERSION}" >> "${GITHUB_ENV}" |
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,327 @@ | ||
| # Publishes only the exact four-package artifact prepared from a verified tag. | ||
| # A manual dispatch prepares artifacts without entering the OIDC publish job. | ||
| name: Publish | ||
|
|
||
| on: | ||
| release: | ||
| types: [published] | ||
| workflow_dispatch: | ||
| inputs: | ||
| tag: | ||
| description: Protected signed annotated stable tag to prepare (vX.Y.Z) | ||
| required: true | ||
| type: string | ||
| expected_commit: | ||
| description: Exact full commit SHA targeted by the tag | ||
| required: true | ||
| type: string | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| concurrency: | ||
| group: npm-publish | ||
| cancel-in-progress: false | ||
|
|
||
| jobs: | ||
| identity: | ||
| name: Verify signed release identity | ||
| if: >- | ||
| github.repository == 'pegma-dev/knowledge-base' && | ||
| (github.event_name == 'workflow_dispatch' || | ||
| (github.event_name == 'release' && !github.event.release.draft && !github.event.release.prerelease)) | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 5 | ||
| outputs: | ||
| tag: ${{ steps.identity.outputs.tag }} | ||
| commit: ${{ steps.identity.outputs.commit }} | ||
| env: | ||
| RELEASE_TAG: ${{ github.event.release.tag_name || inputs.tag }} | ||
| RELEASE_COMMIT: ${{ github.event_name == 'release' && github.sha || inputs.expected_commit }} | ||
| RELEASE_ALLOWED_SIGNERS: ${{ vars.RELEASE_ALLOWED_SIGNERS }} | ||
| steps: | ||
| # Do not execute project code or install dependencies before this check. | ||
| - name: Validate release event inputs | ||
| shell: bash | ||
| run: | | ||
| set -euo pipefail | ||
| if [[ ! "${RELEASE_TAG}" =~ ^v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$ ]]; then | ||
| echo "::error::The release tag must be stable vX.Y.Z" | ||
| exit 1 | ||
| fi | ||
| if [[ ! "${RELEASE_COMMIT}" =~ ^([0-9a-f]{40}|[0-9a-f]{64})$ ]]; then | ||
| echo "::error::The release must supply its exact full commit SHA" | ||
| exit 1 | ||
| fi | ||
| if [[ "${GITHUB_EVENT_NAME}" == "release" && "${GITHUB_REF}" != "refs/tags/${RELEASE_TAG}" ]]; then | ||
| echo "::error::The release event must identify the requested tag" | ||
| exit 1 | ||
| fi | ||
|
|
||
| - name: Check out the requested tag | ||
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 | ||
| with: | ||
| ref: refs/tags/${{ env.RELEASE_TAG }} | ||
| fetch-depth: 0 | ||
| fetch-tags: true | ||
| persist-credentials: false | ||
|
|
||
| - name: Fetch the protected release branch | ||
| run: git fetch --no-tags origin main:refs/remotes/origin/main | ||
|
|
||
| - name: Verify the approved tag signer and main ancestry | ||
| id: identity | ||
| shell: bash | ||
| env: | ||
| GIT_NO_REPLACE_OBJECTS: "1" | ||
| run: | | ||
| set -euo pipefail | ||
| if [[ -z "${RELEASE_ALLOWED_SIGNERS}" ]]; then | ||
| echo "::error::RELEASE_ALLOWED_SIGNERS must contain reviewed SSH allowed-signers entries" | ||
| exit 1 | ||
| fi | ||
| allowed_signers="${RUNNER_TEMP}/release-allowed-signers" | ||
| umask 077 | ||
| printf '%s\n' "${RELEASE_ALLOWED_SIGNERS}" > "${allowed_signers}" | ||
| git config --local gpg.format ssh | ||
| git config --local gpg.ssh.allowedSignersFile "${allowed_signers}" | ||
| tag_ref="refs/tags/${RELEASE_TAG}" | ||
| if [[ "$(git cat-file -t "${tag_ref}")" != "tag" ]]; then | ||
| echo "::error::The release requires an annotated tag" | ||
| exit 1 | ||
| fi | ||
| if [[ "$(git rev-parse HEAD)" != "${RELEASE_COMMIT}" || "$(git rev-parse "${tag_ref}^{commit}")" != "${RELEASE_COMMIT}" ]]; then | ||
| echo "::error::The checkout, tag target, and expected release commit must match" | ||
| exit 1 | ||
| fi | ||
| git verify-tag --raw "${tag_ref}" | ||
| git merge-base --is-ancestor "${RELEASE_COMMIT}" refs/remotes/origin/main | ||
| printf 'tag=%s\ncommit=%s\n' "${RELEASE_TAG}" "${RELEASE_COMMIT}" >> "${GITHUB_OUTPUT}" | ||
|
|
||
| validate: | ||
| name: Release gate / Node.js ${{ matrix.node-version }} | ||
| needs: identity | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 30 | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| node-version: [22, 24] | ||
| steps: | ||
| - name: Check out the verified release commit | ||
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 | ||
| with: | ||
| ref: ${{ needs.identity.outputs.commit }} | ||
| persist-credentials: false | ||
| - name: Install pnpm | ||
| uses: pnpm/action-setup@ea17c68df8912ef543352723c149a84f56e3d413 # v6.1.0 | ||
| with: | ||
| version: 10.34.5 | ||
| - name: Set up Node.js | ||
| uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7 | ||
| with: | ||
| node-version: ${{ matrix.node-version }} | ||
| cache: pnpm | ||
| - name: Install dependencies | ||
| run: pnpm install --frozen-lockfile | ||
| - name: Check formatting | ||
| run: pnpm run format:check | ||
| - name: Check types | ||
| run: pnpm run check | ||
| - name: Run tests including release regressions | ||
| run: pnpm test | ||
| - name: Run synthetic composition | ||
| run: pnpm example | ||
| - name: Check package artifacts | ||
| run: pnpm run release:check | ||
| - name: Prove authenticated agent protocol | ||
| run: pnpm run agent:proof | ||
|
|
||
| prepare: | ||
| name: Prepare exact signed-tag artifacts | ||
| needs: [identity, validate] | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 30 | ||
| outputs: | ||
| artifact-id: ${{ steps.upload.outputs.artifact-id }} | ||
| manifest-sha256: ${{ steps.manifest.outputs.sha256 }} | ||
| env: | ||
| RELEASE_TAG: ${{ needs.identity.outputs.tag }} | ||
| RELEASE_COMMIT: ${{ needs.identity.outputs.commit }} | ||
| RELEASE_ALLOWED_SIGNERS: ${{ vars.RELEASE_ALLOWED_SIGNERS }} | ||
| steps: | ||
| - name: Check out the verified release commit | ||
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 | ||
| with: | ||
| ref: ${{ needs.identity.outputs.commit }} | ||
| fetch-depth: 0 | ||
| fetch-tags: true | ||
| persist-credentials: false | ||
|
|
||
| - name: Fetch the protected release branch | ||
| run: git fetch --no-tags origin main:refs/remotes/origin/main | ||
|
FlyOverCoderKY marked this conversation as resolved.
Resolved
|
||
|
|
||
| - name: Configure approved release signers | ||
| shell: bash | ||
| run: | | ||
| set -euo pipefail | ||
| if [[ -z "${RELEASE_ALLOWED_SIGNERS}" ]]; then | ||
| echo "::error::RELEASE_ALLOWED_SIGNERS must contain reviewed SSH allowed-signers entries" | ||
| exit 1 | ||
| fi | ||
| allowed_signers="${RUNNER_TEMP}/release-allowed-signers" | ||
| umask 077 | ||
| printf '%s\n' "${RELEASE_ALLOWED_SIGNERS}" > "${allowed_signers}" | ||
| git config --local gpg.format ssh | ||
| git config --local gpg.ssh.allowedSignersFile "${allowed_signers}" | ||
|
|
||
| - name: Install pnpm | ||
| uses: pnpm/action-setup@ea17c68df8912ef543352723c149a84f56e3d413 # v6.1.0 | ||
| with: | ||
| version: 10.34.5 | ||
|
|
||
| - name: Set up Node.js | ||
| uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7 | ||
| with: | ||
| node-version: 24.18.0 | ||
| package-manager-cache: false | ||
|
|
||
| - name: Use the reviewed npm release | ||
| uses: ./.github/actions/setup-release-npm | ||
|
|
||
| - name: Install dependencies | ||
| run: pnpm install --frozen-lockfile | ||
|
|
||
| - name: Prepare and strictly verify the signed-tag release | ||
| id: prepared | ||
| run: >- | ||
| node scripts/release-packages.mjs prepare | ||
| --tag "${RELEASE_TAG}" | ||
| --expected-commit "${RELEASE_COMMIT}" | ||
| --out "${RUNNER_TEMP}/knowledge-base-prepared" | ||
|
|
||
| # This independent digest travels through job outputs, never through the | ||
| # artifact whose manifest it authenticates. | ||
| - name: Record the independent manifest digest | ||
| id: manifest | ||
| shell: bash | ||
| env: | ||
| PREPARED_MANIFEST_SHA256: ${{ steps.prepared.outputs.manifest-sha256 }} | ||
| run: | | ||
| set -euo pipefail | ||
| read -r manifest_sha256 _ < <(sha256sum "${RUNNER_TEMP}/knowledge-base-prepared/manifest.json") | ||
| if [[ ! "${manifest_sha256}" =~ ^[0-9a-f]{64}$ || "${manifest_sha256}" != "${PREPARED_MANIFEST_SHA256}" ]]; then | ||
| echo "::error::The prepared manifest digest did not match its independent hash" | ||
| exit 1 | ||
| fi | ||
| printf 'sha256=%s\n' "${manifest_sha256}" >> "${GITHUB_OUTPUT}" | ||
|
|
||
| - name: Upload the immutable prepared release | ||
| id: upload | ||
| uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0 | ||
| with: | ||
| name: knowledge-base-release-${{ github.run_id }}-${{ github.run_attempt }} | ||
| path: ${{ runner.temp }}/knowledge-base-prepared/ | ||
| if-no-files-found: error | ||
| overwrite: false | ||
| retention-days: 30 | ||
|
|
||
| - name: Record prepared artifact identity | ||
| env: | ||
| ARTIFACT_ID: ${{ steps.upload.outputs.artifact-id }} | ||
| ARTIFACT_DIGEST: ${{ steps.upload.outputs.artifact-digest }} | ||
| MANIFEST_SHA256: ${{ steps.manifest.outputs.sha256 }} | ||
| run: | | ||
| printf 'Prepared artifact ID: %s\n\nArtifact SHA-256: %s\n\nManifest SHA-256: %s\n' \ | ||
| "${ARTIFACT_ID}" "${ARTIFACT_DIGEST}" "${MANIFEST_SHA256}" >> "${GITHUB_STEP_SUMMARY}" | ||
|
|
||
| publish: | ||
| name: Publish exact prepared artifacts | ||
| needs: [identity, prepare] | ||
| if: github.event_name == 'release' | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 30 | ||
| environment: npm-publish | ||
| permissions: | ||
| contents: read | ||
| id-token: write | ||
| env: | ||
| RELEASE_TAG: ${{ needs.identity.outputs.tag }} | ||
| RELEASE_COMMIT: ${{ needs.identity.outputs.commit }} | ||
| RELEASE_MANIFEST_SHA256: ${{ needs.prepare.outputs.manifest-sha256 }} | ||
| steps: | ||
| - name: Check out the exact verified release source | ||
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 | ||
| with: | ||
| ref: ${{ needs.identity.outputs.commit }} | ||
| persist-credentials: false | ||
|
|
||
| - name: Set up Node.js | ||
| uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7 | ||
| with: | ||
| node-version: 24.18.0 | ||
| package-manager-cache: false | ||
|
|
||
| # Extract only the reviewed npm CLI; never install project dependencies | ||
| # or run package builds with OIDC authority. | ||
| - name: Use the reviewed npm release | ||
| uses: ./.github/actions/setup-release-npm | ||
|
|
||
| - name: Download the exact immutable prepared artifact | ||
| uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 | ||
| with: | ||
| artifact-ids: ${{ needs.prepare.outputs.artifact-id }} | ||
| path: ${{ runner.temp }}/knowledge-base-prepared | ||
|
|
||
| - name: Publish the exact prepared release | ||
| run: >- | ||
| node scripts/release-packages.mjs publish | ||
| --prepared-dir "${RUNNER_TEMP}/knowledge-base-prepared" | ||
| --manifest-sha256 "${RELEASE_MANIFEST_SHA256}" | ||
| --tag "${RELEASE_TAG}" | ||
| --expected-commit "${RELEASE_COMMIT}" | ||
|
|
||
| verify: | ||
| name: Verify registry release and consumer | ||
| needs: [identity, prepare, publish] | ||
| if: github.event_name == 'release' | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 30 | ||
| permissions: | ||
| contents: read | ||
| id-token: none | ||
| env: | ||
| RELEASE_TAG: ${{ needs.identity.outputs.tag }} | ||
| RELEASE_COMMIT: ${{ needs.identity.outputs.commit }} | ||
| RELEASE_MANIFEST_SHA256: ${{ needs.prepare.outputs.manifest-sha256 }} | ||
| steps: | ||
| - name: Check out the exact verified release source | ||
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 | ||
| with: | ||
| ref: ${{ needs.identity.outputs.commit }} | ||
| persist-credentials: false | ||
|
|
||
| - name: Set up Node.js | ||
| uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7 | ||
| with: | ||
| node-version: 24.18.0 | ||
| package-manager-cache: false | ||
|
|
||
| - name: Use the reviewed npm release | ||
| uses: ./.github/actions/setup-release-npm | ||
|
|
||
| - name: Download the exact immutable prepared artifact | ||
| uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 | ||
| with: | ||
| artifact-ids: ${{ needs.prepare.outputs.artifact-id }} | ||
| path: ${{ runner.temp }}/knowledge-base-prepared | ||
|
|
||
| # Registry availability requires this unprivileged job to pass. Consumer | ||
| # installation and provenance verification never receive OIDC authority. | ||
| - name: Verify registry bytes, provenance, and the public consumer | ||
| run: >- | ||
| node scripts/release-packages.mjs verify | ||
| --prepared-dir "${RUNNER_TEMP}/knowledge-base-prepared" | ||
| --manifest-sha256 "${RELEASE_MANIFEST_SHA256}" | ||
| --tag "${RELEASE_TAG}" | ||
| --expected-commit "${RELEASE_COMMIT}" | ||
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.
Uh oh!
There was an error while loading. Please reload this page.