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

Fix Workflow Global Permissions Nil Check #85

Merged
merged 36 commits into from
Apr 26, 2022
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
73a914b
post endpoint
rohankh532 Mar 30, 2022
0452748
use exported func for verifyTlogEntry
rohankh532 Mar 31, 2022
322a2f4
for trigger
rohankh532 Mar 31, 2022
c156fcc
Merge branch 'main' of https://github.com/ossf/scorecard-webapp into …
rohankh532 Mar 31, 2022
5e2fcdc
reverted go version. was breaking build
rohankh532 Mar 31, 2022
81cf3fb
Merge branch 'main' into post-endpoint
rohankh532 Mar 31, 2022
3158ee0
moved entry/cert lookup code to sep func & process jsonOutput too
rohankh532 Apr 4, 2022
442bef9
removed finished todos
rohankh532 Apr 4, 2022
6bd7ce2
fixed tests + use cert to find wkflw path
rohankh532 Apr 4, 2022
a4aaa4f
refactored if statement
rohankh532 Apr 5, 2022
8d47ee3
check for global wkflw env, defaults, permissions
rohankh532 Apr 5, 2022
1973abd
don't assume main job name
rohankh532 Apr 5, 2022
5b3c94c
verify cert SHAs too
rohankh532 Apr 5, 2022
8179ca9
Merge branch 'main' into post-endpoint
rohankh532 Apr 6, 2022
56d8c8c
Verify that branch is the repo's default branch
rohankh532 Apr 6, 2022
f85a46a
Merge branch 'post-endpoint' of https://github.com/ossf/scorecard-web…
rohankh532 Apr 6, 2022
e39014b
Merge branch 'main' into post-endpoint
rohankh532 Apr 11, 2022
3768d4b
verify cert hasn't expired
rohankh532 Apr 11, 2022
d570658
Merge branch 'post-endpoint' of https://github.com/ossf/scorecard-web…
rohankh532 Apr 11, 2022
5fafee8
merged main into post-endpoint
rohankh532 Apr 12, 2022
5adcdb1
refactored post endpoint
rohankh532 Apr 12, 2022
40aee91
Merge branch 'main' into post-endpoint
rohankh532 Apr 13, 2022
8461ce3
allow multiple jobs
rohankh532 Apr 13, 2022
f4687cf
allow other flavors of ubuntu
rohankh532 Apr 13, 2022
c576d8d
refactored VerifySignature
rohankh532 Apr 13, 2022
40d3a97
check for token-id permissions
rohankh532 Apr 14, 2022
4bc515b
remove sarif results from processing
rohankh532 Apr 15, 2022
b8616d6
Merge branch 'main' into post-endpoint
rohankh532 Apr 15, 2022
63c62c0
fixed logic for verifying wkflw perms
rohankh532 Apr 16, 2022
2666e69
simplified if statement
rohankh532 Apr 19, 2022
ef7ee68
removed unnecessary id-token checking
rohankh532 Apr 19, 2022
2a2cc11
fixed global perm nil check
rohankh532 Apr 22, 2022
5e4f8e4
merged main into post-endpoint
rohankh532 Apr 22, 2022
f0d5ead
more wkflw validation tests
rohankh532 Apr 22, 2022
d3fe120
test for empty wkflw file
rohankh532 Apr 22, 2022
b418bd6
Merge branch 'main' into post-endpoint
laurentsimon Apr 26, 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
23 changes: 12 additions & 11 deletions signing/signing.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func lookupPayload(ctx context.Context, payload []byte) (repoPath, repoRef, repo
func verifyScorecardWorkflow(workflowContent string) error {
// Verify workflow contents using actionlint.
workflow, lintErrs := actionlint.Parse([]byte(workflowContent))
if lintErrs != nil {
if lintErrs != nil || workflow == nil {
return fmt.Errorf("actionlint errors parsing workflow: %v", lintErrs)
}

Expand All @@ -231,17 +231,18 @@ func verifyScorecardWorkflow(workflowContent string) error {
return errors.New("workflow contains global env vars or defaults")
}

// Verify that the all scope, if set, isn't write-all.
globalPermAll := workflow.Permissions.All
if globalPermAll != nil && globalPermAll.Value == "write-all" {
return fmt.Errorf("global perm is set to write-all")
}
if workflow.Permissions != nil {
globalPerms := workflow.Permissions
// Verify that the all scope, if set, isn't write-all.
if globalPerms.All != nil && globalPerms.All.Value == "write-all" {
return fmt.Errorf("global perm is set to write-all")
}

// Verify that there are no global permissions (including id-token) set to write.
globalPerms := workflow.Permissions.Scopes
for globalPerm, val := range globalPerms {
if val.Value.Value == "write" {
return fmt.Errorf("global perm %v is set to write", globalPerm)
// Verify that there are no global permissions (including id-token) set to write.
for globalPerm, val := range globalPerms.Scopes {
if val.Value.Value == "write" {
return fmt.Errorf("global perm %v is set to write", globalPerm)
}
}
}

Expand Down
15 changes: 11 additions & 4 deletions signing/signing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,17 @@ func TestVerifySignatureInvalidRepo(t *testing.T) {
assert.Equal(t, http.StatusInternalServerError, w.Code)
}

func TestVerifyValidWorkflow(t *testing.T) {
workflowContent, _ := ioutil.ReadFile("../testdata/workflow-valid.yml")
err := verifyScorecardWorkflow(string(workflowContent))
assert.Equal(t, err, nil)
func TestVerifyValidWorkflows(t *testing.T) {
workflowFiles := []string{
"../testdata/workflow-valid.yml",
"../testdata/workflow-valid-noglobalperm.yml",
}

for _, workflowFile := range workflowFiles {
workflowContent, _ := ioutil.ReadFile(workflowFile)
err := verifyScorecardWorkflow(string(workflowContent))
rohankh532 marked this conversation as resolved.
Show resolved Hide resolved
assert.Equal(t, err, nil, workflowFile)
}
}

func TestVerifyInvalidWorkflows(t *testing.T) {
Expand Down
56 changes: 56 additions & 0 deletions testdata/workflow-valid-noglobalperm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Scorecards supply-chain security
on:
# Only the default branch is supported.
branch_protection_rule:
schedule:
# Weekly on Saturdays.
- cron: '30 1 * * 6'
push:
branches: [ $default-branch ]
workflow_dispatch:

jobs:
analysis:
name: Scorecards analysis
runs-on: ubuntu-latest
permissions:
# Needed to upload the results to code-scanning dashboard.
security-events: write
actions: read
contents: read
id-token: write # needed for keyless signing

steps:
- name: "Checkout code"
uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579 # v2.4.0
with:
persist-credentials: false

- name: "Run analysis"
uses: ossf/scorecard-action@c8416b0b2bf627c349ca92fc8e3de51a64b005cf # v1.0.2
with:
results_file: results.sarif
results_format: sarif
# Read-only PAT token. To create it,
# follow the steps in https://github.com/ossf/scorecard-action#pat-token-creation.
repo_token: ${{ secrets.SCORECARD_READ_TOKEN }}
# Publish the results for public repositories to enable scorecard badges. For more details, see
# https://github.com/ossf/scorecard-action#publishing-results.
# For private repositories, `publish_results` will automatically be set to `false`, regardless
# of the value entered here.
publish_results: true

# Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF
# format to the repository Actions tab.
- name: "Upload artifact"
uses: actions/upload-artifact@82c141cc518b40d92cc801eee768e7aafc9c2fa2 # v2.3.1
with:
name: SARIF file
path: results.sarif
retention-days: 5

# Upload the results to GitHub's code scanning dashboard.
- name: "Upload to code-scanning"
uses: github/codeql-action/upload-sarif@5f532563584d71fdef14ee64d17bafb34f751ce5 # v1.0.26
with:
sarif_file: results.sarif