9a434bb27a
Python was still reading DOCKERHUB_PAASUP_USER/TOKEN while the env: block sets DOCKERHUB_USER/TOKEN, silently disabling private registry auth. Also restore the nvcr.io (NGC) auth entry that was dropped.
166 lines
7.1 KiB
YAML
166 lines
7.1 KiB
YAML
name: helm-catalog-cve-edge-post
|
|
|
|
# manifests/helm 카탈로그의 컨테이너 이미지 취약점을 스캔해 단일 JSON 요약으로 출력한다.
|
|
# SBOM 산출물 자체는 필요 없으므로(sbom.yml 과 달리), extract-helm-images.sh 로 이미지
|
|
# 목록만 뽑은 뒤 각 이미지를 `trivy image` 로 직접 스캔한다(SBOM 생성 단계 생략).
|
|
#
|
|
# [{"image": "...", "low": 0, "high": 0, "medium": 0, "critical": 0,
|
|
# "scanned_at": "2026-07-13T06:19:44Z", "summary": "CVE-xxxx-xxxxx, ..."}, ...]
|
|
#
|
|
# 이미지별로 배열 원소 하나. summary 는 해당 이미지에서 발견된 CRITICAL CVE ID 전체를
|
|
# 콤마로 나열한다(중복 제거).
|
|
# 생성된 JSON 은 POST https://edge.gke.paasup.io/api/v1/cve-scans 로 전송한다.
|
|
# (X-CVE-API-Key 헤더 필요 — Repo Secret CVE_API_KEY, SSL 검증은 --insecure 로 스킵)
|
|
#
|
|
# 실행 컨테이너: sbom.yml 과 동일하게 vars.SBOM_PIPELINE_IMAGE (helm+trivy+python3+bash+git) 사용.
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
inputs:
|
|
limit:
|
|
description: '대상 이미지 수 상한 (0=전체). 테스트 시 예: 3'
|
|
required: false
|
|
default: '0'
|
|
|
|
permissions:
|
|
contents: read
|
|
|
|
jobs:
|
|
cve-json:
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 120
|
|
container:
|
|
image: ${{ vars.SBOM_PIPELINE_IMAGE }}
|
|
env:
|
|
OUT_DIR: ${{ github.workspace }}/sbom-out
|
|
TRIVY_CACHE_DIR: ${{ github.workspace }}/sbom-out/cache
|
|
PARALLEL: '3'
|
|
steps:
|
|
- name: Preflight — 도구 확인
|
|
run: |
|
|
set -e
|
|
for t in helm trivy python3 bash git; do
|
|
command -v "$t" >/dev/null || { echo "::error::컨테이너에 $t 없음 (vars.SBOM_PIPELINE_IMAGE 확인)"; exit 1; }
|
|
done
|
|
helm version --short; trivy --version | head -1
|
|
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: git safe.directory
|
|
run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
|
|
|
|
# 사설 레지스트리 인증: 시크릿으로 docker config.json 을 만들어 trivy 가 읽게 한다.
|
|
- name: 레지스트리 인증 구성
|
|
env:
|
|
DOCKERHUB_USER: ${{ secrets.DOCKERHUB_USER }}
|
|
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
NGC_API_KEY: ${{ secrets.NGC_API_KEY }}
|
|
run: |
|
|
mkdir -p "$OUT_DIR/.docker"
|
|
python3 - <<'PY'
|
|
import os, json, base64
|
|
auths={}
|
|
def add(reg,user,secret):
|
|
if user and secret:
|
|
auths[reg]={"auth":base64.b64encode(f"{user}:{secret}".encode()).decode()}
|
|
add("https://index.docker.io/v1/", os.environ.get("DOCKERHUB_USER"), os.environ.get("DOCKERHUB_TOKEN"))
|
|
# docker.getcollate.io(openmetadata)는 Docker Hub 프록시 → 익명 pull 시 Docker Hub rate
|
|
# limit(TOOMANYREQUESTS)에 걸린다. Docker Hub 자격증명으로 인증해 해소.
|
|
add("docker.getcollate.io", os.environ.get("DOCKERHUB_USER"), os.environ.get("DOCKERHUB_TOKEN"))
|
|
add("nvcr.io", "$oauthtoken", os.environ.get("NGC_API_KEY"))
|
|
out=os.path.join(os.environ["OUT_DIR"],".docker","config.json")
|
|
json.dump({"auths":auths}, open(out,"w"))
|
|
print("configured registries:", list(auths.keys()) or "(none)")
|
|
PY
|
|
echo "DOCKER_CONFIG=$OUT_DIR/.docker" >> "$GITHUB_ENV"
|
|
|
|
- name: 이미지 인벤토리 추출
|
|
run: bash doc/scripts/extract-helm-images.sh "$GITHUB_WORKSPACE/manifests/helm" "$OUT_DIR"
|
|
|
|
- name: 스캔 대상 결정 (전체)
|
|
env:
|
|
LIMIT: ${{ github.event.inputs.limit || '0' }}
|
|
run: |
|
|
if [ "$LIMIT" -gt 0 ] 2>/dev/null; then
|
|
cut -f3 "$OUT_DIR/images_final.tsv" | sort -u | head -n "$LIMIT" > "$OUT_DIR/images_scan.txt"
|
|
else
|
|
cut -f3 "$OUT_DIR/images_final.tsv" | sort -u > "$OUT_DIR/images_scan.txt"
|
|
fi
|
|
wc -l "$OUT_DIR/images_scan.txt"
|
|
|
|
# SBOM 산출물은 필요 없으므로 trivy image 로 이미지를 직접 스캔한다(SBOM 생성 단계 생략).
|
|
- name: 취약점 스캔 (trivy image 직접 실행)
|
|
run: |
|
|
set -uo pipefail
|
|
REPORTS_DIR="$OUT_DIR/trivy-reports"
|
|
mkdir -p "$REPORTS_DIR"
|
|
[ -s "$OUT_DIR/images_scan.txt" ] || { echo "대상 이미지 없음 — 스캔 생략"; exit 0; }
|
|
|
|
echo ">> trivy DB 워밍 중..."
|
|
trivy image --download-db-only
|
|
|
|
xargs -P "${PARALLEL:-3}" -I{} bash -c '
|
|
img="$1"; reports="$2"
|
|
safe=$(printf "%s" "$img" | tr "/:@" "___")
|
|
echo ">> 스캔: $img"
|
|
trivy image --quiet --skip-db-update \
|
|
--format json --timeout 15m --output "$reports/$safe.json" "$img" \
|
|
|| echo "::warning::스캔 실패: $img"
|
|
' _ {} "$REPORTS_DIR" < "$OUT_DIR/images_scan.txt"
|
|
|
|
# trivy-reports/*.json (이미지별 원본 Trivy 결과)을 python3 로 이미지별 집계.
|
|
- name: CVE JSON 생성
|
|
run: |
|
|
python3 - "$OUT_DIR/trivy-reports" "$OUT_DIR/cve-summary.json" <<'PY'
|
|
import sys, os, json, glob
|
|
from datetime import datetime, timezone
|
|
|
|
reports_dir, out_path = sys.argv[1], sys.argv[2]
|
|
scanned_at = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
|
|
results = []
|
|
|
|
for path in sorted(glob.glob(os.path.join(reports_dir, "*.json"))):
|
|
with open(path) as f:
|
|
data = json.load(f)
|
|
image = data.get("ArtifactName", os.path.basename(path))
|
|
counts = {"LOW": 0, "HIGH": 0, "MEDIUM": 0, "CRITICAL": 0}
|
|
critical_ids = set()
|
|
for result in data.get("Results") or []:
|
|
for vuln in result.get("Vulnerabilities") or []:
|
|
sev = vuln.get("Severity")
|
|
if sev in counts:
|
|
counts[sev] += 1
|
|
if sev == "CRITICAL":
|
|
critical_ids.add(vuln["VulnerabilityID"])
|
|
results.append({
|
|
"image": image,
|
|
"low": counts["LOW"],
|
|
"high": counts["HIGH"],
|
|
"medium": counts["MEDIUM"],
|
|
"critical": counts["CRITICAL"],
|
|
"scanned_at": scanned_at,
|
|
"summary": ", ".join(sorted(critical_ids)),
|
|
})
|
|
|
|
with open(out_path, "w") as f:
|
|
json.dump(results, f)
|
|
print(json.dumps(results, indent=2))
|
|
PY
|
|
|
|
cat "$OUT_DIR/cve-summary.json" >> "$GITHUB_STEP_SUMMARY"
|
|
|
|
- name: CVE 스캔 결과 전송
|
|
if: always()
|
|
env:
|
|
CVE_API_KEY: ${{ secrets.CVE_API_KEY }}
|
|
run: |
|
|
if [ ! -f "$OUT_DIR/cve-summary.json" ]; then
|
|
echo "::warning::$OUT_DIR/cve-summary.json 없음 — 전송 생략"
|
|
exit 0
|
|
fi
|
|
curl --fail-with-body --silent --show-error --insecure \
|
|
--request POST "https://edge.gke.paasup.io/api/v1/cve-scans" \
|
|
--header "Content-Type: application/json" \
|
|
--header "X-CVE-API-Key: $CVE_API_KEY" \
|
|
--data @"$OUT_DIR/cve-summary.json"
|