6e41f09c6e
---ci--- phase: 43 milestone: v1.9 status: verify lessons: - P0 fix: run_platform.sh HITL gate passed approver via string interpolation into Python (GITHUB_ACTOR injection vector) — fixed by passing env vars (ACDL_HITL_*) read via os.environ - P1 fix: attestation_matrix._is_fresh accepted future-dated artifacts (negative age bypassed freshness) — fixed with negative-age guard + test - P1 flagged: WizClient._post does not check GraphQL errors (silent empty-list mask) - P1 flagged: WizClient._post no SSRF validation on WIZ_API_URL - P1 flagged: contract_resolver._load_env duplicates environment_check.load (can drift) ---/ci--- Multi-persona review of the v1.9 diff (v1.8.0..HEAD). Review pass 2 (post-complete) caught issues the initial self-review missed: P0-INJECT (auto-fixed): scripts/run_platform.sh Step 7b interpolated $APPROVER (GITHUB_ACTOR/GITEA_ACTOR) directly into a Python string literal — an attacker-controllable username containing shell/python metacharacters would execute arbitrary Python. Fixed: approver, contract id, and env are now passed as environment variables to the subprocess and read via os.environ[...] (no string interpolation). P1-FRESHNESS (auto-fixed): core/attestation_matrix.py _is_fresh accepted future-dated artifacts (negative age.days <= window_days). Fixed: added age.total_seconds() < 0 guard rejecting future timestamps. Test added: test_freshness_rejects_future_dated_artifact. 3 P1 flagged for post-hoc: - WizClient._post does not surface GraphQL errors (silent empty mask) - WizClient._post no SSRF validation on WIZ_API_URL (operator-supplied, low risk) - contract_resolver._load_env duplicates environment_check.load (drift risk) REVIEW.md updated with the findings. 494 tests pass; run_ci.sh + run_platform.sh --check-only green.
143 lines
5.4 KiB
Python
143 lines
5.4 KiB
Python
"""REQ-109: 8-concern attestation matrix."""
|
|
import datetime
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
ROOT = Path(__file__).resolve().parent.parent
|
|
sys.path.insert(0, str(ROOT))
|
|
|
|
from core.attestation_matrix import check, _is_fresh, _verify_signature, FRESHNESS_DAYS
|
|
|
|
|
|
def _fresh_artifact(concern, days_ago=0):
|
|
ts = datetime.datetime.now(datetime.timezone.utc) - datetime.timedelta(days=days_ago)
|
|
return {"timestamp": ts.isoformat(), "type": concern, "payload": {}, "signature": "sig"}
|
|
|
|
|
|
def test_dev_passes_autonomous():
|
|
ok, reason = check("dev", {})
|
|
assert ok is True
|
|
assert "autonomous" in reason
|
|
|
|
|
|
def test_qa_offline_concerns_pass_with_valid_evidence():
|
|
"""qa concerns: functional_correctness, performance_baseline, security_posture, contract_nfrs.
|
|
The offline-testable contract_nfrs passes by default; the operator-supplied
|
|
ones require artifacts."""
|
|
evidence = {
|
|
"functional_correctness": _fresh_artifact("functional_correctness"),
|
|
"performance_baseline": _fresh_artifact("performance_baseline"),
|
|
"security_posture": _fresh_artifact("security_posture"),
|
|
"contract_nfrs": {"valid": True},
|
|
}
|
|
ok, reason = check("qa", evidence)
|
|
assert ok is True
|
|
|
|
|
|
def test_qa_blocks_on_missing_operator_concern():
|
|
"""A missing operator-supplied concern blocks qa."""
|
|
evidence = {
|
|
"performance_baseline": _fresh_artifact("performance_baseline"),
|
|
"security_posture": _fresh_artifact("security_posture"),
|
|
"contract_nfrs": {"valid": True},
|
|
# functional_correctness missing
|
|
}
|
|
ok, reason = check("qa", evidence)
|
|
assert ok is False
|
|
assert "functional_correctness" in reason
|
|
|
|
|
|
def test_prod_blocks_on_missing_evidence():
|
|
ok, reason = check("prod", {})
|
|
assert ok is False
|
|
assert "missing" in reason or "expired" in reason
|
|
|
|
|
|
def test_prod_passes_with_all_evidence():
|
|
evidence = {
|
|
"operational_readiness": _fresh_artifact("operational_readiness"),
|
|
"incident_response": _fresh_artifact("incident_response"),
|
|
"capacity_cost": _fresh_artifact("capacity_cost"),
|
|
"resilience_dr_drill": _fresh_artifact("resilience_dr_drill"),
|
|
"resilience_chaos": _fresh_artifact("resilience_chaos"),
|
|
"resilience_backup": _fresh_artifact("resilience_backup"),
|
|
"contract_nfrs": {"valid": True},
|
|
}
|
|
ok, reason = check("prod", evidence)
|
|
assert ok is True
|
|
|
|
|
|
def test_expired_artifact_blocks():
|
|
"""An artifact older than its freshness window blocks."""
|
|
evidence = {
|
|
"operational_readiness": _fresh_artifact("operational_readiness", days_ago=31),
|
|
"incident_response": _fresh_artifact("incident_response"),
|
|
"capacity_cost": _fresh_artifact("capacity_cost"),
|
|
"resilience_dr_drill": _fresh_artifact("resilience_dr_drill"),
|
|
"resilience_chaos": _fresh_artifact("resilience_chaos"),
|
|
"resilience_backup": _fresh_artifact("resilience_backup"),
|
|
"contract_nfrs": {"valid": True},
|
|
}
|
|
ok, reason = check("prod", evidence)
|
|
assert ok is False
|
|
assert "operational_readiness" in reason
|
|
|
|
|
|
def test_dr_passes_with_evidence():
|
|
evidence = {
|
|
"dr_region_deploy": _fresh_artifact("dr_region_deploy"),
|
|
"contract_nfrs": {"valid": True},
|
|
}
|
|
ok, reason = check("dr", evidence)
|
|
assert ok is True
|
|
|
|
|
|
def test_dr_blocks_on_missing_dr_drill():
|
|
ok, reason = check("dr", {"contract_nfrs": {"valid": True}})
|
|
assert ok is False
|
|
assert "dr_region_deploy" in reason
|
|
|
|
|
|
def test_signature_skip_when_key_unset(monkeypatch, capsys):
|
|
"""D-089: signature verification is skipped when the signing key is unset."""
|
|
monkeypatch.delenv("ACDL_ATTESTATION_SIGNING_KEY_ID", raising=False)
|
|
artifact = {"timestamp": datetime.datetime.now(datetime.timezone.utc).isoformat(),
|
|
"type": "x", "payload": {}, "signature": "sig"}
|
|
assert _verify_signature(artifact) is True
|
|
captured = capsys.readouterr()
|
|
assert "skipped" in captured.err
|
|
|
|
|
|
def test_signature_required_when_key_set(monkeypatch):
|
|
"""When the signing key is set, a missing signature fails."""
|
|
monkeypatch.setenv("ACDL_ATTESTATION_SIGNING_KEY_ID", "kms-key-id")
|
|
artifact = {"timestamp": datetime.datetime.now(datetime.timezone.utc).isoformat(),
|
|
"type": "x", "payload": {}} # no signature
|
|
assert _verify_signature(artifact) is False
|
|
|
|
|
|
def test_freshness_within_window():
|
|
artifact = _fresh_artifact("functional_correctness", days_ago=0)
|
|
assert _is_fresh(artifact, "functional_correctness") is True
|
|
|
|
|
|
def test_freshness_outside_window():
|
|
artifact = _fresh_artifact("functional_correctness", days_ago=2)
|
|
assert _is_fresh(artifact, "functional_correctness") is False
|
|
|
|
|
|
def test_freshness_rejects_future_dated_artifact():
|
|
"""A future-dated artifact (negative age) must not bypass freshness (review fix)."""
|
|
future = datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta(days=100)
|
|
artifact = {"timestamp": future.isoformat(), "type": "x", "payload": {}}
|
|
assert _is_fresh(artifact, "operational_readiness") is False
|
|
|
|
|
|
def test_freshness_days_table_has_all_concerns():
|
|
"""The freshness table covers all operator-supplied concerns."""
|
|
for concern in ["functional_correctness", "performance_baseline", "security_posture",
|
|
"operational_readiness", "incident_response", "capacity_cost",
|
|
"resilience_dr_drill", "dr_region_deploy"]:
|
|
assert concern in FRESHNESS_DAYS |