From 8683300fe981d49d74d6c52fb0fa2da8b78c7ed1 Mon Sep 17 00:00:00 2001 From: yawangwang Date: Fri, 13 Oct 2023 19:37:03 +0000 Subject: [PATCH] Add String() to print cosign signature details --- launcher/internal/oci/cosign/signature.go | 11 +++++++++++ launcher/internal/signaturediscovery/client.go | 5 +++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/launcher/internal/oci/cosign/signature.go b/launcher/internal/oci/cosign/signature.go index 140167093..91f59dd7b 100644 --- a/launcher/internal/oci/cosign/signature.go +++ b/launcher/internal/oci/cosign/signature.go @@ -21,6 +21,8 @@ type Sig struct { // Blob represents the opaque data uploaded to OCI registry associated with the layer. // This contains the Simple Signing Payload as described in https://github.com/sigstore/cosign/blob/main/specs/SIGNATURE_SPEC.md#tag-based-discovery. Blob []byte + // SourceRepo represents the location that stores this signature. + SourceRepo string } // CosignSigKey is the key of the cosign-generated signature embedded in OCI image manifest. @@ -68,3 +70,12 @@ func (s Sig) PublicKey() ([]byte, error) { func (s Sig) SigningAlgorithm() (oci.SigningAlgorithm, error) { return "", fmt.Errorf("not implemented") } + +// String returns signature details +func (s Sig) String() string { + sig, err := s.Base64Encoded() + if err != nil { + return fmt.Sprintf("[signature error: %s]", err.Error()) + } + return fmt.Sprintf("[signature: %q, sourceRepo: %q]", sig, s.SourceRepo) +} diff --git a/launcher/internal/signaturediscovery/client.go b/launcher/internal/signaturediscovery/client.go index 550d62879..0e9cdb8ea 100644 --- a/launcher/internal/signaturediscovery/client.go +++ b/launcher/internal/signaturediscovery/client.go @@ -62,8 +62,9 @@ func (c *Client) FetchImageSignatures(ctx context.Context, targetRepository stri return nil, err } sig := &cosign.Sig{ - Layer: layer, - Blob: blob, + Layer: layer, + Blob: blob, + SourceRepo: targetRepository, } signatures = append(signatures, sig) }