Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,19 @@ jobs:
- name: Build and verify emitted package entry
run: pnpm build
- name: Independently verify exact packed package and security boundaries
env:
ASSAY_ARCHIVE_DIR: ${{ runner.temp }}/assay-verified-archive
run: pnpm verify:package
- name: Retain verified main candidate
if: github.event_name == 'push' && github.ref == 'refs/heads/main' && matrix.os == 'ubuntu-latest'
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: assay-verified-${{ github.sha }}-${{ github.run_attempt }}
path: |
${{ runner.temp }}/assay-verified-archive/assay.tgz
${{ runner.temp }}/assay-verified-archive/manifest.json
if-no-files-found: error
retention-days: 30
compression-level: 0

# Quality-only CI: no npm publish, deploy or write credentials.
93 changes: 93 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: Stage npm package

on:
workflow_dispatch:
inputs:
quality_run_id:
description: Successful main quality run ID
required: true
type: string

permissions: {}

concurrency:
group: assay-npm-stage
cancel-in-progress: false

jobs:
stage:
if: github.repository == '0xbuffdev/assay' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
timeout-minutes: 10
environment: npm-stage
permissions:
contents: read
actions: read
id-token: write
steps:
- name: Verify approval and quality run
env:
GH_TOKEN: ${{ github.token }}
RUN_ID: ${{ inputs.quality_run_id }}
APPROVED_RUN_ID: ${{ vars.ASSAY_STAGE_RUN_ID }}
APPROVED_SHA: ${{ vars.ASSAY_STAGE_COMMIT }}
APPROVED_DIGEST: ${{ vars.ASSAY_STAGE_SHA256 }}
run: |
set -euo pipefail
[[ "$RUN_ID" =~ ^[1-9][0-9]*$ ]]
[[ "$APPROVED_RUN_ID" == "$RUN_ID" ]]
[[ "$APPROVED_SHA" =~ ^[a-f0-9]{40}$ && "$APPROVED_SHA" == "$GITHUB_SHA" ]]
[[ "$APPROVED_DIGEST" =~ ^[a-f0-9]{64}$ ]]
[[ "$(gh api "repos/$GITHUB_REPOSITORY/git/ref/heads/main" --jq '.object.sha')" == "$GITHUB_SHA" ]]
run_json="$(gh api "repos/$GITHUB_REPOSITORY/actions/runs/$RUN_ID")"
jq -e --arg sha "$GITHUB_SHA" --arg repo "$GITHUB_REPOSITORY" '
.head_sha == $sha and .head_branch == "main" and
.head_repository.full_name == $repo and .repository.full_name == $repo and
.path == ".github/workflows/ci.yml" and .event == "push" and
.status == "completed" and .conclusion == "success"
' <<< "$run_json" >/dev/null
attempt="$(jq -er '.run_attempt' <<< "$run_json")"
[[ "$attempt" =~ ^[1-9][0-9]*$ ]]
gh run download "$RUN_ID" --repo "$GITHUB_REPOSITORY" \
--name "assay-verified-$GITHUB_SHA-$attempt" \
--dir "$RUNNER_TEMP/assay-release"
cd "$RUNNER_TEMP/assay-release"
[[ -f assay.tgz && ! -L assay.tgz && -f manifest.json && ! -L manifest.json ]]
[[ "$(find . -mindepth 1 -maxdepth 1 | wc -l)" -eq 2 ]]
[[ "$(sha256sum assay.tgz | cut -d ' ' -f 1)" == "$APPROVED_DIGEST" ]]
jq -e --arg digest "$APPROVED_DIGEST" --argjson size "$(wc -c < assay.tgz)" '
.name == "@0xbuff/assay" and .version == "0.0.1" and
.sha256 == $digest and .bytes == $size and
([.files[].path] | sort) == [
"CHANGELOG.md", "COPYRIGHT.md", "LICENSE", "README.md",
"dist/index.d.ts", "dist/index.js", "dist/index.js.map", "package.json"
]
' manifest.json >/dev/null
tar -xOzf assay.tgz package/package.json | jq -e '
.name == "@0xbuff/assay" and .version == "0.0.1" and
.private == false and .publishConfig.access == "public" and
.publishConfig.registry == "https://registry.npmjs.org/"
' >/dev/null
tar -xOzf assay.tgz package/CHANGELOG.md > "$RUNNER_TEMP/assay-release-notes.md"
grep -Eq '^## \[0\.0\.1\] - [0-9]{4}-[0-9]{2}-[0-9]{2}$' "$RUNNER_TEMP/assay-release-notes.md"

- name: Set up Node.js
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: 24.22.3
package-manager-cache: false

- name: Stage exact approved archive
env:
GH_TOKEN: ${{ github.token }}
APPROVED_DIGEST: ${{ vars.ASSAY_STAGE_SHA256 }}
NPM_CONFIG_REGISTRY: https://registry.npmjs.org/
working-directory: ${{ runner.temp }}/assay-release
run: |
set -euo pipefail
[[ "$(gh api "repos/$GITHUB_REPOSITORY/git/ref/heads/main" --jq '.object.sha')" == "$GITHUB_SHA" ]]
[[ "$(sha256sum assay.tgz | cut -d ' ' -f 1)" == "$APPROVED_DIGEST" ]]
unset NODE_AUTH_TOKEN NPM_TOKEN
node --version
npm --version
npm stage publish ./assay.tgz --access public --tag latest --ignore-scripts --registry https://registry.npmjs.org/
14 changes: 13 additions & 1 deletion docs/releasing.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ The package must contain exactly:
- `LICENSE`, `COPYRIGHT.md`
- `dist/index.js`, `dist/index.js.map`, `dist/index.d.ts`

The verifier checks package metadata, licensing, no runtime dependencies, no lifecycle scripts, and known synthetic canaries in compiled payloads. It packs locally, installs offline with scripts disabled in an independent temporary directory, runs the ESM scenarios and typechecks the installed declarations. It removes the temporary archive and consumer on exit. The verifier does not publish anything.
The verifier checks package metadata, licensing, no runtime dependencies, no lifecycle scripts, and known synthetic canaries in compiled payloads. It packs locally, installs offline with scripts disabled in an independent temporary directory, runs the ESM scenarios and typechecks the installed declarations. It removes the temporary archive and consumer on exit. Set `ASSAY_ARCHIVE_DIR` to a new absolute directory to retain the verified tarball and manifest. Main-push quality runs retain the Ubuntu archive for 30 days; PR runs exercise the same retention path without uploading it. The verifier does not publish anything.

## Publication checklist

Expand All @@ -36,4 +36,16 @@ The verifier checks package metadata, licensing, no runtime dependencies, no lif

For a public package, prefer [npm trusted publishing](https://docs.npmjs.com/trusted-publishers/) with a protected GitHub environment and stage-only permission. A maintainer must approve the staged package through npm using its required authentication. Keep quality CI read-only; never introduce a long-lived npm token to it.

## Protected staging

The `Stage npm package` workflow (`.github/workflows/release.yml`) runs only by manual dispatch on `main`. It uses the existing successful main quality run and stages its verified archive without rebuilding it. The environment must be configured before use.

1. In repository Settings > Environments, create `npm-stage`. Restrict deployments to `main`, require reviewers and disallow administrator bypass. Enable prevention of self-review if another reviewer is available.
2. After independent inspection and explicit release approval, set environment variables `ASSAY_STAGE_COMMIT`, `ASSAY_STAGE_RUN_ID` and `ASSAY_STAGE_SHA256` to the approved current main SHA, successful main quality run ID and tarball digest. Leave them unset until approval. Finalize dated release notes and reverify any resulting changes before setting these values.
3. In npm package settings, configure a GitHub Actions trusted publisher for `0xbuffdev/assay`, workflow `release.yml`, environment `npm-stage`. Allow staging only; disable direct publish and dist-tag changes. Use a GitHub-hosted runner. No npm token is required in GitHub.
4. Dispatch the workflow with the approved quality run ID. Review and approve the environment job. The workflow checks the approved commit, successful quality run, archive metadata, actual digest and dated changelog before requesting staging. It does not publish or tag anything.
5. Inspect the staged package in npm and compare its tarball digest to the approved artifact. Approve the staged version using npm's required human 2FA only after separate publication authorization. Clear the environment approval variables when done.

For a package that does not yet exist, the owner may need to stage the first inspected tarball locally with an authenticated npm session before package-level trusted publishing is available. Do not create a placeholder package or stage without separate approval. See [staged publishing](https://docs.npmjs.com/staged-publishing/) for the account and CLI requirements.

Actual release execution requires a separate maintainer decision. Host authorization, execution isolation and formal grading remain outside Assay.
32 changes: 20 additions & 12 deletions scripts/verify-package.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -302,18 +302,26 @@ try {
// module/type resolution starts in the isolated consumer directory.
command(process.execPath, [compiler, "--project", "tsconfig.json"], consumerDir);
console.log("AY-I28 installed expanded TypeScript contracts verified");
console.log(
"AY-I26 candidate archive",
JSON.stringify({
name: item.name,
version: item.version,
bytes: (await readFile(archive)).byteLength,
sha256: createHash("sha256")
.update(await readFile(archive))
.digest("hex"),
files: item.files.map(({ path, size }) => ({ path, size })),
}),
);
const archiveBytes = await readFile(archive);
const archiveMetadata = {
name: item.name,
version: item.version,
bytes: archiveBytes.byteLength,
sha256: createHash("sha256").update(archiveBytes).digest("hex"),
files: item.files.map(({ path, size }) => ({ path, size })),
};
const retainDirectory = process.env.ASSAY_ARCHIVE_DIR;
if (retainDirectory !== undefined) {
assert.ok(path.isAbsolute(retainDirectory), "Use a new absolute archive directory");
await mkdir(retainDirectory);
await writeFile(path.join(retainDirectory, "assay.tgz"), archiveBytes, { flag: "wx" });
await writeFile(
path.join(retainDirectory, "manifest.json"),
`${JSON.stringify(archiveMetadata, null, 2)}\n`,
{ flag: "wx" },
);
}
console.log("AY-I26 candidate archive", JSON.stringify(archiveMetadata));
console.log(
"AY-I04 packed consumer verified: exact file allowlist, Apache-2.0, no runtime deps, " +
"offline no-script install, public ESM API, hostile cases and isolated TypeScript declarations",
Expand Down