每一種 VulnCheck CI 整合都是相同的五個步驟:安裝固定版本的 CLI、公開 VC_TOKEN、掃描、把關、發布。因此任何能在容器中執行 shell 指令碼的平台都能執行它。在 CI/CD 中使用 VulnCheck 說明了每個步驟;本頁則將這些步驟套用到沒有專屬指南的平台上。
# 1. Install a pinned CLI
VC_CLI_VERSION=1.1.0
ARCH="$(uname -m)"
case "$ARCH" in x86_64) ARCH=amd64 ;; aarch64) ARCH=arm64 ;; esac
curl -sSL "https://github.com/vulncheck-oss/cli/releases/download/v${VC_CLI_VERSION}/vulncheck_${VC_CLI_VERSION}_linux_${ARCH}.tar.gz" | tar -xz -C /tmp
install -m 0755 "/tmp/vulncheck_${VC_CLI_VERSION}_linux_${ARCH}/bin/vulncheck" /usr/local/bin/vulncheck
# 2. VC_TOKEN comes from the platform's secret store — never from the repository
# 3. Scan
vulncheck scan . --json > scan.json
jq -r '"\((.vulnerabilities // []) | length) vulnerabilities found"' scan.json
# 4. Gate
jq -e --argjson max 7.0 '
[ (.vulnerabilities // [])[]
| select((.cvss_base_score // 0 | tonumber? // 0) >= $max or .in_kev) ] | length == 0
' scan.json > /dev/null || {
echo "VulnCheck policy breach:"
jq -r --argjson max 7.0 '
(.vulnerabilities // [])[]
| select((.cvss_base_score // 0 | tonumber? // 0) >= $max or .in_kev)
| " \(.cve) \(.name)@\(.version) CVSS \(.cvss_base_score) KEV \(.in_kev) fixed in \(.fixed_versions // "n/a")"
' scan.json
exit 1
}
# 5. Publish scan.json as a build artifact
在每個平台上,都有三件事經常讓人踩雷:
vulncheck scan 仍會以 0 結束,因此真正讓建置失敗的是步驟 4。若沒有它,作業會在日誌中留有發現項目的情況下顯示為綠燈。vulnerabilities 鍵,因此必須使用 (.vulnerabilities // [])[]——若未加防護就直接迭代,jq 會在一個毫無問題的儲存庫上以 5 結束。.cvss_base_score // 0 | tonumber? // 0 則防護另一端:否則沒有 CVSS 分數的發現項目會在 tonumber 時中止整個程式,同樣以 5 結束,而且發生在評估 .in_kev 之前。install.sh 指令碼只支援 glibc,而且即使在 root 容器中也假設 --sudo 可用,結果會在沒有任何提示的情況下什麼都沒安裝。上方的 tarball 作法在任何環境都能運作,包括 Alpine。在 Repository settings > Repository variables 下加入 VC_TOKEN,並勾選 Secured。
image: debian:bookworm-slim
definitions:
steps:
- step: &vulncheck-scan
name: Scan with VulnCheck
script:
- apt-get update -qq && apt-get install -y -qq --no-install-recommends ca-certificates curl jq
- export VC_CLI_VERSION=1.1.0
- curl -sSL "https://github.com/vulncheck-oss/cli/releases/download/v${VC_CLI_VERSION}/vulncheck_${VC_CLI_VERSION}_linux_amd64.tar.gz" | tar -xz -C /tmp
- install -m 0755 "/tmp/vulncheck_${VC_CLI_VERSION}_linux_amd64/bin/vulncheck" /usr/local/bin/vulncheck
- vulncheck scan . --json > scan.json
- jq -r '"\((.vulnerabilities // []) | length) vulnerabilities found"' scan.json
- |
jq -e --argjson max 7.0 '
[ (.vulnerabilities // [])[]
| select((.cvss_base_score // 0 | tonumber? // 0) >= $max or .in_kev) ] | length == 0
' scan.json > /dev/null || { echo "VulnCheck policy breach"; exit 1; }
artifacts:
- scan.json
pipelines:
pull-requests:
'**':
- step: *vulncheck-scan
branches:
main:
- step: *vulncheck-scan
將 VC_TOKEN 加入為專案環境變數,或加入可在多個專案間共用的 context。
version: 2.1
jobs:
vulncheck-scan:
docker:
- image: cimg/base:current
environment:
VC_CLI_VERSION: 1.1.0
VC_CVSS_THRESHOLD: '7.0'
steps:
- checkout
- run:
name: Install the VulnCheck CLI
command: |
curl -sSL "https://github.com/vulncheck-oss/cli/releases/download/v${VC_CLI_VERSION}/vulncheck_${VC_CLI_VERSION}_linux_amd64.tar.gz" | tar -xz -C /tmp
sudo install -m 0755 "/tmp/vulncheck_${VC_CLI_VERSION}_linux_amd64/bin/vulncheck" /usr/local/bin/vulncheck
vulncheck version
- run:
name: Scan
command: |
vulncheck scan . --json > scan.json
jq -r '"\((.vulnerabilities // []) | length) vulnerabilities found"' scan.json
- run:
name: Gate on findings
command: |
jq -e --argjson max "$VC_CVSS_THRESHOLD" '
[ (.vulnerabilities // [])[]
| select((.cvss_base_score // 0 | tonumber? // 0) >= $max or .in_kev) ] | length == 0
' scan.json > /dev/null || { echo "VulnCheck policy breach"; exit 1; }
- store_artifacts:
path: scan.json
workflows:
security:
jobs:
- vulncheck-scan
將 vc_token 加入為儲存庫密鑰。下方範例為 Drone;Woodpecker 使用相同的步驟,只需移除最上層的 kind、type 與 name 鍵。
kind: pipeline
type: docker
name: security
steps:
- name: vulncheck-scan
image: debian:bookworm-slim
environment:
VC_TOKEN:
from_secret: vc_token
VC_CLI_VERSION: 1.1.0
commands:
- apt-get update -qq && apt-get install -y -qq --no-install-recommends ca-certificates curl jq
- curl -sSL "https://github.com/vulncheck-oss/cli/releases/download/v${VC_CLI_VERSION}/vulncheck_${VC_CLI_VERSION}_linux_amd64.tar.gz" | tar -xz -C /tmp
- install -m 0755 "/tmp/vulncheck_${VC_CLI_VERSION}_linux_amd64/bin/vulncheck" /usr/local/bin/vulncheck
- vulncheck scan . --json > scan.json
- jq -r '"\((.vulnerabilities // []) | length) vulnerabilities found"' scan.json
- |
jq -e --argjson max 7.0 '
[ (.vulnerabilities // [])[]
| select((.cvss_base_score // 0 | tonumber? // 0) >= $max or .in_kev) ] | length == 0
' scan.json > /dev/null || { echo "VulnCheck policy breach"; exit 1; }
透過 agent 的 environment hook 或 secrets helper 公開 VC_TOKEN,然後在容器中執行掃描:
steps:
- label: 'Scan with VulnCheck'
plugins:
- docker#v5.11.0:
image: debian:bookworm-slim
propagate-environment: true
environment:
- VC_TOKEN
commands:
- apt-get update -qq && apt-get install -y -qq --no-install-recommends ca-certificates curl jq
- export VC_CLI_VERSION=1.1.0
- curl -sSL "https://github.com/vulncheck-oss/cli/releases/download/v${VC_CLI_VERSION}/vulncheck_${VC_CLI_VERSION}_linux_amd64.tar.gz" | tar -xz -C /tmp
- install -m 0755 "/tmp/vulncheck_${VC_CLI_VERSION}_linux_amd64/bin/vulncheck" /usr/local/bin/vulncheck
- vulncheck scan . --json > scan.json
- |
jq -e --argjson max 7.0 '
[ (.vulnerabilities // [])[]
| select((.cvss_base_score // 0 | tonumber? // 0) >= $max or .in_kev) ] | length == 0
' scan.json > /dev/null || { echo "VulnCheck policy breach"; exit 1; }
artifact_paths:
- scan.json
Tekton、Argo Workflows 及 GitLab 的 Kubernetes executor 等 Kubernetes 原生 runner 不需要任何特殊處理:在步驟容器中執行通用作法、從 Secret 掛載 VC_TOKEN,並將 scan.json 寫入共用工作區,供後續步驟發布。