mirror of
https://github.com/anchore/syft.git
synced 2026-10-31 14:36:33 +01:00
510 - SBOM attestation stdout (#785)
add syft attest command to produce an attestation as application/vnd.in-toto+json to standard out using on disk PKI Signed-off-by: Christopher Phillips <christopher.phillips@anchore.com>
This commit is contained in:
@@ -3,6 +3,8 @@ package cli
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -116,6 +118,46 @@ func assertSuccessfulReturnCode(tb testing.TB, _, _ string, rc int) {
|
||||
}
|
||||
}
|
||||
|
||||
func assertVerifyAttestation(coverageImage string) traitAssertion {
|
||||
return func(tb testing.TB, stdout, _ string, _ int) {
|
||||
tb.Helper()
|
||||
cosignPath := filepath.Join(repoRoot(tb), ".tmp/cosign")
|
||||
err := os.WriteFile("attestation.json", []byte(stdout), 0664)
|
||||
if err != nil {
|
||||
tb.Errorf("could not write attestation to disk")
|
||||
}
|
||||
defer os.Remove("attestation.json")
|
||||
attachCmd := exec.Command(
|
||||
cosignPath,
|
||||
"attach",
|
||||
"attestation",
|
||||
"--attestation",
|
||||
"attestation.json",
|
||||
coverageImage, // TODO which remote image to use?
|
||||
)
|
||||
|
||||
stdout, stderr := runCommand(attachCmd, nil)
|
||||
if attachCmd.ProcessState.ExitCode() != 0 {
|
||||
tb.Log("STDOUT", stdout)
|
||||
tb.Log("STDERR", stderr)
|
||||
tb.Fatalf("could not attach image")
|
||||
}
|
||||
|
||||
verifyCmd := exec.Command(
|
||||
cosignPath,
|
||||
"verify-attestation",
|
||||
coverageImage, // TODO which remote image to use?
|
||||
)
|
||||
|
||||
stdout, stderr = runCommand(verifyCmd, nil)
|
||||
if attachCmd.ProcessState.ExitCode() != 0 {
|
||||
tb.Log("STDOUT", stdout)
|
||||
tb.Log("STDERR", stderr)
|
||||
tb.Fatalf("could not verify attestation")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func assertFileExists(file string) traitAssertion {
|
||||
return func(tb testing.TB, _, _ string, _ int) {
|
||||
tb.Helper()
|
||||
|
||||
Reference in New Issue
Block a user