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

🌱 Add OSV scanner PR and schedule workflows #492

Merged
merged 1 commit into from
May 16, 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
20 changes: 20 additions & 0 deletions .github/workflows/osv-scanner-scan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# This file is adapted from https://github.com/google/osv-scanner


name: OSV-Scanner Scan

on:
schedule:
- cron: "12 12 * * 1"
tuminoid marked this conversation as resolved.
Show resolved Hide resolved

# Restrict jobs in this workflow to have no permissions by default; permissions
# should be granted per job as needed using a dedicated `permissions` block
permissions: {}

jobs:
scan-scheduled:
permissions:
contents: read # to fetch code (actions/checkout)
security-events: write # for uploading SARIF files
if: ${{ github.repository == 'metal3-io/ip-address-manager' && github.event_name == 'schedule' }}
tuminoid marked this conversation as resolved.
Show resolved Hide resolved
uses: "./.github/workflows/osv-scanner.yml"
106 changes: 106 additions & 0 deletions .github/workflows/osv-scanner.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# This file is adapted from https://github.com/google/osv-scanner

name: OSV-Scanner

permissions: {}

on:
workflow_call:
inputs:
scan-args:
description: "Custom osv-scanner arguments (See https://google.github.io/osv-scanner/usage/ for options, you cannot set --format or --output)"
type: string
default: |-
-r
--skip-git
./
results-file-name:
description: "File name of the result SARIF file"
type: string
default: results.sarif
upload-sarif:
description: "Whether to upload to Security > Code Scanning"
type: boolean
required: false
default: true
fail-on-vuln:
description: "Whether to fail the action on vulnerability found"
type: boolean
default: true

jobs:
scan-pr:
permissions:
contents: read # to fetch code (actions/checkout)
security-events: write # for uploading SARIF files
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
fetch-depth: 0
# Do persist credentials, as we need it for the git checkout later
- name: "Checkout target branch"
run: git checkout $GITHUB_BASE_REF
- name: "Calculate go version"
id: vars
run: echo "go_version=$(make go-version)" >> $GITHUB_OUTPUT
- name: Set up Go
uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # tag=v5.0.1
with:
go-version: ${{ steps.vars.outputs.go_version }}
- name: "Run scanner on existing code"
uses: google/osv-scanner/actions/scanner@645d5b0bb9c14741b2147a5305b684e4abc039e0 # v1.7.3
continue-on-error: true
with:
scan-args: |-
--format=json
--output=old-results.json
${{ inputs.scan-args }}
- name: "Checkout current branch"
run: git checkout $GITHUB_SHA
- name: "Run scanner on new code"
uses: google/osv-scanner/actions/scanner@645d5b0bb9c14741b2147a5305b684e4abc039e0 # v1.7.3
with:
scan-args: |-
--format=json
--output=new-results.json
${{ inputs.scan-args }}
continue-on-error: true
- name: "Run osv-scanner-reporter"
uses: google/osv-scanner/actions/reporter@645d5b0bb9c14741b2147a5305b684e4abc039e0 # v1.7.3
with:
scan-args: |-
--output=${{ inputs.results-file-name }}
--old=old-results.json
--new=new-results.json
--gh-annotations=true
--fail-on-vuln=${{ inputs.fail-on-vuln }}
# 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"
if: "!cancelled()"
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1
with:
name: SARIF file
path: ${{ inputs.results-file-name }}
retention-days: 5
- name: "Upload old scan json results"
if: "!cancelled()"
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1
with:
name: old-json-results
path: old-results.json
retention-days: 5
- name: "Upload new scan json results"
if: "!cancelled()"
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1
with:
name: new-json-results
path: new-results.json
retention-days: 5
# Upload the results to GitHub's code scanning dashboard.
- name: "Upload to code-scanning"
if: ${{ !cancelled() && inputs.upload-sarif == true }}
uses: github/codeql-action/upload-sarif@4355270be187e1b672a7a1c7c7bae5afdc1ab94a # v3.24.10
with:
sarif_file: ${{ inputs.results-file-name }}