Skip to content

Commit c2d5a81

Browse files
committed
✨ Skip checks that don't apply to the current repo type
Scorecard's Azure DevOps support runs every check regardless of whether it makes sense for the platform. Checks like Dangerous-Workflow and Token-Permissions look exclusively at GitHub Actions files and produce misleading results on non-GitHub repos. The repos field in checks.yaml already listed supported platforms per check, but nothing enforced it at runtime. Now GetEnabled reads that field and drops checks that don't list the repo's platform. - Add RepoType to the Repo interface (GitHub, GitLab, Azure DevOps, local) with implementations on all four concrete types and the mock - Pass RepoType through to policy.GetEnabled, which filters checks against checks.yaml's repos field - Tag 11 checks as supporting Azure DevOps based on which client methods are actually implemented Signed-off-by: Jamie Magee <jamie.magee@gmail.com>
1 parent 4057678 commit c2d5a81

File tree

12 files changed

+108
-18
lines changed

12 files changed

+108
-18
lines changed

clients/azuredevopsrepo/repo.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ func (r *Repo) Metadata() []string {
100100
return r.metadata
101101
}
102102

103+
// Type implements Repo.Type.
104+
func (r *Repo) Type() clients.RepoType {
105+
return clients.RepoTypeAzureDevOps
106+
}
107+
103108
// Path() implements RepoClient.Path.
104109
func (r *Repo) Path() string {
105110
return fmt.Sprintf("%s/%s/%s/%s", r.organization, r.project, "_git", r.name)

clients/githubrepo/repo.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ func (r *Repo) Metadata() []string {
112112
return r.metadata
113113
}
114114

115+
// Type implements Repo.Type.
116+
func (r *Repo) Type() clients.RepoType {
117+
return clients.RepoTypeGitHub
118+
}
119+
115120
func (r *Repo) commitExpression() string {
116121
if strings.EqualFold(r.commitSHA, clients.HeadSHA) {
117122
// TODO(#575): Confirm that this works as expected.

clients/gitlabrepo/repo.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,11 @@ func (r *Repo) Metadata() []string {
166166
return r.metadata
167167
}
168168

169+
// Type implements Repo.Type.
170+
func (r *Repo) Type() clients.RepoType {
171+
return clients.RepoTypeGitLab
172+
}
173+
169174
// Path() implements RepoClient.Path.
170175
func (r *Repo) Path() string {
171176
return fmt.Sprintf("%s/%s", r.owner, r.project)

clients/localdir/repo.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ func (r *Repo) AppendMetadata(m ...string) {
6969
r.metadata = append(r.metadata, m...)
7070
}
7171

72+
// Type implements Repo.Type.
73+
func (r *Repo) Type() clients.RepoType {
74+
return clients.RepoTypeLocal
75+
}
76+
7277
// Path() implements RepoClient.Path.
7378
func (r *Repo) Path() string {
7479
return r.path

clients/mockclients/repo.go

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

clients/repo.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,20 @@
1414

1515
package clients
1616

17+
// RepoType identifies the hosting platform of a repository.
18+
type RepoType string
19+
20+
const (
21+
// RepoTypeGitHub represents a GitHub-hosted repository.
22+
RepoTypeGitHub RepoType = "GitHub"
23+
// RepoTypeGitLab represents a GitLab-hosted repository.
24+
RepoTypeGitLab RepoType = "GitLab"
25+
// RepoTypeAzureDevOps represents an Azure DevOps-hosted repository.
26+
RepoTypeAzureDevOps RepoType = "Azure DevOps"
27+
// RepoTypeLocal represents a local directory.
28+
RepoTypeLocal RepoType = "local"
29+
)
30+
1731
// Repo interface uniquely identifies a repo.
1832
type Repo interface {
1933
// Path returns the specifier of the repository within its forge
@@ -29,4 +43,6 @@ type Repo interface {
2943
IsValid() error
3044
Metadata() []string
3145
AppendMetadata(metadata ...string)
46+
// Type returns the hosting platform type.
47+
Type() RepoType
3248
}

cmd/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func rootCmd(o *options.Options) error {
129129
// this call to policy is different from the one in scorecard.Run
130130
// this one is concerned with a policy file, while the scorecard.Run call is
131131
// more concerned with the supported request types
132-
enabledChecks, err := policy.GetEnabled(pol, o.Checks(), requiredRequestTypes)
132+
enabledChecks, err := policy.GetEnabled(pol, o.Checks(), requiredRequestTypes, repo.Type())
133133
if err != nil {
134134
return fmt.Errorf("GetEnabled: %w", err)
135135
}

cron/internal/worker/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ func processRequest(ctx context.Context,
205205
commitSHA = repoReq.GetCommit()
206206
requiredRequestType = append(requiredRequestType, checker.CommitBased)
207207
}
208-
checksToRun, err := policy.GetEnabled(nil /*policy*/, nil /*checks*/, requiredRequestType)
208+
checksToRun, err := policy.GetEnabled(nil /*policy*/, nil /*checks*/, requiredRequestType, repo.Type())
209209
if err != nil {
210210
return fmt.Errorf("error during policy.GetEnabled: %w", err)
211211
}

docs/checks/internal/checks.yaml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ checks:
5151
Dependency-Update-Tool:
5252
risk: High
5353
tags: supply-chain, security, dependencies
54-
repos: GitHub, local
54+
repos: GitHub, Azure DevOps, local
5555
short: Determines if the project uses a dependency update tool.
5656
description: |
5757
Risk: `High` (possibly vulnerable to attacks on known flaws)
@@ -90,7 +90,7 @@ checks:
9090
Binary-Artifacts:
9191
risk: High
9292
tags: supply-chain, security, dependencies
93-
repos: GitHub, GitLab, local
93+
repos: GitHub, GitLab, Azure DevOps, local
9494
short: Determines if the project has generated executable (binary) artifacts in the source repository.
9595
description: |
9696
Risk: `High` (non-reviewable code)
@@ -141,7 +141,7 @@ checks:
141141
Branch-Protection:
142142
risk: High
143143
tags: supply-chain, security, source-code, code-reviews
144-
repos: GitHub, GitLab
144+
repos: GitHub, GitLab, Azure DevOps
145145
short: Determines if the default and release branches are protected with GitHub's branch protection settings.
146146
description: |
147147
Risk: `High` (vulnerable to intentional malicious code injection)
@@ -227,7 +227,7 @@ checks:
227227
CI-Tests:
228228
risk: Low
229229
tags: supply-chain, testing
230-
repos: GitHub, GitLab
230+
repos: GitHub, GitLab, Azure DevOps
231231
short: Determines if the project runs tests before pull requests are merged.
232232
description: |
233233
Risk: `Low` (possible unknown vulnerabilities)
@@ -287,7 +287,7 @@ checks:
287287
Code-Review:
288288
risk: High
289289
tags: supply-chain, security, source-code, code-reviews
290-
repos: GitHub
290+
repos: GitHub, Azure DevOps
291291
short: Determines if the project requires human code review before pull requests (aka merge requests) are merged.
292292
description: |
293293
Risk: `High` (unintentional vulnerabilities or possible injection of malicious
@@ -360,7 +360,7 @@ checks:
360360
Contributors:
361361
risk: Low
362362
tags: source-code
363-
repos: GitHub
363+
repos: GitHub, Azure DevOps
364364
short: Determines if the project has a set of contributors from multiple organizations (e.g., companies).
365365
description: |
366366
Risk: `Low` (lower number of trusted code reviewers)
@@ -466,7 +466,7 @@ checks:
466466
Pinned-Dependencies:
467467
risk: Medium
468468
tags: supply-chain, security, dependencies
469-
repos: GitHub, local
469+
repos: GitHub, Azure DevOps, local
470470
short: Determines if the project has declared and pinned the dependencies of its build process.
471471
description: |
472472
Risk: `Medium` (possible compromised dependencies)
@@ -532,7 +532,7 @@ checks:
532532
SAST:
533533
risk: Medium
534534
tags: supply-chain, security, testing
535-
repos: GitHub
535+
repos: GitHub, Azure DevOps
536536
short: Determines if the project uses static code analysis.
537537
description: |
538538
Risk: `Medium` (possible unknown bugs)
@@ -603,7 +603,7 @@ checks:
603603
Security-Policy:
604604
risk: Medium
605605
short: Determines if the project has published a security policy.
606-
repos: GitHub
606+
repos: GitHub, Azure DevOps
607607
tags: supply-chain, security, policy
608608
description: |
609609
Risk: `Medium` (possible insecure reporting of vulnerabilities)
@@ -746,7 +746,7 @@ checks:
746746
Vulnerabilities:
747747
risk: High
748748
tags: supply-chain, security, vulnerabilities
749-
repos: GitHub
749+
repos: GitHub, Azure DevOps
750750
short: Determines if the project has open, known unfixed vulnerabilities.
751751
description: |
752752
Risk: `High` (known vulnerabilities)
@@ -810,7 +810,7 @@ checks:
810810
License:
811811
risk: Low
812812
tags: license
813-
repos: GitHub, local
813+
repos: GitHub, Azure DevOps, local
814814
short: Determines if the project has defined a license.
815815
description: |
816816
Risk: `Low` (possible impediment to security review)

pkg/scorecard/scorecard.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ func Run(ctx context.Context, repo clients.Repo, opts ...Option) (Result, error)
425425
requiredRequestTypes = append(requiredRequestTypes, checker.CommitBased)
426426
}
427427

428-
checksToRun, err := policy.GetEnabled(nil, c.checks, requiredRequestTypes)
428+
checksToRun, err := policy.GetEnabled(nil, c.checks, requiredRequestTypes, repo.Type())
429429
if err != nil {
430430
return Result{}, fmt.Errorf("getting enabled checks: %w", err)
431431
}

0 commit comments

Comments
 (0)