|
| 1 | +name: Docker Security Scan |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + - develop |
| 8 | + paths: |
| 9 | + - "docker/**" |
| 10 | + - "templates/docker-compose/**" |
| 11 | + - ".github/workflows/docker-security-scan.yml" |
| 12 | + pull_request: |
| 13 | + paths: |
| 14 | + - "docker/**" |
| 15 | + - "templates/docker-compose/**" |
| 16 | + - ".github/workflows/docker-security-scan.yml" |
| 17 | + schedule: |
| 18 | + - cron: "0 6 * * *" # Daily at 6 AM UTC |
| 19 | + workflow_dispatch: # Allow manual triggering |
| 20 | + |
| 21 | +jobs: |
| 22 | + scan-project-images: |
| 23 | + name: Scan Project-Built Docker Images |
| 24 | + runs-on: ubuntu-latest |
| 25 | + timeout-minutes: 15 |
| 26 | + strategy: |
| 27 | + fail-fast: false |
| 28 | + matrix: |
| 29 | + image: |
| 30 | + - dockerfile: docker/provisioned-instance/Dockerfile |
| 31 | + context: docker/provisioned-instance |
| 32 | + name: provisioned-instance |
| 33 | + - dockerfile: docker/ssh-server/Dockerfile |
| 34 | + context: docker/ssh-server |
| 35 | + name: ssh-server |
| 36 | + steps: |
| 37 | + - name: Checkout code |
| 38 | + uses: actions/checkout@v4 |
| 39 | + |
| 40 | + - name: Build Docker image |
| 41 | + run: | |
| 42 | + docker build -t torrust-tracker-deployer/${{ matrix.image.name }}:latest \ |
| 43 | + -f ${{ matrix.image.dockerfile }} \ |
| 44 | + ${{ matrix.image.context }} |
| 45 | +
|
| 46 | + - name: Run Trivy vulnerability scanner |
| 47 | + uses: aquasecurity/trivy-action@master |
| 48 | + with: |
| 49 | + image-ref: torrust-tracker-deployer/${{ matrix.image.name }}:latest |
| 50 | + format: "sarif" |
| 51 | + output: "trivy-results-${{ matrix.image.name }}.sarif" |
| 52 | + severity: "HIGH,CRITICAL" |
| 53 | + exit-code: "1" |
| 54 | + |
| 55 | + - name: Upload Trivy results to GitHub Security |
| 56 | + uses: github/codeql-action/upload-sarif@v3 |
| 57 | + if: always() |
| 58 | + with: |
| 59 | + sarif_file: "trivy-results-${{ matrix.image.name }}.sarif" |
| 60 | + |
| 61 | + scan-third-party-images: |
| 62 | + name: Scan Third-Party Docker Images |
| 63 | + runs-on: ubuntu-latest |
| 64 | + timeout-minutes: 15 |
| 65 | + strategy: |
| 66 | + fail-fast: false |
| 67 | + matrix: |
| 68 | + # NOTE: These images must match the ones used in templates/docker-compose/docker-compose.yml.tera |
| 69 | + # TODO: Automate image detection from docker-compose templates - see https://github.com/torrust/torrust-tracker-deployer/issues/252 |
| 70 | + image: |
| 71 | + - torrust/tracker:develop |
| 72 | + - mysql:8.0 |
| 73 | + - grafana/grafana:11.4.0 |
| 74 | + - prom/prometheus:v3.0.1 |
| 75 | + steps: |
| 76 | + - name: Run Trivy vulnerability scanner |
| 77 | + uses: aquasecurity/trivy-action@master |
| 78 | + with: |
| 79 | + image-ref: ${{ matrix.image }} |
| 80 | + format: "sarif" |
| 81 | + output: "trivy-results.sarif" |
| 82 | + severity: "HIGH,CRITICAL" |
| 83 | + exit-code: "1" |
| 84 | + |
| 85 | + - name: Upload Trivy results to GitHub Security |
| 86 | + uses: github/codeql-action/upload-sarif@v3 |
| 87 | + if: always() |
| 88 | + with: |
| 89 | + sarif_file: "trivy-results.sarif" |
0 commit comments