diff --git a/docker-compose.yml b/docker-compose.yml index e5381ae5..d593c668 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -19,7 +19,14 @@ services: TASK_BASE_DIGEST: ${TASK_BASE_DIGEST:-sha256:0f374138fcb49fef41609d323cc80b6c2324b1e798d3a2aee5c8038b8c7ac3aa} image: openultrasast:${OUSAST_VERSION:-dev} volumes: - - ${TARGET:-.}:/target:ro # the repository under analysis, read-only + # The repository under analysis, read-only. In the long syntax, like /reports below: in the short syntax Docker + # creates a TARGET that does not exist, as an empty directory, and an empty target scans clean. + - type: bind + source: ${TARGET:-.} + target: /target + read_only: true + bind: + create_host_path: false # Where findings land, the one writable mount. Long syntax on purpose: the short syntax lets Docker create a # missing source, as root, and the image runs as uid 1000. Create the directory first; the wrapper does. - type: bind diff --git a/tests/test_task_images.py b/tests/test_task_images.py index 539c47dc..ccc48921 100644 --- a/tests/test_task_images.py +++ b/tests/test_task_images.py @@ -67,6 +67,16 @@ def test_compose_leaves_the_reports_directory_to_the_user(): assert mounts["/reports"].get("bind", {}).get("create_host_path") is False +def test_compose_refuses_a_target_that_does_not_exist(): + """Docker creates a missing bind source as an empty directory, and an empty target scans clean: a typo reads as clean.""" + service = yaml.safe_load(read("docker-compose.yml"))["services"]["ousast"] + mounts = {v["target"]: v for v in service["volumes"] if isinstance(v, dict)} + assert "/target" in mounts, "the /target volume is short syntax, so Docker creates a missing source as an empty directory" + assert mounts["/target"]["source"] == "${TARGET:-.}" + assert mounts["/target"]["read_only"] is True + assert mounts["/target"].get("bind", {}).get("create_host_path") is False + + def test_shared_ancestry_and_replay_exact_engine(): base = read("plane/Dockerfile.base") assert "FROM ghcr.io/norandom/ax-task-runner:v0.3.1 AS base" in base