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

Bugfix/scorecard producer #449

Merged
merged 3 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 1 addition & 2 deletions components/enrichers/custom-annotation/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,8 @@ func run(name, annotations string) error {
}

func main() {
flag.StringVar(&annotations, "annotations", enrichers.LookupEnvOrString("ANNOTATIONS", ""), "what are the annotations this enricher will add to the issues")
flag.StringVar(&annotations, "annotations", enrichers.LookupEnvOrString("ANNOTATIONS", "{}"), "what are the annotations this enricher will add to the issues")
flag.StringVar(&name, "annotation-name", enrichers.LookupEnvOrString("NAME", defaultName), "what is the name this enricher will masquerade as")

if err := enrichers.ParseFlags(); err != nil {
log.Fatal(err)
}
Expand Down
350 changes: 350 additions & 0 deletions components/producers/ossf-scorecard/examples/scorecard-out.json

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions components/producers/ossf-scorecard/examples/scorecard-out.pb

Large diffs are not rendered by default.

49 changes: 30 additions & 19 deletions components/producers/ossf-scorecard/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"log"
andream16 marked this conversation as resolved.
Show resolved Hide resolved
"log/slog"

v1 "github.com/smithy-security/smithy/api/proto/v1"

Expand Down Expand Up @@ -36,19 +37,28 @@ func main() {
}

func parseIssues(out *ScorecardOut) []*v1.Issue {
slog.Info("read ", slog.Int("numChecks", len(out.Checks)))
issues := []*v1.Issue{}
repo := out.Repo.Name
commit := out.Repo.Commit

for _, r := range out.Checks {
desc, _ := json.Marshal(r)
desc := fmt.Sprintf("Overall Score: %.1f\nCheck Details:\n", out.Score)

for i, deet := range r.Details {
d := deet
if i != len(r.Details)-1 {
d += "\n"
}
desc += d
}
issues = append(issues, &v1.Issue{
Target: fmt.Sprintf("%s:%s", repo, commit),
Type: r.Name,
Title: r.Reason,
Severity: scorecardToSmithySeverity(r.Score),
Cvss: 0.0,
Confidence: v1.Confidence_CONFIDENCE_UNSPECIFIED,
Description: string(desc),
Description: desc,
})
}
return issues
Expand All @@ -72,36 +82,37 @@ func scorecardToSmithySeverity(score float64) v1.Severity {

// ScorecardOut represents the output of a ScoreCard run.
type ScorecardOut struct {
Date string
Repo RepoInfo
Scorecard ScorecardInfo
Score float64
Checks []Check `json:"checks"`
Date string `json:"date,omitempty"`
Repo RepoInfo `json:"repo,omitempty"`
Scorecard ScorecardInfo `json:"scorecard,omitempty"`
Score float64 `json:"score,omitempty"`
Checks []Check `json:"checks,omitempty"`
Metadata any `json:"metadata,omitempty"`
}

// Check represents a ScoreCard Result.
type Check struct {
Details []string
Score float64
Reason string
Name string
Documentation Docs
Details []string `json:"details,omitempty"`
Score float64 `json:"score,omitempty"`
Reason string `json:"reason,omitempty"`
Name string `json:"name,omitempty"`
Documentation Docs `json:"documentation,omitempty"`
}

// Docs represents a ScoreCard "docs" section.
type Docs struct {
URL string
Short string
URL string `json:"url,omitempty"`
andream16 marked this conversation as resolved.
Show resolved Hide resolved
Short string `json:"short,omitempty"`
}

// ScorecardInfo represents a "scorecardinfo" section.
type ScorecardInfo struct {
Version string
Commit string
Version string `json:"version,omitempty"`
Commit string `json:"commit,omitempty"`
}

// RepoInfo represents a repository information section.
type RepoInfo struct {
Name string
Commit string
Name string `json:"name,omitempty"`
Commit string `json:"commit,omitempty"`
}
5 changes: 2 additions & 3 deletions components/producers/ossf-scorecard/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

v1 "github.com/smithy-security/smithy/api/proto/v1"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -53,8 +52,8 @@ func TestParseIssues(t *testing.T) {
Type: "Branch-Protection",
Title: "branch protection is not maximal on development and all release branches",
Severity: v1.Severity_SEVERITY_MEDIUM,
Description: "{\"Details\":[\"Info: 'force pushes' disabled on branch 'main'\",\"Info: 'allow deletion' disabled on branch 'main'\",\"Warn: no status checks found to merge onto branch 'main'\",\"Info: number of required reviewers is 2 on branch 'main'\"],\"Score\":6,\"Reason\":\"branch protection is not maximal on development and all release branches\",\"Name\":\"Branch-Protection\",\"Documentation\":{\"URL\":\"https://github.com/ossf/scorecard/blob/23b0ddb8aa96356321cf31a2709723e29b15a951/docs/checks.md#branch-protection\",\"Short\":\"Determines if the default and release branches are protected with GitHub's branch protection settings.\"}}",
Description: "Overall Score: 4.0\nCheck Details:\nInfo: 'force pushes' disabled on branch 'main'\nInfo: 'allow deletion' disabled on branch 'main'\nWarn: no status checks found to merge onto branch 'main'\nInfo: number of required reviewers is 2 on branch 'main'",
}

assert.Equal(t, []*v1.Issue{expectedIssue}, issues)
require.Equal(t, []*v1.Issue{expectedIssue}, issues)
}
14 changes: 7 additions & 7 deletions components/producers/ossf-scorecard/task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ spec:
description: The workspace containing the source-code to scan.
steps:
- name: run-ossf-scorecard
image: '{{ default "ghcr.io/smithy-security/smithy" .Values.image.registry }}/components/producers/ossf-scorecard/scorecard-smithy:{{ .Chart.AppVersion }}'
image: 'gcr.io/openssf/scorecard:v5.0.0'
env:
- name: GITHUB_AUTH_TOKEN
value: "$(params.producer-ossf-scorecard-github-auth-token)"
script: |
/scorecard \
--format=json \
--show-details \
--repo=$(params.producer-ossf-scorecard-input-repo) >/scratch/out.json
# TODO(spyros): add flags here once scorecard can write results to file
command: ["/scorecard"]
args:
- --format=json
- --show-details
- --output=/scratch/out.json
- --repo=$(params.producer-ossf-scorecard-input-repo)
volumeMounts:
- mountPath: /scratch
name: scratch
Expand Down
11 changes: 11 additions & 0 deletions examples/pipelines/scorecard-project/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
nameSuffix: -scorecard-project
components:
- pkg:helm/smithy-security-oss-components/base
- pkg:helm/smithy-security-oss-components/producer-ossf-scorecard
- pkg:helm/smithy-security-oss-components/producer-aggregator
- pkg:helm/smithy-security-oss-components/enricher-custom-annotation
- pkg:helm/smithy-security-oss-components/enricher-aggregator
- pkg:helm/smithy-security-oss-components/consumer-stdout-json
24 changes: 24 additions & 0 deletions examples/pipelines/scorecard-project/pipelinerun.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
generateName: smithy-scorecard-project-
spec:
pipelineRef:
name: smithy-scorecard-project
params:
- name: producer-ossf-scorecard-input-repo
value: https://github.com/smithy-security/smithy
- name: producer-ossf-scorecard-github-auth-token
value: $github-auth-token-permissions-to-read-repos
- name: enricher-custom-annotation-base-annotation
value: '{"foo":"bar","a":"b","1":"2"}'
workspaces:
- name: output
volumeClaimTemplate:
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi