1fd37a2843
Phase 23 (v1.7) — tagging standards and security adapters.
* schemas/tagging-standard.json (D-054): canonical required-tags schema
(acdl:owner, acdl:contract, acdl:environment, acdl:cost-center).
* adapters/terraform/policy/custom_rules/acdl_tagging.py: Checkov custom
rule (ACDL_TAG_NAMING) loaded via --external-checks-dir; closes D-043
(synthetic SKIPPED record replaced by real PASS/FAIL records).
* checkov_adapter.py: removed _emit_tag_naming_skipped(), added
ACDL_TAG_NAMING to RULE_MAP, updated docstring.
* scripts/run_platform.sh: both Checkov invocations pass
--external-checks-dir adapters/terraform/policy/custom_rules/.
* adapters/wiz/ (D-052): Wiz adapter translating issue records to
PolicyCheckResult (engine: "wiz"); graceful degradation emits
WIZ_NOT_CONFIGURED SKIPPED when unconfigured; is_configured() gate.
* adapters/kyverno/ (D-053): Kyverno adapter translating PolicyReport
results to PolicyCheckResult (engine: "kyverno"); ready but inactive
for Terraform-only stacks; 3 sample ClusterPolicies in policies/.
* schemas/policy_check_result.schema.json: engine enum += "wiz".
* tests: fixtures + test_wiz_adapter.py (8 tests) + test_kyverno_adapter.py
(13 tests); updated test_checkov_adapter.py to not expect the removed
synthetic ACDL_TAG_NAMING SKIPPED record.
* scripts/run_ci.sh: lint stage compiles the new adapter modules.
202 tests pass; CI pipeline OK (lint + test + check-only).
Deviations:
- Wiz adapt() had an AttributeError on bare-list top-level input
(data.get() on a list); fixed to dispatch on isinstance(data, list)
before calling .get(). No spec change — bare-list handling is implied
by the original docstring's "data if isinstance(data, list)" branch.
- Kyverno _to_pcr({}) defaults result to "skipped" (entry.get("result",
"skip") -> "skip"), not "error"; test expectation corrected. Added an
explicit unknown-result-string test to cover the "error" fallback.
---ci---
project: acdl
phase: 23
milestone: v1.7
status: execute
---/ci---
127 lines
4.8 KiB
Python
127 lines
4.8 KiB
Python
import json
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
import jsonschema
|
|
import pytest
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
|
|
|
from adapters.terraform.policy.checkov_adapter import (
|
|
RULE_MAP, _to_pcr, adapt,
|
|
)
|
|
|
|
|
|
class TestRuleMap:
|
|
def test_secrets_rules(self):
|
|
assert RULE_MAP["CKV_AWS_41"][0] == "secrets-in-plaintext"
|
|
assert RULE_MAP["CKV_AWS_45"][0] == "secrets-in-plaintext"
|
|
|
|
def test_public_ingress_rules(self):
|
|
assert RULE_MAP["CKV_AWS_20"][0] == "public-ingress"
|
|
assert RULE_MAP["CKV_AWS_57"][0] == "public-ingress"
|
|
|
|
def test_iam_wildcard(self):
|
|
assert RULE_MAP["CKV_AWS_1"][0] == "iam-wildcard"
|
|
|
|
def test_kms(self):
|
|
assert RULE_MAP["CKV_AWS_7"][0] == "kms-key-reference"
|
|
|
|
def test_all_have_severities(self):
|
|
for rule_id, (cat, sev) in RULE_MAP.items():
|
|
assert sev in ("high", "medium", "low", "info"), f"{rule_id} has bad severity {sev}"
|
|
|
|
|
|
class TestToPcr:
|
|
def test_passed_result(self):
|
|
rec = {"check_id": "CKV_AWS_20", "check_name": "No public ingress", "file_path": "main.tf"}
|
|
pcr = _to_pcr(rec, "contract-123", "PASSED")
|
|
assert pcr["result"] == "pass"
|
|
assert pcr["contractId"] == "contract-123"
|
|
assert pcr["engine"] == "checkov"
|
|
assert pcr["ruleId"] == "CKV_AWS_20"
|
|
assert pcr["severity"] == "high"
|
|
|
|
def test_failed_result(self):
|
|
rec = {"check_id": "CKV_AWS_1", "check_name": "No wildcard IAM"}
|
|
pcr = _to_pcr(rec, "c-1", "FAILED")
|
|
assert pcr["result"] == "fail"
|
|
assert pcr["severity"] == "high"
|
|
|
|
def test_skipped_result(self):
|
|
rec = {"check_id": "UNKNOWN_RULE", "check_name": "some check"}
|
|
pcr = _to_pcr(rec, "c-1", "SKIPPED")
|
|
assert pcr["result"] == "skipped"
|
|
assert pcr["severity"] == "info"
|
|
|
|
def test_unknown_rule_defaults_to_info(self):
|
|
rec = {"check_id": "UNKNOWN_RULE", "check_name": "unknown"}
|
|
pcr = _to_pcr(rec, "c-1", "FAILED")
|
|
assert pcr["severity"] == "info"
|
|
|
|
def test_pcr_validates_against_schema(self, policy_check_result_schema):
|
|
rec = {"check_id": "CKV_AWS_20", "check_name": "test", "file_path": "main.tf",
|
|
"resource": "aws_s3_bucket.s3", "resource_address": "aws_s3_bucket.s3"}
|
|
pcr = _to_pcr(rec, "c-1", "FAILED")
|
|
jsonschema.validate(pcr, policy_check_result_schema)
|
|
|
|
|
|
class TestRuleMapTagging:
|
|
def test_acdl_tag_naming_is_real_rule(self):
|
|
# D-054 / D-043 closure: ACDL_TAG_NAMING is now a real custom Checkov
|
|
# rule, not a synthetic SKIPPED record.
|
|
assert RULE_MAP["ACDL_TAG_NAMING"] == ("tagging-standard", "medium")
|
|
|
|
|
|
class TestAdapt:
|
|
def _sample_checkov_json(self):
|
|
return {
|
|
"terraform_plan": {
|
|
"results": {
|
|
"passed_checks": [
|
|
{"check_id": "CKV_AWS_20", "check_name": "no public ingress",
|
|
"file_path": "main.tf", "resource": "aws_vpc.vpc"}
|
|
],
|
|
"failed_checks": [
|
|
{"check_id": "CKV_AWS_1", "check_name": "no wildcard iam",
|
|
"file_path": "main.tf", "resource": "aws_iam_role.r"}
|
|
],
|
|
"skipped_checks": []
|
|
}
|
|
}
|
|
}
|
|
|
|
def test_adapt_returns_list(self, tmp_path):
|
|
data = self._sample_checkov_json()
|
|
f = tmp_path / "checkov.json"
|
|
f.write_text(json.dumps(data))
|
|
results = adapt(str(f), "c-1")
|
|
assert isinstance(results, list)
|
|
|
|
def test_adapt_does_not_emit_synthetic_tag_naming(self, tmp_path):
|
|
# D-043 closure: adapt() no longer appends a synthetic SKIPPED
|
|
# ACDL_TAG_NAMING record. The custom Checkov rule (loaded via
|
|
# --external-checks-dir) produces real PASS/FAIL records instead.
|
|
data = self._sample_checkov_json()
|
|
f = tmp_path / "checkov.json"
|
|
f.write_text(json.dumps(data))
|
|
results = adapt(str(f), "c-1")
|
|
tag = [r for r in results if r["ruleId"] == "ACDL_TAG_NAMING"]
|
|
assert tag == [] # no synthetic record
|
|
|
|
def test_adapt_has_passed_and_failed(self, tmp_path):
|
|
data = self._sample_checkov_json()
|
|
f = tmp_path / "checkov.json"
|
|
f.write_text(json.dumps(data))
|
|
results = adapt(str(f), "c-1")
|
|
passed = [r for r in results if r["result"] == "pass"]
|
|
failed = [r for r in results if r["result"] == "fail"]
|
|
assert len(passed) >= 1
|
|
assert len(failed) >= 1
|
|
|
|
def test_adapt_empty_input(self, tmp_path):
|
|
data = {"terraform_plan": {"results": {"passed_checks": [], "failed_checks": [], "skipped_checks": []}}}
|
|
f = tmp_path / "checkov.json"
|
|
f.write_text(json.dumps(data))
|
|
results = adapt(str(f), "c-1")
|
|
assert results == [] # no synthetic tag-naming record anymore |