e74a8c2f5d
---ci--- project: acdl phase: 42 milestone: v1.9 status: execute ---/ci--- Phase 42 — stub-implementation (REQ-107..111, D-084): route_halt_artifact (REQ-107): - core/separation_of_duties.py: real SNS publish (ACDL_SOD_HALT_TOPIC_ARN) + outbox fallback (SEPARATION_OF_DUTIES_VIOLATION event via outbox_writer) + stderr emission. No silent print-only stub. - terraform/platform/main.tf: aws_sns_topic.acdl-sod-halt + output. HITL attestation gates (REQ-108): - core/hitl_gates.py: attest(contract_id, env, approver, evidence, outbox_client) records approver_qa/approver_prod/approver_dr to outbox, runs SoD check on prod, invokes attestation matrix, returns (ok, reason). Dev skips (autonomous). approver_from_env() reads GITHUB_ACTOR/GITEA_ACTOR. - scripts/run_platform.sh: Step 7b HITL gate before apply for qa/prod/dr. 8-concern attestation matrix (REQ-109, D-084): - core/attestation_matrix.py: check(env, evidence) runs the 8 concerns from hitl_matrix_design.md §10.4. Offline-testable (contract_nfrs, schema_validity, policy_pass) run for real. Operator-supplied accept signed artifacts validated for freshness (FRESHNESS_DAYS table) + schema. Signature skip when ACDL_ATTESTATION_SIGNING_KEY_ID unset (D-089). Fail loud if missing/expired for prod/dr. Wiz real client (REQ-110): - adapters/wiz/wiz_adapter.py: WizClient (GraphQL API, Bearer auth, pagination via pageInfo.hasNextPage + endCursor). fetch_and_adapt translates issues → PolicyCheckResult; graceful degrade when WIZ_API_TOKEN/WIZ_API_URL unset. Kyverno fleshed out (REQ-111): - adapters/kyverno/kyverno_adapter.py: full PolicyReport → PolicyCheckResult mapping (pass/fail/skip/warn + severity + skip-with- reason + resource ref construction from kind/name/namespace). adapt_inactive() emits KYVERNO_INACTIVE_TF_STACK guard. --kube-version stub parsed for future GitOps. Tests: +47 (test_route_halt_artifact.py, test_hitl_gates.py, test_attestation_matrix.py, test_wiz_adapter_real_client.py, expanded test_kyverno_adapter.py). Existing wiz_adapter tests updated for the real client's control.name ruleId. 493 passed; run_ci.sh green; run_platform.sh --check-only green.
136 lines
5.0 KiB
Python
136 lines
5.0 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_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 |