|
1 | | -# Summary: run Open Source Vulnerabilities (OSV) code scan. |
| 1 | +# Zero-config modular workflow to run Open Source Vulnerabilities code scans. |
| 2 | +# |
| 3 | +# The OSV scanner is a dependency vulnerability scanner that identifies known |
| 4 | +# vulnerabilities in a project's dependencies. It supports C/C++, Python, Java, |
| 5 | +# JavaScript, and others. The findings are reported in the repo's code-scanning |
| 6 | +# results page, https://github.com/quantumlib/REPO/security/code-scanning/. |
2 | 7 | # |
3 | 8 | # The OSV project provides a GA workflow that you can reference as a step with |
4 | | -# "uses: google/osv-scanner-action/.github/workflows/osv-scanner-reusable.yml". |
5 | | -# Unfortunately, that workflow inexplicably doesn't use the latest version of |
6 | | -# the scanner and reporter workflows, and also does other things like hard-code |
7 | | -# the value of the osv-scanner "--gh-annotations" option to "false". Using the |
8 | | -# separate actions directly allows us to adjust the options and use Dependabot |
9 | | -# to update the workflow versions as new ones are introduced. |
| 9 | +# uses: google/osv-scanner-action/.github/workflows/osv-scanner-reusable-pr.yml. |
| 10 | +# Unfortunately, that workflow hardcodes some behaviors (such as uploading the |
| 11 | +# SARIF file to the workflow Actions tab, which we rarely need). The workflow |
| 12 | +# below is basically a heavily modified version of theirs. |
10 | 13 | # |
11 | | -# For more examples and options, including how to ignore specific |
| 14 | +# For more OSV scanner examples and options, including how to ignore specific |
12 | 15 | # vulnerabilities, see https://google.github.io/osv-scanner/github-action/. |
13 | 16 | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
14 | 17 |
|
15 | 18 | name: OSV code scan |
16 | | -run-name: Do ${{inputs.reason}} OSV code scan |
| 19 | +run-name: Run OSV vulnerability scanner ${{inputs.reason}} |
17 | 20 |
|
18 | 21 | on: |
| 22 | + pull_request: |
| 23 | + types: [opened, synchronize] |
| 24 | + branches: |
| 25 | + - main |
| 26 | + - master |
| 27 | + |
| 28 | + # Support merge queues. |
19 | 29 | merge_group: |
20 | 30 | types: |
21 | 31 | - checks_requested |
22 | 32 |
|
| 33 | + # Allow manual invocation. |
| 34 | + workflow_dispatch: |
| 35 | + |
23 | 36 | # Allow calling from nightly.yaml. |
24 | 37 | workflow_call: |
25 | 38 | inputs: |
26 | | - # Why is this workflow being called? |
27 | 39 | reason: |
28 | 40 | type: string |
29 | | - required: false |
30 | | - |
31 | | - # Allow manual invocation. |
32 | | - workflow_dispatch: |
33 | 41 |
|
34 | 42 | # Declare default permissions as read only. |
35 | 43 | permissions: read-all |
36 | 44 |
|
37 | 45 | jobs: |
38 | 46 | osv-scan: |
39 | | - name: Run |
40 | | - runs-on: ubuntu-22.04 |
| 47 | + name: Run OSV scanner |
| 48 | + runs-on: ubuntu-24.04 |
41 | 49 | timeout-minutes: 15 |
42 | 50 | permissions: |
43 | | - # Needed to upload the results to code-scanning dashboard. |
| 51 | + # Needed to read commit contents: |
| 52 | + actions: read |
| 53 | + # Needed to upload the results to code-scanning dashboard: |
44 | 54 | security-events: write |
45 | | - # Read commit contents |
| 55 | + # Needed to upload SARIF file to CodeQL. |
46 | 56 | contents: read |
47 | | - actions: read |
48 | 57 | steps: |
49 | 58 | - name: Check out a copy of the git repository |
50 | 59 | uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
51 | 60 | with: |
52 | | - persist-credentials: false |
| 61 | + fetch-depth: 0 |
| 62 | + |
| 63 | + - name: Check out the target branch |
| 64 | + run: | |
| 65 | + git checkout ${{github.base_ref || github.ref_name}} |
| 66 | + git submodule update --recursive |
| 67 | +
|
| 68 | + - name: Run OSV scanner on existing code |
| 69 | + # yamllint disable rule:line-length |
| 70 | + uses: google/osv-scanner-action/osv-scanner-action@119c605e0e6e6c491e092da25b0c752d109b0b43 # v2.0.0 |
| 71 | + continue-on-error: true |
| 72 | + with: |
| 73 | + scan-args: |- |
| 74 | + --format=json |
| 75 | + --output=old-results.json |
| 76 | + --include-git-root |
| 77 | + --recursive |
| 78 | + ./ |
| 79 | +
|
| 80 | + - name: Check out current branch |
| 81 | + # Use -f in case any changes were made by osv-scanner. |
| 82 | + run: | |
| 83 | + git checkout -f "$GITHUB_SHA" |
| 84 | + git submodule update --recursive |
53 | 85 |
|
54 | | - - name: Run OSV scanner |
| 86 | + - name: Run OSV scanner on new code |
55 | 87 | # yamllint disable rule:line-length |
56 | | - uses: google/osv-scanner-action/osv-scanner-action@90fad544eb4036129491f76db3161ffdc2956748 # v1.9.2 |
| 88 | + uses: google/osv-scanner-action/osv-scanner-action@119c605e0e6e6c491e092da25b0c752d109b0b43 # v2.0.0 |
57 | 89 | continue-on-error: true |
58 | 90 | with: |
59 | 91 | scan-args: |- |
60 | | - --config=.osv-scanner.toml |
61 | 92 | --format=json |
62 | | - --output=osv-results.json |
| 93 | + --output=new-results.json |
| 94 | + --include-git-root |
63 | 95 | --recursive |
64 | 96 | ./ |
65 | 97 |
|
66 | | - - name: Run OSV reporter |
| 98 | + - name: Run the OSV scanner reporter |
67 | 99 | # yamllint disable rule:line-length |
68 | | - uses: google/osv-scanner-action/osv-reporter-action@90fad544eb4036129491f76db3161ffdc2956748 # v1.9.2 |
| 100 | + uses: google/osv-scanner-action/osv-reporter-action@119c605e0e6e6c491e092da25b0c752d109b0b43 # v2.0.0 |
69 | 101 | with: |
70 | 102 | scan-args: |- |
71 | 103 | --output=osv-results.sarif |
72 | | - --new=osv-results.json |
| 104 | + --old=old-results.json |
| 105 | + --new=new-results.json |
73 | 106 | --gh-annotations=true |
74 | 107 | --fail-on-vuln=true |
75 | 108 |
|
76 | | - - name: Upload to code-scanning dashboard |
77 | | - uses: github/codeql-action/upload-sarif@6bb031afdd8eb862ea3fc1848194185e076637e5 # v3.28.11 |
| 109 | + - name: Upload results to the repository's code-scanning results dashboard |
| 110 | + id: upload_artifact |
| 111 | + # yamllint disable rule:line-length |
| 112 | + uses: github/codeql-action/upload-sarif@b56ba49b26e50535fa1e7f7db0f4f7b4bf65d80d # v3.28.10 |
78 | 113 | with: |
79 | 114 | sarif_file: osv-results.sarif |
| 115 | + |
| 116 | + - name: Error troubleshooter |
| 117 | + if: ${{always() && steps.upload_artifact.outcome == 'failure'}} |
| 118 | + run: echo '::error::Artifact upload failed. Check the workflow logs.' |
0 commit comments