Spaces:
Building
Building
Expose bounded deployment-source attestation
#9
by betterwithage - opened
- Dockerfile +1 -1
- README.md +5 -0
- serve.py +29 -0
- szl_source_attestation.py +118 -0
- test/test_source_attestation.py +64 -0
Dockerfile
CHANGED
|
@@ -1605,7 +1605,7 @@ COPY szl_spend_cap.py ./szl_spend_cap.py
|
|
| 1605 |
# reads defensively — degrading honestly (an honest placeholder tile) if the endpoint is
|
| 1606 |
# unreachable at runtime. No backend module.
|
| 1607 |
# --- buildkit max-depth fix: per-file COPYs grouped into one layer (no file dropped; every source token preserved). ---
|
| 1608 |
-
COPY a11oy_model_intel.py a11oy_experimental_tier.py a11oy_markets.py szl_agent_tts.py szl_gated_delta.py szl_blocksparse.py szl_retrieval_attn.py szl_model_harness.py szl_agent_loop_governed.py szl_crypto_pipeline.py szl_confattest.py szl_agent_operate.py szl_agentloop_brain.py szl_governed_rag.py szl_sovereign_flywheel.py szl_brain_corpus.py szl_verify_transcript.py szl_frontier_index.py szl_whatsnew.py szl_honestywall.py szl_brainmemory.py szl_agentos.py szl_brainground.py szl_brainuncertainty.py szl_brainhealth.py szl_brainwatch.py szl_boot_preflight.py szl_guarded_surface.py szl_status_aggregate.py szl_brainconstitution.py szl_brainagent.py szl_surface_manifests.py ./
|
| 1609 |
COPY static/3d/surfaces/gateddelta.js static/3d/surfaces/blocksparse.js static/3d/surfaces/retrievalattn.js static/3d/surfaces/governedagent.js static/3d/surfaces/cryptopipeline.js static/3d/surfaces/confattest.js static/3d/surfaces/agentops.js static/3d/surfaces/frontierindex.js static/3d/surfaces/whatsnew.js static/3d/surfaces/opsdash.js ./static/3d/surfaces/
|
| 1610 |
|
| 1611 |
# git_sha wireup (FORGE-INSTRUCTION-gitsha-quiet-window): surface the deployed commit
|
|
|
|
| 1605 |
# reads defensively — degrading honestly (an honest placeholder tile) if the endpoint is
|
| 1606 |
# unreachable at runtime. No backend module.
|
| 1607 |
# --- buildkit max-depth fix: per-file COPYs grouped into one layer (no file dropped; every source token preserved). ---
|
| 1608 |
+
COPY a11oy_model_intel.py a11oy_experimental_tier.py a11oy_markets.py szl_agent_tts.py szl_gated_delta.py szl_blocksparse.py szl_retrieval_attn.py szl_model_harness.py szl_agent_loop_governed.py szl_crypto_pipeline.py szl_confattest.py szl_agent_operate.py szl_agentloop_brain.py szl_governed_rag.py szl_sovereign_flywheel.py szl_brain_corpus.py szl_verify_transcript.py szl_frontier_index.py szl_whatsnew.py szl_honestywall.py szl_brainmemory.py szl_agentos.py szl_brainground.py szl_brainuncertainty.py szl_brainhealth.py szl_brainwatch.py szl_boot_preflight.py szl_guarded_surface.py szl_status_aggregate.py szl_brainconstitution.py szl_brainagent.py szl_surface_manifests.py szl_source_attestation.py ./
|
| 1609 |
COPY static/3d/surfaces/gateddelta.js static/3d/surfaces/blocksparse.js static/3d/surfaces/retrievalattn.js static/3d/surfaces/governedagent.js static/3d/surfaces/cryptopipeline.js static/3d/surfaces/confattest.js static/3d/surfaces/agentops.js static/3d/surfaces/frontierindex.js static/3d/surfaces/whatsnew.js static/3d/surfaces/opsdash.js ./static/3d/surfaces/
|
| 1610 |
|
| 1611 |
# git_sha wireup (FORGE-INSTRUCTION-gitsha-quiet-window): surface the deployed commit
|
README.md
CHANGED
|
@@ -120,6 +120,11 @@ curl -s https://a-11-oy.com/api/a11oy/v1/honest | jq .doctrine_lock.lambda
|
|
| 120 |
| Evidence-bound Council | [a-11-oy.com/api/a11oy/v1/ayllu/council/manifest](https://a-11-oy.com/api/a11oy/v1/ayllu/council/manifest) |
|
| 121 |
| SZL-Nemo card | [a-11-oy.com/api/a11oy/v1/nemo/card](https://a-11-oy.com/api/a11oy/v1/nemo/card) |
|
| 122 |
| Receipt verifier contract | [a-11-oy.com/api/a11oy/v1/verify/receipt](https://a-11-oy.com/api/a11oy/v1/verify/receipt) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
|
| 124 |
Council v2 is proposal-only. It adds a signed Nemo routing trace, per-turn output
|
| 125 |
digests, explicit limits, a deterministic replay key, and a required human
|
|
|
|
| 120 |
| Evidence-bound Council | [a-11-oy.com/api/a11oy/v1/ayllu/council/manifest](https://a-11-oy.com/api/a11oy/v1/ayllu/council/manifest) |
|
| 121 |
| SZL-Nemo card | [a-11-oy.com/api/a11oy/v1/nemo/card](https://a-11-oy.com/api/a11oy/v1/nemo/card) |
|
| 122 |
| Receipt verifier contract | [a-11-oy.com/api/a11oy/v1/verify/receipt](https://a-11-oy.com/api/a11oy/v1/verify/receipt) |
|
| 123 |
+
| Deployment-source attestation | [HF Space `/.well-known/szl-source.json`](https://szlholdings-a11oy.hf.space/.well-known/szl-source.json) |
|
| 124 |
+
|
| 125 |
+
The source attestation measures the deployed Hugging Face revision separately
|
| 126 |
+
from its pinned GitHub reference. It reports `PENDING_GITHUB_SYNC` and explicitly
|
| 127 |
+
does not claim Space/GitHub byte parity, a reproducible build, or build provenance.
|
| 128 |
|
| 129 |
Council v2 is proposal-only. It adds a signed Nemo routing trace, per-turn output
|
| 130 |
digests, explicit limits, a deterministic replay key, and a required human
|
serve.py
CHANGED
|
@@ -13245,6 +13245,35 @@ except Exception as _ws_e2: # additive: never break the Space
|
|
| 13245 |
# ============================================================================
|
| 13246 |
|
| 13247 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13248 |
if __name__ == "__main__":
|
| 13249 |
import uvicorn
|
| 13250 |
port = int(os.environ.get("PORT", "7860"))
|
|
|
|
| 13245 |
# ============================================================================
|
| 13246 |
|
| 13247 |
|
| 13248 |
+
# Bounded deployment-source attestation. Registered last and front-moved by the
|
| 13249 |
+
# module so the exact well-known JSON route wins over the SPA history fallback.
|
| 13250 |
+
# A pinned GitHub reference is evidence of a source observation only; it does
|
| 13251 |
+
# not assert byte parity, a reproducible Space build, or build provenance.
|
| 13252 |
+
try:
|
| 13253 |
+
import szl_source_attestation as _szl_source_attestation
|
| 13254 |
+
|
| 13255 |
+
_a11oy_source_observation = {
|
| 13256 |
+
"repository": "szl-holdings/a11oy",
|
| 13257 |
+
"commit": "adac37574f88a30ff099f3ec7f548685d4166e6f",
|
| 13258 |
+
"path": "",
|
| 13259 |
+
"relation": "declared-source-with-hf-overlay",
|
| 13260 |
+
"state": "VERIFIED_REFERENCE",
|
| 13261 |
+
"evidence_url": "https://github.com/szl-holdings/a11oy/commit/adac37574f88a30ff099f3ec7f548685d4166e6f",
|
| 13262 |
+
}
|
| 13263 |
+
_szl_source_result = _szl_source_attestation.register(
|
| 13264 |
+
app,
|
| 13265 |
+
"SZLHOLDINGS/a11oy",
|
| 13266 |
+
_a11oy_source_observation,
|
| 13267 |
+
"PENDING_GITHUB_SYNC",
|
| 13268 |
+
)
|
| 13269 |
+
print(f"[a11oy] deployment-source attestation registered: {_szl_source_result}", file=sys.stderr)
|
| 13270 |
+
except Exception as _szl_source_error: # additive: never take down the SPA
|
| 13271 |
+
print(
|
| 13272 |
+
f"[a11oy] deployment-source attestation NOT registered (non-fatal): {_szl_source_error!r}",
|
| 13273 |
+
file=sys.stderr,
|
| 13274 |
+
)
|
| 13275 |
+
|
| 13276 |
+
|
| 13277 |
if __name__ == "__main__":
|
| 13278 |
import uvicorn
|
| 13279 |
port = int(os.environ.get("PORT", "7860"))
|
szl_source_attestation.py
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Bounded deployment-source attestation for public SZL surfaces."""
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
import json
|
| 5 |
+
import os
|
| 6 |
+
import re
|
| 7 |
+
import threading
|
| 8 |
+
import time
|
| 9 |
+
import urllib.request
|
| 10 |
+
from datetime import datetime, timezone
|
| 11 |
+
|
| 12 |
+
from fastapi.responses import JSONResponse
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
_SHA = re.compile(r"^[0-9a-f]{40}$")
|
| 16 |
+
_CACHE_LOCK = threading.Lock()
|
| 17 |
+
_CACHE: dict[str, dict[str, object]] = {}
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def _now_iso() -> str:
|
| 21 |
+
return datetime.now(timezone.utc).isoformat().replace("+00:00", "Z")
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def _valid_sha(value: object) -> str | None:
|
| 25 |
+
candidate = str(value or "").strip().lower()
|
| 26 |
+
return candidate if _SHA.fullmatch(candidate) else None
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def measure_hf_revision(space_id: str, force: bool = False) -> dict[str, object]:
|
| 30 |
+
env_revision = _valid_sha(os.environ.get("SPACE_REPOSITORY_COMMIT"))
|
| 31 |
+
if env_revision:
|
| 32 |
+
return {
|
| 33 |
+
"hf_revision": env_revision,
|
| 34 |
+
"revision_state": "MEASURED",
|
| 35 |
+
"measurement_method": "SPACE_REPOSITORY_COMMIT",
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
now = time.monotonic()
|
| 39 |
+
with _CACHE_LOCK:
|
| 40 |
+
cached = _CACHE.get(space_id)
|
| 41 |
+
if not force and cached and now - float(cached["stored_at"]) < 60:
|
| 42 |
+
return dict(cached["measurement"]) # type: ignore[arg-type]
|
| 43 |
+
|
| 44 |
+
revision = None
|
| 45 |
+
error = None
|
| 46 |
+
request = urllib.request.Request(
|
| 47 |
+
f"https://huggingface.co/api/spaces/{space_id}?expand[]=sha",
|
| 48 |
+
headers={"Accept": "application/json", "User-Agent": "szl-source-attestation/1.0"},
|
| 49 |
+
)
|
| 50 |
+
try:
|
| 51 |
+
with urllib.request.urlopen(request, timeout=4) as response:
|
| 52 |
+
revision = _valid_sha(json.load(response).get("sha"))
|
| 53 |
+
except Exception as exc:
|
| 54 |
+
error = type(exc).__name__
|
| 55 |
+
|
| 56 |
+
measurement: dict[str, object] = {
|
| 57 |
+
"hf_revision": revision,
|
| 58 |
+
"revision_state": "MEASURED" if revision else "UNAVAILABLE",
|
| 59 |
+
"measurement_method": "HUGGINGFACE_API" if revision else "UNAVAILABLE",
|
| 60 |
+
}
|
| 61 |
+
if error:
|
| 62 |
+
measurement["measurement_error"] = error
|
| 63 |
+
with _CACHE_LOCK:
|
| 64 |
+
_CACHE[space_id] = {"stored_at": time.monotonic(), "measurement": dict(measurement)}
|
| 65 |
+
return measurement
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def build_attestation(
|
| 69 |
+
space_id: str,
|
| 70 |
+
source: dict[str, object],
|
| 71 |
+
alignment_state: str,
|
| 72 |
+
force: bool = False,
|
| 73 |
+
) -> dict[str, object]:
|
| 74 |
+
measurement = measure_hf_revision(space_id, force=force)
|
| 75 |
+
return {
|
| 76 |
+
"schema": "szl.deployment-source/v1",
|
| 77 |
+
"observed_at": _now_iso(),
|
| 78 |
+
"transport_state": "REACHABLE",
|
| 79 |
+
"evidence_state": "COMPUTED" if measurement["hf_revision"] else "UNAVAILABLE",
|
| 80 |
+
"verification_state": "STRUCTURAL_ONLY",
|
| 81 |
+
"authority_state": "READ_ONLY",
|
| 82 |
+
"source": dict(source),
|
| 83 |
+
"deployment": {"hf_space": space_id, **measurement},
|
| 84 |
+
"alignment_state": alignment_state,
|
| 85 |
+
"attestation_state": "UNSIGNED_STRUCTURAL",
|
| 86 |
+
"claims": {
|
| 87 |
+
"github_parity": "NOT_CLAIMED",
|
| 88 |
+
"reproducible_build": "NOT_CLAIMED",
|
| 89 |
+
"build_provenance": "NOT_CLAIMED",
|
| 90 |
+
},
|
| 91 |
+
"limits": [
|
| 92 |
+
"The Hugging Face revision is measured independently from the pinned source observation.",
|
| 93 |
+
"A GitHub reference does not establish deployed-artifact equivalence.",
|
| 94 |
+
"This unsigned structural attestation does not prove a reproducible build or build provenance.",
|
| 95 |
+
],
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
def register(app, space_id: str, source: dict[str, object], alignment_state: str) -> dict[str, object]:
|
| 100 |
+
async def source_attestation(refresh: int = 0): # noqa: ANN202
|
| 101 |
+
payload = build_attestation(space_id, source, alignment_state, force=refresh == 1)
|
| 102 |
+
return JSONResponse(
|
| 103 |
+
payload,
|
| 104 |
+
headers={
|
| 105 |
+
"Cache-Control": "no-store",
|
| 106 |
+
"X-SZL-Transport-State": str(payload["transport_state"]),
|
| 107 |
+
"X-SZL-Evidence-State": str(payload["evidence_state"]),
|
| 108 |
+
"X-SZL-Verification-State": str(payload["verification_state"]),
|
| 109 |
+
"X-SZL-Authority-State": str(payload["authority_state"]),
|
| 110 |
+
},
|
| 111 |
+
)
|
| 112 |
+
|
| 113 |
+
existing = list(app.router.routes)
|
| 114 |
+
route = "/.well-known/szl-source.json"
|
| 115 |
+
app.add_api_route(route, source_attestation, methods=["GET"], include_in_schema=True)
|
| 116 |
+
added = list(app.router.routes[len(existing):])
|
| 117 |
+
app.router.routes[:] = added + existing
|
| 118 |
+
return {"ok": True, "route": route, "space": space_id, "position": 0}
|
test/test_source_attestation.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import unittest
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
from unittest.mock import patch
|
| 5 |
+
|
| 6 |
+
from fastapi import FastAPI
|
| 7 |
+
from fastapi.responses import HTMLResponse
|
| 8 |
+
from fastapi.testclient import TestClient
|
| 9 |
+
|
| 10 |
+
import szl_source_attestation as source
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
ROOT = Path(__file__).resolve().parents[1]
|
| 14 |
+
SOURCE_OBSERVATION = {
|
| 15 |
+
"repository": "szl-holdings/a11oy",
|
| 16 |
+
"commit": "adac37574f88a30ff099f3ec7f548685d4166e6f",
|
| 17 |
+
"path": "",
|
| 18 |
+
"relation": "declared-source-with-hf-overlay",
|
| 19 |
+
"state": "VERIFIED_REFERENCE",
|
| 20 |
+
"evidence_url": "https://github.com/szl-holdings/a11oy/commit/adac37574f88a30ff099f3ec7f548685d4166e6f",
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
class SourceAttestationTests(unittest.TestCase):
|
| 25 |
+
def setUp(self):
|
| 26 |
+
self.app = FastAPI()
|
| 27 |
+
|
| 28 |
+
@self.app.get("/{full_path:path}")
|
| 29 |
+
async def spa_fallback(full_path: str): # noqa: ARG001
|
| 30 |
+
return HTMLResponse("<html>SPA</html>")
|
| 31 |
+
|
| 32 |
+
source.register(
|
| 33 |
+
self.app,
|
| 34 |
+
"SZLHOLDINGS/a11oy",
|
| 35 |
+
SOURCE_OBSERVATION,
|
| 36 |
+
"PENDING_GITHUB_SYNC",
|
| 37 |
+
)
|
| 38 |
+
self.client = TestClient(self.app)
|
| 39 |
+
|
| 40 |
+
def test_exact_route_precedes_spa_and_returns_bounded_json(self):
|
| 41 |
+
paths = [getattr(route, "path", None) for route in self.app.router.routes]
|
| 42 |
+
self.assertLess(paths.index("/.well-known/szl-source.json"), paths.index("/{full_path:path}"))
|
| 43 |
+
with patch.dict(os.environ, {"SPACE_REPOSITORY_COMMIT": "a" * 40}):
|
| 44 |
+
response = self.client.get("/.well-known/szl-source.json")
|
| 45 |
+
self.assertEqual(200, response.status_code)
|
| 46 |
+
self.assertEqual("application/json", response.headers["content-type"])
|
| 47 |
+
self.assertEqual("no-store", response.headers["cache-control"])
|
| 48 |
+
self.assertEqual("COMPUTED", response.headers["x-szl-evidence-state"])
|
| 49 |
+
self.assertEqual("STRUCTURAL_ONLY", response.headers["x-szl-verification-state"])
|
| 50 |
+
self.assertEqual("READ_ONLY", response.headers["x-szl-authority-state"])
|
| 51 |
+
body = response.json()
|
| 52 |
+
self.assertEqual("a" * 40, body["deployment"]["hf_revision"])
|
| 53 |
+
self.assertEqual("PENDING_GITHUB_SYNC", body["alignment_state"])
|
| 54 |
+
self.assertEqual("VERIFIED_REFERENCE", body["source"]["state"])
|
| 55 |
+
for claim in ("github_parity", "reproducible_build", "build_provenance"):
|
| 56 |
+
self.assertEqual("NOT_CLAIMED", body["claims"][claim])
|
| 57 |
+
|
| 58 |
+
def test_docker_runtime_includes_module(self):
|
| 59 |
+
dockerfile = (ROOT / "Dockerfile").read_text(encoding="utf-8")
|
| 60 |
+
self.assertIn("szl_source_attestation.py", dockerfile)
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
if __name__ == "__main__":
|
| 64 |
+
unittest.main()
|