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

✨ CLI for scorecard-attestor #2309

Merged
merged 24 commits into from
Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
07d92b6
Reorganize
raghavkaul Sep 20, 2022
a04f1e9
Working commit
raghavkaul Sep 20, 2022
df5f5d7
Compile with local scorecard; go mod tidy
raghavkaul Sep 20, 2022
3a0bc23
Add signing code
raghavkaul Sep 28, 2022
1e61f41
Update deps
raghavkaul Sep 28, 2022
c5e1c37
Edit license, add lint.yml
raghavkaul Sep 28, 2022
445f4f9
Merge remote-tracking branch 'upstream/main' into feature-binauthz-cli
raghavkaul Sep 28, 2022
8121ce4
checks: go mod tidy, license
raghavkaul Sep 29, 2022
49182d1
Address PR comments
raghavkaul Sep 29, 2022
0f9ef5c
License, remove golangci.yml
raghavkaul Sep 29, 2022
a7073ba
Address PR comments
raghavkaul Oct 3, 2022
fea1bc0
Add tests for root command
raghavkaul Oct 4, 2022
aa93ec6
Filter out checks that aren't needed for policy evaluation
raghavkaul Oct 4, 2022
ae2c098
Add `make` targets for attestor; submit coverage stats
raghavkaul Oct 5, 2022
57f5f06
Improvements
raghavkaul Oct 5, 2022
0232df2
Flags: Make note-name constant and fix messaging
raghavkaul Oct 20, 2022
774bcce
Remove SupportedRequestTypes
raghavkaul Oct 20, 2022
8f7694d
Merge branch 'main' into feature-binauthz-cli
raghavkaul Oct 21, 2022
284a25f
go mod tidy
raghavkaul Sep 20, 2022
5b913a2
Merge branch 'main' into feature-binauthz-cli
raghavkaul Oct 27, 2022
d366a21
go mod tidy, makefile
raghavkaul Oct 28, 2022
75cee4d
Merge branch 'main' into feature-binauthz-cli
spencerschrock Oct 31, 2022
66490dd
Fix GH actions run
raghavkaul Oct 31, 2022
0acc68c
Merge branch 'main' into feature-binauthz-cli
spencerschrock Nov 1, 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# binary.
scorecard
attestor/scorecard-attestor
scorecard.docker
scorecard.releaser
gitblobcache
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,10 @@ cron/internal/bq/data-transfer.docker: cron/internal/bq/Dockerfile $(CRON_TRANSF
--tag $(IMAGE_NAME)-bq-transfer && \
touch cron/internal/bq/data-transfer.docker

build-attestor: ## Runs go build on scorecard attestor
raghavkaul marked this conversation as resolved.
Show resolved Hide resolved
# Run go build on scorecard attestor
cd attestor/; CGO_ENABLED=0 go build -trimpath -a -tags netgo -ldflags '$(LDFLAGS)' -o scorecard-attestor

TOKEN_SERVER_DEPS = $(shell find clients/githubrepo/roundtripper/tokens/ -iname "*.go")
build-github-server: ## Build GitHub token server
build-github-server: clients/githubrepo/roundtripper/tokens/server/github-auth-server
Expand Down
155 changes: 155 additions & 0 deletions attestor/.golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
# Copyright 2022 Security Scorecard Authors
raghavkaul marked this conversation as resolved.
Show resolved Hide resolved
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
---
run:
concurrency: 6
deadline: 5m
issues:
# Maximum issues count per one linter.
# Set to 0 to disable.
# Default: 50
max-issues-per-linter: 0
# Maximum count of issues with the same text.
# Set to 0 to disable.
# Default: 3
max-same-issues: 0
new-from-rev: ""
skip-files:
- cron/data/request.pb.go # autogenerated
linters:
disable-all: true
enable:
- asciicheck
- bodyclose
- deadcode
- depguard
- dogsled
- errcheck
- errorlint
- exhaustive
- exportloopref
- gci
- gochecknoinits
- gocognit
- goconst
- gocritic
- gocyclo
- godot
- godox
- goerr113
- gofmt
- gofumpt
- goheader
- goimports
- gomodguard
- goprintffuncname
- gosec
- gosimple
- govet
- ineffassign
- lll
- makezero
- misspell
- nakedret
- nestif
- noctx
- nolintlint
- paralleltest
- predeclared
- staticcheck
- stylecheck
- thelper
- tparallel
- typecheck
- unconvert
- unparam
- unused
- varcheck
- whitespace
- wrapcheck
linters-settings:
errcheck:
check-type-assertions: true
check-blank: true
exhaustive:
# https://golangci-lint.run/usage/linters/#exhaustive
default-signifies-exhaustive: true
govet:
enable:
- fieldalignment
godox:
keywords:
- BUG
- FIXME
- HACK
gci:
sections:
- standard
- default
- prefix(github.com/ossf/scorecard)
gocritic:
enabled-checks:
# Diagnostic
- appendAssign
- badCond
- caseOrder
- codegenComment
- commentedOutCode
- deprecatedComment
- dupBranchBody
- dupCase
- dupSubExpr
- exitAfterDefer
- flagName
- nilValReturn
- weakCond
- octalLiteral

# Performance
- appendCombine
- hugeParam
- rangeExprCopy
- rangeValCopy

# Style
- boolExprSimplify
- captLocal
- commentFormatting
- commentedOutImport
- defaultCaseOrder
- docStub
- elseif
- emptyFallthrough
- hexLiteral
- ifElseChain
- methodExprCall
- singleCaseSwitch
- typeAssertChain
- typeSwitchVar
- underef
- unlabelStmt
- unlambda

# Opinionated
- builtinShadow
- importShadow
- initClause
- nestingReduce
- paramTypeCombine
- ptrToRefParam
- typeUnparen
- unnecessaryBlock
wrapcheck:
ignorePackageGlobs:
- github.com/ossf/scorecard/v4/checks/fileparser
85 changes: 85 additions & 0 deletions attestor/command/check.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package command

import (
"context"
"os"

"github.com/golang/glog"
"github.com/ossf/scorecard-attestor/policy"
"github.com/ossf/scorecard/v4/checker"
"github.com/ossf/scorecard/v4/checks"
sclog "github.com/ossf/scorecard/v4/log"
"github.com/ossf/scorecard/v4/pkg"
)

func checkCommand() {
ctx := context.Background()

// Read the Binauthz attestation policy
if policyPath == "" {
exitOnBadFlags(SignerMode(mode), "policy path is empty")
}
attestationPolicy, err := policy.ParseAttestationPolicyFromFile(policyPath)
if err != nil {
glog.Fatalf("Fail to load scorecard attestation policy: %v", err)
}

if repoURL == "" {
buildRepo := os.Getenv("REPO_NAME")
if buildRepo == "" {
exitOnBadFlags(SignerMode(mode), "repoURL not specified")
}
repoURL = buildRepo
glog.Infof("Found repo URL %s Cloud Build environment", repoURL)
} else {
glog.Infof("Running scorecard on %s", repoURL)
}

if commitSHA == "" {
buildSHA := os.Getenv("COMMIT_SHA")
if buildSHA == "" {
glog.Infof("commit not specified, running on HEAD")
} else {
commitSHA = buildSHA
glog.Infof("Found revision %s Cloud Build environment", commitSHA)
}
}

logger := sclog.NewLogger(sclog.DefaultLevel)

repo, repoClient, ossFuzzRepoClient, ciiClient, vulnsClient, err := checker.GetClients(
ctx, repoURL, "", logger)

enabledChecks := map[string]checker.Check{
raghavkaul marked this conversation as resolved.
Show resolved Hide resolved
"BinaryArtifacts": {
Fn: checks.BinaryArtifacts,
SupportedRequestTypes: []checker.RequestType{
checker.CommitBased,
raghavkaul marked this conversation as resolved.
Show resolved Hide resolved
},
},
}

repoResult, err := pkg.RunScorecards(
ctx,
repo,
commitSHA,
enabledChecks,
repoClient,
ossFuzzRepoClient,
ciiClient,
vulnsClient,
)
if err != nil {
glog.Fatalf("RunScorecards: %w", err)
}

result, err := policy.RunChecksForPolicy(attestationPolicy, &repoResult.RawResults)
if err != nil {
glog.Fatalf("Error when evaluating image %q against policy", image)
}
if result != policy.Pass {
glog.Errorf("policy check failed on image %s:", image)
os.Exit(1)
}
glog.Infof("Image %q passes policy check", image)
}
Loading