KB-11BD

FIX7 P0 Production-Readiness Scoping — production_bad_input_probes.py

7 min read Revision 1
tool-kiem-thufix7p0production-readinessscoping-packet2026-06-12

#!/usr/bin/env python3 """ FIX7 P0 Production-Readiness Surface Scoping -- production bad-input probe harness.

PURELY LOCAL / STATIC. This harness DOES NOT connect to production, PG, Directus, system_issues, CI, or any live running system. It exercises a design-level production-action guard against the nine forbidden bad-input classes required by the macro and proves the guard is FAIL-CLOSED: every forbidden request is BLOCKED and NO production PASS / readiness token is emitted for any invalid input.

The guard models the standing production gates: every production-affecting action requires its OWN explicit, currently-absent owner/GPT grant. In this lane all such grants are absent (this lane is SCOPING-ONLY), so every production request must be blocked. A guard is fail-OPEN if it ever returns allow=True or emits PRODUCTION_PASS for a forbidden request; the selftest asserts that never happens. """ import sys, json

--- the grants that are ABSENT in this scoping lane (production remains gated) ---

GRANTS_PRESENT = { # GPT delegated ONLY production-readiness scoping; nothing below is granted. "PRODUCTION_READINESS_SCOPING": True, # this lane "CANONICAL_FOLD_442_461": True, # this lane (governance bookkeeping) # everything production-affecting is explicitly absent: "PRODUCTION_EXECUTION_OPT4": False, "REAL_RUN": False, "QT001_APPLY": False, "PERMIT": False, "ACTIVATION": False, "REPOINT": False, "CUTOVER": False, "CI_DEPLOY_PRODUCTION": False, "SECRETS_CHANGE": False, "PROD_ROLLBACK_PROVEN": False, # production snapshot/restore NOT proven }

action -> the grant(s) it REQUIRES (all must be present, else BLOCK)

ACTION_REQUIRES = { "production_run": ["PRODUCTION_EXECUTION_OPT4", "PROD_ROLLBACK_PROVEN"], "real_run": ["REAL_RUN"], "qt001_apply": ["QT001_APPLY"], "cutover": ["CUTOVER"], "ci_deploy_production": ["CI_DEPLOY_PRODUCTION"], "secrets_change": ["SECRETS_CHANGE"], }

PROD_TOKEN = "PRODUCTION_PASS" # the token that must NEVER appear for a forbidden input

def production_guard(req): """Fail-closed. Returns dict; allow=True ONLY if every required grant present, target unambiguous, rollback proven, and gate present. Never emits PROD_TOKEN unless allow is True (which cannot happen in this grants-absent lane).""" action = req.get("action") reasons = []

# 1. unknown / missing action -> BLOCK (fail closed on ambiguity)
if action is None or action not in ACTION_REQUIRES:
    return {"allow": False, "verdict": "BLOCK_UNKNOWN_OR_MISSING_ACTION",
            "token": None, "reasons": ["unknown/missing production action"]}

# 2. ambiguous production target -> BLOCK
target = req.get("target")
if not target or target in ("?", "ambiguous", "UNKNOWN"):
    reasons.append("ambiguous/missing production target")

# 3. missing rollback proof for any state-mutating production run -> BLOCK
if action in ("production_run", "qt001_apply", "cutover") and not GRANTS_PRESENT.get("PROD_ROLLBACK_PROVEN"):
    reasons.append("production rollback/snapshot-restore NOT proven")

# 4. CI deploy without a production gate -> BLOCK
if action == "ci_deploy_production" and not req.get("production_gate_present"):
    reasons.append("CI deploy lacks production gate")

# 5. required grants must all be present
missing = [g for g in ACTION_REQUIRES[action] if not GRANTS_PRESENT.get(g)]
if missing:
    reasons.append("missing required grant(s): " + ",".join(missing))

allow = (len(reasons) == 0)
return {
    "allow": allow,
    "verdict": "ALLOW" if allow else "BLOCK_FORBIDDEN_PRODUCTION_ACTION",
    # token emitted ONLY on allow; forbidden inputs get token=None
    "token": PROD_TOKEN if allow else None,
    "reasons": reasons or ["all gates satisfied"],
}

the 9 required bad-input classes

PROBES = [ {"id": "P1_PROD_RUN_NO_AUTH", "req": {"action": "production_run", "target": "fn_birth_register"}}, {"id": "P2_REAL_RUN_NO_GRANT", "req": {"action": "real_run", "target": "birth pipeline"}}, {"id": "P3_QT001_APPLY_NO_GRANT", "req": {"action": "qt001_apply", "target": "QT-001"}}, {"id": "P4_CUTOVER_NO_GRANT", "req": {"action": "cutover", "target": "prod repoint"}}, {"id": "P5_MISSING_ROLLBACK_PROOF","req": {"action": "production_run", "target": "sql/prod/99_run_all.sql"}}, {"id": "P6_AMBIGUOUS_TARGET", "req": {"action": "production_run", "target": "UNKNOWN"}}, {"id": "P7_CI_DEPLOY_NO_GATE", "req": {"action": "ci_deploy_production", "target": "nuxt-repo/web", "production_gate_present": False}}, {"id": "P8_SECRETS_CHANGE", "req": {"action": "secrets_change", "target": "GitHub push credentials"}}, {"id": "P9_PROD_PASS_DESPITE_BLOCK","req": {"action": "qt001_apply", "target": "directus", "claim": "PRODUCTION_PASS"}}, ]

def run(): results = [] any_fail_open = False for p in PROBES: out = production_guard(p["req"]) # fail-open iff guard allowed OR leaked the production token for a forbidden input fail_open = bool(out["allow"]) or (out["token"] == PROD_TOKEN) any_fail_open = any_fail_open or fail_open results.append({"id": p["id"], "verdict": out["verdict"], "allow": out["allow"], "token": out["token"], "fail_open": fail_open, "reasons": out["reasons"]}) summary = { "doc": "fix7-p0-production-bad-input-probes", "date": "2026-06-12", "harness_scope": "PURELY_LOCAL_STATIC_NO_PRODUCTION_CONTACT", "probe_count": len(results), "blocked_count": sum(1 for r in results if not r["allow"]), "any_fail_open": any_fail_open, "production_token_leaked": any(r["token"] == PROD_TOKEN for r in results), "results": results, "verdict": "ALL_FAIL_CLOSED" if (not any_fail_open) else "FAIL_OPEN_DETECTED", } return summary

if name == "main": s = run() print(json.dumps(s, indent=2)) # exit 0 only if every probe fail-closed; non-zero otherwise sys.exit(0 if (not s["any_fail_open"] and s["blocked_count"] == s["probe_count"]) else 1)

Back to Knowledge Hub knowledge/dev/reports/architecture/fix7-p0-production-readiness-surface-scoping-packet-2026-06-12/production_bad_input_probes.py