Skip to content

Commit b529625

Browse files
committed
Add support for signing with Sigstore
Fixes: redhat-actions#89
1 parent c36f454 commit b529625

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Refer to the [`podman push`](http://docs.podman.io/en/latest/markdown/podman-man
3232
| password | Password, encrypted password, or access token to use to log in to the registry. Required unless already logged in to the registry. | None
3333
| tls-verify | Verify TLS certificates when contacting the registry. Set to `false` to skip certificate verification. | `true`
3434
| digestfile | After copying the image, write the digest of the resulting image to the file. The contents of this file are the digest output. | Auto-generated from image and tag
35+
| sigstore-private-key | Sigstore private key to use to sign container images | None
3536
| extra-args | Extra args to be passed to podman push. Separate arguments by newline. Do not use quotes. | None
3637

3738
<a id="image-tag-inputs"></a>

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ inputs:
3333
By default, the filename will be determined from the image and tag.
3434
The contents of this file are the digest output.
3535
required: false
36+
sigstore-private-key:
37+
description: 'Sigstore private key to use to sign container images'
38+
required: false
3639
extra-args:
3740
description: |
3841
Extra args to be passed to podman push.

src/generated/inputs-outputs.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ export enum Inputs {
5252
* Default: None.
5353
*/
5454
USERNAME = "username",
55+
/**
56+
* Sigstore private key to use to sign container images
57+
* Required: false
58+
* Default: None.
59+
*/
60+
SIGSTORE_PRIVATE_KEY = "sigstore-private-key",
5561
}
5662

5763
export enum Outputs {

src/index.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,20 @@ async function run(): Promise<void> {
209209
}
210210
}
211211

212+
const sigstorePrivateKey = core.getInput(Inputs.SIGSTORE_PRIVATE_KEY);
213+
const sigstorePrivateKeyFile = path.join(process.env.RUNNER_TEMP || "", "sigstore_private_key");
214+
if (sigstorePrivateKey) {
215+
// Write sigstore private key to a temporary file in $RUNNER_TEMP that
216+
// will be removed after the image is pushed.
217+
try {
218+
await fs.promises.writeFile(sigstorePrivateKeyFile, sigstorePrivateKey);
219+
}
220+
catch (err) {
221+
throw new Error(`Could not write sigstore private key to temporary file `
222+
+ `"${sigstorePrivateKeyFile}": ${err}`);
223+
}
224+
}
225+
212226
let pushMsg = `⏳ Pushing "${sourceImages.join(", ")}" to "${destinationImages.join(", ")}" respectively`;
213227
if (username) {
214228
pushMsg += ` as "${username}"`;
@@ -269,11 +283,24 @@ async function run(): Promise<void> {
269283
args.push(`--creds=${creds}`);
270284
}
271285

286+
if (sigstorePrivateKey) {
287+
args.push("--sign-by-sigstore-private-key");
288+
args.push(sigstorePrivateKeyFile);
289+
}
290+
272291
await execute(await getPodmanPath(), args);
273292
core.info(`✅ Successfully pushed "${sourceImages[i]}" to "${destinationImages[i]}"`);
274293

275294
registryPathList.push(destinationImages[i]);
276295

296+
try {
297+
await fs.promises.unlink(sigstorePrivateKeyFile);
298+
}
299+
catch (err) {
300+
core.warning(`Failed to remove temporary file used to store sigstore private key `
301+
+ `"${sigstorePrivateKeyFile}": ${err}`);
302+
}
303+
277304
try {
278305
const digest = (await fs.promises.readFile(digestFile)).toString();
279306
core.info(digest);

0 commit comments

Comments
 (0)