Add Trivy scan workflow #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Trivy Vulnerability Scan # 워크플로우 이름 | |
| on: | |
| push: | |
| branches: [ main ] # main 브랜치에 푸시될 때 실행 | |
| pull_request: | |
| branches: [ main ] # main 브랜치로 PR이 생성/업데이트될 때 실행 | |
| workflow_dispatch: # GitHub Actions 탭에서 수동으로 실행 가능하도록 함 | |
| jobs: | |
| scan: # 'scan' 이라는 이름의 잡(job) 정의 | |
| name: Scan Alpine Image # 잡의 표시 이름 | |
| runs-on: ubuntu-latest # 실행될 환경 (가상머신 종류) | |
| steps: # 잡 내에서 실행될 단계들 | |
| - name: Checkout code # 코드 체크아웃 (표준적인 단계) | |
| uses: actions/checkout@v4 # GitHub Actions 체크아웃 액션 사용 | |
| - name: Run Trivy vulnerability scanner on Alpine image | |
| # Aqua Security에서 제공하는 공식 Trivy GitHub Action 사용 | |
| uses: aquasecurity/trivy-action@0.24.0 # 특정 버전 사용 권장 | |
| with: | |
| image-ref: 'alpine:latest' # 스캔할 도커 이미지 지정 | |
| format: 'table' # 결과를 로그에 테이블 형태로 출력 | |
| exit-code: '0' # 취약점이 발견되어도 워크플로우를 실패시키지 않음 (보고만 받기) | |
| # '1'로 설정하면 CRITICAL/HIGH 취약점 발견 시 워크플로우 실패 (병합 방지 등) | |
| ignore-unfixed: true # 아직 패치가 없는 취약점은 무시 (결과 노이즈 줄이기) | |
| vuln-type: 'os,library' # OS 패키지 및 프로그래밍 언어 라이브러리 취약점 스캔 | |
| severity: 'CRITICAL,HIGH' # 심각도 CRITICAL, HIGH만 보고하도록 제한 | |
| # --- 아래는 선택 사항: 스캔 결과를 GitHub Security 탭에 업로드 --- | |
| - name: Run Trivy vulnerability scanner in SARIF format | |
| # Push 또는 Pull Request 이벤트일 때만 실행 (수동 실행 시 제외) | |
| if: github.event_name == 'push' || github.event_name == 'pull_request' | |
| uses: aquasecurity/trivy-action@0.24.0 | |
| with: | |
| image-ref: 'alpine:latest' | |
| format: 'sarif' # 결과를 SARIF 형식으로 저장 (GitHub Security 탭용 표준 형식) | |
| output: 'trivy-results.sarif' # 저장할 파일 이름 | |
| ignore-unfixed: true | |
| vuln-type: 'os,library' | |
| severity: 'CRITICAL,HIGH' | |
| # SARIF 업로드 목적이므로 여기서는 exit-code를 1로 설정하지 않음 | |
| - name: Upload Trivy scan results to GitHub Security tab | |
| if: github.event_name == 'push' || github.event_name == 'pull_request' | |
| uses: github/codeql-action/upload-sarif@v3 # GitHub의 SARIF 업로드 액션 사용 | |
| with: | |
| sarif_file: 'trivy-results.sarif' # 업로드할 SARIF 파일 지정 |