Skip to content

Commit

Permalink
✨ Favor SLSA provenance over plain signature in Signed-Release (#2144)
Browse files Browse the repository at this point in the history
* update

* update
  • Loading branch information
laurentsimon authored Aug 12, 2022
1 parent 1e1bfab commit 7772984
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 18 deletions.
2 changes: 1 addition & 1 deletion checks/all_checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/ossf/scorecard/v4/checker"
)

// allChecks is the list of all registered security checks
// allChecks is the list of all registered security checks.
var allChecks = checker.CheckNameToFnMap{}

func getAll(overrideExperimental bool) checker.CheckNameToFnMap {
Expand Down
55 changes: 48 additions & 7 deletions checks/evaluation/signed_releases.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,21 @@ package evaluation

import (
"fmt"
"math"
"strings"

"github.com/ossf/scorecard/v4/checker"
sce "github.com/ossf/scorecard/v4/errors"
)

var artifactExtensions = []string{".asc", ".minisig", ".sig", ".sign", ".intoto.jsonl"}
var (
signatureExtensions = []string{".asc", ".minisig", ".sig", ".sign"}
provenanceExtensions = []string{".intoto.jsonl"}
)

const releaseLookBack = 5

// nolint
// SignedReleases applies the score policy for the Signed-Releases check.
func SignedReleases(name string, dl checker.DetailLogger, r *checker.SignedReleasesData) checker.CheckResult {
if r == nil {
Expand All @@ -34,8 +39,8 @@ func SignedReleases(name string, dl checker.DetailLogger, r *checker.SignedRelea
}

totalReleases := 0
totalSigned := 0

total := 0
score := 0
for _, release := range r.Releases {
if len(release.Assets) == 0 {
continue
Expand All @@ -47,21 +52,56 @@ func SignedReleases(name string, dl checker.DetailLogger, r *checker.SignedRelea

totalReleases++
signed := false
hasProvenance := false

// Check for provenance.
for _, asset := range release.Assets {
for _, suffix := range provenanceExtensions {
if strings.HasSuffix(asset.Name, suffix) {
dl.Info(&checker.LogMessage{
Path: asset.URL,
Type: checker.FileTypeURL,
Text: fmt.Sprintf("provenance for release artifact: %s", asset.Name),
})
hasProvenance = true
total++
break
}
}
if hasProvenance {
// Assign maximum points.
score += 10
break
}
}

if hasProvenance {
continue
}

dl.Warn(&checker.LogMessage{
Path: release.URL,
Type: checker.FileTypeURL,
Text: fmt.Sprintf("release artifact %s does not have provenance", release.TagName),
})

// No provenance. Try signatures.
for _, asset := range release.Assets {
for _, suffix := range artifactExtensions {
for _, suffix := range signatureExtensions {
if strings.HasSuffix(asset.Name, suffix) {
dl.Info(&checker.LogMessage{
Path: asset.URL,
Type: checker.FileTypeURL,
Text: fmt.Sprintf("signed release artifact: %s", asset.Name),
})
signed = true
total++
break
}
}
if signed {
totalSigned++
// Assign 8 points.
score += 8
break
}
}
Expand All @@ -86,6 +126,7 @@ func SignedReleases(name string, dl checker.DetailLogger, r *checker.SignedRelea
return checker.CreateInconclusiveResult(name, "no releases found")
}

reason := fmt.Sprintf("%d out of %d artifacts are signed", totalSigned, totalReleases)
return checker.CreateProportionalScoreResult(name, reason, totalSigned, totalReleases)
score = int(math.Floor(float64(score) / float64(totalReleases)))
reason := fmt.Sprintf("%d out of %d artifacts are signed or have provenance", total, totalReleases)
return checker.CreateResultWithScore(name, reason, score)
}
16 changes: 8 additions & 8 deletions checks/signed_releases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func TestSignedRelease(t *testing.T) {
},
},
expected: checker.CheckResult{
Score: 10,
Score: 8,
},
},
{
Expand Down Expand Up @@ -129,7 +129,7 @@ func TestSignedRelease(t *testing.T) {
},
},
expected: checker.CheckResult{
Score: 10,
Score: 8,
},
},
{
Expand All @@ -148,7 +148,7 @@ func TestSignedRelease(t *testing.T) {
},
},
expected: checker.CheckResult{
Score: 10,
Score: 8,
},
},
{
Expand All @@ -167,7 +167,7 @@ func TestSignedRelease(t *testing.T) {
},
},
expected: checker.CheckResult{
Score: 10,
Score: 8,
},
},
{
Expand All @@ -190,7 +190,7 @@ func TestSignedRelease(t *testing.T) {
},
},
expected: checker.CheckResult{
Score: 10,
Score: 8,
},
},
{
Expand Down Expand Up @@ -228,7 +228,7 @@ func TestSignedRelease(t *testing.T) {
},
},
expected: checker.CheckResult{
Score: 10,
Score: 8,
},
},
{
Expand Down Expand Up @@ -262,7 +262,7 @@ func TestSignedRelease(t *testing.T) {
},
},
expected: checker.CheckResult{
Score: 5,
Score: 4,
},
},
{
Expand Down Expand Up @@ -360,7 +360,7 @@ func TestSignedRelease(t *testing.T) {
},
},
expected: checker.CheckResult{
Score: 10,
Score: 8,
},
},
{
Expand Down
4 changes: 2 additions & 2 deletions e2e/signedreleases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ var _ = Describe("E2E TEST:"+checks.CheckSignedReleases, func() {
}
expected := scut.TestReturn{
Error: nil,
Score: checker.MaxResultScore,
NumberOfWarn: 0,
Score: 8,
NumberOfWarn: 5,
NumberOfInfo: 5,
NumberOfDebug: 5,
}
Expand Down

0 comments on commit 7772984

Please sign in to comment.