Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .clusterfuzzlite/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM gcr.io/oss-fuzz-base/base-builder-python@sha256:21f6fab17ace4dc76e1c56de91ee95d3d03da021df94b41056ba036f6c6f55e9

COPY .clusterfuzzlite/requirements.txt /src/loom-fuzz-requirements.txt
RUN python3 -m pip install --no-cache-dir --only-binary=:all: --require-hashes --no-deps -r /src/loom-fuzz-requirements.txt

COPY server/__init__.py /src/loom/server/__init__.py
COPY server/core/__init__.py server/core/embedding_space.py /src/loom/server/core/
COPY tests/__init__.py /src/loom/tests/__init__.py
COPY tests/fuzz/ /src/loom/tests/fuzz/
COPY .clusterfuzzlite/build.sh /src/build.sh
WORKDIR /src/loom
18 changes: 18 additions & 0 deletions .clusterfuzzlite/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
set -euo pipefail

# Only this unmodified standard-library module and the maintained oracle are packaged.
python3 -m tests.fuzz.embedding_identity_fuzzer --replay tests/fuzz/corpus/embedding_identity
pyinstaller --distpath "$OUT" --onefile --paths /src/loom \
--hidden-import server.core.embedding_space \
--hidden-import tests.fuzz.embedding_identity_oracle \
--name embedding_identity.pkg tests/fuzz/embedding_identity_fuzzer.py
cat >"$OUT/embedding_identity" <<'WRAPPER'
#!/bin/sh
# LLVMFuzzerTestOneInput
this_dir=$(dirname "$0")
exec "$this_dir/embedding_identity.pkg" "$@"
WRAPPER
chmod +x "$OUT/embedding_identity"
zip -j "$OUT/embedding_identity_seed_corpus.zip" tests/fuzz/corpus/embedding_identity/*
printf '[libfuzzer]\nmax_len = 4096\ntimeout = 5\nrss_limit_mb = 512\n' >"$OUT/embedding_identity.options"
1 change: 1 addition & 0 deletions .clusterfuzzlite/project.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
language: python
2 changes: 2 additions & 0 deletions .clusterfuzzlite/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
atheris==3.0.0 \
--hash=sha256:8a5c8a781467c187da40fd29139784193e2647058831f837f675d0bb8cbd8746
244 changes: 244 additions & 0 deletions .github/workflows/identity-testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,244 @@
name: endpoint identity probes

on:
pull_request:
branches: [main, "release/**"]
paths:
- server/core/embedding_space.py
- tests/fuzz/**
- tests/mutation/**
- .clusterfuzzlite/**
- .github/workflows/identity-testing.yml
push:
branches: [main]
paths:
- server/core/embedding_space.py
- tests/fuzz/**
- tests/mutation/**
- .clusterfuzzlite/**
- .github/workflows/identity-testing.yml
schedule:
- cron: "17 4 * * 3"
workflow_dispatch:

permissions:
contents: read

defaults:
run:
shell: bash

concurrency:
group: endpoint-identity-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
replay_and_mutation:
name: Endpoint identity corpus and mutation pilot
runs-on: ubuntu-24.04
timeout-minutes: 8
outputs:
review_count: ${{ steps.mutation.outputs.review_count }}
steps:
- name: Check out the maintained target and its probes
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
sparse-checkout-cone-mode: false
sparse-checkout: |
/server/__init__.py
/server/core/__init__.py
/server/core/embedding_space.py
/tests/__init__.py
/tests/fuzz/
/tests/mutation/
/.github/workflows/identity-testing.yml
- name: Install the selected Python
uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
with:
python-version: "3.12"
- name: Create a disposable test environment
run: |
python3 -m venv "$RUNNER_TEMP/identity-venv"
"$RUNNER_TEMP/identity-venv/bin/python" -m pip install --require-hashes --only-binary=:all: -r tests/mutation/requirements.txt
- name: Replay the corpus and deterministic public-identity cases
run: |
"$RUNNER_TEMP/identity-venv/bin/python" -m tests.fuzz.embedding_identity_fuzzer --replay tests/fuzz/corpus/embedding_identity
"$RUNNER_TEMP/identity-venv/bin/python" -m unittest tests.mutation.test_embedding_identity tests.mutation.test_equivalence tests.fuzz.test_probe_publisher
- name: Mutate only the public-identity function
id: mutation
env:
IDENTITY_MUTATION_REPORT: ${{ runner.temp }}/identity-mutation.json
run: '"$RUNNER_TEMP/identity-venv/bin/python" tests/mutation/run_identity.py'

coverage_guided:
name: Endpoint identity coverage-guided fuzzing
runs-on: ubuntu-24.04
timeout-minutes: 15
steps:
- name: Check out only the parser and fuzz build inputs
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
sparse-checkout-cone-mode: false
sparse-checkout: |
/server/__init__.py
/server/core/__init__.py
/server/core/embedding_space.py
/tests/__init__.py
/tests/fuzz/
/.clusterfuzzlite/
- name: Build the one parser fuzzer
id: build
uses: docker://gcr.io/oss-fuzz-base/clusterfuzzlite-build-fuzzers@sha256:c531ed554dbd3ed24e2bd11570a0e2dfb042146806236cdfd2d7d0d648b6c473
env:
LANGUAGE: python
SANITIZER: address
PROJECT_SRC_PATH: /github/workspace
KEEP_UNAFFECTED_FUZZ_TARGETS: "true"
UPLOAD_BUILD: "false"
BAD_BUILD_CHECK: "true"
ALLOWED_BROKEN_TARGETS_PERCENTAGE: "0"
DRY_RUN: "false"
CFL_PLATFORM: standalone
WORKSPACE: /github/workspace
FILESTORE: no_filestore
FILESTORE_ROOT_DIR: /github/workspace/out/ephemeral
NO_CLUSTERFUZZ_DEPLOYMENT: "true"
REPOSITORY: loom
LOW_DISK_SPACE: "True"
- name: Require the one built target
run: |
test -x build-out/embedding_identity
test -s build-out/embedding_identity.pkg
- name: Fuzz the parser within the selected time budget
id: fuzz
uses: docker://gcr.io/oss-fuzz-base/clusterfuzzlite-run-fuzzers@sha256:ec2a38a69babe087df3025a6babcb2a5a3675811a5cf4bfba23cece85c10e8d1
env:
LANGUAGE: python
SANITIZER: address
FUZZ_SECONDS: ${{ github.event_name == 'pull_request' && 30 || 180 }}
MODE: batch
PARALLEL_FUZZING: "false"
OUTPUT_SARIF: "true"
REPORT_TIMEOUTS: "true"
REPORT_OOMS: "true"
REPORT_UNREPRODUCIBLE_CRASHES: "false"
MINIMIZE_CRASHES: "false"
DRY_RUN: "false"
CFL_PLATFORM: standalone
WORKSPACE: /github/workspace
FILESTORE: no_filestore
FILESTORE_ROOT_DIR: /github/workspace/out/ephemeral
NO_CLUSTERFUZZ_DEPLOYMENT: "true"
REPOSITORY: loom
LOW_DISK_SPACE: "True"
- name: Report the bounded native probe outcome
if: always()
env:
BUILD_OUTCOME: ${{ steps.build.outcome }}
FUZZ_OUTCOME: ${{ steps.fuzz.outcome }}
run: |
python3 - <<'PY'
import os
allowed = {"success", "failure", "cancelled", "skipped"}
build, fuzz = os.environ["BUILD_OUTCOME"], os.environ["FUZZ_OUTCOME"]
assert build in allowed and fuzz in allowed
text = f"Endpoint identity target: build={build}, bounded fuzzing={fuzz}. Inspect the native log for executed inputs and replay records."
print("::notice title=Endpoint identity probe::" + text)
with open(os.environ["GITHUB_STEP_SUMMARY"], "a") as output:
output.write(text + "\n")
PY

maintenance:
name: Record trusted probe maintenance
needs: [replay_and_mutation, coverage_guided]
if: >-
always() && github.repository == 'ClickHouse/loom' &&
github.ref == 'refs/heads/main' &&
(github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch')
runs-on: ubuntu-24.04
timeout-minutes: 5
permissions:
contents: read
issues: write # Record bounded probe maintenance on trusted main runs only.
steps:
- name: Reconcile failure tasks without executing project code
env:
GH_TOKEN: ${{ github.token }}
PROBE_RESULTS: ${{ toJSON(needs) }}
run: |
python3 - <<'PY'
import json, os, re, subprocess
from urllib.parse import urlencode
repo = "repos/ClickHouse/loom/issues"
bot = "github-actions[bot]"
marker = re.compile(r"<!-- loom-endpoint-probe:v1 (replay_and_mutation|coverage_guided) -->")
state = re.compile(r"<!-- loom-endpoint-probe-state:v1 (failure|success|review) -->")
titles = {"replay_and_mutation": "[endpoint-identity-ci] Review the bounded mutation pilot", "coverage_guided": "[endpoint-identity-ci] Diagnose the bounded fuzzer check"}
calls = 0
def api(method, endpoint, payload=None):
global calls
calls += 1
assert calls <= 40, "Probe issue API budget exhausted"
command = ["gh", "api", "--method", method, endpoint, "--hostname", "github.com"]
if payload is not None:
command += ["--input", "-"]
result = subprocess.run(command, input=None if payload is None else json.dumps(payload), text=True, capture_output=True, timeout=20, check=True)
assert len(result.stdout) <= 2 * 1024 * 1024, "Probe issue response exceeds budget"
return json.loads(result.stdout)
managed = {}
for page in range(1, 11):
issues = api("GET", repo + "?" + urlencode({"state": "all", "creator": bot, "per_page": 100, "page": page}))
assert isinstance(issues, list)
for issue in issues:
if "pull_request" in issue or issue.get("user", {}).get("login") != bot:
continue
keys = marker.findall(issue.get("body") or "")
keys += [key for key, title in titles.items() if issue.get("title") == title]
keys = set(keys)
assert len(keys) <= 1, "Conflicting Probe issue markers"
if keys:
key = keys.pop()
assert key not in managed, "Duplicate Probe maintenance task"
managed[key] = issue
if len(issues) < 100:
break
else:
raise RuntimeError("Probe issue pagination budget exhausted")
results = json.loads(os.environ["PROBE_RESULTS"])
assert set(results) == set(titles)
run_id = os.environ["GITHUB_RUN_ID"]
assert run_id.isdecimal()
url = "https://github.com/ClickHouse/loom/actions/runs/" + run_id
changed = 0
for key in titles:
result = results[key]["result"]
if key == "replay_and_mutation" and result == "success":
count = results[key]["outputs"]["review_count"]
assert count.isdecimal() and 0 <= int(count) <= 10000
if int(count):
result = "review"
assert result in {"success", "failure", "review", "cancelled", "skipped"}
issue = managed.get(key)
if result not in {"success", "failure", "review"} or (issue and issue["state"] == "closed"):
continue
text = f"<!-- loom-endpoint-probe:v1 {key} -->\n<!-- loom-endpoint-probe-state:v1 {result} -->\n\n### Company or project name\n\nClickHouse\n\nThe bounded {key} probe reports **{result}** on trusted main. [Read the bounded probe logs and mutation summary]({url}).\n\nReproduce the named workflow job. A mutation survivor needs review for a missing assertion or equivalent mutation; it is not a vulnerability claim. No crash input or source excerpt is published here. Keep security-sensitive reports in the private route in SECURITY.md. Automation preserves edited bodies and closed decisions."
if issue is None:
if result in {"failure", "review"}:
api("POST", repo, {"title": titles[key], "body": text})
changed += 1
continue
number = issue["number"]
assert isinstance(number, int) and number > 0
comments = api("GET", f"{repo}/{number}/comments?per_page=100")
assert isinstance(comments, list) and len(comments) < 100, "Probe comment history budget exhausted"
candidates = [issue] + sorted(comments, key=lambda row: (row["created_at"], row["id"]))
states = [state.findall(row.get("body") or "") for row in candidates if row.get("user", {}).get("login") == bot]
states = [value[-1] for value in states if value]
if not states or states[-1] != result:
api("POST", f"{repo}/{number}/comments", {"body": text})
changed += 1
with open(os.environ["GITHUB_STEP_SUMMARY"], "a") as output:
output.write(f"Probe task reconciliation: {changed} task or status writes; closed decisions preserved.\n")
PY
49 changes: 49 additions & 0 deletions tests/fuzz/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Endpoint identity probes

The target is `server/core/embedding_space.py` (`public_identity`). It converts an
external endpoint configuration into the public identity used by deployment checks
and calibration. The probes check URL userinfo, allowed query names, fragments,
case normalization, preserved endpoint differences and unchanged non-URL identity
fields. This is a URL-identity boundary, not a general secret scrubber, network
allowlist or proof of API authorization.

Replay the checked-in synthetic corpus without installing a fuzzing engine:

```bash
python3 -m tests.fuzz.embedding_identity_fuzzer --replay tests/fuzz/corpus/embedding_identity
python3 -m unittest tests.mutation.test_embedding_identity
python3 tests/fuzz/test_probe_publisher.py
```

Inputs are at most 4096 bytes. Malformed raw URLs may raise the parser's documented
validation error; unexpected exceptions and accepted identities that break the
public contract fail. Every input also exercises a structured accepted URL with
synthetic credentials. This keeps malformed input from starving the useful branch.
Never add real credentials, deployment data or a third-party target to this corpus.

The hosted workflow replays the corpus and runs the fixed cases. Its coverage-guided
job uses the Python engine through the continuous-fuzzing runner, one target, one
worker and explicit time, input, memory and per-input limits. The image, engine and
executor references are pinned; engine selection matches the image's Python ABI.
Crashes fail the job and leave the runner's replay record in the job log. The supported
standalone/no-filestore mode makes no artifact, corpus, build or cloud upload.
Stateless batch runs start from the checked-in seeds without a differential-build
claim or persistent corpus that needs pruning. Review any real
security finding through the private route in [SECURITY.md](../../SECURITY.md),
without pasting inputs into public issues. The build packages only the named
standard-library module and these probes; no Loom service or provider is started.

The mutation pilot stages an unchanged copy of the same module and tests. It selects
only `public_identity` mutants, uses two workers with a two-minute process budget,
and kills its own process group on completion or failure. Empty test or mutation
results fail. Reported survivors need inspection: add an independent assertion for a
meaningful behavior difference, or record why the mutant is equivalent. The report
is not a whole-module score, a security result or permission to suppress a case.

A trusted-main publisher automatically creates a maintenance task for a broken
probe or a mutation result needing review. It posts static status and a log link,
without raw source or crash input, and appends a comment only when status changes.
It preserves edited bodies and closed decisions; keep an identity marker in the
title or body. API, history and pagination limits fail explicitly. Pull requests
retain read-only tokens. Standard public runners are used without a provider,
account, storage repository, new token or paid service.
1 change: 1 addition & 0 deletions tests/fuzz/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Bounded parser probes shared by replay and coverage-guided runs."""
1 change: 1 addition & 0 deletions tests/fuzz/corpus/embedding_identity/credentials
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://person:synthetic@example.invalid/v1?api-version=v1&token=synthetic#fragment
1 change: 1 addition & 0 deletions tests/fuzz/corpus/embedding_identity/duplicate-query
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
HTTPS://EXAMPLE.INVALID/v1/?MODEL=a&model=b&api_version=v
Empty file.
1 change: 1 addition & 0 deletions tests/fuzz/corpus/embedding_identity/ipv6
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://user:synthetic@[2001:db8::1]:443/v1/
1 change: 1 addition & 0 deletions tests/fuzz/corpus/embedding_identity/malformed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://[invalid/
1 change: 1 addition & 0 deletions tests/fuzz/corpus/embedding_identity/multiple-userinfo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://first:synthetic@alias@example.invalid/v1/?model=m
1 change: 1 addition & 0 deletions tests/fuzz/corpus/embedding_identity/unicode
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://example.invalid/é?token=ÿ
1 change: 1 addition & 0 deletions tests/fuzz/corpus/embedding_identity/uppercase-path
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://example.invalid/pathX///?model=m
31 changes: 31 additions & 0 deletions tests/fuzz/embedding_identity_fuzzer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""One maintained endpoint-identity target with deterministic corpus replay."""

from __future__ import annotations

import sys
from pathlib import Path


def main() -> None:
if len(sys.argv) == 3 and sys.argv[1] == "--replay":
from tests.fuzz.embedding_identity_oracle import check_input

paths = sorted(Path(sys.argv[2]).iterdir())
if not paths or not all(path.is_file() for path in paths):
raise ValueError("Replay requires a nonempty directory of seed files")
for path in paths:
check_input(path.read_bytes())
print(f"Replayed {len(paths)} endpoint-identity seeds")
return

import atheris

with atheris.instrument_imports():
from tests.fuzz.embedding_identity_oracle import check_input

atheris.Setup(sys.argv, check_input)
atheris.Fuzz()


if __name__ == "__main__":
main()
Loading
Loading