1+ name : Trivy Vulnerability Scan # 워크플로우 이름
2+
3+ on :
4+ push :
5+ branches : [ main ] # main 브랜치에 푸시될 때 실행
6+ pull_request :
7+ branches : [ main ] # main 브랜치로 PR이 생성/업데이트될 때 실행
8+ workflow_dispatch : # GitHub Actions 탭에서 수동으로 실행 가능하도록 함
9+
10+ jobs :
11+ scan : # 'scan' 이라는 이름의 잡(job) 정의
12+ name : Scan Alpine Image # 잡의 표시 이름
13+ runs-on : ubuntu-latest # 실행될 환경 (가상머신 종류)
14+
15+ steps : # 잡 내에서 실행될 단계들
16+ - name : Checkout code # 코드 체크아웃 (표준적인 단계)
17+ uses : actions/checkout@v4 # GitHub Actions 체크아웃 액션 사용
18+
19+ - name : Run Trivy vulnerability scanner on Alpine image
20+ # Aqua Security에서 제공하는 공식 Trivy GitHub Action 사용
21+ uses : aquasecurity/trivy-action@0.24.0 # 특정 버전 사용 권장
22+ with :
23+ image-ref : ' alpine:latest' # 스캔할 도커 이미지 지정
24+ format : ' table' # 결과를 로그에 테이블 형태로 출력
25+ exit-code : ' 0' # 취약점이 발견되어도 워크플로우를 실패시키지 않음 (보고만 받기)
26+ # '1'로 설정하면 CRITICAL/HIGH 취약점 발견 시 워크플로우 실패 (병합 방지 등)
27+ ignore-unfixed : true # 아직 패치가 없는 취약점은 무시 (결과 노이즈 줄이기)
28+ vuln-type : ' os,library' # OS 패키지 및 프로그래밍 언어 라이브러리 취약점 스캔
29+ severity : ' CRITICAL,HIGH' # 심각도 CRITICAL, HIGH만 보고하도록 제한
30+
31+ # --- 아래는 선택 사항: 스캔 결과를 GitHub Security 탭에 업로드 ---
32+ - name : Run Trivy vulnerability scanner in SARIF format
33+ # Push 또는 Pull Request 이벤트일 때만 실행 (수동 실행 시 제외)
34+ if : github.event_name == 'push' || github.event_name == 'pull_request'
35+ uses : aquasecurity/trivy-action@0.24.0
36+ with :
37+ image-ref : ' alpine:latest'
38+ format : ' sarif' # 결과를 SARIF 형식으로 저장 (GitHub Security 탭용 표준 형식)
39+ output : ' trivy-results.sarif' # 저장할 파일 이름
40+ ignore-unfixed : true
41+ vuln-type : ' os,library'
42+ severity : ' CRITICAL,HIGH'
43+ # SARIF 업로드 목적이므로 여기서는 exit-code를 1로 설정하지 않음
44+
45+ - name : Upload Trivy scan results to GitHub Security tab
46+ if : github.event_name == 'push' || github.event_name == 'pull_request'
47+ uses : github/codeql-action/upload-sarif@v3 # GitHub의 SARIF 업로드 액션 사용
48+ with :
49+ sarif_file : ' trivy-results.sarif' # 업로드할 SARIF 파일 지정
0 commit comments