20 lines
1.1 KiB
Python
20 lines
1.1 KiB
Python
#!/usr/bin/env python3
|
|
"""Scan a local image archive without mounting the Docker socket into a scanner."""
|
|
import os
|
|
from pathlib import Path
|
|
import subprocess
|
|
import tempfile
|
|
|
|
ROOT=Path(__file__).resolve().parents[1]
|
|
with tempfile.TemporaryDirectory(prefix='lab7-image-scan-') as directory:
|
|
archive=Path(directory)/'image.tar'
|
|
cache=Path(directory)/'cache';cache.mkdir()
|
|
temporary=Path(directory)/'tmp';temporary.mkdir()
|
|
subprocess.run(['docker','save','--output',str(archive),'mtusi-lab7-api:lab7'],check=True)
|
|
subprocess.run(['docker','run','--rm','--user',str(os.getuid())+':'+str(os.getgid()),'--read-only',
|
|
'--cap-drop','ALL','--security-opt','no-new-privileges','--memory','1g','--cpus','1','-v',str(temporary)+':/tmp',
|
|
'-v',str(cache)+':/cache',
|
|
'-v',str(archive)+':/image.tar:ro','-v',str(ROOT/'evidence')+':/out','aquasec/trivy:0.62.1',
|
|
'--quiet','image','--parallel','1','--input','/image.tar','--cache-dir','/cache','--skip-java-db-update','--scanners','vuln',
|
|
'--format','json','--output','/out/image-scan.json'],check=True)
|