|
55 | 55 |
|
56 | 56 | - name: Install AppArmor tooling |
57 | 57 | run: | |
| 58 | + sudo rm -f /etc/apt/sources.list.d/microsoft-prod.list /etc/apt/sources.list.d/azure-cli.list || true |
58 | 59 | sudo apt-get update |
59 | 60 | sudo apt-get install -y apparmor-utils |
60 | 61 |
|
@@ -140,60 +141,47 @@ jobs: |
140 | 141 | set -e |
141 | 142 |
|
142 | 143 | - name: Attest vulnerability scan metadata |
| 144 | + env: |
| 145 | + TARGET: ${{ matrix.target }} |
| 146 | + TRIVY_EXIT: ${{ steps.trivy.outputs.trivy_exit }} |
| 147 | + GRYPE_EXIT: ${{ steps.grype.outputs.grype_exit }} |
143 | 148 | run: | |
144 | 149 | TRIVY_VERSION="$(trivy --version | head -n 1 | sed 's/^Version: //')" |
145 | 150 | GRYPE_VERSION="$(grype version | head -n 1 | sed 's/^Version: //')" |
146 | | - TARGET="${{ matrix.target }}" |
147 | | - TRIVY_EXIT="${{ steps.trivy.outputs.trivy_exit }}" |
148 | | - GRYPE_EXIT="${{ steps.grype.outputs.grype_exit }}" |
149 | | - IMAGE_REF="${REGISTRY}:${{ matrix.target }}" |
150 | | - python3 <<'PY' |
151 | | -import json |
152 | | -import os |
| 151 | + IMAGE_REF="${REGISTRY}:${TARGET}" |
| 152 | + export TRIVY_VERSION GRYPE_VERSION |
| 153 | + python3 - <<'EOF' |
| 154 | +import json, os |
153 | 155 | from datetime import datetime, timezone |
154 | | - |
155 | 156 | target = os.environ["TARGET"] |
156 | 157 | trivy_path = f"attestations/trivy-{target}.json" |
157 | 158 | grype_path = f"attestations/grype-{target}.json" |
158 | | - |
159 | 159 | def count_trivy(data): |
160 | 160 | counts = {} |
161 | 161 | for result in data.get("Results", []): |
162 | 162 | for vuln in result.get("Vulnerabilities") or []: |
163 | 163 | sev = vuln.get("Severity", "UNKNOWN") |
164 | 164 | counts[sev] = counts.get(sev, 0) + 1 |
165 | 165 | return counts |
166 | | - |
167 | 166 | def count_grype(data): |
168 | 167 | counts = {} |
169 | 168 | for match in data.get("matches", []): |
170 | 169 | sev = match.get("vulnerability", {}).get("severity", "Unknown") |
171 | 170 | counts[sev] = counts.get(sev, 0) + 1 |
172 | 171 | return counts |
173 | | - |
174 | 172 | with open(trivy_path, "r", encoding="utf-8") as fh: |
175 | 173 | trivy_data = json.load(fh) |
176 | 174 | with open(grype_path, "r", encoding="utf-8") as fh: |
177 | 175 | grype_data = json.load(fh) |
178 | | - |
179 | 176 | payload = { |
180 | 177 | "target": target, |
181 | 178 | "generated_at": datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ"), |
182 | | - "trivy": { |
183 | | - "version": os.environ["TRIVY_VERSION"], |
184 | | - "exit_code": int(os.environ["TRIVY_EXIT"]), |
185 | | - "counts": count_trivy(trivy_data), |
186 | | - }, |
187 | | - "grype": { |
188 | | - "version": os.environ["GRYPE_VERSION"], |
189 | | - "exit_code": int(os.environ["GRYPE_EXIT"]), |
190 | | - "counts": count_grype(grype_data), |
191 | | - }, |
| 179 | + "trivy": {"version": os.environ["TRIVY_VERSION"], "exit_code": int(os.environ["TRIVY_EXIT"]), "counts": count_trivy(trivy_data)}, |
| 180 | + "grype": {"version": os.environ["GRYPE_VERSION"], "exit_code": int(os.environ["GRYPE_EXIT"]), "counts": count_grype(grype_data)}, |
192 | 181 | } |
193 | | - |
194 | 182 | with open(f"attestations/scan-{target}.json", "w", encoding="utf-8") as fh: |
195 | 183 | json.dump(payload, fh, indent=2) |
196 | | -PY |
| 184 | +EOF |
197 | 185 | cosign attest --yes \ |
198 | 186 | --predicate attestations/scan-${{ matrix.target }}.json \ |
199 | 187 | --type https://artagon.dev/attestations/vulnerability-scan/v1 \ |
|
0 commit comments