Skip to content

Commit 0ccc2bb

Browse files
authored
Merge pull request #6 from stackabletech/feat/upload_sbom
feat: upload SBOM for SBOM scans
2 parents 80b0b3c + 7c3fb7e commit 0ccc2bb

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

stack_scanner/main.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ def _build_base_env(secobserve_api_token: str, product_name: str, branch_name: s
264264
_GRYPE_REPORT = "grype.json"
265265

266266

267-
def _combined_scan_script(mode: str) -> str:
267+
def _combined_scan_script(env: dict, mode: str) -> str:
268268
"""Return a shell script that scans with Trivy and Grype, then uploads results.
269269
270270
Trivy and Grype scan the same target independently, so they are launched
@@ -279,8 +279,11 @@ def _combined_scan_script(mode: str) -> str:
279279
280280
The existing per-scanner entrypoints are reused (with ``SO_UPLOAD=false`` so
281281
they only scan) to avoid duplicating the scanner invocation flags here.
282+
283+
In ``sbom`` mode the target itself is a CycloneDX SBOM, so it is additionally
284+
uploaded to SecObserve. In ``image`` mode there is no SBOM file to upload.
282285
"""
283-
return (
286+
script = (
284287
"export TRIVY_NO_PROGRESS=true\n"
285288
f"SO_UPLOAD=false REPORT_NAME={_TRIVY_REPORT} /entrypoints/entrypoint_trivy_{mode}.sh &\n"
286289
"trivy_pid=$!\n"
@@ -293,6 +296,9 @@ def _combined_scan_script(mode: str) -> str:
293296
f"if [ -f {_GRYPE_REPORT} ]; then SO_FILE_NAME={_GRYPE_REPORT} SO_PARSER_NAME=CycloneDX "
294297
'file_upload_observations.sh; else echo "WARNING: no Grype report to upload"; fi\n'
295298
)
299+
if mode == "sbom":
300+
script += f"SO_FILE_NAME={env.get('TARGET')} file_upload_sbom.sh\n"
301+
return script
296302

297303

298304
def _run_combined_scan(env: dict, mode: str) -> None:
@@ -306,7 +312,7 @@ def _run_combined_scan(env: dict, mode: str) -> None:
306312
for key, value in env.items():
307313
cmd.extend(["-e", f"{key}={value}"])
308314
cmd.append(SECOBSERVE_SCANNER_IMAGE)
309-
cmd.extend(["-c", _combined_scan_script(mode)])
315+
cmd.extend(["-c", _combined_scan_script(env, mode)])
310316

311317
print(f"docker run (combined trivy+grype, {mode} mode) TARGET={env.get('TARGET')}")
312318
subprocess.run(cmd)

0 commit comments

Comments
 (0)