From ff7b7c15a754b3b4604a0edd44bf54ae95393b32 Mon Sep 17 00:00:00 2001 From: "containarium-ci[bot]" <287705844+containarium-ci[bot]@users.noreply.github.com> Date: Tue, 27 Oct 2026 01:12:29 +0000 Subject: [PATCH 1/3] feat(e2e): add Docker image and passive-only compose e2e (#10) Co-authored-by: hsinatfootprintai <149764663+hsinatfootprintai@users.noreply.github.com> --- .dockerignore | 9 +++ .gitignore | 2 + Dockerfile | 28 ++++++++ docker-compose.yml | 39 +++++++++++ test/e2e/run.sh | 71 +++++++++++++++++++++ test/fixtures/fixture-vendor.conf | 20 ++++++ test/fixtures/sites/index.html | 11 ++++ test/fixtures/sites/js/jquery-1.12.4.min.js | 2 + 8 files changed, 182 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100644 test/e2e/run.sh create mode 100644 test/fixtures/fixture-vendor.conf create mode 100644 test/fixtures/sites/index.html create mode 100644 test/fixtures/sites/js/jquery-1.12.4.min.js diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..726dd1e --- /dev/null +++ b/.dockerignore @@ -0,0 +1,9 @@ +.git +.github +node_modules +**/node_modules +web/.next +web/next-env.d.ts +web/out/* +!web/out/.gitkeep +test/e2e/out diff --git a/.gitignore b/.gitignore index ec484cd..14e39d0 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ web/.next/ web/next-env.d.ts web/out/* !web/out/.gitkeep +# e2e output (test/e2e/run.sh): reports, access log, compose logs +test/e2e/out/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..076bf62 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,28 @@ +# One image with two commands: `touchstone serve` (the page and POST /v1/scans) +# and `touchstone scan ` (the CLI). See docs/architecture/touchstone.md, +# "Deployment shape". + +# The page is embedded at build time (web/embed.go), so it is built first. +FROM node:20-alpine AS web +RUN apk add --no-cache make +WORKDIR /src +COPY Makefile ./ +COPY web ./web +RUN make web-build + +FROM golang:1.26 AS build +WORKDIR /src +COPY go.mod go.sum ./ +RUN go mod download +COPY . . +COPY --from=web /src/web/out/ ./web/out/ +RUN CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o /out/touchstone ./cmd/touchstone + +FROM gcr.io/distroless/static-debian12:nonroot +COPY --from=build /out/touchstone /touchstone +# serve listens on all interfaces inside the container; the default is loopback. +ENV TOUCHSTONE_ADDR=0.0.0.0:8080 +EXPOSE 8080 +USER nonroot:nonroot +ENTRYPOINT ["/touchstone"] +CMD ["serve"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..248b4ce --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,39 @@ +# Local dev and the passive-only e2e (test/e2e/run.sh). +# +# The vendor network uses the documentation range 198.51.100.0/24, which the +# SSRF guard (internal/fetch/passive.go, IsPrivate) does not refuse. So both +# `serve` and the CLI scan fixture-vendor with the guard fully on; no +# --allow-private is used anywhere in this stack. +services: + touchstone: + build: . + command: ["serve"] + ports: + - "127.0.0.1:8080:8080" + networks: + vendor: + depends_on: + fixture-vendor: + condition: service_healthy + + fixture-vendor: + image: nginx:1.27-alpine + volumes: + - ./test/fixtures/sites:/usr/share/nginx/html:ro + - ./test/fixtures/fixture-vendor.conf:/etc/nginx/conf.d/default.conf:ro + # The access log the e2e reads; see test/e2e/run.sh. + - ./test/e2e/out/access:/var/log/fixture + healthcheck: + test: ["CMD", "wget", "-q", "-O", "/dev/null", "http://127.0.0.1/healthz"] + interval: 2s + timeout: 2s + retries: 15 + networks: + vendor: + ipv4_address: 198.51.100.10 + +networks: + vendor: + ipam: + config: + - subnet: 198.51.100.0/24 diff --git a/test/e2e/run.sh b/test/e2e/run.sh new file mode 100644 index 0000000..1c17153 --- /dev/null +++ b/test/e2e/run.sh @@ -0,0 +1,71 @@ +#!/usr/bin/env bash +# Passive-only e2e for docker-compose.yml. It scans fixture-vendor through the +# CLI and through POST /v1/scans, then checks that the two reports agree and +# that the vendor's nginx access log matches the report's checked list. +# +# Usage: bash test/e2e/run.sh (needs docker compose, curl and jq) +set -euo pipefail + +cd "$(dirname "$0")/../.." + +OUT=test/e2e/out +TARGET=http://fixture-vendor/ +SERVE=http://127.0.0.1:8080 +ALLOWED='["TARGET","SUBRESOURCE","DISCOVERY_PATH","DECLARED"]' +# The two scans start and finish at different times; nothing else may differ. +STRIP='del(.startedAt, .completedAt, .vulnDataAsOf)' + +fail() { + echo "e2e: FAIL: $*" >&2 + exit 1 +} + +teardown() { + docker compose logs --no-color > "$OUT/compose.log" 2>&1 || true + docker compose down -v +} + +rm -rf "$OUT" +mkdir -p "$OUT/access" +trap teardown EXIT + +docker compose up -d --build --wait + +for _ in $(seq 60); do + curl -fsS -o /dev/null "$SERVE/" 2>/dev/null && break + sleep 1 +done +curl -fsS -o /dev/null "$SERVE/" || fail "touchstone serve did not answer on $SERVE" + +# Both scans go to fixture-vendor by its compose name; neither uses +# --allow-private, so the SSRF guard is on for both. +docker compose run --rm -T touchstone scan "$TARGET" > "$OUT/cli.json" +curl -fsS -X POST -H 'Content-Type: application/json' \ + -d "{\"url\": \"$TARGET\"}" "$SERVE/v1/scans" > "$OUT/http.json" + +jq -S "$STRIP" "$OUT/cli.json" > "$OUT/cli.norm.json" +jq -S "$STRIP" "$OUT/http.json" > "$OUT/http.norm.json" +diff -u "$OUT/cli.norm.json" "$OUT/http.norm.json" \ + || fail "CLI and POST /v1/scans reports differ (see diff above)" + +jq -e --argjson allowed "$ALLOWED" \ + '[.checked[] | select(.reason as $r | $allowed | contains([$r]) | not)] | length == 0' \ + "$OUT/cli.json" > /dev/null \ + || fail "checked list has a location with a reason outside $ALLOWED" + +# Passive-only proof. Refused requests never left touchstone, so they are +# left out of the checked side. The access log is combined format: field 2 is +# the request line. +LOG="$OUT/access/access.log" +[ -s "$LOG" ] || fail "no access log at $LOG" +awk -F'"' '{ split($2, r, " "); print r[1] }' "$LOG" | sort -u > "$OUT/methods.txt" +[ "$(cat "$OUT/methods.txt")" = "GET" ] \ + || fail "fixture-vendor saw methods other than GET: $(tr '\n' ' ' < "$OUT/methods.txt")" + +awk -F'"' '{ split($2, r, " "); print r[2] }' "$LOG" | sort -u > "$OUT/logged.txt" +jq -r '.checked[] | select(.result != "RESULT_REFUSED") | .url | sub("^https?://[^/]+"; "")' \ + "$OUT/cli.json" | sort -u > "$OUT/sent.txt" +diff -u "$OUT/sent.txt" "$OUT/logged.txt" \ + || fail "access log and checked list differ: '-' is checked but never requested, '+' is requested but not checked" + +echo "e2e: OK: $(wc -l < "$OUT/logged.txt") requested paths, all in the checked list; CLI and POST /v1/scans reports identical" diff --git a/test/fixtures/fixture-vendor.conf b/test/fixtures/fixture-vendor.conf new file mode 100644 index 0000000..aa3daaa --- /dev/null +++ b/test/fixtures/fixture-vendor.conf @@ -0,0 +1,20 @@ +# fixture-vendor: serves test/fixtures/sites and logs every request to the +# access log that test/e2e/run.sh checks against the report's checked list. +server { + listen 80; + root /usr/share/nginx/html; + + access_log /var/log/fixture/access.log combined; + + # Compose's health check. Not logged, so the passive-only check never + # sees it. + location = /healthz { + access_log off; + default_type text/plain; + return 200 "ok\n"; + } + + location / { + try_files $uri $uri/ =404; + } +} diff --git a/test/fixtures/sites/index.html b/test/fixtures/sites/index.html new file mode 100644 index 0000000..2f63a9c --- /dev/null +++ b/test/fixtures/sites/index.html @@ -0,0 +1,11 @@ + + + + +Fixture vendor + + +

Fixture vendor

+ + + diff --git a/test/fixtures/sites/js/jquery-1.12.4.min.js b/test/fixtures/sites/js/jquery-1.12.4.min.js new file mode 100644 index 0000000..cc92ce8 --- /dev/null +++ b/test/fixtures/sites/js/jquery-1.12.4.min.js @@ -0,0 +1,2 @@ +/*! jQuery v1.12.4 fixture stand-in | the scanner reads the version from the URL, not from this body */ +window.jQuery = window.$ = function () { return {}; }; From 628e1934ac9d88898a0f724c5f70b720a55eb9b7 Mon Sep 17 00:00:00 2001 From: hsinatfootprintai <149764663+hsinatfootprintai@users.noreply.github.com> Date: Tue, 27 Oct 2026 10:18:39 +0800 Subject: [PATCH 2/3] ci(e2e): add the workflow that runs test/e2e/run.sh (#10) The agent's result cannot carry .github paths, so it returned this workflow as a follow-up (follow-up 1 of 3 in the PR body). Added here unchanged: pull_request with a paths filter, push to main, and workflow_dispatch so it can be run on demand with `gh workflow run e2e.yml --ref `. It runs `bash test/e2e/run.sh` on ubuntu-latest with contents: read and uploads test/e2e/out as an artifact. Co-Authored-By: Claude Sonnet 5.5 --- .github/workflows/e2e.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 .github/workflows/e2e.yml diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml new file mode 100644 index 0000000..3d99295 --- /dev/null +++ b/.github/workflows/e2e.yml @@ -0,0 +1,20 @@ +name: e2e +on: + pull_request: + paths: [Dockerfile, docker-compose.yml, .dockerignore, test/**, cmd/**, internal/**, web/**, proto/**, .github/workflows/e2e.yml] + push: + branches: [main] + workflow_dispatch: +permissions: + contents: read +jobs: + e2e: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - run: bash test/e2e/run.sh + - if: always() + uses: actions/upload-artifact@v4 + with: + name: e2e-out + path: test/e2e/out From 134747e06272308441be59a5150911f45e23d150 Mon Sep 17 00:00:00 2001 From: hsinatfootprintai <149764663+hsinatfootprintai@users.noreply.github.com> Date: Tue, 27 Oct 2026 11:44:38 +0800 Subject: [PATCH 3/3] ci(e2e): run on every pull request so it can be a required check (#10) A required status check that a paths filter skips leaves a pull request waiting for a check that never starts. The e2e takes about 75 seconds, so it runs on every pull request, plus push to main and workflow_dispatch. Co-Authored-By: Claude Sonnet 5.5 --- .github/workflows/e2e.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 3d99295..b10314e 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -1,7 +1,6 @@ name: e2e on: pull_request: - paths: [Dockerfile, docker-compose.yml, .dockerignore, test/**, cmd/**, internal/**, web/**, proto/**, .github/workflows/e2e.yml] push: branches: [main] workflow_dispatch: