reubenbowlby commited on
Commit
61b0f63
·
verified ·
1 Parent(s): cb8c82f

Revert F4 runtime-fetch back to build-time fetch (P3 supply-chain hardening)

Browse files
Files changed (3) hide show
  1. Dockerfile +16 -4
  2. app.py +0 -22
  3. requirements.txt +0 -1
Dockerfile CHANGED
@@ -5,16 +5,28 @@ WORKDIR /app
5
  # Copy space app files
6
  COPY . /app
7
 
8
- # Install dependencies (huggingface-hub is in requirements.txt for runtime dataset fetch)
9
  RUN pip install --no-cache-dir -r requirements.txt
10
 
11
- # Set environment
12
  ENV HF_HUB_DOWNLOAD_TIMEOUT=120
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  ENV BENCH_ROOT=/bench
14
  ENV PYTHONPATH=/bench/scripts:/app
15
 
16
- # Dataset is fetched at runtime (app startup), not build time,
17
- # so dataset updates surface without a space rebuild (F4 refactor).
18
  EXPOSE 7860
19
 
20
  CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
 
5
  # Copy space app files
6
  COPY . /app
7
 
8
+ # Install dependencies
9
  RUN pip install --no-cache-dir -r requirements.txt
10
 
11
+ # Set environment for dataset download
12
  ENV HF_HUB_DOWNLOAD_TIMEOUT=120
13
+
14
+ # Fetch benchmark tasks from Hugging Face dataset at BUILD time (immutable in image).
15
+ # Reverted from runtime fetch (F4) back to build-time fetch per peer review C3/C5:
16
+ # runtime fetch from a public admin-writable dataset introduced a supply-chain attack
17
+ # surface (poisoned verify.py auto-propagating into the Space). Build-time fetch bakes
18
+ # the dataset into the immutable Docker image — dataset updates require a deliberate
19
+ # rebuild, which acts as a safety check.
20
+ RUN pip install --no-cache-dir huggingface-hub && \
21
+ python -c "from huggingface_hub import snapshot_download; snapshot_download('hummbl-hf/governance-bench', repo_type='dataset', local_dir='/bench')"
22
+
23
+ # Verify download
24
+ RUN ls /bench/tasks/ | head -5
25
+
26
+ # Set environment
27
  ENV BENCH_ROOT=/bench
28
  ENV PYTHONPATH=/bench/scripts:/app
29
 
 
 
30
  EXPOSE 7860
31
 
32
  CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
app.py CHANGED
@@ -34,23 +34,6 @@ SCRIPTS_DIR = BENCH_ROOT / "scripts"
34
  TEMPLATES_DIR = Path(__file__).resolve().parent / "templates"
35
  STATIC_DIR = Path(__file__).resolve().parent / "static"
36
 
37
-
38
- def ensure_bench_downloaded() -> None:
39
- """Download the benchmark dataset at runtime if BENCH_ROOT is empty/missing.
40
-
41
- Fetches from hummbl-hf/governance-bench so dataset updates surface without
42
- a space rebuild (F4 refactor — was previously baked in at Docker build time).
43
- """
44
- if TASKS_ROOT.exists() and any(TASKS_ROOT.iterdir()):
45
- return # already populated
46
- from huggingface_hub import snapshot_download
47
- snapshot_download(
48
- "hummbl-hf/governance-bench",
49
- repo_type="dataset",
50
- local_dir=str(BENCH_ROOT),
51
- )
52
-
53
-
54
  app = FastAPI(
55
  title="Governance-Bench Agent Reasoning Audit",
56
  description="Interactive benchmark for AI agent governance primitives",
@@ -61,11 +44,6 @@ app.mount("/static", StaticFiles(directory=str(STATIC_DIR)), name="static")
61
  templates = Jinja2Templates(directory=str(TEMPLATES_DIR))
62
 
63
 
64
- @app.on_event("startup")
65
- async def _startup_download_bench() -> None:
66
- ensure_bench_downloaded()
67
-
68
-
69
  # ---------------------------------------------------------------------------
70
  # Data models
71
  # ---------------------------------------------------------------------------
 
34
  TEMPLATES_DIR = Path(__file__).resolve().parent / "templates"
35
  STATIC_DIR = Path(__file__).resolve().parent / "static"
36
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  app = FastAPI(
38
  title="Governance-Bench Agent Reasoning Audit",
39
  description="Interactive benchmark for AI agent governance primitives",
 
44
  templates = Jinja2Templates(directory=str(TEMPLATES_DIR))
45
 
46
 
 
 
 
 
 
47
  # ---------------------------------------------------------------------------
48
  # Data models
49
  # ---------------------------------------------------------------------------
requirements.txt CHANGED
@@ -2,4 +2,3 @@ fastapi
2
  uvicorn[standard]
3
  jinja2
4
  hummbl-governance>=1.1.0
5
- huggingface-hub
 
2
  uvicorn[standard]
3
  jinja2
4
  hummbl-governance>=1.1.0