Skip to content

Commit 970997f

Browse files
authored
feat(graphql & repodb): add info about signature validity (#1344)
Signed-off-by: Andreea-Lupu <andreealupu1470@yahoo.com>
1 parent 6e6ffe8 commit 970997f

24 files changed

Lines changed: 2053 additions & 31 deletions

errors/errors.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,7 @@ var (
8989
ErrUserDataNotAllowed = errors.New("repodb: user data operations are not allowed")
9090
ErrCouldNotPersistData = errors.New("repodb: could not persist to db")
9191
ErrDedupeRebuild = errors.New("dedupe: couldn't rebuild dedupe index")
92+
ErrSignConfigDirNotSet = errors.New("signatures: signature config dir not set")
93+
ErrBadManifestDigest = errors.New("signatures: bad manifest digest")
94+
ErrInvalidSignatureType = errors.New("signatures: invalid signature type")
9295
)

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ require (
384384
github.com/shibumi/go-pathspec v1.3.0 // indirect
385385
github.com/sigstore/fulcio v1.2.0 // indirect
386386
github.com/sigstore/rekor v1.1.1 // indirect
387-
github.com/sigstore/sigstore v1.6.3 // indirect
387+
github.com/sigstore/sigstore v1.6.3
388388
github.com/sirupsen/logrus v1.9.0 // indirect
389389
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 // indirect
390390
github.com/smartystreets/assertions v1.13.1 // indirect

pkg/extensions/search/convert/convert_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,3 +385,43 @@ func TestLabels(t *testing.T) {
385385
So(vendor, ShouldEqual, "zot-vendor")
386386
})
387387
}
388+
389+
func TestGetSignaturesInfo(t *testing.T) {
390+
Convey("Test get signatures info - cosign", t, func() {
391+
indexDigest := godigest.FromString("123")
392+
repoMeta := repodb.RepoMetadata{
393+
Signatures: map[string]repodb.ManifestSignatures{string(indexDigest): {"cosign": []repodb.SignatureInfo{{
394+
LayersInfo: []repodb.LayerInfo{{LayerContent: []byte{}, LayerDigest: "", SignatureKey: "", Signer: "author"}},
395+
}}}},
396+
}
397+
398+
signaturesSummary := convert.GetSignaturesInfo(true, repoMeta, indexDigest)
399+
So(signaturesSummary, ShouldNotBeEmpty)
400+
So(*signaturesSummary[0].Author, ShouldEqual, "author")
401+
So(*signaturesSummary[0].IsTrusted, ShouldEqual, true)
402+
So(*signaturesSummary[0].Tool, ShouldEqual, "cosign")
403+
})
404+
405+
Convey("Test get signatures info - notation", t, func() {
406+
indexDigest := godigest.FromString("123")
407+
repoMeta := repodb.RepoMetadata{
408+
Signatures: map[string]repodb.ManifestSignatures{string(indexDigest): {"notation": []repodb.SignatureInfo{{
409+
LayersInfo: []repodb.LayerInfo{
410+
{
411+
LayerContent: []byte{},
412+
LayerDigest: "",
413+
SignatureKey: "",
414+
Signer: "author",
415+
Date: time.Now().AddDate(0, 0, -1),
416+
},
417+
},
418+
}}}},
419+
}
420+
421+
signaturesSummary := convert.GetSignaturesInfo(true, repoMeta, indexDigest)
422+
So(signaturesSummary, ShouldNotBeEmpty)
423+
So(*signaturesSummary[0].Author, ShouldEqual, "author")
424+
So(*signaturesSummary[0].IsTrusted, ShouldEqual, false)
425+
So(*signaturesSummary[0].Tool, ShouldEqual, "notation")
426+
})
427+
}

pkg/extensions/search/convert/repodb.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,8 @@ func ImageIndex2ImageSummary(ctx context.Context, repo, tag string, indexDigest
243243

244244
annotations := GetAnnotations(indexContent.Annotations, map[string]string{})
245245

246+
signaturesInfo := GetSignaturesInfo(isSigned, repoMeta, indexDigest)
247+
246248
indexSummary := gql_generated.ImageSummary{
247249
RepoName: &repo,
248250
Tag: &tag,
@@ -251,6 +253,7 @@ func ImageIndex2ImageSummary(ctx context.Context, repo, tag string, indexDigest
251253
Manifests: manifestSummaries,
252254
LastUpdated: &indexLastUpdated,
253255
IsSigned: &isSigned,
256+
SignatureInfo: signaturesInfo,
254257
Size: &indexSize,
255258
DownloadCount: &totalDownloadCount,
256259
Description: &annotations.Description,
@@ -354,6 +357,8 @@ func ImageManifest2ImageSummary(ctx context.Context, repo, tag string, digest go
354357
}
355358
}
356359

360+
signaturesInfo := GetSignaturesInfo(isSigned, repoMeta, digest)
361+
357362
imageSummary := gql_generated.ImageSummary{
358363
RepoName: &repoName,
359364
Tag: &tag,
@@ -366,6 +371,7 @@ func ImageManifest2ImageSummary(ctx context.Context, repo, tag string, digest go
366371
LastUpdated: &imageLastUpdated,
367372
Size: &imageSize,
368373
IsSigned: &isSigned,
374+
SignatureInfo: signaturesInfo,
369375
Platform: &platform,
370376
DownloadCount: &downloadCount,
371377
Layers: getLayersSummaries(manifestContent),
@@ -380,6 +386,7 @@ func ImageManifest2ImageSummary(ctx context.Context, repo, tag string, digest go
380386
},
381387
LastUpdated: &imageLastUpdated,
382388
IsSigned: &isSigned,
389+
SignatureInfo: signaturesInfo,
383390
Size: &imageSize,
384391
DownloadCount: &downloadCount,
385392
Description: &annotations.Description,
@@ -511,6 +518,8 @@ func ImageManifest2ManifestSummary(ctx context.Context, repo, tag string, descri
511518
}
512519
}
513520

521+
signaturesInfo := GetSignaturesInfo(isSigned, repoMeta, digest)
522+
514523
manifestSummary := gql_generated.ManifestSummary{
515524
Digest: &manifestDigestStr,
516525
ConfigDigest: &configDigest,
@@ -521,6 +530,7 @@ func ImageManifest2ManifestSummary(ctx context.Context, repo, tag string, descri
521530
Layers: getLayersSummaries(manifestContent),
522531
History: historyEntries,
523532
IsSigned: &isSigned,
533+
SignatureInfo: signaturesInfo,
524534
Vulnerabilities: &gql_generated.ImageVulnerabilitySummary{
525535
MaxSeverity: &imageCveSummary.MaxSeverity,
526536
Count: &imageCveSummary.Count,
@@ -744,3 +754,44 @@ func GetPreloadString(prefix, name string) string {
744754

745755
return name
746756
}
757+
758+
func GetSignaturesInfo(isSigned bool, repoMeta repodb.RepoMetadata, indexDigest godigest.Digest,
759+
) []*gql_generated.SignatureSummary {
760+
signaturesInfo := []*gql_generated.SignatureSummary{}
761+
762+
if !isSigned {
763+
return signaturesInfo
764+
}
765+
766+
for sigType, signatures := range repoMeta.Signatures[indexDigest.String()] {
767+
for _, sig := range signatures {
768+
for _, layer := range sig.LayersInfo {
769+
var (
770+
isTrusted bool
771+
author string
772+
tool string
773+
)
774+
775+
if layer.Signer != "" {
776+
author = layer.Signer
777+
778+
if !layer.Date.IsZero() && time.Now().After(layer.Date) {
779+
isTrusted = false
780+
} else {
781+
isTrusted = true
782+
}
783+
} else {
784+
isTrusted = false
785+
author = ""
786+
}
787+
788+
tool = sigType
789+
790+
signaturesInfo = append(signaturesInfo,
791+
&gql_generated.SignatureSummary{Tool: &tool, IsTrusted: &isTrusted, Author: &author})
792+
}
793+
}
794+
}
795+
796+
return signaturesInfo
797+
}

0 commit comments

Comments
 (0)