decisionmodels's picture
TEE inference prototype attestation report, 22 Nov 2026
d2d803c verified
Raw History Blame Contribute Delete
4.96 kB
"""TLS front for the decisionmodels.io TEE prototype (runs inside the SEV-SNP CVM).
- GET /attestation public: SNP report + AMD cert chain + NVIDIA GPU evidence + NRAS token + the TLS cert they bind to
- GET /attestation/fresh?nonce=<64 hex> public: new SNP report with report_data = SHA-512(spki_der || nonce) (freshness)
- * /v1/* bearer-token protected, proxied to vLLM on 127.0.0.1:8000 (no request/response bodies logged)
Logging: one metadata line per request (method, path, status, duration). Never bodies.
"""
import base64, hashlib, json, os, pathlib, re, subprocess, time, uuid
import httpx, uvicorn
from starlette.applications import Starlette
from starlette.responses import JSONResponse, Response, StreamingResponse
from starlette.routing import Route
D = pathlib.Path("/root/tee")
TOKEN = (D / "api_token").read_text().strip()
UP = httpx.AsyncClient(base_url="http://127.0.0.1:8000", timeout=600)
def b64(p): return base64.b64encode((D / p).read_bytes()).decode()
def log(**kw):
kw["ts"] = time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime()); kw["app"] = "tee-front"
print(json.dumps(kw), flush=True)
def snp_report(report_data: bytes) -> bytes:
d = pathlib.Path("/sys/kernel/config/tsm/report") / ("r" + uuid.uuid4().hex[:8])
d.mkdir()
try:
(d / "inblob").write_bytes(report_data)
return (d / "outblob").read_bytes()
finally:
d.rmdir()
async def attestation(request):
spki = (D / "spki.der").read_bytes()
bundle = {
"schema": "decisionmodels-tee-attestation/0.1",
"generated_at": (D / "generated_at").read_text().strip(),
"binding": {
"tls_cert_pem": (D / "tls.crt").read_text(),
"spki_sha512_hex": hashlib.sha512(spki).hexdigest(),
"snp_report_data": "SHA-512(DER SubjectPublicKeyInfo of tls_cert)",
"gpu_nonce": "SHA-256(DER SubjectPublicKeyInfo of tls_cert), hex",
"gpu_nonce_hex": hashlib.sha256(spki).hexdigest(),
},
"cpu_tee": {"type": "AMD SEV-SNP", "report_b64": b64("snp-report.bin"),
"vcek_pem": (D / "certs/vcek.pem").read_text(), "ask_pem": (D / "certs/ask.pem").read_text(),
"ark_pem": (D / "certs/ark.pem").read_text(), "report_text": (D / "snp-report.txt").read_text()},
"gpu_tee": {"type": "NVIDIA Confidential Computing (RTX PRO 6000 Blackwell Server Edition)",
"evidence": json.loads((D / "gpu-evidence.json").read_text()),
"nras_token": json.loads((D / "nras-token.json").read_text())},
"verify": "https://huggingface.co/datasets/decisionmodels/tee-attestation-prototype (verify_tee.py; trusts only AMD KDS + NVIDIA NRAS JWKS)",
"limits": "Prototype. Proves a genuine SEV-SNP CVM (debug off) and a CC-mode NVIDIA GPU hold this TLS key. "
"It does NOT yet prove which software runs inside (no measured rootfs) and the operator still has SSH.",
}
log(method="GET", path="/attestation", status=200)
return JSONResponse(bundle)
async def fresh(request):
n = request.query_params.get("nonce", "")
if not re.fullmatch(r"[0-9a-fA-F]{64}", n):
return JSONResponse({"error": "nonce must be 64 hex chars"}, status_code=400)
spki = (D / "spki.der").read_bytes()
rd = hashlib.sha512(spki + bytes.fromhex(n)).digest()
rep = snp_report(rd)
log(method="GET", path="/attestation/fresh", status=200)
return JSONResponse({"report_data": "SHA-512(spki_der || nonce_bytes)", "nonce": n.lower(),
"report_b64": base64.b64encode(rep).decode()})
async def proxy(request):
t0 = time.monotonic()
if request.headers.get("authorization", "") != "Bearer " + TOKEN:
log(method=request.method, path=request.url.path, status=401)
return JSONResponse({"error": "unauthorized"}, status_code=401)
body = await request.body()
req = UP.build_request(request.method, request.url.path, content=body,
headers={"content-type": request.headers.get("content-type", "application/json")})
r = await UP.send(req, stream=True)
async def gen():
try:
async for chunk in r.aiter_raw():
yield chunk
finally:
await r.aclose()
log(method=request.method, path=request.url.path, status=r.status_code,
ms=round((time.monotonic() - t0) * 1000))
return StreamingResponse(gen(), status_code=r.status_code,
media_type=r.headers.get("content-type"))
app = Starlette(routes=[Route("/attestation", attestation), Route("/attestation/fresh", fresh),
Route("/v1/{p:path}", proxy, methods=["GET", "POST"])])
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=443, ssl_keyfile=str(D / "tls.key"), ssl_certfile=str(D / "tls.crt"),
access_log=False, log_level="warning")