Security Analysis #1527
This file contains 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
--- | |
name: Security Analysis | |
on: | |
push: | |
branches: [master] | |
paths: | |
- "**.go" | |
- "go.mod" | |
- "go.sum" | |
pull_request: | |
branches: [master] | |
paths: | |
- "**.go" | |
- "go.mod" | |
- "go.sum" | |
schedule: | |
# 06:12 - offset from the hour to avoid other build jobs | |
- cron: "12 6 * * *" | |
jobs: | |
codeql: | |
name: CodeQL | |
runs-on: ubuntu-latest | |
permissions: | |
# allow uploading sarif results | |
security-events: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Initialize CodeQL | |
uses: github/codeql-action/init@v3 | |
with: | |
languages: go | |
# analyzes + uploads sarif | |
- name: Perform CodeQL Analysis | |
uses: github/codeql-action/analyze@v3 | |
govulncheck: | |
name: govulncheck | |
runs-on: ubuntu-latest | |
permissions: | |
# allow uploading sarif results | |
security-events: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Vulnerability Scan Go Code | |
uses: golang/govulncheck-action@v1 | |
with: | |
go-version-file: go.mod | |
repo-checkout: false | |
output-format: sarif | |
output-file: govulncheck.sarif | |
- name: Fix govulncheck SARIF output | |
# https://github.com/docker/buildx/blob/d4eca07af8385dca95b4c38535a9bbaa3bfc0fa9/hack/dockerfiles/govulncheck.Dockerfile#L22-L25 | |
# Make sure "results" field is defined in SARIF output otherwise GitHub Code Scanning | |
# will fail when uploading report with "Invalid SARIF. Missing 'results' array in run." | |
# Relates to https://github.com/golang/vuln/blob/ffdef74cc44d7eb71931d8d414c478b966812488/internal/sarif/sarif.go#L69 | |
run: | | |
cat <<< $(jq '(.runs[] | select(.results == null) | .results) |= []' govulncheck.sarif) > govulncheck.sarif | |
- name: Upload Scan SARIF file | |
uses: github/codeql-action/upload-sarif@v3 | |
with: | |
sarif_file: govulncheck.sarif | |
category: govulncheck |