|
| 1 | +name: Trivy Image and Dependency Scan |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened, synchronize, reopened] |
| 6 | + branches: [main] |
| 7 | + push: |
| 8 | + branches: [main] |
| 9 | + |
| 10 | +permissions: |
| 11 | + contents: read |
| 12 | + pull-requests: write |
| 13 | + actions: read |
| 14 | + security-events: write |
| 15 | + |
| 16 | +jobs: |
| 17 | + trivy: |
| 18 | + runs-on: ubuntu-latest |
| 19 | + timeout-minutes: 20 |
| 20 | + steps: |
| 21 | + - name: Checkout |
| 22 | + uses: actions/checkout@v4 |
| 23 | + |
| 24 | + - name: Set up Docker Buildx |
| 25 | + uses: docker/setup-buildx-action@v3 |
| 26 | + |
| 27 | + - name: Log in to Chainguard Container Registry |
| 28 | + uses: docker/login-action@v3 |
| 29 | + with: |
| 30 | + registry: cgr.dev |
| 31 | + username: ${{ secrets.CHAINGUARD_USERNAME }} |
| 32 | + password: ${{ secrets.CHAINGUARD_PASSWORD }} |
| 33 | + |
| 34 | + - name: Build image |
| 35 | + uses: docker/build-push-action@v6 |
| 36 | + with: |
| 37 | + context: . |
| 38 | + file: ./Dockerfile |
| 39 | + push: false |
| 40 | + load: true |
| 41 | + tags: pyatlan-trivy:latest |
| 42 | + |
| 43 | + - name: Trivy image scan (table) |
| 44 | + uses: aquasecurity/trivy-action@0.33.1 |
| 45 | + with: |
| 46 | + image-ref: pyatlan-trivy:latest |
| 47 | + scanners: 'vuln' |
| 48 | + version: 'v0.69.0' |
| 49 | + ignore-unfixed: true |
| 50 | + format: 'table' |
| 51 | + output: 'trivy-image.txt' |
| 52 | + severity: 'CRITICAL,HIGH' |
| 53 | + exit-code: '0' |
| 54 | + env: |
| 55 | + TRIVY_DB_REPOSITORY: public.ecr.aws/aquasecurity/trivy-db:2 |
| 56 | + TRIVY_JAVA_DB_REPOSITORY: public.ecr.aws/aquasecurity/trivy-java-db:1 |
| 57 | + |
| 58 | + - name: Show Trivy image table |
| 59 | + if: always() |
| 60 | + shell: bash |
| 61 | + run: | |
| 62 | + echo "Trivy image scan (table)"; |
| 63 | + if [ -f trivy-image.txt ]; then |
| 64 | + cat trivy-image.txt; |
| 65 | + else |
| 66 | + echo "No trivy-image.txt output found."; |
| 67 | + fi |
| 68 | +
|
| 69 | + - name: Trivy image scan (SARIF) |
| 70 | + uses: aquasecurity/trivy-action@0.33.1 |
| 71 | + with: |
| 72 | + image-ref: pyatlan-trivy:latest |
| 73 | + scanners: 'vuln' |
| 74 | + version: 'v0.69.0' |
| 75 | + ignore-unfixed: true |
| 76 | + format: 'sarif' |
| 77 | + output: 'trivy-image.sarif' |
| 78 | + severity: 'CRITICAL,HIGH' |
| 79 | + exit-code: '0' |
| 80 | + env: |
| 81 | + TRIVY_DB_REPOSITORY: public.ecr.aws/aquasecurity/trivy-db:2 |
| 82 | + TRIVY_JAVA_DB_REPOSITORY: public.ecr.aws/aquasecurity/trivy-java-db:1 |
| 83 | + |
| 84 | + - name: Trivy dependency scan (uv.lock, table) |
| 85 | + uses: aquasecurity/trivy-action@0.33.1 |
| 86 | + with: |
| 87 | + scan-type: fs |
| 88 | + scan-ref: uv.lock |
| 89 | + scanners: 'vuln' |
| 90 | + version: 'v0.69.0' |
| 91 | + ignore-unfixed: true |
| 92 | + format: 'table' |
| 93 | + output: 'trivy-deps.txt' |
| 94 | + severity: 'CRITICAL,HIGH' |
| 95 | + exit-code: '0' |
| 96 | + env: |
| 97 | + TRIVY_DB_REPOSITORY: public.ecr.aws/aquasecurity/trivy-db:2 |
| 98 | + |
| 99 | + - name: Show Trivy dependency table |
| 100 | + if: always() |
| 101 | + shell: bash |
| 102 | + run: | |
| 103 | + echo "Trivy dependency scan (table)"; |
| 104 | + if [ -f trivy-deps.txt ]; then |
| 105 | + cat trivy-deps.txt; |
| 106 | + else |
| 107 | + echo "No trivy-deps.txt output found."; |
| 108 | + fi |
| 109 | +
|
| 110 | + - name: Trivy dependency scan (uv.lock, SARIF) |
| 111 | + uses: aquasecurity/trivy-action@0.33.1 |
| 112 | + with: |
| 113 | + scan-type: fs |
| 114 | + scan-ref: uv.lock |
| 115 | + scanners: 'vuln' |
| 116 | + version: 'v0.69.0' |
| 117 | + ignore-unfixed: true |
| 118 | + format: 'sarif' |
| 119 | + output: 'trivy-deps.sarif' |
| 120 | + severity: 'CRITICAL,HIGH' |
| 121 | + exit-code: '0' |
| 122 | + env: |
| 123 | + TRIVY_DB_REPOSITORY: public.ecr.aws/aquasecurity/trivy-db:2 |
| 124 | + |
| 125 | + - name: Upload Trivy image results |
| 126 | + if: github.event.repository.security_and_analysis.advanced_security.status == 'enabled' |
| 127 | + uses: github/codeql-action/upload-sarif@v3 |
| 128 | + with: |
| 129 | + sarif_file: 'trivy-image.sarif' |
| 130 | + category: 'trivy-image' |
| 131 | + |
| 132 | + - name: Upload Trivy dependency results |
| 133 | + if: github.event.repository.security_and_analysis.advanced_security.status == 'enabled' |
| 134 | + uses: github/codeql-action/upload-sarif@v3 |
| 135 | + with: |
| 136 | + sarif_file: 'trivy-deps.sarif' |
| 137 | + category: 'trivy-deps' |
| 138 | + |
| 139 | + - name: Publish Trivy summary |
| 140 | + if: always() |
| 141 | + shell: bash |
| 142 | + run: | |
| 143 | + { |
| 144 | + echo "## Trivy Image Scan (pyatlan-trivy:latest)"; |
| 145 | + echo ""; |
| 146 | + if [ -f trivy-image.txt ]; then |
| 147 | + echo '```'; |
| 148 | + cat trivy-image.txt; |
| 149 | + echo '```'; |
| 150 | + else |
| 151 | + echo "No image scan output found."; |
| 152 | + fi |
| 153 | + echo ""; |
| 154 | + echo "## Trivy Dependency Scan (uv.lock)"; |
| 155 | + echo ""; |
| 156 | + if [ -f trivy-deps.txt ]; then |
| 157 | + echo '```'; |
| 158 | + cat trivy-deps.txt; |
| 159 | + echo '```'; |
| 160 | + else |
| 161 | + echo "No dependency scan output found."; |
| 162 | + fi |
| 163 | + } >> "$GITHUB_STEP_SUMMARY" |
| 164 | +
|
| 165 | + - name: Fail on High/Critical vulnerabilities (image) |
| 166 | + uses: aquasecurity/trivy-action@0.33.1 |
| 167 | + with: |
| 168 | + image-ref: pyatlan-trivy:latest |
| 169 | + scanners: 'vuln' |
| 170 | + version: 'v0.69.0' |
| 171 | + ignore-unfixed: true |
| 172 | + format: 'table' |
| 173 | + severity: 'CRITICAL,HIGH' |
| 174 | + exit-code: '1' |
| 175 | + env: |
| 176 | + TRIVY_DB_REPOSITORY: public.ecr.aws/aquasecurity/trivy-db:2 |
| 177 | + TRIVY_JAVA_DB_REPOSITORY: public.ecr.aws/aquasecurity/trivy-java-db:1 |
| 178 | + |
| 179 | + - name: Fail on High/Critical vulnerabilities (uv.lock) |
| 180 | + uses: aquasecurity/trivy-action@0.33.1 |
| 181 | + with: |
| 182 | + scan-type: fs |
| 183 | + scan-ref: uv.lock |
| 184 | + scanners: 'vuln' |
| 185 | + version: 'v0.69.0' |
| 186 | + ignore-unfixed: true |
| 187 | + format: 'table' |
| 188 | + severity: 'CRITICAL,HIGH' |
| 189 | + exit-code: '1' |
| 190 | + env: |
| 191 | + TRIVY_DB_REPOSITORY: public.ecr.aws/aquasecurity/trivy-db:2 |
0 commit comments