Skip to content

Commit 1b1b92b

Browse files
committed
Reject pull requests that change imported licenses
We import dependencies that use a handful of open-source licenses. We want to be intentional about any change to these licenses, so this automation flags pull requests that do so. Go modules are immutable, so checking during pull requests and pushes should suffice. Issue: PGO-1556
1 parent 61b9728 commit 1b1b92b

File tree

2 files changed

+42
-6
lines changed

2 files changed

+42
-6
lines changed

.github/workflows/trivy-pr-scan.yaml renamed to .github/workflows/trivy.yaml

+28-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# Uses Trivy to scan every pull request, rejecting those with severe, fixable vulnerabilities.
2-
# Scans on PR to master and weekly with same behavior.
31
name: Trivy
42

53
on:
@@ -11,7 +9,29 @@ on:
119
- master
1210

1311
jobs:
14-
scan:
12+
licenses:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
17+
# Trivy needs a populated Go module cache to detect Go module licenses.
18+
- uses: actions/setup-go@v5
19+
with: { go-version: stable }
20+
- run: go mod download
21+
22+
# Report success only when detected licenses are listed in [/trivy.yaml].
23+
# The "aquasecurity/trivy-action" action cannot access the Go module cache,
24+
# so run Trivy from an image with the cache and local configuration mounted.
25+
# - https://github.com/aquasecurity/trivy-action/issues/219
26+
# - https://github.com/aquasecurity/trivy/pkgs/container/trivy
27+
- run: >
28+
docker run
29+
--env 'GOPATH=/go' --volume "$(go env GOPATH):/go"
30+
--workdir '/mnt' --volume "$(pwd):/mnt"
31+
'ghcr.io/aquasecurity/trivy:latest'
32+
filesystem --exit-code=1 --scanners=license .
33+
34+
vulnerabilities:
1535
if: ${{ github.repository == 'CrunchyData/postgres-operator' }}
1636

1737
permissions:
@@ -30,21 +50,23 @@ jobs:
3050
- name: Log all detected vulnerabilities
3151
uses: aquasecurity/trivy-action@master
3252
with:
33-
scan-type: fs
53+
scan-type: filesystem
3454
hide-progress: true
3555
ignore-unfixed: true
36-
56+
scanners: secret,vuln
57+
3758
# Upload actionable results to the GitHub Security tab.
3859
# Pull request checks fail according to repository settings.
3960
# - https://docs.github.com/en/code-security/code-scanning/integrating-with-code-scanning/uploading-a-sarif-file-to-github
4061
# - https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning
4162
- name: Report actionable vulnerabilities
4263
uses: aquasecurity/trivy-action@master
4364
with:
44-
scan-type: fs
65+
scan-type: filesystem
4566
ignore-unfixed: true
4667
format: 'sarif'
4768
output: 'trivy-results.sarif'
69+
scanners: secret,vuln
4870

4971
- name: Upload Trivy scan results to GitHub Security tab
5072
uses: github/codeql-action/upload-sarif@v3

trivy.yaml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# https://aquasecurity.github.io/trivy/latest/docs/references/configuration/config-file/
2+
---
3+
# Specify an exact list of recognized and acceptable licenses.
4+
# [A GitHub workflow](/.github/workflows/trivy.yaml) rejects pull requests that
5+
# import licenses not in this list.
6+
#
7+
# https://aquasecurity.github.io/trivy/latest/docs/scanner/license/
8+
license:
9+
ignored:
10+
- Apache-2.0
11+
- BSD-2-Clause
12+
- BSD-3-Clause
13+
- ISC
14+
- MIT

0 commit comments

Comments
 (0)