-
Notifications
You must be signed in to change notification settings - Fork 175
126 lines (109 loc) · 3.7 KB
/
osv-scanner.yml
File metadata and controls
126 lines (109 loc) · 3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# A sample workflow which sets up periodic OSV-Scanner scanning for vulnerabilities,
# in addition to a PR check which fails if new vulnerabilities are introduced.
#
# For more examples and options, including how to ignore specific vulnerabilities,
# see https://google.github.io/osv-scanner/github-action/
name: OSV-Scanner
on:
schedule:
- cron: '43 20 * * 3'
push:
branches: [ "main" ]
permissions:
# Require writing security events to upload SARIF file to security tab
security-events: write
# Read commit contents
contents: read
actions: read
jobs:
scan-scheduled:
uses: "google/osv-scanner-action/.github/workflows/osv-scanner-reusable.yml@6fc714450122bda9d00e4ad5d639ad6a39eedb1f" # v2.0.1
with:
# Example of specifying custom arguments
scan-args: |-
-r
./
prepare-container-matrix:
name: Discover Dockerfiles
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Checkout the revision
uses: actions/checkout@v6
with:
lfs: false
- name: Find Dockerfiles to scan
id: set-matrix
run: |
echo "Scanning all Dockerfiles"
DOCKERFILES=$(find docker -type f -name "*.dockerfile" ! -name "backend.ai-*.dockerfile")
# Build JSON matrix
MATRIX_JSON=$(echo "$DOCKERFILES" | jq -R -s -c '
split("\n") |
map(select(length > 0)) |
map({
name: (split("/")[-1] | split(".dockerfile")[0]),
dockerfile: .,
context: "docker"
}) |
{include: .}
')
echo "Found Dockerfiles matrix:"
echo "$MATRIX_JSON" | jq .
echo "matrix=$MATRIX_JSON" >> $GITHUB_OUTPUT
scan-containers:
name: Scan Container Images
runs-on: ubuntu-latest
needs: prepare-container-matrix
if: needs.prepare-container-matrix.outputs.matrix != '{"include":[]}'
strategy:
matrix: ${{ fromJson(needs.prepare-container-matrix.outputs.matrix) }}
fail-fast: false
steps:
- name: Checkout the revision
uses: actions/checkout@v6
with:
lfs: false
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Resolve project Python version
id: pyver
run: |
PYTHON_VERSION=$(grep -m 1 -oP '(?<=CPython==)([^"]+)' pants.toml)
echo "version=$PYTHON_VERSION" >> "$GITHUB_OUTPUT"
- name: Build Docker image
uses: docker/build-push-action@v6
with:
context: ${{ matrix.context }}
file: ${{ matrix.dockerfile }}
platforms: linux/amd64
tags: backendai-${{ matrix.name }}:scan
load: true
cache-from: type=gha,scope=${{ matrix.name }}
cache-to: type=gha,mode=max,scope=${{ matrix.name }}
build-args: |
PYTHON_VERSION=${{ steps.pyver.outputs.version }}
- name: Save Docker image as archive
run: docker save backendai-${{ matrix.name }}:scan -o image.tar
- name: Run OSV Scanner on Docker image
uses: google/osv-scanner-action/osv-scanner-action@6fc714450122bda9d00e4ad5d639ad6a39eedb1f # v2.0.1
with:
scan-args: |-
--format=sarif
--output=results.sarif
scan
image
--archive
image.tar
continue-on-error: true
- name: Upload SARIF file
uses: github/codeql-action/upload-sarif@v4
if: always() && hashFiles('results.sarif') != ''
with:
sarif_file: results.sarif
category: container-${{ matrix.name }}