Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Add Additional Details to License Check #2442

Merged
merged 52 commits into from
Nov 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
91f5041
:sparkles: Improved Security Policy Check (#2137)
shissam Aug 23, 2022
0c59ded
Repaired Security Policy to correctly use linked content length for e…
shissam Aug 24, 2022
7827ea9
gofmt'ed changes
shissam Aug 24, 2022
5a518e7
Repaired the case in the evaluation which was too sensitive to conten…
shissam Aug 24, 2022
cad900c
added unit test cases for the new content-based Security Policy checks
shissam Aug 24, 2022
9f9a8e6
reverted the direct (mistaken) change to checks.md and updated the ch…
shissam Aug 27, 2022
3bb3e09
:sparkles: Improved Security Policy Check (#2137) (revisted based on …
shissam Aug 27, 2022
98e9ca1
revised the score value based on observation of one *or more* url(s) …
shissam Aug 27, 2022
80b0e17
revised the score value based on observation of one *or more* url(s) …
shissam Aug 27, 2022
811b537
revised the score value based on observation of one *or more* url(s) …
shissam Aug 27, 2022
5998703
Addressed PR comments; added telemetry for policy hits in security po…
shissam Oct 19, 2022
cb71397
Resolved merge conflict with checks.yaml
shissam Oct 20, 2022
7e45c19
updated raw results to emit all the raw information for the new secur…
shissam Oct 22, 2022
c007797
Resolved merge conflicts and lint errors with json_raw_results.go
shissam Oct 23, 2022
ec1fcff
Addressed review comments to reorganize security policy data struct t…
shissam Oct 26, 2022
6ef1f14
Added logic to the security policy to process multiple security polic…
shissam Oct 27, 2022
f2accd4
added comments regarding the capacity to support multiple policy file…
shissam Oct 27, 2022
088bfb2
Addressed review comments to remove the dependency on the path in the…
shissam Oct 28, 2022
d53ce75
restored reporting full security policy path and filename for policie…
shissam Oct 28, 2022
0dd3c1d
Resolved conflicts in checks.yaml for documentation
shissam Oct 29, 2022
aae4808
resolved merge conflicts
shissam Nov 1, 2022
61fed0b
Merge branch 'main' into main
shissam Nov 1, 2022
bd720d7
✨ CLI for scorecard-attestor (#2309)
raghavkaul Nov 1, 2022
60ba3c8
Merge branch 'main' of https://github.com/shissam/scorecard into main
shissam Nov 1, 2022
776d4d6
removed whitespace before stanza for Run attestor e2e
shissam Nov 1, 2022
e0739b4
merge security-policy test branch with upstream:main
shissam Nov 2, 2022
48719cb
Merge branch 'main' of https://github.com/ossf/scorecard into main
shissam Nov 4, 2022
c46a581
resolved code review and doc review comments
shissam Nov 4, 2022
658d6d6
Merge branch 'main' of https://github.com/ossf/scorecard into main
shissam Nov 4, 2022
2668737
repaired the link for the maintainer's guide for supporting the coord…
shissam Nov 4, 2022
a0294c3
Merge branch 'ossf:main' into main
shissam Nov 7, 2022
edcc8cf
initial implementation of https://github.com/ossf/scorecard/issues/13…
shissam Nov 7, 2022
1e6b676
Merge branch 'ossf:main' into main
shissam Nov 9, 2022
9ae62ee
draft implementation to provide more information on license details
shissam Nov 9, 2022
6f84cb9
Merge branch 'lic-policy' into main
shissam Nov 9, 2022
58deae0
Merge branch 'ossf:main' into main
shissam Nov 10, 2022
bd98885
repaired a misspelling
shissam Nov 12, 2022
9d5e090
Changed to handle http errors with 404 not found as being a non-error…
shissam Nov 16, 2022
d9dd38f
Return an error status similar to other gitlab checks
shissam Nov 16, 2022
56aa979
add new raw licenses data
shissam Nov 16, 2022
a027827
updated e2e test as new license check generates more info and warn as…
shissam Nov 16, 2022
90afdbf
added numerous more test filenames and a shouldFail boolean as some f…
shissam Nov 16, 2022
14b0ec8
license check now, primarily, uses the GH API for checking licenses
shissam Nov 16, 2022
0e6bfd0
updated local checker as new license check generates more info and wa…
shissam Nov 16, 2022
4955561
added draft license gradation for scoring, add a map to OSI and FSF l…
shissam Nov 17, 2022
37cf58e
Merge branch 'main' of https://github.com/ossf/scorecard into main
shissam Nov 17, 2022
b70f2ee
repaired race condition for case insensitive map, improved regex matc…
shissam Nov 26, 2022
541d38f
Merge branch 'main' of https://github.com/ossf/scorecard into main
shissam Nov 26, 2022
bdfe341
completed disambiguation of SPDX Identifiers and filename extensions,…
shissam Nov 27, 2022
1f55b7a
Merge branch 'lic-policy' into main
shissam Nov 27, 2022
1ef1703
Merge branch 'ossf:main' into main
shissam Nov 28, 2022
c1b7373
removed repo Key from LicenseInformation as unneeded, changed attribu…
shissam Nov 28, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions checker/raw_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

// RawResults contains results before a policy
// is applied.
//nolint
// nolint
type RawResults struct {
PackagingResults PackagingData
CIIBestPracticesResults CIIBestPracticesData
Expand Down Expand Up @@ -68,7 +68,7 @@ type PackagingData struct {
}

// Package represents a package.
//nolint
// nolint
type Package struct {
// TODO: not supported yet. This needs to be unique across
// ecosystems: purl, OSV, CPE, etc.
Expand Down Expand Up @@ -125,10 +125,34 @@ type MaintainedData struct {
ArchivedStatus ArchivedStatus
}

type LicenseAttributionType string

const (
// sources of license information used to assert repo's license.
LicenseAttributionTypeOther LicenseAttributionType = "other"
LicenseAttributionTypeAPI LicenseAttributionType = "repositoryAPI"
LicenseAttributionTypeHeuristics LicenseAttributionType = "builtinHeuristics"
)

// license details.
type License struct {
shissam marked this conversation as resolved.
Show resolved Hide resolved
Name string // OSI standardized license name
SpdxID string // SPDX standardized identifier
shissam marked this conversation as resolved.
Show resolved Hide resolved
Attribution LicenseAttributionType // source of licensing information
Approved bool // FSF or OSI Approved License
}

// one file contains one license.
type LicenseFile struct {
LicenseInformation License
File File
}

// LicenseData contains the raw results
// for the License check.
// Some repos may have more than one license.
type LicenseData struct {
Files []File
LicenseFiles []LicenseFile
}

// CodeReviewData contains the raw results
Expand Down
65 changes: 57 additions & 8 deletions checks/evaluation/license.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,76 @@ import (
sce "github.com/ossf/scorecard/v4/errors"
)

func scoreLicenseCriteria(f *checker.LicenseFile,
dl checker.DetailLogger,
) int {
var score int
msg := checker.LogMessage{
Path: "",
Type: checker.FileTypeNone,
Text: "",
Offset: 1,
}
msg.Path = f.File.Path
msg.Type = checker.FileTypeSource
// #1 a license file was found.
score += 6

// #2 the licence was found at the top-level or LICENSE/ folder.
switch f.LicenseInformation.Attribution {
case checker.LicenseAttributionTypeAPI, checker.LicenseAttributionTypeHeuristics:
// both repoAPI and scorecard (not using the API) follow checks.md
// for a file to be found it must have been in the correct location
// award location points.
score += 3
msg.Text = "License file found in expected location"
dl.Info(&msg)
// for repo attribution prepare warning if not an recognized license"
msg.Text = "Any licence detected not an FSF or OSI recognized license"
case checker.LicenseAttributionTypeOther:
// TODO ascertain location found
score += 0
msg.Text = "License file found in unexpected location"
dl.Warn(&msg)
// for non repo attribution not the license detection is not supported
msg.Text = "Detecting license content not supported"
default:
}

// #3 is the license either an FSF or OSI recognized/approved license
if f.LicenseInformation.Approved {
score += 1
msg.Text = "FSF or OSI recognized license"
dl.Info(&msg)
} else {
// message text for this condition set above
dl.Warn(&msg)
}
return score
}

// License applies the score policy for the License check.
func License(name string, dl checker.DetailLogger,
r *checker.LicenseData,
) checker.CheckResult {
var score int
if r == nil {
e := sce.WithMessage(sce.ErrScorecardInternal, "empty raw data")
return checker.CreateRuntimeErrorResult(name, e)
}

// Apply the policy evaluation.
if r.Files == nil || len(r.Files) == 0 {
if r.LicenseFiles == nil || len(r.LicenseFiles) == 0 {
return checker.CreateMinScoreResult(name, "license file not detected")
}

for _, f := range r.Files {
dl.Info(&checker.LogMessage{
Path: f.Path,
Type: checker.FileTypeSource,
Offset: 1,
})
// TODO: although this a loop, the raw checks will only return one licence file
// when more than one license file can be aggregated into a composite
// score, that logic can be comprehended here.
score = 0
for idx := range r.LicenseFiles {
score = scoreLicenseCriteria(&r.LicenseFiles[idx], dl)
}

return checker.CreateMaxScoreResult(name, "license file detected")
return checker.CreateResultWithScore(name, "license file detected", score)
}
1 change: 0 additions & 1 deletion checks/license.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ const CheckLicense = "License"
//nolint:gochecknoinits
func init() {
supportedRequestTypes := []checker.RequestType{
checker.FileBased,
checker.CommitBased,
}
if err := registerCheck(CheckLicense, License, supportedRequestTypes); err != nil {
Expand Down
3 changes: 2 additions & 1 deletion checks/license_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ func TestLicenseFileSubdirectory(t *testing.T) {
inputFolder: "testdata/licensedir/withlicense",
expected: scut.TestReturn{
Error: nil,
Score: checker.MaxResultScore,
Score: checker.MaxResultScore - 1,
NumberOfInfo: 1,
NumberOfWarn: 1,
},
err: nil,
},
Expand Down
Loading