Skip to content

Commit

Permalink
Scan images using trivy
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkmueller committed Oct 24, 2023
1 parent 4a02d0a commit 9adb95f
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from pytest_container import get_extra_run_args
from pytest_container import MultiStageBuild
from pytest_container.container import ContainerData
from pytest_container.runtime import LOCALHOST

from bci_tester.data import ALL_CONTAINERS
from bci_tester.data import BUSYBOX_CONTAINER
Expand All @@ -23,6 +24,7 @@
from bci_tester.data import PCP_CONTAINER
from bci_tester.data import POSTGRESQL_CONTAINERS
from bci_tester.data import TARGET
from bci_tester.runtime_choice import DOCKER_SELECTED

CONTAINER_IMAGES = ALL_CONTAINERS

Expand Down Expand Up @@ -261,6 +263,33 @@ def test_zypper_verify_passes(container_per_test: ContainerData) -> None:
)


@pytest.mark.skipif(
DOCKER_SELECTED, reason="Trivy-Scan images only with podman"
)
@pytest.mark.skipif(
LOCALHOST.system_info.arch not in ("x86_64",),
reason=f"{LOCALHOST.system_info.arch} is not supported to run trivy",
)
def test_trivy_image_scan(host, auto_container: ContainerData) -> None:
"""Check that trivy image is able to scan the container."""

trivy_container = "docker.io/aquasec/trivy:latest"
baseurl = auto_container.container.baseurl
if not baseurl:
pytest.skip(
reason=f"container {auto_container.container} has no baseurl"
)

host.run_expect(
[0],
(
f"podman run -v trivy:/root {trivy_container} image {baseurl} "
"--exit-code 1 --exit-on-eol 2 -f template "
"--template '@contrib/sarif.tpl'"
),
)


@pytest.mark.parametrize(
"container",
[
Expand Down

0 comments on commit 9adb95f

Please sign in to comment.