|
| 1 | +name: 安全扫描 |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + pull_request: |
| 7 | + branches: [main] |
| 8 | + schedule: |
| 9 | + # 每周三 UTC 8:00(北京时间 16:00)自动扫描 |
| 10 | + - cron: "0 8 * * 3" |
| 11 | + |
| 12 | +concurrency: |
| 13 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 14 | + cancel-in-progress: true |
| 15 | + |
| 16 | +jobs: |
| 17 | + trivy-frontend: |
| 18 | + name: Trivy 前端依赖扫描 |
| 19 | + runs-on: ubuntu-latest |
| 20 | + timeout-minutes: 10 |
| 21 | + |
| 22 | + permissions: |
| 23 | + security-events: write |
| 24 | + contents: read |
| 25 | + |
| 26 | + steps: |
| 27 | + - name: 签出代码 |
| 28 | + uses: actions/checkout@v6 |
| 29 | + |
| 30 | + - name: Trivy 漏洞扫描(前端) |
| 31 | + uses: aquasecurity/trivy-action@master |
| 32 | + with: |
| 33 | + scan-type: fs |
| 34 | + scan-ref: . |
| 35 | + scanners: vuln |
| 36 | + severity: CRITICAL,HIGH |
| 37 | + format: sarif |
| 38 | + output: trivy-frontend.sarif |
| 39 | + |
| 40 | + - name: 上传扫描结果到 GitHub Security |
| 41 | + uses: github/codeql-action/upload-sarif@v3 |
| 42 | + if: always() |
| 43 | + with: |
| 44 | + sarif_file: trivy-frontend.sarif |
| 45 | + category: trivy-frontend |
| 46 | + |
| 47 | + trivy-backend: |
| 48 | + name: Trivy 后端依赖扫描 |
| 49 | + runs-on: ubuntu-latest |
| 50 | + timeout-minutes: 10 |
| 51 | + |
| 52 | + permissions: |
| 53 | + security-events: write |
| 54 | + contents: read |
| 55 | + |
| 56 | + steps: |
| 57 | + - name: 签出代码 |
| 58 | + uses: actions/checkout@v6 |
| 59 | + |
| 60 | + - name: Trivy 漏洞扫描(后端) |
| 61 | + uses: aquasecurity/trivy-action@master |
| 62 | + with: |
| 63 | + scan-type: fs |
| 64 | + scan-ref: backend |
| 65 | + scanners: vuln |
| 66 | + severity: CRITICAL,HIGH |
| 67 | + format: sarif |
| 68 | + output: trivy-backend.sarif |
| 69 | + |
| 70 | + - name: 上传扫描结果到 GitHub Security |
| 71 | + uses: github/codeql-action/upload-sarif@v3 |
| 72 | + if: always() |
| 73 | + with: |
| 74 | + sarif_file: trivy-backend.sarif |
| 75 | + category: trivy-backend |
| 76 | + |
| 77 | + govulncheck: |
| 78 | + name: Go 官方漏洞检查 |
| 79 | + runs-on: ubuntu-latest |
| 80 | + timeout-minutes: 10 |
| 81 | + defaults: |
| 82 | + run: |
| 83 | + working-directory: backend |
| 84 | + |
| 85 | + steps: |
| 86 | + - name: 签出代码 |
| 87 | + uses: actions/checkout@v6 |
| 88 | + |
| 89 | + - name: 配置 Go |
| 90 | + uses: actions/setup-go@v6 |
| 91 | + with: |
| 92 | + go-version-file: backend/go.mod |
| 93 | + cache-dependency-path: backend/go.sum |
| 94 | + |
| 95 | + - name: 安装 govulncheck |
| 96 | + run: go install golang.org/x/vuln/cmd/govulncheck@latest |
| 97 | + |
| 98 | + - name: 执行漏洞检查 |
| 99 | + run: govulncheck ./... |
| 100 | + |
| 101 | + gitleaks: |
| 102 | + name: Gitleaks 敏感信息泄露检测 |
| 103 | + runs-on: ubuntu-latest |
| 104 | + timeout-minutes: 10 |
| 105 | + |
| 106 | + permissions: |
| 107 | + security-events: write |
| 108 | + contents: read |
| 109 | + |
| 110 | + steps: |
| 111 | + - name: 签出代码 |
| 112 | + uses: actions/checkout@v6 |
| 113 | + with: |
| 114 | + fetch-depth: 0 |
| 115 | + |
| 116 | + - name: Gitleaks 扫描 |
| 117 | + uses: gitleaks/gitleaks-action@v2 |
| 118 | + env: |
| 119 | + GITLEAKS_LICENSE: ${{ secrets.GITLEAKS_LICENSE }} |
| 120 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments