|
| 1 | +name: security |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + pull_request: |
| 8 | + schedule: |
| 9 | + # Run every day at 10:00 UTC (6:00 AM ET / 3:00 AM PT) |
| 10 | + - cron: "0 10 * * *" |
| 11 | + workflow_dispatch: |
| 12 | + |
| 13 | +permissions: |
| 14 | + contents: read |
| 15 | + |
| 16 | +# Cancel in-progress runs for pull requests when developers push |
| 17 | +# additional changes |
| 18 | +concurrency: |
| 19 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 20 | + cancel-in-progress: ${{ github.event_name == 'pull_request' }} |
| 21 | + |
| 22 | +jobs: |
| 23 | + codeql: |
| 24 | + name: CodeQL Analysis |
| 25 | + runs-on: ubuntu-latest |
| 26 | + permissions: |
| 27 | + security-events: write |
| 28 | + actions: read |
| 29 | + contents: read |
| 30 | + steps: |
| 31 | + - name: Checkout repository |
| 32 | + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 |
| 33 | + with: |
| 34 | + persist-credentials: false |
| 35 | + |
| 36 | + - name: Setup Go |
| 37 | + uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0 |
| 38 | + with: |
| 39 | + go-version-file: "go.mod" |
| 40 | + |
| 41 | + - name: Initialize CodeQL |
| 42 | + uses: github/codeql-action/init@755f44910c12a3d7ca0d8c6e42c048b3362f7cec # v3.30.8 |
| 43 | + with: |
| 44 | + languages: go |
| 45 | + |
| 46 | + - name: Perform CodeQL Analysis |
| 47 | + uses: github/codeql-action/analyze@755f44910c12a3d7ca0d8c6e42c048b3362f7cec # v3.30.8 |
| 48 | + with: |
| 49 | + category: "/language:go" |
| 50 | + |
| 51 | + trivy: |
| 52 | + name: Trivy Docker Image Scan |
| 53 | + runs-on: ubuntu-latest |
| 54 | + permissions: |
| 55 | + security-events: write |
| 56 | + contents: read |
| 57 | + steps: |
| 58 | + - name: Checkout repository |
| 59 | + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 |
| 60 | + with: |
| 61 | + persist-credentials: false |
| 62 | + |
| 63 | + - name: Setup Go |
| 64 | + uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0 |
| 65 | + with: |
| 66 | + go-version-file: "go.mod" |
| 67 | + |
| 68 | + - name: Build binary for linux/amd64 |
| 69 | + run: make bin/code-marketplace-linux-amd64 |
| 70 | + |
| 71 | + - name: Set up Docker Buildx |
| 72 | + uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1 |
| 73 | + |
| 74 | + - name: Build Docker image |
| 75 | + id: build |
| 76 | + run: | |
| 77 | + docker buildx bake \ |
| 78 | + -f ./docker-bake.hcl \ |
| 79 | + --set "*.platform=linux/amd64" \ |
| 80 | + --set "*.tags=code-marketplace:scan" \ |
| 81 | + --load |
| 82 | + echo "image=code-marketplace:scan" >> "$GITHUB_OUTPUT" |
| 83 | +
|
| 84 | + - name: Run Trivy vulnerability scanner (table output for logs) |
| 85 | + uses: aquasecurity/trivy-action@b6643a29fecd7f34b3597bc6acb0a98b03d33ff8 # v0.33.1 |
| 86 | + with: |
| 87 | + image-ref: ${{ steps.build.outputs.image }} |
| 88 | + format: "table" |
| 89 | + severity: "LOW,MEDIUM,HIGH,CRITICAL" |
| 90 | + |
| 91 | + - name: Run Trivy vulnerability scanner (SARIF output for GitHub) |
| 92 | + uses: aquasecurity/trivy-action@b6643a29fecd7f34b3597bc6acb0a98b03d33ff8 # v0.33.1 |
| 93 | + with: |
| 94 | + image-ref: ${{ steps.build.outputs.image }} |
| 95 | + format: "sarif" |
| 96 | + output: "trivy-results.sarif" |
| 97 | + severity: "LOW,MEDIUM,HIGH,CRITICAL" |
| 98 | + |
| 99 | + - name: Upload Trivy scan results to GitHub Security tab |
| 100 | + uses: github/codeql-action/upload-sarif@755f44910c12a3d7ca0d8c6e42c048b3362f7cec # v3.30.8 |
| 101 | + with: |
| 102 | + sarif_file: "trivy-results.sarif" |
| 103 | + category: "Trivy" |
| 104 | + |
| 105 | + - name: Upload Trivy scan results as artifact |
| 106 | + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 |
| 107 | + with: |
| 108 | + name: trivy-results |
| 109 | + path: trivy-results.sarif |
| 110 | + retention-days: 7 |
0 commit comments