| # verify_v3.py hardening patch |
| # |
| # pre-hardening sha256 507a53d2c6fd38fba3eb4cbe50c73cb43c1689061920f944c18995b748afcc3d (attested in sha256sums.txt line 30) |
| # post-hardening sha256 d6c1d4299aab831d61174daea651e8e779b6fa46ae7279cc17bd33a6de1f47c4 |
| # |
| a/verify_v3.py 2026-08-10 19:40:29.385003841 -0400 |
| |
| @@ -29,10 +29,12 @@ |
| HERE = os.path.dirname(os.path.abspath(__file__)) |
| sys.path.insert(0, HERE) |
| |
| +import exclusivity_model # noqa: E402 |
| import preflight # noqa: E402 |
| import privilege_graph # noqa: E402 |
| |
| ATTACK_RESULTS = os.path.join(HERE, "attack_results.json") |
| +TOPOLOGY = os.path.join(HERE, "PRIVILEGE_TOPOLOGY.json") |
| CARRIER_MATRIX = os.path.join(HERE, "carrier_matrix.json") |
| REGISTRY = os.path.join(HERE, "ROOT_EQUIVALENCE_REGISTRY.json") |
| ANALYSIS = os.path.join(HERE, "AUTHORITY_PRINCIPAL_ANALYSIS.json") |
| @@ -40,16 +42,17 @@ |
| HISTORY_PATH = os.path.join(HERE, "run_history.jsonl") |
| REQUIRED_IDENTICAL_RUNS = 4 |
| |
| -VERIFIED = "VERIFIED_EXCLUSIVE_AUTHORITY" |
| -BLOCKED_ROOT = "BLOCKED_ROOT_EQUIVALENCE" |
| -BLOCKED_AUTHORITY = "BLOCKED_AUTHORITY_EQUIVALENCE" |
| +VERIFIED = exclusivity_model.VERIFIED |
| +BLOCKED_ROOT = exclusivity_model.BLOCKED_ROOT |
| +BLOCKED_AUTHORITY = exclusivity_model.BLOCKED_AUTHORITY |
| +BLOCKED_UNCERTAIN = exclusivity_model.BLOCKED_UNCERTAIN |
| INTEGRATION_BLOCKED = "INTEGRATION_BLOCKED" |
| PROVABLY_UNREACHABLE = "PROVABLY_UNREACHABLE" |
| ENV_NOT_EQUIVALENT = "ENVIRONMENT_NOT_EQUIVALENT" |
| |
| #: Conditions whose failure is caused by the host's privilege configuration |
| #: rather than by the architecture. Used to compute the conditional result. |
| -CUTOVER_DEPENDENT = {"06", "07", "12", "17"} |
| +CUTOVER_DEPENDENT = {"06", "07", "12", "17", "19"} |
| |
| |
| def die(label: str, message: str) -> None: |
| @@ -64,7 +67,13 @@ |
| return subprocess.run(argv, cwd=HERE, capture_output=True, text=True, timeout=1800) |
| |
| |
| -def conditions_from(attacks: dict, registry: dict, analysis: dict, graph: dict) -> dict: |
| +def conditions_from( |
| + attacks: dict, |
| + registry: dict, |
| + analysis: dict, |
| + graph: dict, |
| + topology: dict | None = None, |
| +) -> dict: |
| carriers = {entry["carrier"]: entry for entry in attacks["carriers"]} |
| attack = attacks["attacks"] |
| protocol = attacks["protocol"] |
| @@ -241,6 +250,13 @@ |
| # Condition 18 is filled in by `repeatability()` once the verdict and digest |
| # for this run are known; it is the only condition that cannot be evaluated |
| # from a single run's measurements. |
| + # |
| + # Condition 19 is the hardening added after the cutover preflight found that |
| + # `registry["unknown_paths"]` was recorded and consumed by nothing: a host |
| + # whose only remaining escalation path was UNKNOWN would have been reported |
| + # VERIFIED. It unions the registry's UNKNOWNs with the read-only topology |
| + # inventory's. |
| + conditions["19"] = exclusivity_model.unknown_condition(registry, topology) |
| return conditions |
| |
| |
| @@ -275,7 +291,7 @@ |
| ) |
| return { |
| "text": f"{REQUIRED_IDENTICAL_RUNS} consecutive verifier runs produce the " |
| - f"same result and evidence digest", |
| + f"same result and evidence digest", |
| "met": identical, |
| "evidence": { |
| "runs_recorded": len(history), |
| @@ -289,8 +305,11 @@ |
| def property_split(conditions: dict, registry: dict) -> dict: |
| """Section 15: three properties that fail independently.""" |
| dac = all(conditions[key]["met"] for key in ("03", "04", "05")) |
| + # 19 belongs to exclusivity: an unresolved escalation path is exactly the |
| + # question "can the agent obtain equivalent capability", left unanswered. |
| exclusivity = all( |
| - conditions[key]["met"] for key in ("06", "07", "08", "09", "10", "11", "12") |
| + conditions[key]["met"] |
| + for key in ("06", "07", "08", "09", "10", "11", "12", "19") |
| ) |
| liveness = all(conditions[key]["met"] for key in ("13", "14", "15", "16")) |
| return { |
| @@ -318,8 +337,11 @@ |
| # architecture or of the host's privilege configuration. Counting it as an |
| # architectural failure while the run window fills would misreport every |
| # run before the fourth. |
| - failed = [key for key, entry in conditions.items() |
| - if entry["met"] is False and key != "18"] |
| + failed = [ |
| + key |
| + for key, entry in conditions.items() |
| + if entry["met"] is False and key != "18" |
| + ] |
| failed_independent = [ |
| key for key in failed if not conditions[key].get("cutover_dependent") |
| ] |
| @@ -342,8 +364,9 @@ |
| } |
| |
| |
| -def evidence_digest(attacks: dict, registry: dict, analysis: dict, |
| - graph: dict, conditions: dict) -> str: |
| +def evidence_digest( |
| + attacks: dict, registry: dict, analysis: dict, graph: dict, conditions: dict |
| +) -> str: |
| """A digest over the security-relevant surface only. |
| |
| Built from an explicit whitelist rather than by filtering volatile keys out |
| @@ -354,32 +377,42 @@ |
| hashed. |
| """ |
| surface = { |
| - "carriers": {entry["carrier"]: entry["verdict"] |
| - for entry in attacks["carriers"]}, |
| + "carriers": { |
| + entry["carrier"]: entry["verdict"] for entry in attacks["carriers"] |
| + }, |
| "attacks": { |
| "D_subuid": attacks["attacks"]["D_subuid"]["verdict"], |
| "E_setns_procfs": attacks["attacks"]["E_setns"]["procfs_route"]["verdict"], |
| "E_setns_docker": attacks["attacks"]["E_setns"]["docker_route"]["verdict"], |
| "F_ptrace": attacks["attacks"]["F_ptrace"]["verdict"], |
| "F_ptrace_control": attacks["attacks"]["F_ptrace"][ |
| - "control_attached_agent_owned_process"], |
| + "control_attached_agent_owned_process" |
| + ], |
| "H_rootful": attacks["attacks"]["container_roots"][ |
| - "H_rootful_container_root"]["verdict"], |
| + "H_rootful_container_root" |
| + ]["verdict"], |
| "I_rootless": attacks["attacks"]["container_roots"][ |
| - "I_rootless_container_root"]["verdict"], |
| - "J1": attacks["attacks"]["J_broker_replacement"][ |
| - "J1_host_write_to_code"]["verdict"], |
| + "I_rootless_container_root" |
| + ]["verdict"], |
| + "J1": attacks["attacks"]["J_broker_replacement"]["J1_host_write_to_code"][ |
| + "verdict" |
| + ], |
| "J2": attacks["attacks"]["J_broker_replacement"][ |
| - "J2_docker_cp_into_container"]["verdict"], |
| + "J2_docker_cp_into_container" |
| + ]["verdict"], |
| "K_socket": attacks["attacks"]["K_socket_impersonation"]["verdict"], |
| "Q_key": attacks["attacks"]["Q_key_material"]["verdict"], |
| }, |
| - "protocol": {name: entry.get("pass") |
| - for name, entry in attacks["protocol"].items() |
| - if isinstance(entry, dict)}, |
| - "leakage": {name: entry.get("verdict") |
| - for name, entry in attacks["leakage"].items() |
| - if isinstance(entry, dict)}, |
| + "protocol": { |
| + name: entry.get("pass") |
| + for name, entry in attacks["protocol"].items() |
| + if isinstance(entry, dict) |
| + }, |
| + "leakage": { |
| + name: entry.get("verdict") |
| + for name, entry in attacks["leakage"].items() |
| + if isinstance(entry, dict) |
| + }, |
| "git_all_passed": attacks["workspace_git"]["all_passed"], |
| "git_check_count": attacks["workspace_git"]["count"], |
| "identity_separation": { |
| @@ -387,8 +420,10 @@ |
| "broker_uid": attacks["environment"]["broker_uid"], |
| "decision_uid": attacks["environment"]["decision_uid"], |
| }, |
| - "registry": {name: entry["classification"] |
| - for name, entry in registry["mechanisms"].items()}, |
| + "registry": { |
| + name: entry["classification"] |
| + for name, entry in registry["mechanisms"].items() |
| + }, |
| "root_equivalent_paths": sorted(registry["root_equivalent_paths"]), |
| "authority_uid": analysis["selected_authority_uid"], |
| "graph_edges": sorted( |
| @@ -396,8 +431,9 @@ |
| for entry in graph["edges"] |
| ), |
| "graph_closed": graph["closure"]["closed"], |
| - "conditions": {key: entry["met"] for key, entry in conditions.items() |
| - if key != "18"}, |
| + "conditions": { |
| + key: entry["met"] for key, entry in conditions.items() if key != "18" |
| + }, |
| } |
| return hashlib.sha256( |
| json.dumps(surface, sort_keys=True, separators=(",", ":")).encode() |
| @@ -431,6 +467,16 @@ |
| if analysis_run.returncode != 0 or not os.path.exists(ANALYSIS): |
| die(BLOCKED_ROOT, f"analysis failed: {analysis_run.stderr.strip()[:400]}") |
| |
| + topology_run = run_stage( |
| + "privilege topology inventory", |
| + [sys.executable, os.path.join(HERE, "privilege_topology.py")], |
| + ) |
| + if topology_run.returncode != 0 or not os.path.exists(TOPOLOGY): |
| + die( |
| + BLOCKED_UNCERTAIN, |
| + f"topology inventory failed: {topology_run.stderr.strip()[:400]}", |
| + ) |
| + |
| attacks_run = run_stage( |
| "attack suite", |
| [sys.executable, os.path.join(HERE, "attack_suite", "run_attacks_v3.py")], |
| @@ -445,18 +491,23 @@ |
| with open(ANALYSIS, encoding="utf-8") as handle: |
| analysis = json.load(handle) |
| |
| + with open(TOPOLOGY, encoding="utf-8") as handle: |
| + topology = json.load(handle) |
| + |
| graph = privilege_graph.build_and_save(attacks, registry) |
| - conditions = conditions_from(attacks, registry, analysis, graph) |
| + conditions = conditions_from(attacks, registry, analysis, graph, topology) |
| digest = evidence_digest(attacks, registry, analysis, graph, conditions) |
| - # Section 16's ordering: root-equivalence dominates everything else. |
| - if registry["agent_is_root_equivalent"]: |
| - verdict = BLOCKED_ROOT |
| - elif not graph["closure"]["conditions"]["no_path_to_authority_principal"]["holds"]: |
| - verdict = BLOCKED_AUTHORITY |
| - elif all(entry["met"] for key, entry in conditions.items() if key != "18"): |
| - verdict = VERIFIED |
| - else: |
| - verdict = BLOCKED_AUTHORITY |
| + # Section 16's ordering, now computed by exclusivity_model: root-equivalence |
| + # dominates everything, then authority-equivalence, then UNRESOLVED privilege |
| + # paths -- which can no longer be silently absorbed into a VERIFIED verdict. |
| + exclusivity = exclusivity_model.compute( |
| + registry, |
| + topology, |
| + graph["closure"], |
| + conditions, |
| + ignore_conditions={"18"}, |
| + ) |
| + verdict = exclusivity["verdict"] |
| |
| conditions["18"] = repeatability(verdict, digest) |
| split = property_split(conditions, registry) |
| @@ -478,6 +529,12 @@ |
| "privilege_graph_closure": graph["closure"], |
| "root_equivalent_paths": registry["root_equivalent_paths"], |
| "unknown_paths": registry["unknown_paths"], |
| + "exclusivity": exclusivity, |
| + "privilege_topology": { |
| + "counts": topology["counts"], |
| + "root_equivalent_paths": topology["root_equivalent_paths"], |
| + "unknown_privilege_paths": topology["unknown_privilege_paths"], |
| + }, |
| "selected_authority_uid": analysis["selected_authority_uid"], |
| "prior_packages_unchanged": prior_unchanged, |
| "environment_equivalence": pre["environment_equivalence"], |
| @@ -518,7 +575,15 @@ |
| f"{conditional['would_hold_after_cutover']}" |
| ) |
| print() |
| - print(f"root-equivalent paths: {registry['root_equivalent_paths']}") |
| + print(f"root-equivalent paths: {exclusivity['root_equivalent_paths']}") |
| + print( |
| + f"unresolved privilege paths: " |
| + f"{len(exclusivity['unknown_privilege_paths'])} " |
| + f"{exclusivity['unknown_privilege_paths'][:4]}" |
| + f"{' ...' if len(exclusivity['unknown_privilege_paths']) > 4 else ''}" |
| + ) |
| + for reason in exclusivity["reasons"]: |
| + print(f" verdict reason: {reason}") |
| print(f"privilege graph closed: {graph['closure']['closed']}") |
| print(f"prior packages unchanged: {prior_unchanged}") |
| print(f"evidence digest: {result['evidence_digest'][:32]}") |
|
|