-
Notifications
You must be signed in to change notification settings - Fork 0
fix: bind release verification to platform artifact namespaces #308
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
Closed
Closed
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
64b5c91
test: bind release verifier to matrix artifact namespaces
seonghobae 46d2198
fix: verify Windows release artifact namespace
seonghobae 8394087
test: reject cross-platform release artifact placement
seonghobae e93f286
fix: bind release artifacts to platform directories
seonghobae af2e1b4
test: bind operational CLIs to release platform namespace
seonghobae 18b709d
test: require exact tag release artifact verification
seonghobae 1c78736
fix: verify tag artifacts before sbom
seonghobae 49964b9
docs: document release verifier test helpers
seonghobae b248f1a
docs: document release workflow test helper
seonghobae c39deae
docs: document release verifier shell helpers
seonghobae 4047ffd
chore(release): keep verifier shellcheck-clean
seonghobae d2127d4
test: reject nested release bundle placement
seonghobae a71d4d7
fix: bind release bundles to exact matrix directories
seonghobae 4dfbe63
test: preserve attest v4.2.2 provenance contract
seonghobae 1de59f2
fix: preserve attest v4.2.2 on release verifier branch
seonghobae 67306e9
merge main into release artifact verifier owner
seonghobae 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
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
158 changes: 158 additions & 0 deletions
158
src/lib/releaseArtifactVerifierDirectoryContract.test.ts
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,158 @@ | ||
| import { createHash } from 'node:crypto'; | ||
| import { mkdirSync, mkdtempSync, renameSync, rmSync, writeFileSync } from 'node:fs'; | ||
| import { tmpdir } from 'node:os'; | ||
| import { dirname, join, resolve } from 'node:path'; | ||
| import { spawnSync } from 'node:child_process'; | ||
| import { fileURLToPath } from 'node:url'; | ||
| import { describe, expect, it } from 'vitest'; | ||
|
|
||
| const repositoryRoot = resolve(dirname(fileURLToPath(import.meta.url)), '../..'); | ||
| const runAttempt = '1'; | ||
| const platformDirectories = { | ||
| linux: `release-disksage-ubuntu-22.04-${runAttempt}`, | ||
| windows: `release-disksage-windows-2022-${runAttempt}`, | ||
| macos: `release-disksage-macos-latest-${runAttempt}`, | ||
| } as const; | ||
|
|
||
| /** Writes one fixture file, creating only the parent directories required by that fixture. */ | ||
| function write(path: string, bytes: Buffer | string) { | ||
| mkdirSync(dirname(path), { recursive: true }); | ||
| writeFileSync(path, bytes); | ||
| } | ||
|
|
||
| /** Adds one operational CLI fixture together with its adjacent SHA-256 receipt. */ | ||
| function addCli(artifactRoot: string, directory: string, name: string) { | ||
| const bytes = Buffer.from(`cli:${name}`); | ||
| const assetPath = join(artifactRoot, directory, name); | ||
| write(assetPath, bytes); | ||
| write( | ||
| `${assetPath}.sha256`, | ||
| `${createHash('sha256').update(bytes).digest('hex')} ${name}\n`, | ||
| ); | ||
| } | ||
|
|
||
| /** Materializes the exact 17-file Linux, Windows, and macOS release artifact contract. */ | ||
| function materializeExactArtifactSet(artifactRoot: string) { | ||
| write(join(artifactRoot, platformDirectories.linux, 'bundle/deb/disksage.deb'), 'deb'); | ||
| write(join(artifactRoot, platformDirectories.linux, 'bundle/appimage/disksage.AppImage'), 'appimage'); | ||
| write(join(artifactRoot, platformDirectories.windows, 'bundle/msi/disksage.msi'), 'msi'); | ||
| write(join(artifactRoot, platformDirectories.windows, 'bundle/nsis/disksage-setup.exe'), 'nsis'); | ||
| write(join(artifactRoot, platformDirectories.macos, 'bundle/dmg/disksage.dmg'), 'dmg'); | ||
|
|
||
| addCli(artifactRoot, platformDirectories.linux, 'disksage-cloud-plan-linux-x86_64'); | ||
| addCli(artifactRoot, platformDirectories.linux, 'disksage-duplicate-audit-linux-x86_64'); | ||
| addCli(artifactRoot, platformDirectories.windows, 'disksage-cloud-plan-windows-x86_64.exe'); | ||
| addCli(artifactRoot, platformDirectories.windows, 'disksage-duplicate-audit-windows-x86_64.exe'); | ||
| addCli(artifactRoot, platformDirectories.macos, 'disksage-cloud-plan-macos-arm64'); | ||
| addCli(artifactRoot, platformDirectories.macos, 'disksage-duplicate-audit-macos-arm64'); | ||
| } | ||
|
|
||
| /** Runs the repository-owned verifier against one isolated downloaded-artifact fixture. */ | ||
| function verify(artifactRoot: string) { | ||
| return spawnSync( | ||
| 'bash', | ||
| [ | ||
| resolve(repositoryRoot, '.github/scripts/verify-release-artifacts.sh'), | ||
| artifactRoot, | ||
| runAttempt, | ||
| ], | ||
| { cwd: repositoryRoot, encoding: 'utf8' }, | ||
| ); | ||
| } | ||
|
|
||
| describe('release artifact verifier directory contract', () => { | ||
| it.runIf(process.platform !== 'win32')( | ||
| 'accepts the exact platform namespaces uploaded by the release matrix', | ||
| () => { | ||
| const fixtureRoot = mkdtempSync(join(tmpdir(), 'disksage-release-artifact-verifier-')); | ||
| const artifactRoot = join(fixtureRoot, 'release-artifacts'); | ||
| try { | ||
| materializeExactArtifactSet(artifactRoot); | ||
|
|
||
| const result = verify(artifactRoot); | ||
|
|
||
| expect(result.status, result.stderr).toBe(0); | ||
| expect(result.stderr).toBe(''); | ||
| } finally { | ||
| rmSync(fixtureRoot, { recursive: true, force: true }); | ||
| } | ||
| }, | ||
| ); | ||
|
|
||
| it.runIf(process.platform !== 'win32')( | ||
| 'rejects a Windows bundle that escaped its Windows artifact directory', | ||
| () => { | ||
| const fixtureRoot = mkdtempSync(join(tmpdir(), 'disksage-release-artifact-verifier-')); | ||
| const artifactRoot = join(fixtureRoot, 'release-artifacts'); | ||
| try { | ||
| materializeExactArtifactSet(artifactRoot); | ||
| const source = join(artifactRoot, platformDirectories.windows, 'bundle/msi/disksage.msi'); | ||
| const misplaced = join(artifactRoot, platformDirectories.linux, 'bundle/msi/disksage.msi'); | ||
| mkdirSync(dirname(misplaced), { recursive: true }); | ||
| renameSync(source, misplaced); | ||
|
|
||
| const result = verify(artifactRoot); | ||
|
|
||
| expect(result.status).not.toBe(0); | ||
| expect(result.stdout).toBe(''); | ||
| expect(result.stderr).toContain('Windows MSI bundle'); | ||
| } finally { | ||
| rmSync(fixtureRoot, { recursive: true, force: true }); | ||
| } | ||
| }, | ||
| ); | ||
|
|
||
| it.runIf(process.platform !== 'win32')( | ||
| 'rejects a bundle nested below its exact release matrix directory', | ||
| () => { | ||
| const fixtureRoot = mkdtempSync(join(tmpdir(), 'disksage-release-artifact-verifier-')); | ||
| const artifactRoot = join(fixtureRoot, 'release-artifacts'); | ||
| try { | ||
| materializeExactArtifactSet(artifactRoot); | ||
| const source = join(artifactRoot, platformDirectories.linux, 'bundle/deb/disksage.deb'); | ||
| const misplaced = join( | ||
| artifactRoot, | ||
| platformDirectories.linux, | ||
| 'bundle/deb/unexpected/disksage.deb', | ||
| ); | ||
| mkdirSync(dirname(misplaced), { recursive: true }); | ||
| renameSync(source, misplaced); | ||
|
|
||
| const result = verify(artifactRoot); | ||
|
|
||
| expect(result.status).not.toBe(0); | ||
|
seonghobae marked this conversation as resolved.
|
||
| expect(result.stdout).toBe(''); | ||
| expect(result.stderr).toContain('Debian bundle'); | ||
| } finally { | ||
| rmSync(fixtureRoot, { recursive: true, force: true }); | ||
| } | ||
| }, | ||
| ); | ||
|
|
||
| it.runIf(process.platform !== 'win32')( | ||
| 'rejects a Windows operational CLI and checksum outside the Windows artifact directory', | ||
| () => { | ||
| const fixtureRoot = mkdtempSync(join(tmpdir(), 'disksage-release-artifact-verifier-')); | ||
| const artifactRoot = join(fixtureRoot, 'release-artifacts'); | ||
| try { | ||
| materializeExactArtifactSet(artifactRoot); | ||
| const cliName = 'disksage-cloud-plan-windows-x86_64.exe'; | ||
| const source = join(artifactRoot, platformDirectories.windows, cliName); | ||
| const sourceChecksum = `${source}.sha256`; | ||
| const misplaced = join(artifactRoot, platformDirectories.linux, cliName); | ||
| const misplacedChecksum = `${misplaced}.sha256`; | ||
| renameSync(source, misplaced); | ||
| renameSync(sourceChecksum, misplacedChecksum); | ||
|
|
||
| const result = verify(artifactRoot); | ||
|
|
||
| expect(result.status).not.toBe(0); | ||
| expect(result.stdout).toBe(''); | ||
| expect(result.stderr).toContain(cliName); | ||
| expect(result.stderr).toContain(platformDirectories.windows); | ||
| } finally { | ||
| rmSync(fixtureRoot, { recursive: true, force: 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import { readFileSync } from 'node:fs'; | ||
| import { dirname, resolve } from 'node:path'; | ||
| import { fileURLToPath } from 'node:url'; | ||
| import { describe, expect, it } from 'vitest'; | ||
|
|
||
| const repositoryRoot = resolve(dirname(fileURLToPath(import.meta.url)), '../..'); | ||
|
|
||
| /** Reads the source-controlled release workflow with normalized line endings for stable assertions. */ | ||
| function readReleaseWorkflow(): string { | ||
| return readFileSync(resolve(repositoryRoot, '.github/workflows/release.yml'), 'utf8').replace(/\r\n?/g, '\n'); | ||
| } | ||
|
|
||
| describe('tag release artifact verifier contract', () => { | ||
| it('runs the shared exact build-artifact verifier before generating the SBOM', () => { | ||
| const workflow = readReleaseWorkflow(); | ||
| const attestStart = workflow.indexOf('\n attest-release:\n'); | ||
| const publishStart = workflow.indexOf('\n publish-release:\n', attestStart); | ||
| expect(attestStart).toBeGreaterThanOrEqual(0); | ||
| expect(publishStart).toBeGreaterThan(attestStart); | ||
|
|
||
| const attestJob = workflow.slice(attestStart, publishStart); | ||
| const sharedVerifier = 'bash .github/scripts/verify-release-artifacts.sh release-artifacts "${{ github.run_attempt }}"'; | ||
| const verifierOffset = attestJob.indexOf(sharedVerifier); | ||
| const sbomOffset = attestJob.indexOf('- name: Generate and validate source-bound SBOM'); | ||
|
|
||
| expect(verifierOffset).toBeGreaterThanOrEqual(0); | ||
| expect(sbomOffset).toBeGreaterThan(verifierOffset); | ||
| }); | ||
| }); |
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.