Skip to content
Draft
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
42 changes: 42 additions & 0 deletions .github/workflows/update-deps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ jobs:
- compose
- cosign
- regctl
- trusted-root
- undock
steps:
-
Expand Down Expand Up @@ -61,6 +62,7 @@ jobs:
script: |
const fs = require('fs');
const path = require('path');
const crypto = require('crypto');

const dep = core.getInput('dep');

Expand All @@ -83,6 +85,10 @@ jobs:
return [...new Set(values)];
}

function sha256(value) {
return crypto.createHash('sha256').update(value).digest('hex');
}

function stripLeadingV(value) {
return value.startsWith('v') ? value.slice(1) : value;
}
Expand Down Expand Up @@ -264,6 +270,33 @@ jobs:
]
};
}
},
'trusted-root': {
name: 'Sigstore trusted root',
branch: 'deps/sigstore-trusted-root',
sourceUrl: 'https://github.com/sigstore/root-signing/blob/main/targets/trusted_root.json',
async resolve({github}) {
const res = await github.rest.repos.getContent({
owner: 'sigstore',
repo: 'root-signing',
path: 'targets/trusted_root.json',
ref: 'main'
});
if (Array.isArray(res.data) || res.data.type !== 'file' || !res.data.content) {
throw new Error('Unable to resolve Sigstore trusted_root.json content');
}
const content = `${Buffer.from(res.data.content, res.data.encoding).toString('utf8').trim()}\n`;
return {
titleValue: res.data.sha.slice(0, 12),
targets: [
{
path: 'src/sigstore/trusted_root.json',
key: 'trusted_root.json',
content
}
]
};
}
}
};

Expand All @@ -280,6 +313,15 @@ jobs:
for (const target of resolved.targets) {
const absolutePath = path.join(process.env.GITHUB_WORKSPACE, target.path);
const content = fs.readFileSync(absolutePath, 'utf8');
if (target.content !== undefined) {
currentValues.push(sha256(content).slice(0, 12));
if (content === target.content) {
continue;
}
fs.writeFileSync(absolutePath, target.content, 'utf8');
changedFiles.push(target.path);
continue;
}
const match = content.match(target.pattern);
if (!match) {
throw new Error(`Missing ${target.key} in ${target.path}`);
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Toolkit for Docker (GitHub) Actions",
"type": "module",
"scripts": {
"build": "tsc",
"build": "tsc && node -e \"require('fs').copyFileSync('src/sigstore/trusted_root.json', 'lib/sigstore/trusted_root.json')\"",
"lint": "eslint --max-warnings=0 .",
"format": "eslint --fix .",
"test": "vitest run -c vitest.config.ts",
Expand Down Expand Up @@ -51,8 +51,8 @@
"@actions/io": "^3.0.2",
"@actions/tool-cache": "^4.0.0",
"@sigstore/bundle": "^4.0.0",
"@sigstore/protobuf-specs": "^0.5.0",
"@sigstore/sign": "^4.1.1",
"@sigstore/tuf": "^4.0.2",
"@sigstore/verify": "^3.1.0",
"async-retry": "^1.3.3",
"csv-parse": "^6.2.1",
Expand Down
29 changes: 25 additions & 4 deletions src/sigstore/sigstore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
import {X509Certificate} from 'crypto';
import fs from 'fs';
import path from 'path';
import {fileURLToPath} from 'url';

import * as core from '@actions/core';
import {bundleFromJSON, bundleToJSON, SerializedBundle} from '@sigstore/bundle';
import {TrustedRoot} from '@sigstore/protobuf-specs';
import {Artifact, Bundle, CIContextProvider, DSSEBundleBuilder, FulcioSigner, RekorWitness, TSAWitness, Witness} from '@sigstore/sign';
import * as tuf from '@sigstore/tuf';
import {toSignedEntity, toTrustMaterial, Verifier} from '@sigstore/verify';

import {Context} from '../context.js';
Expand Down Expand Up @@ -53,17 +54,21 @@ import {
export interface SigstoreOpts {
cosign?: Cosign;
imageTools?: ImageTools;
trustedRootPath?: string;
}

const COSIGN_PREDICATE_SLSA_PROVENANCE_V1 = 'slsaprovenance1';
const DEFAULT_TRUSTED_ROOT_PATH = path.join(path.dirname(fileURLToPath(import.meta.url)), 'trusted_root.json');

export class Sigstore {
private readonly cosign: Cosign;
private readonly imageTools: ImageTools;
private readonly trustedRootPath: string;

constructor(opts?: SigstoreOpts) {
this.cosign = opts?.cosign || new Cosign();
this.imageTools = opts?.imageTools || new ImageTools();
this.trustedRootPath = opts?.trustedRootPath || DEFAULT_TRUSTED_ROOT_PATH;
}

public async signAttestationManifests(opts: SignAttestationManifestsOpts): Promise<Record<string, SignAttestationManifestsResult>> {
Expand Down Expand Up @@ -130,6 +135,7 @@ export class Sigstore {
'--oidc-provider', 'github-actions',
'--registry-referrers-mode', 'oci-1-1',
'--new-bundle-format',
...this.trustedRootArgs(),
...cosignExtraArgs
];
core.info(`[command]${this.cosign.binPath} ${[...cosignArgs, attestationRef].join(' ')}`);
Expand Down Expand Up @@ -220,6 +226,7 @@ export class Sigstore {
'verify',
'--experimental-oci11',
'--new-bundle-format',
...this.trustedRootArgs(),
'--certificate-oidc-issuer', 'https://token.actions.githubusercontent.com',
'--certificate-identity-regexp', opts.certificateIdentityRegexp
];
Expand Down Expand Up @@ -353,6 +360,7 @@ export class Sigstore {
const cosignArgs = [
'verify-blob-attestation',
'--new-bundle-format',
...this.trustedRootArgs(),
'--certificate-oidc-issuer', 'https://token.actions.githubusercontent.com',
'--certificate-identity-regexp', opts.certificateIdentityRegexp,
'--type', opts.predicateType ?? COSIGN_PREDICATE_SLSA_PROVENANCE_V1
Expand Down Expand Up @@ -382,9 +390,8 @@ export class Sigstore {
const parsedBundle = JSON.parse(fs.readFileSync(bundlePath, 'utf-8')) as SerializedBundle;
const bundle = bundleFromJSON(parsedBundle);

core.info(`Fetching Sigstore TUF trusted root metadata`);
const trustedRoot = await tuf.getTrustedRoot();
const trustMaterial = toTrustMaterial(trustedRoot);
core.info(`Loading Sigstore trusted root from ${this.trustedRootPath}`);
const trustMaterial = toTrustMaterial(this.trustedRoot());

try {
core.info(`Verifying artifact signature`);
Expand Down Expand Up @@ -432,6 +439,20 @@ export class Sigstore {
};
}

private trustedRootArgs(): Array<string> {
if (!fs.existsSync(this.trustedRootPath)) {
throw new Error(`Sigstore trusted root not found at ${this.trustedRootPath}`);
}
return [`--trusted-root=${this.trustedRootPath}`];
}

private trustedRoot(): TrustedRoot {
if (!fs.existsSync(this.trustedRootPath)) {
throw new Error(`Sigstore trusted root not found at ${this.trustedRootPath}`);
}
return TrustedRoot.fromJSON(JSON.parse(fs.readFileSync(this.trustedRootPath, {encoding: 'utf-8'})));
}

private static noTransparencyLog(noTransparencyLog?: boolean): boolean {
return noTransparencyLog ?? GitHub.context.payload.repository?.private;
}
Expand Down
126 changes: 126 additions & 0 deletions src/sigstore/trusted_root.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
{
"mediaType": "application/vnd.dev.sigstore.trustedroot+json;version=0.1",
"tlogs": [
{
"baseUrl": "https://rekor.sigstore.dev",
"hashAlgorithm": "SHA2_256",
"publicKey": {
"rawBytes": "MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE2G2Y+2tabdTV5BcGiBIx0a9fAFwrkBbmLSGtks4L3qX6yYY0zufBnhC8Ur/iy55GhWP/9A/bY2LhC30M9+RYtw==",
"keyDetails": "PKIX_ECDSA_P256_SHA_256",
"validFor": {
"start": "2021-01-12T11:53:27Z"
}
},
"logId": {
"keyId": "wNI9atQGlz+VWfO6LRygH4QUfY/8W4RFwiT5i5WRgB0="
}
},
{
"baseUrl": "https://log2025-1.rekor.sigstore.dev",
"hashAlgorithm": "SHA2_256",
"publicKey": {
"rawBytes": "MCowBQYDK2VwAyEAt8rlp1knGwjfbcXAYPYAkn0XiLz1x8O4t0YkEhie244=",
"keyDetails": "PKIX_ED25519",
"validFor": {
"start": "2025-09-23T00:00:00Z"
}
},
"logId": {
"keyId": "zxGZFVvd0FEmjR8WrFwMdcAJ9vtaY/QXf44Y1wUeP6A="
}
}
],
"certificateAuthorities": [
{
"subject": {
"organization": "sigstore.dev",
"commonName": "sigstore"
},
"uri": "https://fulcio.sigstore.dev",
"certChain": {
"certificates": [
{
"rawBytes": "MIIB+DCCAX6gAwIBAgITNVkDZoCiofPDsy7dfm6geLbuhzAKBggqhkjOPQQDAzAqMRUwEwYDVQQKEwxzaWdzdG9yZS5kZXYxETAPBgNVBAMTCHNpZ3N0b3JlMB4XDTIxMDMwNzAzMjAyOVoXDTMxMDIyMzAzMjAyOVowKjEVMBMGA1UEChMMc2lnc3RvcmUuZGV2MREwDwYDVQQDEwhzaWdzdG9yZTB2MBAGByqGSM49AgEGBSuBBAAiA2IABLSyA7Ii5k+pNO8ZEWY0ylemWDowOkNa3kL+GZE5Z5GWehL9/A9bRNA3RbrsZ5i0JcastaRL7Sp5fp/jD5dxqc/UdTVnlvS16an+2Yfswe/QuLolRUCrcOE2+2iA5+tzd6NmMGQwDgYDVR0PAQH/BAQDAgEGMBIGA1UdEwEB/wQIMAYBAf8CAQEwHQYDVR0OBBYEFMjFHQBBmiQpMlEk6w2uSu1KBtPsMB8GA1UdIwQYMBaAFMjFHQBBmiQpMlEk6w2uSu1KBtPsMAoGCCqGSM49BAMDA2gAMGUCMH8liWJfMui6vXXBhjDgY4MwslmN/TJxVe/83WrFomwmNf056y1X48F9c4m3a3ozXAIxAKjRay5/aj/jsKKGIkmQatjI8uupHr/+CxFvaJWmpYqNkLDGRU+9orzh5hI2RrcuaQ=="
}
]
},
"validFor": {
"start": "2021-03-07T03:20:29Z",
"end": "2022-12-31T23:59:59.999Z"
}
},
{
"subject": {
"organization": "sigstore.dev",
"commonName": "sigstore"
},
"uri": "https://fulcio.sigstore.dev",
"certChain": {
"certificates": [
{
"rawBytes": "MIICGjCCAaGgAwIBAgIUALnViVfnU0brJasmRkHrn/UnfaQwCgYIKoZIzj0EAwMwKjEVMBMGA1UEChMMc2lnc3RvcmUuZGV2MREwDwYDVQQDEwhzaWdzdG9yZTAeFw0yMjA0MTMyMDA2MTVaFw0zMTEwMDUxMzU2NThaMDcxFTATBgNVBAoTDHNpZ3N0b3JlLmRldjEeMBwGA1UEAxMVc2lnc3RvcmUtaW50ZXJtZWRpYXRlMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE8RVS/ysH+NOvuDZyPIZtilgUF9NlarYpAd9HP1vB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9TNMea7Ix/stJ5TfcLLeABLE4BNJOsQ4vnBHJ"
}
]
},
"validFor": {
"start": "2022-04-13T20:06:15Z"
}
}
],
"ctlogs": [
{
"baseUrl": "https://ctfe.sigstore.dev/test",
"hashAlgorithm": "SHA2_256",
"publicKey": {
"rawBytes": "MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEbfwR+RJudXscgRBRpKX1XFDy3PyudDxz/SfnRi1fT8ekpfBd2O1uoz7jr3Z8nKzxA69EUQ+eFCFI3zeubPWU7w==",
"keyDetails": "PKIX_ECDSA_P256_SHA_256",
"validFor": {
"start": "2021-03-14T00:00:00Z",
"end": "2022-10-31T23:59:59.999Z"
}
},
"logId": {
"keyId": "CGCS8ChS/2hF0dFrJ4ScRWcYrBY9wzjSbea8IgY2b3I="
}
},
{
"baseUrl": "https://ctfe.sigstore.dev/2022",
"hashAlgorithm": "SHA2_256",
"publicKey": {
"rawBytes": "MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEiPSlFi0CmFTfEjCUqF9HuCEcYXNKAaYalIJmBZ8yyezPjTqhxrKBpMnaocVtLJBI1eM3uXnQzQGAJdJ4gs9Fyw==",
"keyDetails": "PKIX_ECDSA_P256_SHA_256",
"validFor": {
"start": "2022-10-20T00:00:00Z"
}
},
"logId": {
"keyId": "3T0wasbHETJjGR4cmWc3AqJKXrjePK3/h4pygC8p7o4="
}
}
],
"timestampAuthorities": [
{
"subject": {
"organization": "sigstore.dev",
"commonName": "sigstore-tsa-selfsigned"
},
"uri": "https://timestamp.sigstore.dev/api/v1/timestamp",
"certChain": {
"certificates": [
{
"rawBytes": "MIICEDCCAZagAwIBAgIUOhNULwyQYe68wUMvy4qOiyojiwwwCgYIKoZIzj0EAwMwOTEVMBMGA1UEChMMc2lnc3RvcmUuZGV2MSAwHgYDVQQDExdzaWdzdG9yZS10c2Etc2VsZnNpZ25lZDAeFw0yNTA0MDgwNjU5NDNaFw0zNTA0MDYwNjU5NDNaMC4xFTATBgNV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