Spaces:
Running
Running
feat: add local self-validation command
Browse files- README.md +13 -0
- scripts/build_release.py +1 -0
- scripts/self_validate.py +226 -0
- scripts/verify_release.py +1 -0
README.md
CHANGED
|
@@ -81,4 +81,17 @@ To remove Eggcracker completely:
|
|
| 81 |
sudo python3 scripts/uninstall.py
|
| 82 |
```
|
| 83 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
See [SECURITY_MODEL.md](SECURITY_MODEL.md), [LIMITATIONS.md](LIMITATIONS.md), and [QUALIFICATION.md](QUALIFICATION.md) before using this engineering preview.
|
|
|
|
| 81 |
sudo python3 scripts/uninstall.py
|
| 82 |
```
|
| 83 |
|
| 84 |
+
## Local validation
|
| 85 |
+
|
| 86 |
+
Run a complete local qualification after installation. It uses the pinned external AI assets, takes several minutes, and writes a self-contained evidence directory; it does not publish anything.
|
| 87 |
+
|
| 88 |
+
```sh
|
| 89 |
+
sudo python3 scripts/self_validate.py \
|
| 90 |
+
--operator "$USER" \
|
| 91 |
+
--assets-manifest /opt/lumi-eggcracker-ai-smoke/ai-smoke-assets.json \
|
| 92 |
+
--evidence-dir /opt/lumi-eggcracker-evidence
|
| 93 |
+
```
|
| 94 |
+
|
| 95 |
+
It runs the real-AI approval smoke, renamed content matrix, benign model-handling matrix, descendants/startup/restart checks, autonomous regression and selected-workload security regression.
|
| 96 |
+
|
| 97 |
See [SECURITY_MODEL.md](SECURITY_MODEL.md), [LIMITATIONS.md](LIMITATIONS.md), and [QUALIFICATION.md](QUALIFICATION.md) before using this engineering preview.
|
scripts/build_release.py
CHANGED
|
@@ -115,6 +115,7 @@ def main() -> int:
|
|
| 115 |
ROOT / "scripts" / "run_content_matrix.py": "scripts/run_content_matrix.py",
|
| 116 |
ROOT / "scripts" / "run_content_benign_matrix.py": "scripts/run_content_benign_matrix.py",
|
| 117 |
ROOT / "scripts" / "run_content_adversarial_matrix.py": "scripts/run_content_adversarial_matrix.py",
|
|
|
|
| 118 |
ROOT / "scripts" / "run_autonomous_matrix.py": "scripts/run_autonomous_matrix.py",
|
| 119 |
}
|
| 120 |
with zipfile.ZipFile(bundle, "w", compression=zipfile.ZIP_DEFLATED, compresslevel=9) as archive:
|
|
|
|
| 115 |
ROOT / "scripts" / "run_content_matrix.py": "scripts/run_content_matrix.py",
|
| 116 |
ROOT / "scripts" / "run_content_benign_matrix.py": "scripts/run_content_benign_matrix.py",
|
| 117 |
ROOT / "scripts" / "run_content_adversarial_matrix.py": "scripts/run_content_adversarial_matrix.py",
|
| 118 |
+
ROOT / "scripts" / "self_validate.py": "scripts/self_validate.py",
|
| 119 |
ROOT / "scripts" / "run_autonomous_matrix.py": "scripts/run_autonomous_matrix.py",
|
| 120 |
}
|
| 121 |
with zipfile.ZipFile(bundle, "w", compression=zipfile.ZIP_DEFLATED, compresslevel=9) as archive:
|
scripts/self_validate.py
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Run Eggcracker's local full qualification and produce a portable evidence pack."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import argparse
|
| 6 |
+
import hashlib
|
| 7 |
+
import json
|
| 8 |
+
import os
|
| 9 |
+
import platform
|
| 10 |
+
import subprocess
|
| 11 |
+
import sys
|
| 12 |
+
from datetime import UTC, datetime
|
| 13 |
+
from pathlib import Path
|
| 14 |
+
from typing import Any
|
| 15 |
+
|
| 16 |
+
ROOT = Path(__file__).resolve().parents[1]
|
| 17 |
+
CLI = Path("/usr/local/bin/eggcracker")
|
| 18 |
+
POLICY = Path("/etc/lumi-eggcracker/policy.json")
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def run(argv: list[str], *, timeout: int = 900) -> None:
|
| 22 |
+
result = subprocess.run(argv, capture_output=True, text=True, check=False, timeout=timeout)
|
| 23 |
+
if result.returncode:
|
| 24 |
+
raise RuntimeError(
|
| 25 |
+
result.stderr.strip() or result.stdout.strip() or "qualification command failed"
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def digest(path: Path) -> str:
|
| 30 |
+
value = hashlib.sha256()
|
| 31 |
+
with path.open("rb") as handle:
|
| 32 |
+
for block in iter(lambda: handle.read(64 * 1024), b""):
|
| 33 |
+
value.update(block)
|
| 34 |
+
return value.hexdigest()
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def new_directory(path: Path) -> Path:
|
| 38 |
+
if not path.is_absolute() or path.exists() or path.is_symlink() or not path.parent.is_dir():
|
| 39 |
+
raise RuntimeError(
|
| 40 |
+
"evidence directory must be a new absolute child of an existing directory"
|
| 41 |
+
)
|
| 42 |
+
path.mkdir(mode=0o700)
|
| 43 |
+
return path
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def doctor(operator: str) -> dict[str, Any]:
|
| 47 |
+
result = subprocess.run(
|
| 48 |
+
["/usr/sbin/runuser", "-u", operator, "--", str(CLI), "doctor"],
|
| 49 |
+
capture_output=True,
|
| 50 |
+
text=True,
|
| 51 |
+
check=False,
|
| 52 |
+
timeout=30,
|
| 53 |
+
)
|
| 54 |
+
if result.returncode:
|
| 55 |
+
raise RuntimeError(result.stderr.strip() or "Eggcracker doctor failed")
|
| 56 |
+
value = json.loads(result.stdout)
|
| 57 |
+
if not isinstance(value, dict) or value.get("result") != "PASS":
|
| 58 |
+
raise RuntimeError("Eggcracker doctor did not pass")
|
| 59 |
+
return value
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
def main() -> int:
|
| 63 |
+
parser = argparse.ArgumentParser(
|
| 64 |
+
description="Run Eggcracker's complete local qualification against an installed instance."
|
| 65 |
+
)
|
| 66 |
+
parser.add_argument("--operator", required=True)
|
| 67 |
+
parser.add_argument("--assets-manifest", required=True, type=Path)
|
| 68 |
+
parser.add_argument("--evidence-dir", required=True, type=Path)
|
| 69 |
+
args = parser.parse_args()
|
| 70 |
+
if not hasattr(os, "geteuid") or os.geteuid() != 0:
|
| 71 |
+
raise SystemExit("self-validation must run as root")
|
| 72 |
+
evidence: Path | None = None
|
| 73 |
+
summary: dict[str, Any] = {
|
| 74 |
+
"result": "FAIL",
|
| 75 |
+
"schema_version": "lumi-eggcracker.self-validation.v1",
|
| 76 |
+
}
|
| 77 |
+
try:
|
| 78 |
+
evidence = new_directory(args.evidence_dir)
|
| 79 |
+
if not CLI.is_file() or not POLICY.is_file() or POLICY.is_symlink():
|
| 80 |
+
raise RuntimeError("Eggcracker is not installed")
|
| 81 |
+
policy = json.loads(POLICY.read_text(encoding="utf-8"))
|
| 82 |
+
if policy.get("operator_uid") is None or policy.get("source_commit") is None:
|
| 83 |
+
raise RuntimeError("installed policy is invalid")
|
| 84 |
+
checked = doctor(args.operator)
|
| 85 |
+
environment = {
|
| 86 |
+
"catalogue": checked["catalogue"],
|
| 87 |
+
"platform": platform.platform(),
|
| 88 |
+
"python": sys.version.split()[0],
|
| 89 |
+
"source_commit": policy["source_commit"],
|
| 90 |
+
"validated_utc": datetime.now(UTC).isoformat().replace("+00:00", "Z"),
|
| 91 |
+
"version": checked["version"],
|
| 92 |
+
}
|
| 93 |
+
(evidence / "environment.json").write_text(
|
| 94 |
+
json.dumps(environment, sort_keys=True) + "\n", encoding="utf-8"
|
| 95 |
+
)
|
| 96 |
+
(evidence / "doctor.json").write_text(
|
| 97 |
+
json.dumps(checked, sort_keys=True) + "\n", encoding="utf-8"
|
| 98 |
+
)
|
| 99 |
+
jobs = (
|
| 100 |
+
(
|
| 101 |
+
"real-ai-smoke.json",
|
| 102 |
+
[
|
| 103 |
+
"smoke_content_ai.py",
|
| 104 |
+
"--assets-manifest",
|
| 105 |
+
str(args.assets_manifest),
|
| 106 |
+
"--user",
|
| 107 |
+
args.operator,
|
| 108 |
+
"--repetitions",
|
| 109 |
+
"5",
|
| 110 |
+
],
|
| 111 |
+
),
|
| 112 |
+
(
|
| 113 |
+
"content-matrix.json",
|
| 114 |
+
[
|
| 115 |
+
"run_content_matrix.py",
|
| 116 |
+
"--assets-manifest",
|
| 117 |
+
str(args.assets_manifest),
|
| 118 |
+
"--user",
|
| 119 |
+
args.operator,
|
| 120 |
+
"--repetitions",
|
| 121 |
+
"100",
|
| 122 |
+
],
|
| 123 |
+
),
|
| 124 |
+
(
|
| 125 |
+
"benign-model-matrix.json",
|
| 126 |
+
[
|
| 127 |
+
"run_content_benign_matrix.py",
|
| 128 |
+
"--assets-manifest",
|
| 129 |
+
str(args.assets_manifest),
|
| 130 |
+
"--user",
|
| 131 |
+
args.operator,
|
| 132 |
+
"--repetitions",
|
| 133 |
+
"300",
|
| 134 |
+
],
|
| 135 |
+
),
|
| 136 |
+
(
|
| 137 |
+
"content-adversarial-matrix.json",
|
| 138 |
+
[
|
| 139 |
+
"run_content_adversarial_matrix.py",
|
| 140 |
+
"--assets-manifest",
|
| 141 |
+
str(args.assets_manifest),
|
| 142 |
+
"--user",
|
| 143 |
+
args.operator,
|
| 144 |
+
"--tree-repetitions",
|
| 145 |
+
"100",
|
| 146 |
+
"--startup-repetitions",
|
| 147 |
+
"20",
|
| 148 |
+
"--restart-repetitions",
|
| 149 |
+
"20",
|
| 150 |
+
],
|
| 151 |
+
),
|
| 152 |
+
(
|
| 153 |
+
"autonomous-regression.json",
|
| 154 |
+
[
|
| 155 |
+
"run_autonomous_matrix.py",
|
| 156 |
+
"--discoveries",
|
| 157 |
+
"100",
|
| 158 |
+
"--approved",
|
| 159 |
+
"50",
|
| 160 |
+
"--benign",
|
| 161 |
+
"200",
|
| 162 |
+
],
|
| 163 |
+
),
|
| 164 |
+
(
|
| 165 |
+
"selected-workload-regression.json",
|
| 166 |
+
[
|
| 167 |
+
"run_native_matrix.py",
|
| 168 |
+
"--fork-race-repetitions",
|
| 169 |
+
"100",
|
| 170 |
+
"--benign-repetitions",
|
| 171 |
+
"50",
|
| 172 |
+
"--restart-repetitions",
|
| 173 |
+
"20",
|
| 174 |
+
"--socket-attempts",
|
| 175 |
+
"100",
|
| 176 |
+
],
|
| 177 |
+
),
|
| 178 |
+
)
|
| 179 |
+
for filename, arguments in jobs:
|
| 180 |
+
run(
|
| 181 |
+
[
|
| 182 |
+
sys.executable,
|
| 183 |
+
str(ROOT / "scripts" / arguments[0]),
|
| 184 |
+
*arguments[1:],
|
| 185 |
+
"--output",
|
| 186 |
+
str(evidence / filename),
|
| 187 |
+
]
|
| 188 |
+
)
|
| 189 |
+
summary.update(
|
| 190 |
+
{
|
| 191 |
+
"result": "PASS",
|
| 192 |
+
"source_commit": policy["source_commit"],
|
| 193 |
+
"version": checked["version"],
|
| 194 |
+
}
|
| 195 |
+
)
|
| 196 |
+
(evidence / "validation.json").write_text(
|
| 197 |
+
json.dumps(summary, sort_keys=True) + "\n", encoding="utf-8"
|
| 198 |
+
)
|
| 199 |
+
report = "# Lumi Eggcracker local validation\n\nPASS: all precommitted local qualification matrices completed on the installed instance.\n"
|
| 200 |
+
(evidence / "report.md").write_text(report, encoding="utf-8")
|
| 201 |
+
sums = "".join(
|
| 202 |
+
f"{digest(path)} {path.name}\n"
|
| 203 |
+
for path in sorted(evidence.iterdir())
|
| 204 |
+
if path.name != "SHA256SUMS"
|
| 205 |
+
)
|
| 206 |
+
(evidence / "SHA256SUMS").write_text(sums, encoding="utf-8")
|
| 207 |
+
print(json.dumps({"evidence_dir": str(evidence), **summary}, sort_keys=True))
|
| 208 |
+
return 0
|
| 209 |
+
except (
|
| 210 |
+
OSError,
|
| 211 |
+
RuntimeError,
|
| 212 |
+
TypeError,
|
| 213 |
+
ValueError,
|
| 214 |
+
json.JSONDecodeError,
|
| 215 |
+
subprocess.SubprocessError,
|
| 216 |
+
) as error:
|
| 217 |
+
summary["error"] = str(error)
|
| 218 |
+
if evidence is not None:
|
| 219 |
+
(evidence / "validation.json").write_text(
|
| 220 |
+
json.dumps(summary, sort_keys=True) + "\n", encoding="utf-8"
|
| 221 |
+
)
|
| 222 |
+
raise SystemExit(f"self-validation failed: {error}") from error
|
| 223 |
+
|
| 224 |
+
|
| 225 |
+
if __name__ == "__main__":
|
| 226 |
+
raise SystemExit(main())
|
scripts/verify_release.py
CHANGED
|
@@ -90,6 +90,7 @@ def main() -> int:
|
|
| 90 |
"scripts/run_content_matrix.py",
|
| 91 |
"scripts/run_content_benign_matrix.py",
|
| 92 |
"scripts/run_content_adversarial_matrix.py",
|
|
|
|
| 93 |
"scripts/run_autonomous_matrix.py",
|
| 94 |
)
|
| 95 |
}
|
|
|
|
| 90 |
"scripts/run_content_matrix.py",
|
| 91 |
"scripts/run_content_benign_matrix.py",
|
| 92 |
"scripts/run_content_adversarial_matrix.py",
|
| 93 |
+
"scripts/self_validate.py",
|
| 94 |
"scripts/run_autonomous_matrix.py",
|
| 95 |
)
|
| 96 |
}
|