Skip to content

Commit 8d09f90

Browse files
committed
fix: convert cyclonedx XML to JSON if needed
1 parent e8555d7 commit 8d09f90

3 files changed

Lines changed: 30 additions & 4 deletions

File tree

.github/workflows/scan.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ jobs:
2424
uses: abatilo/actions-poetry@3765cf608f2d4a72178a9fc5b918668e542b89b1 # v4.0.0
2525
with:
2626
poetry-version: 1.7.1
27+
- name: Install CycloneDX CLI
28+
run: |
29+
curl -sSfL https://github.com/CycloneDX/cyclonedx-cli/releases/download/v0.30.0/cyclonedx-linux-x64 -o /usr/local/bin/cyclonedx
30+
chmod +x /usr/local/bin/cyclonedx
2731
- name: Install deps
2832
run: poetry install
2933
- name: Scan dev images

.github/workflows/scan_release.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ jobs:
2727
uses: abatilo/actions-poetry@3765cf608f2d4a72178a9fc5b918668e542b89b1 # v4.0.0
2828
with:
2929
poetry-version: 1.7.1
30+
- name: Install CycloneDX CLI
31+
run: |
32+
curl -sSfL https://github.com/CycloneDX/cyclonedx-cli/releases/download/v0.30.0/cyclonedx-linux-x64 -o /usr/local/bin/cyclonedx
33+
chmod +x /usr/local/bin/cyclonedx
3034
- name: Install deps
3135
run: poetry install
3236
- name: Scan release

stack_scanner/main.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,20 +185,38 @@ def scan_stackablectl(secobserve_api_token: str) -> None:
185185
f"https://github.com/stackabletech/stackable-cockpit/releases/download"
186186
f"/{version}/{sbom_name}"
187187
)
188-
sbom_path = f"/tmp/stackable/{sbom_name}"
188+
xml_path = f"/tmp/stackable/{sbom_name}"
189189

190190
request = urllib.request.Request(download_url)
191191
request.add_header("User-Agent", "stack-scanner")
192192
try:
193193
with urllib.request.urlopen(request) as response:
194-
with open(sbom_path, "wb") as f:
194+
with open(xml_path, "wb") as f:
195195
f.write(response.read())
196-
print(f"Downloaded SBOM to {sbom_path}")
196+
print(f"Downloaded SBOM to {xml_path}")
197197
except urllib.error.URLError as error:
198198
print(f"Failed to download SBOM {sbom_name}: {error}")
199199
continue
200200

201-
scan_sbom(secobserve_api_token, sbom_name, "stackablectl", version)
201+
# Trivy does not support CycloneDX XML, so convert to JSON first.
202+
json_name = sbom_name.replace(".cdx.xml", ".cdx.json")
203+
json_path = f"/tmp/stackable/{json_name}"
204+
result = subprocess.run(
205+
[
206+
"cyclonedx", "convert",
207+
"--input-file", xml_path,
208+
"--input-format", "xml",
209+
"--output-file", json_path,
210+
"--output-format", "json",
211+
"--output-version", "v1_5",
212+
],
213+
)
214+
if result.returncode != 0:
215+
print(f"Failed to convert {sbom_name} from XML to JSON")
216+
continue
217+
print(f"Converted {xml_path} to {json_path}")
218+
219+
scan_sbom(secobserve_api_token, json_name, "stackablectl", version)
202220

203221

204222
def _build_base_env(secobserve_api_token: str, product_name: str, branch_name: str) -> dict:

0 commit comments

Comments
 (0)