Repository navigation
153 lines (131 loc) · 6.33 KB
/
Copy pathbump-vuln-deps.yml
File metadata and controls
153 lines (131 loc) · 6.33 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
name: Bump vulnerable dependencies
on:
schedule:
# Run daily at 05:30 UTC, just after the Go toolchain bumper.
- cron: "30 5 * * *"
workflow_dispatch:
inputs:
dry_run:
description: "Compute and show the bump without creating a pull request or failure issue"
type: boolean
default: false
permissions:
contents: write
pull-requests: write
# Required to open or comment on the failure-tracking issue.
issues: write
# Required by setup-jfrog (GOPROXY exchange).
id-token: write
jobs:
bump-vuln-deps:
runs-on:
group: databricks-protected-runner-group-large
labels: linux-ubuntu-latest-large
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Setup JFrog
uses: ./.github/actions/setup-jfrog
- name: Setup Go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
# vulnbump lives in the tools module, which is what this job compiles.
go-version-file: tools/go.mod
- name: Build vulnbump and repoadvisory
run: |
go -C tools/vulnbump build -o "$RUNNER_TEMP/vulnbump" .
go -C tools/repoadvisory build -o "$RUNNER_TEMP/repoadvisory" .
- name: Bump vulnerable dependencies
id: bump
env:
# repoadvisory reads public repository advisories through the GitHub API.
GITHUB_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
# govulncheck is pinned as a tool dependency in tools/go.mod; -modfile
# resolves it from there while it scans the root module (the working
# directory). Only the root module ships; tools/ is build- and
# CI-only, so it is not scanned. Its vulnerability database is fetched from vuln.go.dev at
# runtime, so the pinned binary still uses the latest advisories.
#
# -scan module reports every advisory affecting a required module,
# regardless of whether the vulnerable symbol is reachable. In JSON
# mode govulncheck exits 0 on success whether or not it finds anything,
# and non-zero only on a real error; a failure must abort the job
# rather than be silently mistaken for "no vulnerabilities".
scan="$(mktemp)"
go tool -modfile=tools/go.mod govulncheck -scan module -format json > "$scan"
# Maintainers publish GitHub repository security advisories before
# they reach the Go vulnerability database, so govulncheck misses
# them. repoadvisory checks the modules linked into the CLI against
# those advisories and emits the ones with a patched version in the
# same JSON format. Each scan writes to its own file so a failure in
# either aborts the job.
advisories="$(mktemp)"
go list -deps -f '{{with .Module}}{{if .Version}}{{.Path}} {{.Version}}{{end}}{{end}}' . \
| "$RUNNER_TEMP/repoadvisory" > "$advisories"
summary_file="$(mktemp)"
cat "$scan" "$advisories" | "$RUNNER_TEMP/vulnbump" . > "$summary_file"
if git diff --quiet; then
echo "No vulnerable dependencies to bump."
echo "needed=false" >> "$GITHUB_OUTPUT"
else
echo "needed=true" >> "$GITHUB_OUTPUT"
{
echo "summary<<SUMMARY_EOF"
cat "$summary_file"
echo "SUMMARY_EOF"
} >> "$GITHUB_OUTPUT"
fi
- name: Show diff
if: steps.bump.outputs.needed == 'true'
run: git diff
- name: Create pull request
id: cpr
if: steps.bump.outputs.needed == 'true' && !inputs.dry_run
uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1
with:
# A fixed branch means a daily run updates the existing open PR in
# place rather than opening a new one; no branch-suffix is needed.
branch: auto/bump-vuln-deps
commit-message: "Bump dependencies with known vulnerabilities"
title: "Bump dependencies with known vulnerabilities"
body: |
Bump dependencies flagged by `govulncheck -scan module` or by GitHub repository security advisories to their fixed versions.
Each advisory links to its advisory page.
${{ steps.bump.outputs.summary }}
Vulnerabilities in the Go standard library are left to the `Bump Go toolchain` workflow.
If a bump promotes a new direct dependency, double-check its license annotation in `go.mod` and `NOTICE`.
reviewers: simonfaltum,andrewnester,anton-107,denik,janniklasrose,pietern,shreyas-goenka
labels: dependencies
# Add the changelog fragment as a follow-up commit on the PR branch: the
# fragment references the PR number, which only exists once the PR above
# has been created. The fixed branch is re-checked out on each daily run,
# so guard against re-committing when the fragment already exists.
- name: Add changelog fragment
if: steps.cpr.outputs.pull-request-number
env:
BRANCH: ${{ steps.cpr.outputs.pull-request-branch }}
PR: ${{ steps.cpr.outputs.pull-request-number }}
run: |-
git fetch origin "$BRANCH"
git checkout -f -B "$BRANCH" FETCH_HEAD
fragment=".nextchanges/dependency-updates/${PR}.md"
echo "* Bump dependencies with known vulnerabilities. ([#${PR}](https://github.com/databricks/cli/pull/${PR}))" > "$fragment"
git add "$fragment"
# Skip commit if nothing changed (fragment already present on this branch).
if git diff --cached --quiet; then
echo "fragment already present"
exit 0
fi
git -c user.name='github-actions[bot]' \
-c user.email='41898282+github-actions[bot]@users.noreply.github.com' \
commit -m "Add changelog fragment"
git push origin "HEAD:$BRANCH"
# A failed scheduled run is otherwise only visible in the Actions tab.
- name: Report failure
if: failure() && !inputs.dry_run
uses: ./.github/actions/report-failure
with:
label: bump-vuln-deps-failure
assignees: simonfaltum,andrewnester,anton-107,denik,janniklasrose,pietern,shreyas-goenka