Spaces:
Running
Running
File size: 20,919 Bytes
da0ce7b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 | """Minimal isolated HOLD boundary before any Aureon package or target import.
Run this file directly with ``python -I -S -B``. It imports only the Python
standard library, derives the repository root from its own fixed location, and
never imports Aureon, invokes Git, starts a child, writes a file, or accepts an
arbitrary entrypoint. Until a production guard and durable HNC sink exist, its
only valid decision is HOLD.
"""
from __future__ import annotations
import argparse
import hashlib
import json
import re
import time
from pathlib import Path
from types import MappingProxyType
SCHEMA = "aureon.plumber.isolated-protected-bootstrap.v05"
_TARGET_RE = re.compile(r"^[a-z][a-z0-9-]{0,63}$")
_MAX_ARGUMENTS = 64
_MAX_ARGUMENT_BYTES = 4096
_MAX_ARGUMENT_AGGREGATE_BYTES = 64 * 1024
_ZERO_SHA256 = "0" * 64
_SOURCE_SCOPE_SCHEMA = "aureon.plumber.isolated-perimeter-source-scope.v05"
_MAX_SOURCE_FILES = 256
_MAX_SOURCE_BYTES = 512 * 1024 * 1024
_MAX_SINGLE_SOURCE_BYTES = 128 * 1024 * 1024
_PROTECTION_SOURCE_PATHS = frozenset(
{
"aureon/autonomous/aureon_intrusion_protection_bridge.py",
"aureon/autonomous/aureon_runtime_protection_proposal_vault_v05.py",
"aureon/plumber/authorization_chain_v02.py",
"aureon/plumber/magic_star_v02.py",
"aureon/plumber/os_protection.py",
"aureon/plumber/production_release_broker_v03.py",
"aureon/plumber/protected_bootstrap_v05.py",
"aureon/plumber/release_boundary_v02.py",
"aureon/plumber/runtime_guard_v04.py",
"aureon/plumber/runtime_intrusion_ledger_v04.py",
"aureon/plumber/star_custody_v02.py",
"protected_console_bootstrap_v05.py",
"pyproject.toml",
"scripts/bootstrap/protected_bootstrap_v05.py",
"scripts/validation/audit_economic_mutation_boundaries.py",
"scripts/validation/audit_os_protection_boundaries.py",
}
)
_NODE_TARGET_SOURCES = MappingProxyType(
{
"flameborn:runtime": "flameborn/runtime/server.mjs",
"frontend:vite": "frontend/package.json",
}
)
# Only perimeter IDs are needed here. Inner fixed Python targets remain in the
# package registry, but cannot be reached until this outer boundary is ready.
_TARGETS = MappingProxyType(
{
"cloud-autonomous-worker": (
"python",
"aureon.autonomous.aureon_autonomous_worker",
),
"cloud-command-center": (
"python",
"aureon.command_centers.aureon_command_center_ui",
),
"cloud-kraken-cache": (
"python",
"aureon.exchanges.kraken_cache_feeder",
),
"cloud-market-cache": (
"python",
"aureon.data_feeds.unified_market_cache",
),
"cloud-orca": ("python", "aureon.bots.orca_complete_kill_cycle"),
"cloud-pro-dashboard": (
"python",
"aureon.monitors.aureon_pro_dashboard",
),
"cloud-queen-redistribution": (
"python",
"aureon.queen.queen_power_redistribution",
),
"cloud-supervisor": ("native", "deploy/supervisord.conf"),
"capability-demo": ("python", "aureon.saas.capability_demo"),
"canonical-cloud-organism": (
"python",
"scripts.operations.run_canonical_cloud_organism",
),
"data-ocean": ("python", "aureon.autonomous.aureon_data_ocean"),
"druidic-live-calibration": (
"python",
"scripts.operations.run_live_druidic_calibration",
),
"docker-runtime": ("native", "Dockerfile"),
"ephemeris-pipeline": ("native", "Dockerfile.ephemeris"),
"flameborn-runtime": ("node", "flameborn:runtime"),
"frontend-vite": ("node", "frontend:vite"),
"hnc": ("python", "aureon.core.hnc_live_daemon"),
"ignition": ("python", "scripts/aureon_ignition.py"),
"linux-supervisor": ("native", "deploy/supervisord.linux.conf"),
"local-gui": ("python", "aureon.operator.local_gui_organism"),
"master-launcher": (
"python",
"aureon.autonomous.aureon_master_launcher",
),
"mind-hub": (
"python",
"aureon.autonomous.aureon_mind_thought_action_hub",
),
"operator": ("python", "aureon.operator.operator_server"),
"operator-wsgi": ("python", "aureon.operator.wsgi"),
"organism": ("python", "aureon.core.organism_daemon"),
"organism-observer": (
"python",
"aureon.autonomous.aureon_organism_runtime_observer",
),
"parallel-strategy-unity": (
"python",
"aureon.trading.parallel_strategy_unity",
),
"production-supervisor": ("native", "production/supervisord.conf"),
"queen-eternal-machine": (
"python",
"aureon.queen.queen_eternal_machine",
),
"queen-web-dashboard": (
"python",
"aureon.queen.queen_web_dashboard",
),
"power-redistribution-engine": (
"python",
"aureon.utils.aureon_power_redistribution_engine",
),
"self-questioning": (
"python",
"aureon.autonomous.aureon_self_questioning_ai",
),
"scorm-benchmark": (
"python",
"aureon.operator.scorm_cloud_runner",
),
"autonomous-self-run": (
"python",
"aureon.autonomous.aureon_autonomous_self_run_loop",
),
"unified-market-status": (
"python",
"aureon.exchanges.unified_market_status_server",
),
"unified-market-trader": (
"python",
"aureon.exchanges.unified_market_trader",
),
"website": ("python", "aureon.operator.website_operator"),
"windows-wake": (
"powershell",
"scripts/launchers/AUREON_WAKE_UP_FULL_AUTONOMOUS.ps1",
),
"ws-market-data-feeder": (
"python",
"aureon.data_feeds.ws_market_data_feeder",
),
}
)
def _canonical_bytes(value: dict[str, object]) -> bytes:
return json.dumps(
value,
sort_keys=True,
separators=(",", ":"),
ensure_ascii=True,
allow_nan=False,
).encode("utf-8")
def _sha256_bytes(value: bytes) -> str:
return hashlib.sha256(value).hexdigest()
def _target_commitment(target_id: str, runtime_kind: str, entrypoint: str) -> str:
return _sha256_bytes(
_canonical_bytes(
{
"entrypoint": entrypoint,
"runtime_kind": runtime_kind,
"schema": "aureon.plumber.isolated-bootstrap-target.v05",
"target_id": target_id,
}
)
)
def _bounded_arguments(values: list[str]) -> tuple[str, ...]:
if values[:1] == ["--"]:
values = values[1:]
if len(values) > _MAX_ARGUMENTS:
raise ValueError("bounded_bootstrap_target_arguments_required")
aggregate = 0
for value in values:
if type(value) is not str or "\x00" in value:
raise ValueError("exact_bootstrap_target_argument_required")
if value == "--root" or value.startswith("--root="):
raise ValueError("caller_controlled_bootstrap_root_forbidden")
size = len(value.encode("utf-8"))
if size > _MAX_ARGUMENT_BYTES:
raise ValueError("bounded_bootstrap_target_argument_required")
aggregate += size
if aggregate > _MAX_ARGUMENT_AGGREGATE_BYTES:
raise ValueError("bounded_bootstrap_target_argument_aggregate_required")
return tuple(values)
def _repo_root() -> Path:
script = Path(__file__).resolve()
root = script.parents[2]
expected = (root / "scripts" / "bootstrap" / "protected_bootstrap_v05.py").resolve()
if script != expected or not expected.is_file():
raise ValueError("fixed_bootstrap_path_invalid")
return root
def _bootstrap_source_sha256() -> str:
try:
return _sha256_bytes(Path(__file__).resolve().read_bytes())
except OSError:
return _ZERO_SHA256
def _runtime_guard_source_sha256(root: Path) -> str:
path = root / "aureon" / "plumber" / "runtime_guard_v04.py"
try:
return _sha256_bytes(path.read_bytes())
except OSError:
return _ZERO_SHA256
def _safe_source_path(root: Path, relative: str) -> Path:
candidate_relative = Path(relative.replace("\\", "/"))
if (
not relative
or candidate_relative.is_absolute()
or any(part in {"", ".", ".."} for part in candidate_relative.parts)
):
raise ValueError("bounded_bootstrap_source_path_required")
root_resolved = root.resolve(strict=True)
candidate = root_resolved.joinpath(candidate_relative)
current = root_resolved
for part in candidate_relative.parts:
current = current / part
if current.is_symlink():
raise ValueError("bootstrap_source_symlink_forbidden")
resolved = candidate.resolve(strict=True)
try:
resolved.relative_to(root_resolved)
except ValueError as exc:
raise ValueError("bootstrap_source_path_escape") from exc
if not resolved.is_file():
raise ValueError("bootstrap_source_file_required")
return resolved
def _stable_file_measurement(path: Path) -> tuple[str, int]:
before = path.stat()
if before.st_size < 0 or before.st_size > _MAX_SINGLE_SOURCE_BYTES:
raise ValueError("bounded_bootstrap_source_file_required")
digest = hashlib.sha256()
size = 0
with path.open("rb") as handle:
while True:
chunk = handle.read(1024 * 1024)
if not chunk:
break
size += len(chunk)
if size > _MAX_SINGLE_SOURCE_BYTES:
raise ValueError("bounded_bootstrap_source_file_required")
digest.update(chunk)
after = path.stat()
identity_before = (
before.st_dev,
before.st_ino,
before.st_size,
before.st_mtime_ns,
)
identity_after = (
after.st_dev,
after.st_ino,
after.st_size,
after.st_mtime_ns,
)
if identity_before != identity_after or size != after.st_size:
raise ValueError("bootstrap_source_changed_during_measurement")
return digest.hexdigest(), size
def _source_files(root: Path) -> tuple[tuple[str, Path], ...]:
root_resolved = root.resolve(strict=True)
relative_paths = set(_PROTECTION_SOURCE_PATHS)
for runtime_kind, entrypoint in _TARGETS.values():
relative_paths.add(
_target_source_relative(runtime_kind, entrypoint, root_resolved)
)
if len(relative_paths) > _MAX_SOURCE_FILES:
raise ValueError("bootstrap_source_file_capacity_exceeded")
return tuple(
(relative, _safe_source_path(root_resolved, relative))
for relative in sorted(relative_paths, key=lambda item: item.encode("utf-8"))
)
def _measure_source_scope(root: Path) -> tuple[dict[str, object], dict[str, tuple[str, int]]]:
files = _source_files(root)
aggregate = hashlib.sha256()
aggregate.update((_SOURCE_SCOPE_SCHEMA + "\n").encode("ascii"))
measurements: dict[str, tuple[str, int]] = {}
total_bytes = 0
for relative, path in files:
digest, size = _stable_file_measurement(path)
total_bytes += size
if total_bytes > _MAX_SOURCE_BYTES:
raise ValueError("bootstrap_source_byte_capacity_exceeded")
measurements[relative] = (digest, size)
aggregate.update(
_canonical_bytes(
{
"path": relative,
"sha256": digest,
"size": size,
}
)
)
aggregate.update(b"\n")
if not measurements:
raise ValueError("bootstrap_source_inventory_required")
return (
{
"schema": _SOURCE_SCOPE_SCHEMA,
"sha256": aggregate.hexdigest(),
"file_count": len(measurements),
"total_bytes": total_bytes,
},
measurements,
)
def _target_source_relative(runtime_kind: str, entrypoint: str, root: Path) -> str:
if runtime_kind == "node":
relative = _NODE_TARGET_SOURCES.get(entrypoint)
if relative is None:
raise ValueError("fixed_node_target_source_required")
return relative
if runtime_kind in {"native", "powershell", "shell"}:
return entrypoint.replace("\\", "/")
if runtime_kind != "python":
raise ValueError("recognized_bootstrap_runtime_kind_required")
if entrypoint.casefold().endswith(".py") or "/" in entrypoint or "\\" in entrypoint:
return entrypoint.replace("\\", "/")
base = entrypoint.replace(".", "/")
candidates = (f"{base}.py", f"{base}/__init__.py")
present = [item for item in candidates if (root / item).is_file()]
if len(present) != 1:
raise ValueError("exact_python_target_source_required")
return present[0]
def _receipt(
*,
target_id: str,
arguments: tuple[str, ...],
checked_at: float,
) -> dict[str, object]:
root = _repo_root()
target = _TARGETS.get(target_id)
registered = target is not None
runtime_kind = "" if target is None else target[0]
entrypoint = "" if target is None else target[1]
failures = {
"durable_hnc_evidence",
"full_os_protection",
"native_outer_boundary",
"runtime_guard_production_readiness",
}
if not registered:
failures.add("fixed_bootstrap_target")
if runtime_kind and runtime_kind != "python":
failures.add(f"{runtime_kind}_outer_boundary")
source_scope: dict[str, object] = {
"schema": _SOURCE_SCOPE_SCHEMA,
"sha256": _ZERO_SHA256,
"file_count": 0,
"total_bytes": 0,
}
source_scope_stable = False
source_measurements: dict[str, tuple[str, int]] = {}
try:
first_scope, first_measurements = _measure_source_scope(root)
second_scope, second_measurements = _measure_source_scope(root)
source_scope_stable = (
first_scope == second_scope
and first_measurements == second_measurements
)
if not source_scope_stable:
raise ValueError("bootstrap_source_scope_changed_during_measurement")
source_scope = second_scope
source_measurements = second_measurements
except (OSError, ValueError):
failures.add("source_scope_measurement")
target_source_sha256 = _ZERO_SHA256
target_source_size = 0
target_source_measured = False
target_source_in_scope = False
if target is not None:
try:
target_relative = _target_source_relative(runtime_kind, entrypoint, root)
target_path = _safe_source_path(root, target_relative)
target_source_sha256, target_source_size = _stable_file_measurement(
target_path
)
recorded = source_measurements.get(target_relative)
target_source_in_scope = recorded == (
target_source_sha256,
target_source_size,
)
target_source_measured = target_source_in_scope
except (OSError, ValueError):
target_source_measured = False
if not target_source_measured:
failures.add("target_source_measurement")
argument_policy_attested = len(arguments) == 0
if not argument_policy_attested:
failures.add("target_argument_policy")
causal: dict[str, object] = {
"schema": SCHEMA,
"decision": "HOLD",
"reason": "complete_isolated_protected_bootstrap_required",
"failed_checks": sorted(failures),
"target_id": target_id,
"target_registered": registered,
"target_runtime_kind": runtime_kind,
"target_entrypoint_commitment": (
_ZERO_SHA256
if target is None
else _target_commitment(target_id, runtime_kind, entrypoint)
),
"target_argument_count": len(arguments),
"target_arguments_sha256": _sha256_bytes(
json.dumps(list(arguments), separators=(",", ":"), ensure_ascii=True).encode(
"utf-8"
)
),
"repo_root_sha256": _sha256_bytes(str(root).casefold().encode("utf-8")),
"repo_root_derived_from_bootstrap_path": True,
"bootstrap_path_bound": True,
"bootstrap_source_sha256": _bootstrap_source_sha256(),
"caller_controlled_root_accepted": False,
"source_scope_schema": source_scope["schema"],
"source_scope_sha256": source_scope["sha256"],
"source_scope_file_count": source_scope["file_count"],
"source_scope_total_bytes": source_scope["total_bytes"],
"source_scope_measured": source_scope_stable,
"source_scope_stable": source_scope_stable,
"target_source_sha256": target_source_sha256,
"target_source_size": target_source_size,
"target_source_measured": target_source_measured,
"target_source_in_source_scope": target_source_in_scope,
"target_argument_policy": "empty-arguments-v1",
"target_argument_policy_attested": argument_policy_attested,
"runtime_guard_source_sha256": _runtime_guard_source_sha256(root),
"runtime_guard_production_ready": False,
"full_os_protection_evaluated": False,
"durable_hnc_evidence_attested": False,
"magic_star_durable_custody_attested": False,
"external_head_anchor_attested": False,
"target_imported": False,
"target_called": False,
"child_process_started": False,
"bootstrap_subprocess_started": False,
"git_invoked": False,
"network_accessed": False,
"file_written": False,
"hnc_denial_recorded": False,
"durable_hnc_denial_recorded": False,
"process_start_authorized": False,
"action_eligible": False,
"economic_eligible": False,
"operational_eligible": False,
"production_ready": False,
"checked_at": checked_at,
}
return {
**causal,
"receipt_id": f"bootstrap:isolated-v05:{_sha256_bytes(_canonical_bytes(causal))}",
}
def _invalid_receipt(*, checked_at: float) -> dict[str, object]:
causal: dict[str, object] = {
"schema": SCHEMA,
"decision": "HOLD",
"reason": "exact_isolated_bootstrap_request_required",
"failed_checks": ["bootstrap_request"],
"target_id": "",
"target_imported": False,
"target_called": False,
"child_process_started": False,
"bootstrap_subprocess_started": False,
"git_invoked": False,
"network_accessed": False,
"file_written": False,
"process_start_authorized": False,
"production_ready": False,
"checked_at": checked_at,
}
return {
**causal,
"receipt_id": f"bootstrap:isolated-v05:{_sha256_bytes(_canonical_bytes(causal))}",
}
def _parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--target-id", required=True)
parser.add_argument("--pretty", action="store_true")
parser.add_argument("target_arguments", nargs=argparse.REMAINDER)
return parser
def main(argv: list[str] | None = None) -> int:
args = _parser().parse_args(argv)
checked_at = time.time()
try:
if type(args.target_id) is not str or _TARGET_RE.fullmatch(args.target_id) is None:
raise ValueError("exact_bootstrap_target_id_required")
arguments = _bounded_arguments(args.target_arguments)
receipt = _receipt(
target_id=args.target_id,
arguments=arguments,
checked_at=checked_at,
)
exit_code = 1
except (OSError, TypeError, ValueError):
receipt = _invalid_receipt(checked_at=checked_at)
exit_code = 2
print(
json.dumps(
receipt,
sort_keys=True,
indent=2 if args.pretty else None,
separators=None if args.pretty else (",", ":"),
)
)
return exit_code
if __name__ == "__main__":
raise SystemExit(main())
|