Skip to content

Commit 707d19b

Browse files
authored
ci: vulnerability scan tweaks (#126)
* ci: vulnerability scan tweaks I don't see a need to use a custom path for the nvd database, so turfed that complexity. Let it go to its default spot under ~/.m2/repository... Don't base github action cache on date, base it instead on deps and bb.edn. Use action/cache/restore and actions/cache/save to control caching. This should allow us to save nvd database for subsequent runs. Seems to work, but we'll see. Closes #125
1 parent b1fc866 commit 707d19b

File tree

5 files changed

+78
-23
lines changed

5 files changed

+78
-23
lines changed

.github/workflows/nvd_scanner.yml

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,65 @@ jobs:
1717
steps:
1818
- uses: actions/checkout@v4
1919

20-
- name: Setup
21-
uses: ./.github/workflows/shared-setup
20+
- name: Setup Java
21+
uses: actions/setup-java@v4
2222
with:
23-
jdk: '11'
23+
distribution: 'temurin'
24+
java-version: 21
2425

25-
- name: Get Date
26-
id: get-date
26+
- name: Install Clojure Tools
27+
uses: DeLaGuardo/[email protected]
28+
with:
29+
cli: 'latest'
30+
bb: 'latest'
31+
32+
- name: Generate Cache Key
2733
run: |
28-
echo "date=$(/bin/date -u "+%Y%m%d")" >> $GITHUB_OUTPUT
29-
shell: bash
34+
bb --version
35+
bb latest-release nvd-clojure | tee nvd_check_helper_project/nvd-clojure-version.txt
3036
31-
- name: Cache NVD Database
32-
uses: actions/cache@v4
37+
- name: Restore NVD DB & Clojure Deps Cache
38+
# nvd caches its db under ~/.m2/repository/org/owasp so that it can
39+
# conveniently be cached with deps
40+
uses: actions/cache/restore@v4
3341
with:
34-
path: /home/runner/.nvd-cache/
35-
key: nvd-cache-we-are-happy-to-share-across-branches-${{ steps.get-date.outputs.date }}
42+
path: |
43+
~/.m2/repository
44+
~/.deps.clj
45+
~/.gitlibs
46+
# because we are using a RELEASE version of nvd-clojure
47+
# we also include its version
48+
key: |
49+
nvd-${{ hashFiles(
50+
'nvd_check_helper_project/nvd-clojure-version.txt',
51+
'nvd_check_helper_project/deps.edn',
52+
'nvd_check_helper_project/bb.edn',
53+
'bb.edn') }}
54+
restore-keys: |
55+
nvd-
56+
57+
- name: Download Clojure deps
58+
run: clojure -X:deps prep
59+
working-directory: nvd_check_helper_project
3660

3761
- name: Run NVD Scanner
3862
env:
3963
NVD_API_TOKEN: ${{ secrets.NVD_API_TOKEN }}
4064
run: bb nvd-scan
65+
66+
- name: Save NVD DB & Clojure Deps Cache
67+
if: always() # always cache regardless of outcome of nvd scan
68+
uses: actions/cache/save@v4
69+
with:
70+
path: |
71+
~/.m2/repository
72+
~/.deps.clj
73+
~/.gitlibs
74+
# we tack on github.run_id to uniquely identify the cache
75+
# the next cache restore will find the best (and most current) match
76+
key: |
77+
nvd-${{ hashFiles(
78+
'nvd_check_helper_project/nvd-clojure-version.txt',
79+
'nvd_check_helper_project/deps.edn',
80+
'nvd_check_helper_project/bb.edn',
81+
'bb.edn') }}-${{ github.run_id }}

bb.edn

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,17 @@
55
version-clj/version-clj {:mvn/version "2.0.2"}}
66
:tasks {;; setup
77
:requires ([babashka.fs :as fs]
8+
[babashka.http-client :as http]
9+
[clojure.edn :as edn]
810
[clojure.string :as string]
911
[lread.status-line :as status])
10-
:enter (let [{:keys [name]} (current-task)] (status/line :head "TASK %s %s" name (string/join " " *command-line-args*)))
11-
:leave (let [{:keys [name]} (current-task)] (status/line :detail "\nTASK %s done." name))
12+
13+
:enter (let [{:keys [name task-decoration] :as f} (current-task)]
14+
(when-not (= :none task-decoration)
15+
(status/line :head "TASK %s" name)))
16+
:leave (let [{:keys [name task-decoration] :as f} (current-task)]
17+
(when-not (= :none task-decoration)
18+
(status/line :detail "\nTASK %s done." name)))
1219

1320
;; tasks
1421
clean
@@ -47,16 +54,24 @@
4754
lint
4855
{:doc "Run all lints"
4956
:depends [lint-kondo lint-eastwood]}
57+
latest-release
58+
{:doc "Return latest clojars release of given artifact"
59+
:task-decoration :none
60+
;; we use RELEASE for nvd-clojure, so use its version as our cache key
61+
:task (let [artifact (first *command-line-args*)]
62+
(-> (http/get (str "https://clojars.org/api/artifacts/" artifact)
63+
{:headers {"Accept" "application/edn"}})
64+
:body
65+
edn/read-string
66+
:latest_release
67+
println))}
5068
nvd-scan
5169
{:doc "Check for security vulnerabilities in dependencies"
52-
:task (let [config (if (System/getenv "CI")
53-
"./github_actions_config.json" ;; to support CI caching
54-
"./local_config.json")]
55-
(status/line :detail "Using config: %s" config)
70+
:task (let [cp (with-out-str (clojure "-Spath"))]
5671
(clojure {:dir "./nvd_check_helper_project"}
5772
"-J-Dclojure.main.report=stderr -M -m nvd.task.check"
58-
config
59-
(with-out-str (clojure "-Spath"))))}
73+
"./config.json"
74+
cp))}
6075
pubcheck
6176
{:doc "run only publish checks (without publishing)"
6277
:task publish/pubcheck}
File renamed without changes.

nvd_check_helper_project/deps.edn

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22
;; it is generally considered bad practice to use RELEASE, but we always want the latest
33
;; security tooling
44
#_:clj-kondo/ignore
5-
{:mvn/version "RELEASE"}}}
5+
{:mvn/version "RELEASE"}
6+
;; temporarily try bumping transitive dep to current release
7+
org.owasp/dependency-check-maven {:mvn/version "10.0.0"}}}

nvd_check_helper_project/github_actions_config.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)