Skip to content

Commit 7ab28f9

Browse files
authored
Merge pull request #841 from crazy-max/sigstore-multi-images
sigstore: multi image names support for signing
2 parents b449e6e + 6bd8db3 commit 7ab28f9

File tree

1 file changed

+39
-37
lines changed

1 file changed

+39
-37
lines changed

src/sigstore/sigstore.ts

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import {MEDIATYPE_PAYLOAD as INTOTO_MEDIATYPE_PAYLOAD, Subject} from '../types/i
3434
import {FULCIO_URL, REKOR_URL, SEARCH_URL, TSASERVER_URL} from '../types/sigstore/sigstore';
3535

3636
export interface SignAttestationManifestsOpts {
37-
imageName: string;
37+
imageNames: Array<string>;
3838
imageDigest: string;
3939
noTransparencyLog?: boolean;
4040
}
@@ -101,12 +101,13 @@ export class Sigstore {
101101
core.info(`Using Sigstore signing endpoint: ${endpoints.fulcioURL}`);
102102
const noTransparencyLog = Sigstore.noTransparencyLog(opts.noTransparencyLog);
103103

104-
const attestationDigests = await this.imageTools.attestationDigests(`${opts.imageName}@${opts.imageDigest}`);
105-
for (const attestationDigest of attestationDigests) {
106-
const attestationRef = `${opts.imageName}@${attestationDigest}`;
107-
await core.group(`Signing attestation manifest ${attestationRef}`, async () => {
108-
// prettier-ignore
109-
const cosignArgs = [
104+
for (const imageName of opts.imageNames) {
105+
const attestationDigests = await this.imageTools.attestationDigests(`${imageName}@${opts.imageDigest}`);
106+
for (const attestationDigest of attestationDigests) {
107+
const attestationRef = `${imageName}@${attestationDigest}`;
108+
await core.group(`Signing attestation manifest ${attestationRef}`, async () => {
109+
// prettier-ignore
110+
const cosignArgs = [
110111
'--verbose',
111112
'sign',
112113
'--yes',
@@ -115,38 +116,39 @@ export class Sigstore {
115116
'--new-bundle-format',
116117
'--use-signing-config'
117118
];
118-
if (noTransparencyLog) {
119-
cosignArgs.push('--tlog-upload=false');
120-
}
121-
core.info(`[command]cosign ${[...cosignArgs, attestationRef].join(' ')}`);
122-
const execRes = await Exec.getExecOutput('cosign', [...cosignArgs, attestationRef], {
123-
ignoreReturnCode: true,
124-
silent: true,
125-
env: Object.assign({}, process.env, {
126-
COSIGN_EXPERIMENTAL: '1'
127-
}) as {
128-
[key: string]: string;
119+
if (noTransparencyLog) {
120+
cosignArgs.push('--tlog-upload=false');
129121
}
130-
});
131-
const signResult = Cosign.parseCommandOutput(execRes.stderr.trim());
132-
if (execRes.exitCode != 0) {
133-
if (signResult.errors && signResult.errors.length > 0) {
134-
const errorMessages = signResult.errors.map(e => `- [${e.code}] ${e.message} : ${e.detail}`).join('\n');
135-
throw new Error(`Cosign sign command failed with errors:\n${errorMessages}`);
136-
} else {
137-
throw new Error(`Cosign sign command failed with exit code ${execRes.exitCode}`);
122+
core.info(`[command]cosign ${[...cosignArgs, attestationRef].join(' ')}`);
123+
const execRes = await Exec.getExecOutput('cosign', [...cosignArgs, attestationRef], {
124+
ignoreReturnCode: true,
125+
silent: true,
126+
env: Object.assign({}, process.env, {
127+
COSIGN_EXPERIMENTAL: '1'
128+
}) as {
129+
[key: string]: string;
130+
}
131+
});
132+
const signResult = Cosign.parseCommandOutput(execRes.stderr.trim());
133+
if (execRes.exitCode != 0) {
134+
if (signResult.errors && signResult.errors.length > 0) {
135+
const errorMessages = signResult.errors.map(e => `- [${e.code}] ${e.message} : ${e.detail}`).join('\n');
136+
throw new Error(`Cosign sign command failed with errors:\n${errorMessages}`);
137+
} else {
138+
throw new Error(`Cosign sign command failed with exit code ${execRes.exitCode}`);
139+
}
138140
}
139-
}
140-
const attest = Sigstore.toAttestation(bundleFromJSON(signResult.bundle));
141-
if (attest.tlogID) {
142-
core.info(`Uploaded to Rekor transparency log: ${SEARCH_URL}?logIndex=${attest.tlogID}`);
143-
}
144-
core.info(`Signature manifest pushed: https://oci.dag.dev/?referrers=${attestationRef}`);
145-
result[attestationRef] = {
146-
...attest,
147-
imageName: opts.imageName
148-
};
149-
});
141+
const attest = Sigstore.toAttestation(bundleFromJSON(signResult.bundle));
142+
if (attest.tlogID) {
143+
core.info(`Uploaded to Rekor transparency log: ${SEARCH_URL}?logIndex=${attest.tlogID}`);
144+
}
145+
core.info(`Signature manifest pushed: https://oci.dag.dev/?referrers=${attestationRef}`);
146+
result[attestationRef] = {
147+
...attest,
148+
imageName: imageName
149+
};
150+
});
151+
}
150152
}
151153
} catch (err) {
152154
throw new Error(`Signing BuildKit attestation manifests failed: ${(err as Error).message}`);

0 commit comments

Comments
 (0)