Skip to content

Commit 24a9fc8

Browse files
committed
chore: use build type function; remove old slsa verifier check
Signed-off-by: Ben Selwyn-Smith <[email protected]>
1 parent 83a1f3e commit 24a9fc8

File tree

4 files changed

+15
-14
lines changed

4 files changed

+15
-14
lines changed

src/macaron/database/db_custom_types.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,9 @@ def process_result_value(self, value: str | None, dialect: Any) -> InTotoPayload
149149
raise TypeError("Missing keys in dict for ProvenancePayload type.")
150150

151151
payload = payload_dict["payload"]
152-
if payload["payload_type"] == "InTotoV01Payload":
152+
if payload_dict["payload_type"] == "InTotoV01Payload":
153153
return InTotoV01Payload(statement=payload)
154-
if payload["payload_type"] == "InTotoV1Payload":
154+
if payload_dict["payload_type"] == "InTotoV1Payload":
155155
return InTotoV1Payload(statement=payload)
156156

157157
return validate_intoto_payload(payload)

src/macaron/provenance/provenance_verifier.py

+4-7
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
from macaron.config.defaults import defaults
1818
from macaron.config.global_config import global_config
19-
from macaron.json_tools import json_extract
19+
from macaron.provenance.provenance_extractor import ProvenancePredicate
2020
from macaron.repo_finder.commit_finder import AbstractPurlType, determine_abstract_purl_type
2121
from macaron.slsa_analyzer.analyze_context import AnalyzeContext
2222
from macaron.slsa_analyzer.asset import AssetLocator
@@ -199,6 +199,7 @@ def verify_ci_provenance(analyze_ctx: AnalyzeContext, ci_info: CIInfo, download_
199199
)
200200

201201
if not sub_verified:
202+
logger.info("Sub asset not verified: %s", sub_asset["name"])
202203
return False
203204

204205
if sub_verified:
@@ -322,10 +323,8 @@ def _verify_slsa(
322323
cwd=download_path,
323324
timeout=defaults.getint("slsa.verifier", "timeout", fallback=120),
324325
)
325-
326326
output = verifier_output.stdout.decode("utf-8")
327-
verified = "PASSED: Verified SLSA provenance" in output
328-
327+
verified = "PASSED: SLSA verification passed" in output
329328
log_path = os.path.join(global_config.build_log_path, f"{os.path.basename(source_path)}.slsa_verifier.log")
330329
with open(log_path, mode="a", encoding="utf-8") as log_file:
331330
logger.info("Storing SLSA verifier output for %s to %s", asset_name, log_path)
@@ -385,9 +384,7 @@ def determine_provenance_slsa_level(
385384
predicate = provenance_payload.statement.get("predicate")
386385
build_type = None
387386
if predicate:
388-
build_type = json_extract(predicate, ["buildDefinition", "buildType"], str)
389-
if not build_type:
390-
build_type = json_extract(predicate, ["buildType"], str)
387+
build_type = ProvenancePredicate.get_build_type(provenance_payload.statement)
391388

392389
if build_type == "https://github.com/slsa-framework/slsa-github-generator/generic@v1" and verified_l3:
393390
# 3. Provenance is created by the SLSA GitHub generator and verified.

src/macaron/slsa_analyzer/checks/provenance_l3_check.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,12 @@ def run_check(self, ctx: AnalyzeContext) -> CheckResultData:
6868
"""
6969
result_tables: list[CheckFacts] = []
7070
result_value = CheckResultType.FAILED
71-
if ctx.dynamic_data["provenance_info"] and ctx.dynamic_data["provenance_info"].slsa_level == 3:
71+
prov = ctx.dynamic_data["provenance_info"] or None
72+
slsa = 0
73+
if prov:
74+
slsa = prov.slsa_level
75+
76+
if prov and slsa == 3:
7277
result_tables.append(ProvenanceL3VerifiedFacts(confidence=Confidence.HIGH))
7378
result_value = CheckResultType.PASSED
7479

src/macaron/slsa_analyzer/checks/provenance_verified_check.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from sqlalchemy.orm import Mapped, mapped_column
99

1010
from macaron.database.table_definitions import CheckFacts
11-
from macaron.json_tools import json_extract
11+
from macaron.provenance.provenance_extractor import ProvenancePredicate
1212
from macaron.slsa_analyzer.analyze_context import AnalyzeContext
1313
from macaron.slsa_analyzer.checks.base_check import BaseCheck
1414
from macaron.slsa_analyzer.checks.check_result import CheckResultData, CheckResultType, Confidence, JustificationType
@@ -69,10 +69,9 @@ def run_check(self, ctx: AnalyzeContext) -> CheckResultData:
6969
"""
7070
build_type = None
7171
provenance_info = ctx.dynamic_data["provenance_info"]
72+
7273
if provenance_info and provenance_info.provenance_payload:
73-
predicate = provenance_info.provenance_payload.statement.get("predicate")
74-
if predicate:
75-
build_type = json_extract(predicate, ["buildDefinition", "buildType"], str)
74+
build_type = ProvenancePredicate.get_build_type(provenance_info.provenance_payload.statement)
7675

7776
slsa_level = 0
7877
if provenance_info:

0 commit comments

Comments
 (0)