-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add OSV scanner #7768
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
Closed
Closed
Add OSV scanner #7768
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
320b332
Update Scorecard scanner and rename file
mhucka 6663655
Update OSV scanner workflow
mhucka c685db5
Update versions of GitHub Actions used in workflows
mhucka 2adf8ab
Restore existing scorecard workflow
mhucka 9a91b4a
Merge branch 'main' into mh-update-scanners
mhucka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| # Copyright 2025 Google LLC | ||
| # | ||
| # 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 | ||
| # | ||
| # https://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. | ||
|
|
||
| name: OSV scan | ||
| run-name: Run open-source vulnerabilities (OSV) scanner | ||
|
|
||
| # The OSV scanner is a dependency vulnerability scanner that identifies known | ||
| # vulnerabilities in a project's dependencies. It supports C/C++, Python, Java, | ||
| # JavaScript, and others. The findings are reported in the repo's code-scanning | ||
| # results page, https://github.com/quantumlib/REPO/security/code-scanning/. | ||
| # For more OSV scanner examples and options, including how to ignore specific | ||
| # vulnerabilities, see https://google.github.io/osv-scanner/github-action/. | ||
|
|
||
| on: | ||
| schedule: | ||
| # Run weekly on Saturdays. | ||
| - cron: '30 10 * * 6' | ||
|
|
||
| pull_request: | ||
| types: [opened, synchronize] | ||
| branches: | ||
| - main | ||
|
|
||
| # Allow manual invocation. | ||
| workflow_dispatch: | ||
| inputs: | ||
| debug: | ||
| description: 'Run with debugging options' | ||
| type: boolean | ||
| default: true | ||
|
|
||
| concurrency: | ||
| # Cancel any previously-started but still active runs on the same branch. | ||
| cancel-in-progress: true | ||
| group: ${{github.workflow}}-${{github.event.pull_request.number||github.ref}} | ||
|
|
||
| # Declare default workflow permissions as read only. | ||
| permissions: read-all | ||
|
|
||
| jobs: | ||
| osv-scan: | ||
| if: github.repository_owner == 'quantumlib' | ||
| name: OSV scanner | ||
| runs-on: ubuntu-24.04 | ||
| timeout-minutes: 30 | ||
| permissions: | ||
| # Needed to upload the results to code-scanning dashboard: | ||
| security-events: write | ||
| env: | ||
| # Setting Bash SHELLOPTS here takes effect for all shell commands below. | ||
| SHELLOPTS: ${{inputs.debug && 'xtrace' || '' }} | ||
| steps: | ||
| - name: Check out a copy of the git repository | ||
| uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Check out the target branch | ||
| run: | | ||
| git checkout ${{github.base_ref || github.ref_name}} | ||
| git submodule update --recursive | ||
|
|
||
| - name: Run OSV scanner on existing code | ||
| # yamllint disable rule:line-length | ||
| uses: google/osv-scanner-action/osv-scanner-action@b77c075a1235514558f0eb88dbd31e22c45e0cd2 # v2.3.0 | ||
| continue-on-error: true | ||
| with: | ||
| scan-args: |- | ||
| --include-git-root | ||
| --format=json | ||
| --output=old-results.json | ||
| --recursive | ||
| ./ | ||
|
|
||
| - name: Check out current branch | ||
| # Use -f in case any changes were made by osv-scanner. | ||
| run: | | ||
| git checkout -f "$GITHUB_SHA" | ||
| git submodule update --recursive | ||
|
|
||
| - name: Run OSV scanner on new code | ||
| # yamllint disable rule:line-length | ||
| uses: google/osv-scanner-action/osv-scanner-action@b77c075a1235514558f0eb88dbd31e22c45e0cd2 # v2.3.0 | ||
| continue-on-error: true | ||
| with: | ||
| scan-args: |- | ||
| --include-git-root | ||
| --format=json | ||
| --output=new-results.json | ||
| --recursive | ||
| ./ | ||
|
|
||
| - name: Run the OSV scanner reporter for the job summary page | ||
| # yamllint disable rule:line-length | ||
| uses: google/osv-scanner-action/osv-reporter-action@b77c075a1235514558f0eb88dbd31e22c45e0cd2 # v2.3.0 | ||
| with: | ||
| scan-args: |- | ||
| --output=markdown:output.md | ||
| --old=old-results.json | ||
| --new=new-results.json | ||
| --fail-on-vuln=false | ||
|
|
||
| - name: Write the results to the job summary page | ||
| run: cat output.md >> "$GITHUB_STEP_SUMMARY" | ||
|
|
||
| - name: Run the OSV scanner reporter for the code-scanning dashboard | ||
| # yamllint disable rule:line-length | ||
| uses: google/osv-scanner-action/osv-reporter-action@b77c075a1235514558f0eb88dbd31e22c45e0cd2 # v2.3.0 | ||
| with: | ||
| scan-args: |- | ||
| --output=osv-results.sarif | ||
| --old=old-results.json | ||
| --new=new-results.json | ||
| --gh-annotations=true | ||
| --fail-on-vuln=true | ||
|
|
||
| - name: Upload results to the code-scanning results dashboard | ||
| id: upload_artifact | ||
| # yamllint disable rule:line-length | ||
| uses: github/codeql-action/upload-sarif@ba454b8ab46733eb6145342877cd148270bb77ab # codeql-bundle-v2.23.5 | ||
| with: | ||
| sarif_file: osv-results.sarif | ||
|
|
||
| - if: github.event.inputs.debug == true | ||
| name: Upload results as artifacts to the workflow Summary page | ||
| uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0 | ||
| with: | ||
| name: SARIF file | ||
| path: osv-results.sarif | ||
| retention-days: 5 | ||
|
|
||
| - name: Print an alert message if an error occurred | ||
| if: ${{always() && steps.upload_artifact.outcome == 'failure'}} | ||
| run: echo '::error::Artifact upload failed. Check the workflow logs.' | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please move this to a separate PR?
Also, let us try to keep this as simple and as close as possible to the example workflows at https://github.com/google/osv-scanner. Running this on schedule should be sufficient; again, we do not need to create noise in CI-checks for our contributors. (we have no large scale continuous deployment of Cirq so it is not that critical to catch vulnerabilities on the spot. Also the only kind of PRs that can introduce them are changes Python dependencies or GHA workflows)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved the Scorecard changes to another PR (#7776)