Compare commits
30 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 648860c1d2 | |||
| 799667e711 | |||
| 7d9b9d6f3a | |||
| 35d5f4375d | |||
| 876bb5fef3 | |||
| 6cf30ca381 | |||
| e395115c2b | |||
| afc801dbf7 | |||
| 6ec0860adb | |||
| 532af8af79 | |||
| 4f3e64cb63 | |||
| ba126a2b5e | |||
| 3867ba47a1 | |||
| 95613fb241 | |||
| b2a1607a55 | |||
| 2dab46ceb6 | |||
| 9dc6831a72 | |||
| b8f802ae8b | |||
| 542c22bbcc | |||
| d519ae0726 | |||
| fd7a65e0c0 | |||
| f2e6656b8e | |||
| c3380f58e7 | |||
| 61614eea5c | |||
| e24c2a9074 | |||
| 9e5a1e06d2 | |||
| 580d4aff21 | |||
| def7784df6 | |||
| 4e404e7097 | |||
| 4651f806c0 |
@@ -28,11 +28,11 @@ jobs:
|
||||
steps:
|
||||
- name: Checkout
|
||||
id: checkout
|
||||
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
|
||||
- name: Setup Node.js
|
||||
id: setup-node
|
||||
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
|
||||
uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
|
||||
with:
|
||||
node-version-file: .node-version
|
||||
cache: npm
|
||||
@@ -60,7 +60,7 @@ jobs:
|
||||
- if: ${{ failure() && steps.diff.outcome == 'failure' }}
|
||||
name: Upload Artifact
|
||||
id: upload
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
||||
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
|
||||
with:
|
||||
name: dist
|
||||
path: dist/
|
||||
|
||||
@@ -21,11 +21,11 @@ jobs:
|
||||
steps:
|
||||
- name: Checkout
|
||||
id: checkout
|
||||
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
|
||||
- name: Setup Node.js
|
||||
id: setup-node
|
||||
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
|
||||
uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
|
||||
with:
|
||||
node-version-file: .node-version
|
||||
cache: npm
|
||||
@@ -57,7 +57,7 @@ jobs:
|
||||
steps:
|
||||
- name: Checkout
|
||||
id: checkout
|
||||
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
- name: Run attest-sbom
|
||||
id: attest-sbom
|
||||
uses: ./
|
||||
|
||||
@@ -32,19 +32,19 @@ jobs:
|
||||
steps:
|
||||
- name: Checkout
|
||||
id: checkout
|
||||
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
|
||||
- name: Initialize CodeQL
|
||||
id: initialize
|
||||
uses: github/codeql-action/init@df559355d593797519d70b90fc8edd5db049e7a2 # v3.29.9
|
||||
uses: github/codeql-action/init@19b2f06db2b6f5108140aeb04014ef02b648f789 # v4.31.11
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
source-root: src
|
||||
|
||||
- name: Autobuild
|
||||
id: autobuild
|
||||
uses: github/codeql-action/autobuild@df559355d593797519d70b90fc8edd5db049e7a2 # v3.29.9
|
||||
uses: github/codeql-action/autobuild@19b2f06db2b6f5108140aeb04014ef02b648f789 # v4.31.11
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
id: analyze
|
||||
uses: github/codeql-action/analyze@df559355d593797519d70b90fc8edd5db049e7a2 # v3.29.9
|
||||
uses: github/codeql-action/analyze@19b2f06db2b6f5108140aeb04014ef02b648f789 # v4.31.11
|
||||
|
||||
@@ -3,10 +3,14 @@
|
||||
Generate signed SBOM attestations for workflow artifacts. Internally powered by
|
||||
the [@actions/attest][1] package.
|
||||
|
||||
Attestations bind some subject (a named artifact along with its digest) to a a
|
||||
Software Bill of Materials (SBOM) using the [in-toto][2] format. The action
|
||||
accepts SBOMs which have been generated by external tools. Provided SBOMs must
|
||||
be in either the [SPDX][4] or [CycloneDX][5] JSON-serialized format.
|
||||
Attestations bind some subject (a named artifact along with its digest) to a
|
||||
Software Bill of Materials (SBOM) using the [in-toto][2] format. This action
|
||||
generates a [reference predicate][3] that points to the SBOM rather than
|
||||
embedding the full SBOM content. The SBOM file is uploaded as a GitHub release
|
||||
asset, and the attestation references its download location and digest.
|
||||
|
||||
The action accepts SBOMs which have been generated by external tools. Provided
|
||||
SBOMs must be in either the [SPDX][4] or [CycloneDX][5] JSON-serialized format.
|
||||
|
||||
A verifiable signature is generated for the attestation using a short-lived
|
||||
[Sigstore][6]-issued signing certificate. If the repository initiating the
|
||||
@@ -44,18 +48,20 @@ attest:
|
||||
```yaml
|
||||
permissions:
|
||||
id-token: write
|
||||
contents: write
|
||||
attestations: write
|
||||
```
|
||||
|
||||
The `id-token` permission gives the action the ability to mint the OIDC token
|
||||
necessary to request a Sigstore signing certificate. The `attestations`
|
||||
permission is necessary to persist the attestation.
|
||||
permission is necessary to persist the attestation. The `contents` permission
|
||||
is required to create releases and upload the SBOM as a release asset.
|
||||
|
||||
1. Add the following to your workflow after your artifact has been built and
|
||||
your SBOM has been generated:
|
||||
|
||||
```yaml
|
||||
- uses: actions/attest-sbom@v2
|
||||
- uses: actions/attest-sbom@v3
|
||||
with:
|
||||
subject-path: '<PATH TO ARTIFACT>'
|
||||
sbom-path: '<PATH TO SBOM>'
|
||||
@@ -70,7 +76,7 @@ attest:
|
||||
See [action.yml](action.yml)
|
||||
|
||||
```yaml
|
||||
- uses: actions/attest-sbom@v2
|
||||
- uses: actions/attest-sbom@v3
|
||||
with:
|
||||
# Path to the artifact serving as the subject of the attestation. Must
|
||||
# specify exactly one of "subject-path", "subject-digest", or
|
||||
@@ -92,8 +98,8 @@ See [action.yml](action.yml)
|
||||
# or "subject-checksums".
|
||||
subject-checksums:
|
||||
|
||||
# Path to the JSON-formatted SBOM file to attest. File size cannot exceed
|
||||
# 16MB.
|
||||
# Path to the JSON-formatted SBOM file to attest. The SBOM will be
|
||||
# uploaded as a release asset and referenced in the attestation.
|
||||
sbom-path:
|
||||
|
||||
# Whether to push the attestation to the image registry. Requires that the
|
||||
@@ -105,11 +111,26 @@ See [action.yml](action.yml)
|
||||
# summary page. Defaults to true.
|
||||
show-summary:
|
||||
|
||||
# The GitHub token used to make authenticated API requests. Default is
|
||||
# ${{ github.token }}
|
||||
# The GitHub token used to make authenticated API requests and upload
|
||||
# the SBOM to a release. Default is ${{ github.token }}
|
||||
github-token:
|
||||
```
|
||||
|
||||
### How It Works
|
||||
|
||||
When you run this action:
|
||||
|
||||
1. The SBOM file is read and its SHA-256 digest is calculated
|
||||
1. A GitHub release tagged "sbom" is created (if it doesn't already exist)
|
||||
1. The SBOM is uploaded as a release asset with a unique filename incorporating
|
||||
the workflow run ID (e.g., `12345-sbom.spdx.json`)
|
||||
1. A [reference predicate][3] is generated containing:
|
||||
- The download URL for the release asset
|
||||
- The SHA-256 digest of the SBOM
|
||||
- The media type (`application/spdx+json` or `application/vnd.cyclonedx+json`)
|
||||
- An attester ID identifying the workflow that created the attestation
|
||||
1. The reference predicate is signed and uploaded as an attestation
|
||||
|
||||
### Outputs
|
||||
|
||||
<!-- markdownlint-disable MD013 -->
|
||||
@@ -137,10 +158,6 @@ paths to all attestations created over the course of a single workflow.
|
||||
|
||||
No more than 1024 subjects can be attested at the same time.
|
||||
|
||||
### SBOM Limits
|
||||
|
||||
The SBOM supplied via the `sbom-path` input cannot exceed 16MB.
|
||||
|
||||
## Examples
|
||||
|
||||
### Identify Subject and SBOM by Path
|
||||
@@ -160,7 +177,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
id-token: write
|
||||
contents: read
|
||||
contents: write
|
||||
attestations: write
|
||||
|
||||
steps:
|
||||
@@ -174,7 +191,7 @@ jobs:
|
||||
format: 'spdx-json'
|
||||
output-file: 'sbom.spdx.json'
|
||||
- name: Attest
|
||||
uses: actions/attest-sbom@v2
|
||||
uses: actions/attest-sbom@v3
|
||||
with:
|
||||
subject-path: '${{ github.workspace }}/my-app'
|
||||
sbom-path: 'sbom.spdx.json'
|
||||
@@ -186,7 +203,7 @@ If you are generating multiple artifacts, you can attest all of them at the same
|
||||
time by using a wildcard in the `subject-path` input.
|
||||
|
||||
```yaml
|
||||
- uses: actions/attest-sbom@v2
|
||||
- uses: actions/attest-sbom@v3
|
||||
with:
|
||||
subject-path: 'dist/**/my-bin-*'
|
||||
sbom-path: '${{ github.workspace }}/my-bin.sbom.spdx.json'
|
||||
@@ -199,13 +216,13 @@ Alternatively, you can explicitly list multiple subjects with either a comma or
|
||||
newline delimited list:
|
||||
|
||||
```yaml
|
||||
- uses: actions/attest-sbom@v2
|
||||
- uses: actions/attest-sbom@v3
|
||||
with:
|
||||
subject-path: 'dist/foo, dist/bar'
|
||||
```
|
||||
|
||||
```yaml
|
||||
- uses: actions/attest-sbom@v2
|
||||
- uses: actions/attest-sbom@v3
|
||||
with:
|
||||
subject-path: |
|
||||
dist/foo
|
||||
@@ -226,7 +243,7 @@ attestation.
|
||||
- name: Calculate artifact digests
|
||||
run: |
|
||||
shasum -a 256 foo_0.0.1_* > subject.checksums.txt
|
||||
- uses: actions/attest-sbom@v2
|
||||
- uses: actions/attest-sbom@v3
|
||||
with:
|
||||
subject-checksums: subject.checksums.txt
|
||||
sbom-path: sbom.spdx.json
|
||||
@@ -274,7 +291,7 @@ jobs:
|
||||
permissions:
|
||||
id-token: write
|
||||
packages: write
|
||||
contents: read
|
||||
contents: write
|
||||
attestations: write
|
||||
env:
|
||||
REGISTRY: ghcr.io
|
||||
@@ -303,7 +320,7 @@ jobs:
|
||||
format: 'cyclonedx-json'
|
||||
output-file: 'sbom.cyclonedx.json'
|
||||
- name: Attest
|
||||
uses: actions/attest-sbom@v2
|
||||
uses: actions/attest-sbom@v3
|
||||
id: attest
|
||||
with:
|
||||
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
||||
@@ -314,6 +331,8 @@ jobs:
|
||||
|
||||
[1]: https://github.com/actions/toolkit/tree/main/packages/attest
|
||||
[2]: https://github.com/in-toto/attestation/tree/main/spec/v1
|
||||
[3]:
|
||||
https://github.com/in-toto/attestation/blob/main/spec/predicates/reference.md
|
||||
[4]: https://spdx.dev/
|
||||
[5]: https://cyclonedx.org/
|
||||
[6]: https://www.sigstore.dev/
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
module.exports = {
|
||||
context: {
|
||||
repo: { owner: 'test-owner', repo: 'test-repo' },
|
||||
runId: 12345,
|
||||
serverUrl: 'https://github.com'
|
||||
},
|
||||
getOctokit: jest.fn()
|
||||
}
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
import * as main from '../src/main'
|
||||
|
||||
jest.mock('@actions/github')
|
||||
|
||||
// Mock the action's entrypoint
|
||||
const runMock = jest.spyOn(main, 'run').mockImplementation()
|
||||
|
||||
|
||||
+121
-19
@@ -1,11 +1,15 @@
|
||||
import * as core from '@actions/core'
|
||||
import * as github from '@actions/github'
|
||||
import * as main from '../src/main'
|
||||
import * as fs from 'fs'
|
||||
import os from 'os'
|
||||
import * as path from 'path'
|
||||
import { REFERENCE_PREDICATE_TYPE } from '../src/reference'
|
||||
|
||||
// Mock the GitHub Actions core library
|
||||
jest.mock('@actions/core')
|
||||
jest.mock('@actions/github')
|
||||
|
||||
const getInputMock = jest.spyOn(core, 'getInput')
|
||||
const setOutputMock = jest.spyOn(core, 'setOutput')
|
||||
const setFailedMock = jest.spyOn(core, 'setFailed')
|
||||
@@ -13,6 +17,21 @@ const setFailedMock = jest.spyOn(core, 'setFailed')
|
||||
// Ensure that setFailed doesn't set an exit code during tests
|
||||
setFailedMock.mockImplementation(() => {})
|
||||
|
||||
// Mock Octokit
|
||||
const mockUploadReleaseAsset = jest.fn()
|
||||
const mockGetReleaseByTag = jest.fn()
|
||||
const mockCreateRelease = jest.fn()
|
||||
|
||||
const mockOctokit = {
|
||||
rest: {
|
||||
repos: {
|
||||
uploadReleaseAsset: mockUploadReleaseAsset,
|
||||
getReleaseByTag: mockGetReleaseByTag,
|
||||
createRelease: mockCreateRelease
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
describe('SBOM Action', () => {
|
||||
let tempDir = '/'
|
||||
let outputs = {} as Record<string, string>
|
||||
@@ -24,6 +43,18 @@ describe('SBOM Action', () => {
|
||||
setOutputMock.mockImplementation((key, value) => {
|
||||
outputs[key] = value
|
||||
})
|
||||
|
||||
// Setup GitHub mock
|
||||
;(github.getOctokit as jest.Mock).mockReturnValue(mockOctokit)
|
||||
|
||||
// Default mock responses
|
||||
mockGetReleaseByTag.mockResolvedValue({ data: { id: 999 } })
|
||||
mockUploadReleaseAsset.mockResolvedValue({
|
||||
data: {
|
||||
browser_download_url:
|
||||
'https://github.com/test-owner/test-repo/releases/download/sbom/12345-spdxSBOM.json'
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
@@ -31,7 +62,7 @@ describe('SBOM Action', () => {
|
||||
outputs = {}
|
||||
})
|
||||
|
||||
it('successfully processes an SBOM', async () => {
|
||||
it('successfully processes an SBOM and generates reference predicate', async () => {
|
||||
const spdxSBOM = JSON.stringify({
|
||||
spdxVersion: 'SPDX-2.2',
|
||||
SPDXID: 'SPDXRef-DOCUMENT',
|
||||
@@ -40,22 +71,27 @@ describe('SBOM Action', () => {
|
||||
const filePath = path.join(tempDir, 'spdxSBOM.json')
|
||||
fs.writeFileSync(filePath, spdxSBOM)
|
||||
|
||||
const inputs = {
|
||||
'sbom-path': filePath
|
||||
const inputs: Record<string, string> = {
|
||||
'sbom-path': filePath,
|
||||
'github-token': 'fake-token'
|
||||
}
|
||||
getInputMock.mockImplementation(mockInput(inputs))
|
||||
const originalEnv = process.env
|
||||
process.env = { ...originalEnv, RUNNER_TEMP: '/tmp' }
|
||||
process.env = {
|
||||
...originalEnv,
|
||||
RUNNER_TEMP: '/tmp',
|
||||
GITHUB_WORKFLOW_REF:
|
||||
'test-owner/test-repo/.github/workflows/ci.yml@refs/heads/main'
|
||||
}
|
||||
|
||||
// Run the main function
|
||||
await main.run()
|
||||
|
||||
// Verify that outputs were set correctly
|
||||
expect(setOutputMock).toHaveBeenCalledTimes(2)
|
||||
expect(setOutputMock).toHaveBeenNthCalledWith(
|
||||
2,
|
||||
expect(setOutputMock).toHaveBeenCalledWith(
|
||||
'predicate-type',
|
||||
'https://spdx.dev/Document/v2.2'
|
||||
REFERENCE_PREDICATE_TYPE
|
||||
)
|
||||
expect(outputs['predicate-path']).toBeTruthy()
|
||||
const predicatePath = outputs['predicate-path']
|
||||
@@ -65,9 +101,34 @@ describe('SBOM Action', () => {
|
||||
|
||||
// Read the content of the temporary file
|
||||
const fileContent = fs.readFileSync(predicatePath, 'utf-8')
|
||||
const predicate = JSON.parse(fileContent) as {
|
||||
attester: { id: string }
|
||||
references: {
|
||||
downloadLocation: string
|
||||
mediaType: string
|
||||
digest: { sha256: string }
|
||||
}[]
|
||||
}
|
||||
|
||||
// Verify that the content matches the predicate params
|
||||
expect(JSON.parse(fileContent)).toEqual(JSON.parse(spdxSBOM))
|
||||
// Verify reference predicate structure
|
||||
expect(predicate.attester.id).toBe(
|
||||
'https://github.com/test-owner/test-repo/.github/workflows/ci.yml'
|
||||
)
|
||||
expect(predicate.references).toHaveLength(1)
|
||||
expect(predicate.references[0].downloadLocation).toBe(
|
||||
'https://github.com/test-owner/test-repo/releases/download/sbom/12345-spdxSBOM.json'
|
||||
)
|
||||
expect(predicate.references[0].mediaType).toBe('application/spdx+json')
|
||||
expect(predicate.references[0].digest.sha256).toBeTruthy()
|
||||
|
||||
// Verify GitHub API calls
|
||||
expect(github.getOctokit).toHaveBeenCalledWith('fake-token')
|
||||
expect(mockGetReleaseByTag).toHaveBeenCalledWith({
|
||||
owner: 'test-owner',
|
||||
repo: 'test-repo',
|
||||
tag: 'sbom'
|
||||
})
|
||||
expect(mockUploadReleaseAsset).toHaveBeenCalled()
|
||||
|
||||
// Clean up the temporary file
|
||||
fs.unlinkSync(predicatePath)
|
||||
@@ -75,22 +136,61 @@ describe('SBOM Action', () => {
|
||||
process.env = originalEnv
|
||||
})
|
||||
|
||||
it('fails when an error occurs without input', async () => {
|
||||
await main.run()
|
||||
expect(setFailedMock).toHaveBeenCalledWith(
|
||||
'TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string or an instance of Buffer or URL. Received undefined'
|
||||
)
|
||||
})
|
||||
|
||||
it('fails when an error occurs with wrong sbom format', async () => {
|
||||
it('creates release if it does not exist', async () => {
|
||||
const spdxSBOM = JSON.stringify({
|
||||
spdxVersion: 'SPDX-2.2',
|
||||
SPDXID: 'SPDXRef-DOCUMENT'
|
||||
})
|
||||
const filePath = path.join(tempDir, 'spdxSBOM.json')
|
||||
fs.writeFileSync(filePath, spdxSBOM)
|
||||
|
||||
const inputs = {
|
||||
'sbom-path': filePath
|
||||
const inputs: Record<string, string> = {
|
||||
'sbom-path': filePath,
|
||||
'github-token': 'fake-token'
|
||||
}
|
||||
getInputMock.mockImplementation(mockInput(inputs))
|
||||
const originalEnv = process.env
|
||||
process.env = {
|
||||
...originalEnv,
|
||||
RUNNER_TEMP: '/tmp',
|
||||
GITHUB_WORKFLOW_REF:
|
||||
'test-owner/test-repo/.github/workflows/ci.yml@refs/heads/main'
|
||||
}
|
||||
|
||||
// Mock release not found
|
||||
mockGetReleaseByTag.mockRejectedValue({ status: 404 })
|
||||
mockCreateRelease.mockResolvedValue({ data: { id: 1000 } })
|
||||
|
||||
await main.run()
|
||||
|
||||
expect(mockCreateRelease).toHaveBeenCalledWith({
|
||||
owner: 'test-owner',
|
||||
repo: 'test-repo',
|
||||
tag_name: 'sbom',
|
||||
name: 'SBOM Attestations',
|
||||
body: 'This release contains SBOM files referenced by attestations.',
|
||||
draft: false,
|
||||
prerelease: false
|
||||
})
|
||||
|
||||
process.env = originalEnv
|
||||
})
|
||||
|
||||
it('fails when an error occurs without input', async () => {
|
||||
await main.run()
|
||||
expect(setFailedMock).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('fails when an error occurs with wrong sbom format', async () => {
|
||||
const invalidSBOM = JSON.stringify({
|
||||
SPDXID: 'SPDXRef-DOCUMENT'
|
||||
})
|
||||
const filePath = path.join(tempDir, 'invalid.json')
|
||||
fs.writeFileSync(filePath, invalidSBOM)
|
||||
|
||||
const inputs: Record<string, string> = {
|
||||
'sbom-path': filePath,
|
||||
'github-token': 'fake-token'
|
||||
}
|
||||
getInputMock.mockImplementation(mockInput(inputs))
|
||||
const originalEnv = process.env
|
||||
@@ -99,6 +199,8 @@ describe('SBOM Action', () => {
|
||||
// Run the main function
|
||||
await main.run()
|
||||
expect(setFailedMock).toHaveBeenCalledWith('Unsupported SBOM format')
|
||||
|
||||
process.env = originalEnv
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
import {
|
||||
calculateSHA256,
|
||||
generateReferencePredicate,
|
||||
getMediaType,
|
||||
REFERENCE_PREDICATE_TYPE
|
||||
} from '../src/reference'
|
||||
import * as fs from 'fs'
|
||||
import os from 'os'
|
||||
import * as path from 'path'
|
||||
|
||||
describe('calculateSHA256', () => {
|
||||
let tempDir = '/'
|
||||
|
||||
beforeEach(() => {
|
||||
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'reference'))
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
fs.rmSync(tempDir, { recursive: true })
|
||||
})
|
||||
|
||||
it('calculates correct SHA-256 digest', async () => {
|
||||
const content = 'test content for hashing'
|
||||
const filePath = path.join(tempDir, 'test.json')
|
||||
fs.writeFileSync(filePath, content)
|
||||
|
||||
const digest = await calculateSHA256(filePath)
|
||||
|
||||
// Expected SHA-256 of 'test content for hashing'
|
||||
expect(digest).toBe(
|
||||
'e25dd806d495b413931f4eea50b677a7a5c02d00460924661283f211a37f7e7f'
|
||||
)
|
||||
})
|
||||
|
||||
it('produces different digests for different content', async () => {
|
||||
const file1 = path.join(tempDir, 'file1.json')
|
||||
const file2 = path.join(tempDir, 'file2.json')
|
||||
fs.writeFileSync(file1, 'content one')
|
||||
fs.writeFileSync(file2, 'content two')
|
||||
|
||||
const digest1 = await calculateSHA256(file1)
|
||||
const digest2 = await calculateSHA256(file2)
|
||||
|
||||
expect(digest1).not.toBe(digest2)
|
||||
})
|
||||
})
|
||||
|
||||
describe('generateReferencePredicate', () => {
|
||||
it('generates correct reference predicate structure', () => {
|
||||
const params = {
|
||||
attesterId: 'https://github.com/owner/repo/.github/workflows/ci.yml',
|
||||
downloadLocation:
|
||||
'https://github.com/owner/repo/releases/download/sbom/sbom.json',
|
||||
digest: 'abc123def456',
|
||||
mediaType: 'application/spdx+json'
|
||||
}
|
||||
|
||||
const predicate = generateReferencePredicate(params)
|
||||
|
||||
expect(predicate.type).toBe(REFERENCE_PREDICATE_TYPE)
|
||||
expect(predicate.params).toEqual({
|
||||
attester: {
|
||||
id: 'https://github.com/owner/repo/.github/workflows/ci.yml'
|
||||
},
|
||||
references: [
|
||||
{
|
||||
downloadLocation:
|
||||
'https://github.com/owner/repo/releases/download/sbom/sbom.json',
|
||||
digest: {
|
||||
sha256: 'abc123def456'
|
||||
},
|
||||
mediaType: 'application/spdx+json'
|
||||
}
|
||||
]
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('getMediaType', () => {
|
||||
it('returns correct media type for SPDX', () => {
|
||||
expect(getMediaType('spdx')).toBe('application/spdx+json')
|
||||
})
|
||||
|
||||
it('returns correct media type for CycloneDX', () => {
|
||||
expect(getMediaType('cyclonedx')).toBe('application/vnd.cyclonedx+json')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,45 @@
|
||||
import { generateAssetName, buildAttesterId } from '../src/release'
|
||||
|
||||
describe('generateAssetName', () => {
|
||||
it('generates asset name with run ID prefix', () => {
|
||||
const result = generateAssetName(12345, '/path/to/sbom.json')
|
||||
expect(result).toBe('12345-sbom.json')
|
||||
})
|
||||
|
||||
it('handles paths with multiple directories', () => {
|
||||
const result = generateAssetName(99999, '/a/b/c/d/my-sbom.spdx.json')
|
||||
expect(result).toBe('99999-my-sbom.spdx.json')
|
||||
})
|
||||
})
|
||||
|
||||
describe('buildAttesterId', () => {
|
||||
it('builds correct attester ID URL from workflow ref', () => {
|
||||
const result = buildAttesterId(
|
||||
'https://github.com',
|
||||
'octocat/hello-world/.github/workflows/ci.yml@refs/heads/main'
|
||||
)
|
||||
expect(result).toBe(
|
||||
'https://github.com/octocat/hello-world/.github/workflows/ci.yml'
|
||||
)
|
||||
})
|
||||
|
||||
it('handles workflow refs with tags', () => {
|
||||
const result = buildAttesterId(
|
||||
'https://github.com',
|
||||
'owner/repo/.github/workflows/release.yml@refs/tags/v1.0.0'
|
||||
)
|
||||
expect(result).toBe(
|
||||
'https://github.com/owner/repo/.github/workflows/release.yml'
|
||||
)
|
||||
})
|
||||
|
||||
it('handles enterprise server URLs', () => {
|
||||
const result = buildAttesterId(
|
||||
'https://github.example.com',
|
||||
'owner/repo/.github/workflows/build.yml@refs/heads/main'
|
||||
)
|
||||
expect(result).toBe(
|
||||
'https://github.example.com/owner/repo/.github/workflows/build.yml'
|
||||
)
|
||||
})
|
||||
})
|
||||
+3
-39
@@ -1,9 +1,4 @@
|
||||
import {
|
||||
storePredicate,
|
||||
parseSBOMFromPath,
|
||||
generateSBOMPredicate,
|
||||
SBOM
|
||||
} from '../src/sbom'
|
||||
import { storePredicate, parseSBOMFromPath } from '../src/sbom'
|
||||
import type { Predicate } from '@actions/attest'
|
||||
import * as fs from 'fs'
|
||||
import os from 'os'
|
||||
@@ -28,8 +23,7 @@ describe('parseSBOMFromPath', () => {
|
||||
const filePath = path.join(tempDir, 'spdxSBOM.json')
|
||||
fs.writeFileSync(filePath, spdxSBOM)
|
||||
await expect(parseSBOMFromPath(filePath)).resolves.toEqual({
|
||||
type: 'spdx',
|
||||
object: JSON.parse(spdxSBOM)
|
||||
type: 'spdx'
|
||||
})
|
||||
})
|
||||
|
||||
@@ -43,8 +37,7 @@ describe('parseSBOMFromPath', () => {
|
||||
fs.writeFileSync(filePath, cycloneDXSBOM)
|
||||
|
||||
await expect(parseSBOMFromPath(filePath)).resolves.toEqual({
|
||||
type: 'cyclonedx',
|
||||
object: JSON.parse(cycloneDXSBOM)
|
||||
type: 'cyclonedx'
|
||||
})
|
||||
})
|
||||
|
||||
@@ -99,32 +92,3 @@ describe('storePredicate', () => {
|
||||
process.env = originalEnv
|
||||
})
|
||||
})
|
||||
|
||||
describe('generateSBOMPredicate', () => {
|
||||
it('generates SPDX predicate correctly', () => {
|
||||
const sbom = { type: 'spdx', object: { spdxVersion: 'SPDX-2.2' } } as SBOM
|
||||
const result = generateSBOMPredicate(sbom)
|
||||
expect(result.type).toContain('https://spdx.dev/Document/v2.2')
|
||||
expect(result.params).toEqual(sbom.object)
|
||||
})
|
||||
|
||||
it('throws an error for missing SPDX version', () => {
|
||||
const sbom = { type: 'spdx' } as SBOM
|
||||
expect(() => generateSBOMPredicate(sbom)).toThrow(
|
||||
'Cannot find spdxVersion in the SBOM'
|
||||
)
|
||||
})
|
||||
|
||||
it('generates CycloneDX predicate correctly', () => {
|
||||
const sbom = { type: 'cyclonedx', object: {} } as SBOM
|
||||
const result = generateSBOMPredicate(sbom)
|
||||
expect(result.type).toEqual('https://cyclonedx.org/bom')
|
||||
expect(result.params).toEqual(sbom.object)
|
||||
})
|
||||
|
||||
it('throws error for unsupported SBOM formats', () => {
|
||||
const sbom = { type: 'foo', object: {} }
|
||||
// @ts-expect-error test error case
|
||||
expect(() => generateSBOMPredicate(sbom)).toThrow('Unsupported SBOM format')
|
||||
})
|
||||
})
|
||||
|
||||
+3
-2
@@ -67,11 +67,12 @@ outputs:
|
||||
runs:
|
||||
using: 'composite'
|
||||
steps:
|
||||
- uses: actions/attest-sbom/predicate@534423496eab34674190bc45fdacbb8b1198e07f # predicate@1.0.0
|
||||
- uses: actions/attest-sbom/predicate@bdehamer/detached-sbom
|
||||
id: generate-sbom-predicate
|
||||
with:
|
||||
sbom-path: ${{ inputs.sbom-path }}
|
||||
- uses: actions/attest@daf44fb950173508f38bd2406030372c1d1162b1 # v3.0.0
|
||||
github-token: ${{ inputs.github-token }}
|
||||
- uses: actions/attest@7667f588f2f73a90cea6c7ac70e78266c4f76616 # v3.1.0
|
||||
id: attest
|
||||
env:
|
||||
NODE_OPTIONS: '--max-http-header-size=32768'
|
||||
|
||||
+33208
-264
File diff suppressed because one or more lines are too long
+457
@@ -22,6 +22,18 @@ The above copyright notice and this permission notice shall be included in all c
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
@actions/github
|
||||
MIT
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright 2019 GitHub
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
@actions/http-client
|
||||
MIT
|
||||
Actions Http Client for Node.js
|
||||
@@ -81,6 +93,421 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
IN THE SOFTWARE.
|
||||
|
||||
@octokit/auth-token
|
||||
MIT
|
||||
The MIT License
|
||||
|
||||
Copyright (c) 2019 Octokit contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
|
||||
@octokit/core
|
||||
MIT
|
||||
The MIT License
|
||||
|
||||
Copyright (c) 2019 Octokit contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
|
||||
@octokit/endpoint
|
||||
MIT
|
||||
The MIT License
|
||||
|
||||
Copyright (c) 2018 Octokit contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
|
||||
@octokit/graphql
|
||||
MIT
|
||||
The MIT License
|
||||
|
||||
Copyright (c) 2018 Octokit contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
|
||||
@octokit/plugin-paginate-rest
|
||||
MIT
|
||||
MIT License Copyright (c) 2019 Octokit contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
|
||||
@octokit/plugin-rest-endpoint-methods
|
||||
MIT
|
||||
MIT License Copyright (c) 2019 Octokit contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
|
||||
@octokit/request
|
||||
MIT
|
||||
The MIT License
|
||||
|
||||
Copyright (c) 2018 Octokit contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
|
||||
@octokit/request-error
|
||||
MIT
|
||||
The MIT License
|
||||
|
||||
Copyright (c) 2019 Octokit contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
|
||||
before-after-hook
|
||||
Apache-2.0
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "{}"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright 2018 Gregor Martynus and other contributors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
|
||||
deprecation
|
||||
ISC
|
||||
The ISC License
|
||||
|
||||
Copyright (c) Gregor Martynus and contributors
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
|
||||
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
|
||||
once
|
||||
ISC
|
||||
The ISC License
|
||||
|
||||
Copyright (c) Isaac Z. Schlueter and Contributors
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
|
||||
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
|
||||
tunnel
|
||||
MIT
|
||||
The MIT License (MIT)
|
||||
@@ -129,3 +556,33 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
|
||||
universal-user-agent
|
||||
ISC
|
||||
# [ISC License](https://spdx.org/licenses/ISC)
|
||||
|
||||
Copyright (c) 2018, Gregor Martynus (https://github.com/gr2m)
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
|
||||
wrappy
|
||||
ISC
|
||||
The ISC License
|
||||
|
||||
Copyright (c) Isaac Z. Schlueter and Contributors
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
|
||||
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ export default tseslint.config(
|
||||
// Ignore non-project files
|
||||
{
|
||||
name: 'ignore',
|
||||
ignores: ['.github', 'dist', 'coverage', '**/*.json', 'jest.setup.js', 'eslint.config.mjs']
|
||||
ignores: ['.github', 'dist', 'coverage', '**/*.json', 'jest.setup.js', 'eslint.config.mjs', '__mocks__']
|
||||
},
|
||||
// Use recommended rules from ESLint, TypeScript, and other plugins
|
||||
eslint.configs.recommended,
|
||||
|
||||
Generated
+1062
-1129
File diff suppressed because it is too large
Load Diff
+14
-13
@@ -70,22 +70,23 @@
|
||||
]
|
||||
},
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.11.1"
|
||||
"@actions/core": "^2.0.2",
|
||||
"@actions/github": "^6.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@actions/attest": "^1.6.0",
|
||||
"@eslint/js": "^9.34.0",
|
||||
"@actions/attest": "^2.2.0",
|
||||
"@eslint/js": "^9.39.2",
|
||||
"@types/jest": "^30.0.0",
|
||||
"@types/node": "^24.3.0",
|
||||
"@vercel/ncc": "^0.38.3",
|
||||
"eslint": "^9.34.0",
|
||||
"@types/node": "^25.0.9",
|
||||
"@vercel/ncc": "^0.38.4",
|
||||
"eslint": "^9.39.2",
|
||||
"eslint-plugin-import": "^2.32.0",
|
||||
"eslint-plugin-jest": "^29.0.1",
|
||||
"jest": "^30.1.1",
|
||||
"markdownlint-cli": "^0.45.0",
|
||||
"prettier": "^3.6.2",
|
||||
"ts-jest": "^29.4.1",
|
||||
"typescript": "^5.9.2",
|
||||
"typescript-eslint": "^8.41.0"
|
||||
"eslint-plugin-jest": "^29.12.1",
|
||||
"jest": "^30.2.0",
|
||||
"markdownlint-cli": "^0.47.0",
|
||||
"prettier": "^3.8.0",
|
||||
"ts-jest": "^29.4.6",
|
||||
"typescript": "^5.9.3",
|
||||
"typescript-eslint": "^8.53.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
name: 'SBOM Predicate'
|
||||
description: 'Generate predicate for SBOM attestations'
|
||||
description: 'Generate reference predicate for SBOM attestations'
|
||||
author: 'GitHub'
|
||||
|
||||
inputs:
|
||||
sbom-path:
|
||||
description: >
|
||||
Path to the SBOM file to generate sbom statement
|
||||
required: false
|
||||
Path to the SBOM file to generate reference predicate
|
||||
required: true
|
||||
github-token:
|
||||
description: >
|
||||
The GitHub token used to upload the SBOM to a release
|
||||
required: true
|
||||
outputs:
|
||||
predicate-path:
|
||||
description: >
|
||||
|
||||
+42
-6
@@ -1,9 +1,12 @@
|
||||
import * as core from '@actions/core'
|
||||
import * as github from '@actions/github'
|
||||
import { parseSBOMFromPath, storePredicate } from './sbom'
|
||||
import {
|
||||
parseSBOMFromPath,
|
||||
storePredicate,
|
||||
generateSBOMPredicate
|
||||
} from './sbom'
|
||||
calculateSHA256,
|
||||
generateReferencePredicate,
|
||||
getMediaType
|
||||
} from './reference'
|
||||
import { uploadSBOMToRelease, buildAttesterId } from './release'
|
||||
|
||||
/**
|
||||
* The main function for the action.
|
||||
@@ -12,12 +15,45 @@ import {
|
||||
export async function run(): Promise<void> {
|
||||
try {
|
||||
const sbomPath = core.getInput('sbom-path')
|
||||
const token = core.getInput('github-token')
|
||||
|
||||
core.debug(`Reading SBOM from ${sbomPath}`)
|
||||
const sbom = await parseSBOMFromPath(sbomPath)
|
||||
|
||||
// Calculate subject from inputs and generate provenance
|
||||
const predicate = generateSBOMPredicate(sbom)
|
||||
// Calculate SHA-256 digest of the SBOM file
|
||||
core.debug('Calculating SBOM digest')
|
||||
const digest = await calculateSHA256(sbomPath)
|
||||
|
||||
// Get context for release upload
|
||||
const { owner, repo } = github.context.repo
|
||||
const runId = github.context.runId
|
||||
const serverUrl = github.context.serverUrl
|
||||
const workflowRef = process.env.GITHUB_WORKFLOW_REF
|
||||
|
||||
if (!workflowRef) {
|
||||
throw new Error('Missing GITHUB_WORKFLOW_REF environment variable')
|
||||
}
|
||||
|
||||
// Upload SBOM to release
|
||||
core.debug('Uploading SBOM to release')
|
||||
const octokit = github.getOctokit(token)
|
||||
const { downloadUrl } = await uploadSBOMToRelease(
|
||||
octokit,
|
||||
owner,
|
||||
repo,
|
||||
runId,
|
||||
sbomPath
|
||||
)
|
||||
|
||||
// Generate reference predicate
|
||||
const attesterId = buildAttesterId(serverUrl, workflowRef)
|
||||
const mediaType = getMediaType(sbom.type)
|
||||
const predicate = generateReferencePredicate({
|
||||
attesterId,
|
||||
downloadLocation: downloadUrl,
|
||||
digest,
|
||||
mediaType
|
||||
})
|
||||
|
||||
const predicatePath = storePredicate(predicate)
|
||||
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
import fs from 'fs'
|
||||
import crypto from 'crypto'
|
||||
import type { Predicate } from '@actions/attest'
|
||||
|
||||
export const REFERENCE_PREDICATE_TYPE =
|
||||
'https://in-toto.io/attestation/reference/v0.1'
|
||||
|
||||
export type ReferencePredicate = {
|
||||
attester: {
|
||||
id: string
|
||||
}
|
||||
references: ResourceDescriptor[]
|
||||
}
|
||||
|
||||
export type ResourceDescriptor = {
|
||||
downloadLocation: string
|
||||
digest: {
|
||||
sha256: string
|
||||
}
|
||||
mediaType: string
|
||||
}
|
||||
|
||||
export async function calculateSHA256(filePath: string): Promise<string> {
|
||||
const fileBuffer = await fs.promises.readFile(filePath)
|
||||
const hash = crypto.createHash('sha256')
|
||||
hash.update(fileBuffer)
|
||||
return hash.digest('hex')
|
||||
}
|
||||
|
||||
export type ReferencePredicateParams = {
|
||||
attesterId: string
|
||||
downloadLocation: string
|
||||
digest: string
|
||||
mediaType: string
|
||||
}
|
||||
|
||||
export function generateReferencePredicate(
|
||||
params: ReferencePredicateParams
|
||||
): Predicate {
|
||||
const predicate: ReferencePredicate = {
|
||||
attester: {
|
||||
id: params.attesterId
|
||||
},
|
||||
references: [
|
||||
{
|
||||
downloadLocation: params.downloadLocation,
|
||||
digest: {
|
||||
sha256: params.digest
|
||||
},
|
||||
mediaType: params.mediaType
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
return {
|
||||
type: REFERENCE_PREDICATE_TYPE,
|
||||
params: predicate
|
||||
}
|
||||
}
|
||||
|
||||
export function getMediaType(sbomType: 'spdx' | 'cyclonedx'): string {
|
||||
switch (sbomType) {
|
||||
case 'spdx':
|
||||
return 'application/spdx+json'
|
||||
case 'cyclonedx':
|
||||
return 'application/vnd.cyclonedx+json'
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
import * as github from '@actions/github'
|
||||
|
||||
const RELEASE_TAG = 'sbom'
|
||||
|
||||
type Octokit = ReturnType<typeof github.getOctokit>
|
||||
|
||||
export type UploadResult = {
|
||||
downloadUrl: string
|
||||
}
|
||||
|
||||
export async function uploadSBOMToRelease(
|
||||
octokit: Octokit,
|
||||
owner: string,
|
||||
repo: string,
|
||||
runId: number,
|
||||
sbomPath: string
|
||||
): Promise<UploadResult> {
|
||||
const release = await findOrCreateRelease(octokit, owner, repo)
|
||||
const assetName = generateAssetName(runId, sbomPath)
|
||||
|
||||
const fileContent = await fs.promises.readFile(sbomPath)
|
||||
|
||||
const asset = await octokit.rest.repos.uploadReleaseAsset({
|
||||
owner,
|
||||
repo,
|
||||
release_id: release.id,
|
||||
name: assetName,
|
||||
// @ts-expect-error - octokit types expect string but Buffer works
|
||||
data: fileContent
|
||||
})
|
||||
|
||||
return {
|
||||
downloadUrl: asset.data.browser_download_url
|
||||
}
|
||||
}
|
||||
|
||||
async function findOrCreateRelease(
|
||||
octokit: Octokit,
|
||||
owner: string,
|
||||
repo: string
|
||||
): Promise<{ id: number }> {
|
||||
try {
|
||||
const { data: release } = await octokit.rest.repos.getReleaseByTag({
|
||||
owner,
|
||||
repo,
|
||||
tag: RELEASE_TAG
|
||||
})
|
||||
return { id: release.id }
|
||||
} catch (error) {
|
||||
// Release doesn't exist, create it
|
||||
if (isNotFoundError(error)) {
|
||||
const { data: release } = await octokit.rest.repos.createRelease({
|
||||
owner,
|
||||
repo,
|
||||
tag_name: RELEASE_TAG,
|
||||
name: 'SBOM Attestations',
|
||||
body: 'This release contains SBOM files referenced by attestations.',
|
||||
draft: false,
|
||||
prerelease: false
|
||||
})
|
||||
return { id: release.id }
|
||||
}
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
function isNotFoundError(error: unknown): boolean {
|
||||
return (
|
||||
typeof error === 'object' &&
|
||||
error !== null &&
|
||||
'status' in error &&
|
||||
error.status === 404
|
||||
)
|
||||
}
|
||||
|
||||
export function generateAssetName(runId: number, sbomPath: string): string {
|
||||
const originalName = path.basename(sbomPath)
|
||||
return `${runId}-${originalName}`
|
||||
}
|
||||
|
||||
export function buildAttesterId(
|
||||
serverUrl: string,
|
||||
workflowRef: string
|
||||
): string {
|
||||
// workflowRef is in the format: owner/repo/.github/workflows/file.yml@refs/heads/branch
|
||||
// Extract just the owner/repo/.github/workflows/file.yml part
|
||||
const workflowPath = workflowRef.split('@')[0]
|
||||
return `${serverUrl}/${workflowPath}`
|
||||
}
|
||||
+2
-37
@@ -5,7 +5,6 @@ import type { Predicate } from '@actions/attest'
|
||||
|
||||
export type SBOM = {
|
||||
type: 'spdx' | 'cyclonedx'
|
||||
object: object
|
||||
}
|
||||
|
||||
export async function parseSBOMFromPath(filePath: string): Promise<SBOM> {
|
||||
@@ -15,9 +14,9 @@ export async function parseSBOMFromPath(filePath: string): Promise<SBOM> {
|
||||
const sbom = JSON.parse(fileContent) as object
|
||||
|
||||
if (checkIsSPDX(sbom)) {
|
||||
return { type: 'spdx', object: sbom }
|
||||
return { type: 'spdx' }
|
||||
} else if (checkIsCycloneDX(sbom)) {
|
||||
return { type: 'cyclonedx', object: sbom }
|
||||
return { type: 'cyclonedx' }
|
||||
}
|
||||
throw new Error('Unsupported SBOM format')
|
||||
}
|
||||
@@ -64,37 +63,3 @@ export const storePredicate = (predicate: Predicate): string => {
|
||||
fs.writeFileSync(tempFile, JSON.stringify(predicate.params))
|
||||
return tempFile
|
||||
}
|
||||
|
||||
export const generateSBOMPredicate = (sbom: SBOM): Predicate => {
|
||||
switch (sbom.type) {
|
||||
case 'spdx':
|
||||
return generateSPDXIntoto(sbom.object)
|
||||
case 'cyclonedx':
|
||||
return generateCycloneDXIntoto(sbom.object)
|
||||
default:
|
||||
throw new Error('Unsupported SBOM format')
|
||||
}
|
||||
}
|
||||
|
||||
// ref: https://github.com/in-toto/attestation/blob/main/spec/predicates/spdx.md
|
||||
const generateSPDXIntoto = (sbom: object): Predicate => {
|
||||
const spdxVersion = (sbom as { spdxVersion?: string })?.['spdxVersion']
|
||||
if (!spdxVersion) {
|
||||
throw new Error('Cannot find spdxVersion in the SBOM')
|
||||
}
|
||||
|
||||
const version = spdxVersion.split('-')[1]
|
||||
|
||||
return {
|
||||
type: `https://spdx.dev/Document/v${version}`,
|
||||
params: sbom
|
||||
}
|
||||
}
|
||||
|
||||
// ref: https://github.com/in-toto/attestation/blob/main/spec/predicates/cyclonedx.md
|
||||
const generateCycloneDXIntoto = (sbom: object): Predicate => {
|
||||
return {
|
||||
type: 'https://cyclonedx.org/bom',
|
||||
params: sbom
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user