From 625399b52b183ea2d188660d64ef2710dddcd819 Mon Sep 17 00:00:00 2001 From: behnazh-w Date: Fri, 20 Nov 2026 11:31:21 +1000 Subject: [PATCH 1/5] fix: preserve workflow analysis errors in GitHub Actions finding Signed-off-by: behnazh-w --- .../detect_vulnerable_github_actions.rst | 6 + .../code_analyzer/dataflow_analysis/core.py | 5 +- src/macaron/parsers/actionparser.py | 12 +- .../github_actions_vulnerability_check.py | 36 ++++- .../github_actions/github_actions_ci.py | 13 +- ...test_github_actions_vulnerability_check.py | 151 +++++++++++++++++- 6 files changed, 212 insertions(+), 11 deletions(-) diff --git a/docs/source/pages/tutorials/detect_vulnerable_github_actions.rst b/docs/source/pages/tutorials/detect_vulnerable_github_actions.rst index 4f37e6138..87bec7e40 100644 --- a/docs/source/pages/tutorials/detect_vulnerable_github_actions.rst +++ b/docs/source/pages/tutorials/detect_vulnerable_github_actions.rst @@ -211,6 +211,12 @@ does not remove an unpinned finding. Missing lockfiles preserve inline SHA check invalid or unsupported present lockfiles produce actionable findings. Regenerate and review the lockfile when dependencies change. +If Macaron cannot parse or analyze a workflow, it reports +``workflow-analysis-incomplete`` with the affected workflow and available error +details. For schema validation failures, the message identifies the rejected +field or value and its location. Fix the workflow error and rerun the analysis; +regenerating the lockfile does not resolve a workflow parsing failure. + For further reading, see GitHub's announcement: `GitHub Actions workflow lockfiles are generally available `_. diff --git a/src/macaron/code_analyzer/dataflow_analysis/core.py b/src/macaron/code_analyzer/dataflow_analysis/core.py index 2fd1db26e..ef80f458f 100644 --- a/src/macaron/code_analyzer/dataflow_analysis/core.py +++ b/src/macaron/code_analyzer/dataflow_analysis/core.py @@ -286,11 +286,14 @@ class NodeForest: root_nodes: list[Node] #: Mapping of nodes to their parent nodes. parents: dict[Node, Node] + #: Source files that could not be analyzed, with concise diagnostics for consumers. + analysis_errors: dict[str, str] - def __init__(self, root_nodes: list[Node]) -> None: + def __init__(self, root_nodes: list[Node], *, analysis_errors: dict[str, str] | None = None) -> None: """Construct a NodeForest for the given nodes, and build the parent mapping.""" self.root_nodes = root_nodes self.parents = {} + self.analysis_errors = dict(analysis_errors) if analysis_errors is not None else {} for root_node in root_nodes: root_node_parents = build_parent_mapping(root_node) self.parents.update(root_node_parents) diff --git a/src/macaron/parsers/actionparser.py b/src/macaron/parsers/actionparser.py index f26f58994..1ccf4631f 100644 --- a/src/macaron/parsers/actionparser.py +++ b/src/macaron/parsers/actionparser.py @@ -10,6 +10,7 @@ import jsonschema import yamale +from ruamel.yaml.error import MarkedYAMLError from macaron import MACARON_PATH from macaron.errors import ParseError @@ -40,6 +41,12 @@ def parse(workflow_path: str) -> Workflow: parse_result = yamale.make_data(workflow_path, parser="ruamel") # type: ignore[no-untyped-call] except OSError as error: raise ParseError("Cannot parse GitHub Workflow: " + workflow_path) from error + except MarkedYAMLError as error: + location = "" + if error.problem_mark is not None: + location = f" at line {error.problem_mark.line + 1}, column {error.problem_mark.column + 1}" + problem = error.problem or error.context or "Invalid YAML syntax" + raise ParseError(f"Cannot parse GitHub workflow {workflow_path}: invalid YAML{location}: {problem}") from error if len(parse_result) != 1: raise ParseError("Cannot parse GitHub Workflow: " + workflow_path) @@ -52,7 +59,10 @@ def parse(workflow_path: str) -> Workflow: try: jsonschema.validate(parse_result[0][0], schema) except jsonschema.ValidationError as e: - raise ParseError("Cannot parse GitHub Workflow, schema validation failed: " + workflow_path) from e + raise ParseError( + f"Cannot parse GitHub workflow {workflow_path}: schema validation failed at {e.json_path}: {e.message}. " + "Check the workflow syntax: https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-syntax" + ) from e return cast(Workflow, parse_result[0][0]) diff --git a/src/macaron/slsa_analyzer/checks/github_actions_vulnerability_check.py b/src/macaron/slsa_analyzer/checks/github_actions_vulnerability_check.py index 55ab1a09b..626646602 100644 --- a/src/macaron/slsa_analyzer/checks/github_actions_vulnerability_check.py +++ b/src/macaron/slsa_analyzer/checks/github_actions_vulnerability_check.py @@ -175,6 +175,7 @@ class WorkflowActionAnalysis: actions: list[ResolvedWorkflowAction] errors: dict[str, ActionsLockfileError] + workflow_errors: dict[str, str] def collect_resolved_workflow_actions( @@ -188,6 +189,7 @@ def collect_resolved_workflow_actions( actions: dict[tuple[str, str, str], ResolvedWorkflowAction] = {} workflows: dict[str, str] = {} errors: dict[str, ActionsLockfileError] = {} + workflow_errors = dict(callgraph.analysis_errors) for root in callgraph.root_nodes: for node in traverse_bfs(root): if isinstance(node, GitHubActionsWorkflowNode): @@ -244,8 +246,9 @@ def collect_resolved_workflow_actions( if repo_root: for relative in lockfile.workflows: if relative not in workflows and (repo_root / relative).is_file(): - errors[str(repo_root / relative)] = ActionsLockfileError( - f"{lockfile.path}: adopted workflow {relative} could not be analyzed" + workflow_errors.setdefault( + str(repo_root / relative), + f"Workflow {relative} could not be analyzed; its lockfile coverage could not be checked", ) for relative, source in workflows.items(): try: @@ -279,6 +282,7 @@ def collect_resolved_workflow_actions( key=lambda action: (action.caller_path, action.name, action.version), ), errors, + workflow_errors, ) @@ -371,6 +375,32 @@ def run_check(self, ctx: AnalyzeContext) -> CheckResultData: action_analysis = collect_resolved_workflow_actions(callgraph, repo_root, lockfile) resolution_errors.extend(action_analysis.errors.values()) resolved_actions = action_analysis.actions + for source, diagnostic in action_analysis.workflow_errors.items(): + # Report the discovered workflow path, not a symlink target outside the checkout. + caller_path = ( + Path(source).absolute().relative_to(repo_root.absolute()).as_posix() if repo_root else source + ) + if gh_api_client: + caller_path = gh_api_client.get_file_link( + repository.full_name, repository.commit_sha, file_path=caller_path + ) + result_tables.append( + GitHubActionsVulnsFacts( + caller_workflow=caller_path, + finding_type="workflow-analysis-incomplete", + finding_group=GitHubActionsFindingGroup.WORKFLOW_SECURITY_ISSUE.value, + finding_message=( + f"Workflow security analysis is incomplete: {diagnostic}. " + "Resolve the workflow analysis error and rerun Macaron." + ), + finding_priority=80, + action_name=None, + action_ref=None, + sha_pinned=None, + vuln_urls=[], + confidence=Confidence.HIGH, + ) + ) if lockfile_error is not None: resolved_actions = [ action @@ -381,7 +411,7 @@ def run_check(self, ctx: AnalyzeContext) -> CheckResultData: callgraph, lockfile=lockfile, repo_root=repo_root, - unresolved_workflows=frozenset(action_analysis.errors), + unresolved_workflows=frozenset(action_analysis.errors) | frozenset(action_analysis.workflow_errors), ) if workflow_findings: for finding in workflow_findings: diff --git a/src/macaron/slsa_analyzer/ci_service/github_actions/github_actions_ci.py b/src/macaron/slsa_analyzer/ci_service/github_actions/github_actions_ci.py index b9c975297..b13d61f6d 100644 --- a/src/macaron/slsa_analyzer/ci_service/github_actions/github_actions_ci.py +++ b/src/macaron/slsa_analyzer/ci_service/github_actions/github_actions_ci.py @@ -604,20 +604,23 @@ def build_call_graph_for_files(self, files: list[str], repo_path: str) -> NodeFo Returns ------- NodeForest - A forest containing one root node per successfully parsed workflow. - Workflows that raise ``ParseError`` are skipped. + A forest containing successfully analyzed workflows and diagnostics for skipped files. """ nodes: list[Node] = [] + analysis_errors: dict[str, str] = {} for workflow_path in files: try: workflow_node = analyse_github_workflow_file(workflow_path, repo_path) - except (ParseError, CallGraphError): - logger.debug("Skip adding workflow at %s to the callgraph.", workflow_path) + except (ParseError, CallGraphError) as error: + # Preserve the concise parser diagnostic instead of the schema/instance traceback. + cause = error.__cause__ if isinstance(error.__cause__, (ParseError, CallGraphError)) else error + analysis_errors[workflow_path] = str(cause) + logger.warning("Cannot analyze GitHub Actions workflow %s: %s", workflow_path, cause) logger.debug("Reason: %s", traceback.format_exc()) continue nodes.append(workflow_node) - return NodeForest(nodes) + return NodeForest(nodes, analysis_errors=analysis_errors) def get_third_party_configurations(self) -> list[str]: """Get the list of third-party CI configuration files. diff --git a/tests/slsa_analyzer/checks/test_github_actions_vulnerability_check.py b/tests/slsa_analyzer/checks/test_github_actions_vulnerability_check.py index f44a6393c..db7bbc409 100644 --- a/tests/slsa_analyzer/checks/test_github_actions_vulnerability_check.py +++ b/tests/slsa_analyzer/checks/test_github_actions_vulnerability_check.py @@ -23,6 +23,7 @@ collect_resolved_workflow_actions, ) from macaron.slsa_analyzer.ci_service.base_ci_service import BaseCIService +from macaron.slsa_analyzer.ci_service.github_actions.github_actions_ci import GitHubActions from macaron.slsa_analyzer.package_registry.osv_dev import OSVDevService from macaron.slsa_analyzer.provenance.intoto import InTotoV01Payload from macaron.slsa_analyzer.specs.ci_spec import CIInfo @@ -290,7 +291,155 @@ def test_adopted_workflow_cannot_be_silently_skipped( assert len(result.result_tables) == 1 fact = result.result_tables[0] assert isinstance(fact, GitHubActionsVulnsFacts) - assert fact.finding_type == "invalid-actions-lockfile" + assert fact.finding_type == "workflow-analysis-incomplete" + assert "ci.yml" in fact.caller_workflow + assert "gh actions-lock" not in (fact.finding_message or "") + + +@pytest.mark.parametrize("with_lockfile", [True, False]) +@pytest.mark.parametrize( + ("invalid_field", "runner", "needs", "expected_location", "expected_detail"), + [ + ("description: Build GraalVM\n", "ubuntu-latest", "", "$", "'description' was unexpected"), + ("", "17", "", "$.jobs.build['runs-on']", "17"), + ("", "ubuntu-latest", " needs: missing-job\n", "needs", "needs refers to invalid job 'missing-job'"), + ], +) +def test_workflow_analysis_errors_reach_the_security_report( + tmp_path: Path, + monkeypatch: pytest.MonkeyPatch, + ci_services: dict[str, BaseCIService], + caplog: pytest.LogCaptureFixture, + with_lockfile: bool, + invalid_field: str, + runner: str, + needs: str, + expected_location: str, + expected_detail: str, +) -> None: + """Keep the parser cause and workflow attribution instead of blaming a valid lockfile.""" + directory = tmp_path / ".github/workflows" + directory.mkdir(parents=True) + broken = directory / "broken.yml" + broken.write_text( + f"name: Build\n{invalid_field}on: push\npermissions: {{}}\njobs:\n" + f" build:\n{needs} runs-on: {runner}\n steps:\n - run: echo hello\n", + encoding="utf-8", + ) + healthy = directory / "healthy.yml" + healthy.write_text( + "on: push\npermissions: {}\njobs:\n build:\n runs-on: ubuntu-latest\n" + " steps:\n - uses: example/healthy@v1\n", + encoding="utf-8", + ) + if with_lockfile: + (directory / "actions.lock").write_text( + "version: v0.0.3\nworkflows:\n .github/workflows/broken.yml: []\ndependencies: {}\n", + encoding="utf-8", + ) + service = ci_services["github_actions"] + assert isinstance(service, GitHubActions) + info = get_ci_info(ci_services, "jenkins", "") + info["service"] = service + info["callgraph"] = service.build_call_graph_for_files([str(broken), str(healthy)], str(tmp_path)) + ctx = MockAnalyzeContext(fs_path=str(tmp_path)) + ctx.dynamic_data["ci_services"] = [info] + monkeypatch.setattr(OSVDevService, "get_vulnerabilities_package_name_batch", lambda _: []) + monkeypatch.setattr(service.api_client, "get_commit_sha_from_ref", lambda *_: None) + result = GitHubActionsVulnsCheck().run_check(ctx) + assert result.result_type == CheckResultType.FAILED + diagnostics = [] + for fact in result.result_tables: + assert isinstance(fact, GitHubActionsVulnsFacts) + assert fact.finding_type != "invalid-actions-lockfile" + if fact.finding_type == "workflow-analysis-incomplete": + diagnostics.append(fact) + elif fact.finding_type == "unpinned-third-party-action": + assert fact.action_name == "example/healthy" + assert len(diagnostics) == 1 + diagnostic = diagnostics[0] + assert diagnostic.caller_workflow.endswith("/.github/workflows/broken.yml") + assert expected_detail in (diagnostic.finding_message or "") + assert expected_location in (diagnostic.finding_message or "") + assert "gh actions-lock" not in (diagnostic.finding_message or "") + assert expected_detail in caplog.text + assert any( + isinstance(fact, GitHubActionsVulnsFacts) and fact.action_name == "example/healthy" + for fact in result.result_tables + ), "An invalid workflow must not hide independent findings" + + +@pytest.mark.parametrize("with_lockfile", [True, False]) +@pytest.mark.parametrize( + ("mode", "expected_detail"), + [ + ("external_symlink", "'description' was unexpected"), + ("dangling_symlink", "Cannot parse GitHub Workflow"), + ("yaml_parser", "line 4, column 1"), + ("yaml_scanner", "line 3, column 1"), + ], +) +def test_failed_workflow_diagnostics_preserve_source_and_yaml_location( + tmp_path: Path, + monkeypatch: pytest.MonkeyPatch, + ci_services: dict[str, BaseCIService], + with_lockfile: bool, + mode: str, + expected_detail: str, +) -> None: + """A skipped symlink or malformed YAML must produce a useful finding without hiding healthy workflows.""" + repo_root = tmp_path / "checkout" + directory = repo_root / ".github/workflows" + directory.mkdir(parents=True) + broken = directory / "broken.yml" + if mode in {"external_symlink", "dangling_symlink"}: + target = tmp_path / "outside.yml" + if mode == "external_symlink": + target.write_text("description: unsupported\non: push\njobs: {}\n", encoding="utf-8") + broken.symlink_to(target) + elif mode == "yaml_parser": + broken.write_text("on: push\njobs:\n build: [\n", encoding="utf-8") + else: + broken.write_text("on: push\njobs:\n\tbuild: {}\n", encoding="utf-8") + (directory / "healthy.yml").write_text( + "on: push\npermissions: {}\njobs:\n build:\n runs-on: ubuntu-latest\n" + " steps:\n - uses: example/healthy@v1\n", + encoding="utf-8", + ) + if with_lockfile: + (directory / "actions.lock").write_text( + "version: v0.0.3\nworkflows:\n .github/workflows/broken.yml: []\ndependencies: {}\n", + encoding="utf-8", + ) + service = ci_services["github_actions"] + assert isinstance(service, GitHubActions) + info = get_ci_info(ci_services, "jenkins", "") + info["service"] = service + info["callgraph"] = service.build_call_graph_for_files(service.get_workflows(str(repo_root)), str(repo_root)) + ctx = MockAnalyzeContext(fs_path=str(repo_root)) + ctx.dynamic_data["ci_services"] = [info] + monkeypatch.setattr(OSVDevService, "get_vulnerabilities_package_name_batch", lambda _: []) + monkeypatch.setattr(service.api_client, "get_commit_sha_from_ref", lambda *_: None) + result = GitHubActionsVulnsCheck().run_check(ctx) + assert result.result_type == CheckResultType.FAILED + diagnostics = [] + for fact in result.result_tables: + assert isinstance(fact, GitHubActionsVulnsFacts) + assert fact.finding_type != "invalid-actions-lockfile" + if fact.finding_type == "workflow-analysis-incomplete": + diagnostics.append(fact) + assert len(diagnostics) == 1 + assert diagnostics[0].caller_workflow.endswith("/.github/workflows/broken.yml") + assert "outside.yml" not in diagnostics[0].caller_workflow + assert expected_detail in (diagnostics[0].finding_message or "") + if mode == "yaml_parser": + assert "did not find expected node content" in (diagnostics[0].finding_message or "") + elif mode == "yaml_scanner": + assert "found character that cannot start any token" in (diagnostics[0].finding_message or "") + assert any( + isinstance(fact, GitHubActionsVulnsFacts) and fact.action_name == "example/healthy" + for fact in result.result_tables + ), "An invalid workflow must not hide independent findings" @pytest.mark.parametrize("mode", ["missing_pin", "unsupported_version"]) From dfe88a6c8e958d1eed15d44b9a93917ee6b4b5d6 Mon Sep 17 00:00:00 2001 From: behnazh-w Date: Fri, 20 Nov 2026 12:11:52 +1000 Subject: [PATCH 2/5] chore(deps): document and ignore unreachable MCP OAuth advisor Signed-off-by: behnazh-w --- Makefile | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 029787573..942795354 100644 --- a/Makefile +++ b/Makefile @@ -302,11 +302,13 @@ requirements.txt: pyproject.toml # found an issue. If an advisory needs to be ignored, use the --ignore-vuln option. # # Semgrep 1.185.0 pins mcp to 1.29.0 and restricts opentelemetry-api to 1.37.x. -# The four MCP advisories below affect MCP server/client functionality. Macaron -# invokes `semgrep scan` and does not use that functionality. OpenTelemetry -# GHSA-xcq7-p3pf-p88h affects tracestate parsing; GHSA-mf5v-w3w3-f6cg affects -# traceparent parsing. Semgrep's scan telemetry constructs only traceparent from -# process environment variables, not scanned files or untrusted request metadata. +# The five MCP advisories below affect MCP server/client functionality. Macaron +# invokes `semgrep scan` and does not use that functionality. In particular, +# GHSA-qx49-fqc8-xw99 affects OAuth-enabled MCP HTTP clients, which Macaron does not use. +# OpenTelemetry GHSA-xcq7-p3pf-p88h affects tracestate parsing; +# GHSA-mf5v-w3w3-f6cg affects traceparent parsing. Semgrep's scan telemetry +# constructs only traceparent from process environment variables, not scanned +# files or untrusted request metadata. # Temporarily ignore these advisories until Semgrep allows mcp >=1.30.0 and # opentelemetry-api >=1.45.2. Reassess these exceptions if Macaron's usage changes. @@ -318,6 +320,7 @@ audit: python -m pip_audit --skip-editable --desc on --fix --dry-run \ --ignore-vuln GHSA-84m7-p3x7-pcfv --ignore-vuln GHSA-5h93-6whr-6q8j \ --ignore-vuln GHSA-w4fh-qvv9-3v23 --ignore-vuln GHSA-rwrf-2pqf-9j8j \ + --ignore-vuln GHSA-qx49-fqc8-xw99 \ --ignore-vuln GHSA-xcq7-p3pf-p88h --ignore-vuln GHSA-mf5v-w3w3-f6cg # Run some or all checks over the package code base. From 41f19e8868c4cdf3c52286be556b0309fec340ac Mon Sep 17 00:00:00 2001 From: behnazh-w Date: Fri, 20 Nov 2026 12:35:40 +1000 Subject: [PATCH 3/5] test: fix the failing test Signed-off-by: behnazh-w --- .../checks/test_github_actions_vulnerability_check.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/slsa_analyzer/checks/test_github_actions_vulnerability_check.py b/tests/slsa_analyzer/checks/test_github_actions_vulnerability_check.py index db7bbc409..477f27f7c 100644 --- a/tests/slsa_analyzer/checks/test_github_actions_vulnerability_check.py +++ b/tests/slsa_analyzer/checks/test_github_actions_vulnerability_check.py @@ -369,6 +369,7 @@ def test_workflow_analysis_errors_reach_the_security_report( ), "An invalid workflow must not hide independent findings" +@pytest.mark.parametrize("pure_yaml", [True, False]) @pytest.mark.parametrize("with_lockfile", [True, False]) @pytest.mark.parametrize( ("mode", "expected_detail"), @@ -383,11 +384,14 @@ def test_failed_workflow_diagnostics_preserve_source_and_yaml_location( tmp_path: Path, monkeypatch: pytest.MonkeyPatch, ci_services: dict[str, BaseCIService], + pure_yaml: bool, with_lockfile: bool, mode: str, expected_detail: str, ) -> None: """A skipped symlink or malformed YAML must produce a useful finding without hiding healthy workflows.""" + if pure_yaml: + monkeypatch.setattr("ruamel.yaml.main.CParser", None) repo_root = tmp_path / "checkout" directory = repo_root / ".github/workflows" directory.mkdir(parents=True) @@ -432,10 +436,11 @@ def test_failed_workflow_diagnostics_preserve_source_and_yaml_location( assert diagnostics[0].caller_workflow.endswith("/.github/workflows/broken.yml") assert "outside.yml" not in diagnostics[0].caller_workflow assert expected_detail in (diagnostics[0].finding_message or "") + # C and pure-Python YAML parsers describe the same syntax errors differently. if mode == "yaml_parser": - assert "did not find expected node content" in (diagnostics[0].finding_message or "") + assert "node content" in (diagnostics[0].finding_message or "") elif mode == "yaml_scanner": - assert "found character that cannot start any token" in (diagnostics[0].finding_message or "") + assert "cannot start any token" in (diagnostics[0].finding_message or "") assert any( isinstance(fact, GitHubActionsVulnsFacts) and fact.action_name == "example/healthy" for fact in result.result_tables From a78588e22044f71f3860c6418ac7e2ab8d1b6e1d Mon Sep 17 00:00:00 2001 From: behnazh-w Date: Fri, 20 Nov 2026 14:14:46 +1000 Subject: [PATCH 4/5] build: pin the Ubuntu version Signed-off-by: behnazh-w --- .github/workflows/_build.yaml | 12 ++++++------ .github/workflows/_build_docker.yaml | 2 +- .github/workflows/_deploy-github-pages.yaml | 2 +- .github/workflows/_generate-rebase.yaml | 2 +- .github/workflows/build_base_image.yaml | 2 +- .github/workflows/codeql-analysis.yaml | 2 +- .github/workflows/dependabot-automerge.yaml | 4 ++-- .github/workflows/macaron-analysis.yaml | 2 +- .../workflows/manual-deploy-github-pages.yaml | 6 +++--- .github/workflows/pr-conventional-commits.yaml | 2 +- .github/workflows/release.yaml | 10 +++++----- .github/workflows/scorecards-analysis.yaml | 2 +- .github/workflows/test_macaron_action.yaml | 18 +++++++++--------- 13 files changed, 33 insertions(+), 33 deletions(-) diff --git a/.github/workflows/_build.yaml b/.github/workflows/_build.yaml index c9cf45cb0..73df2d907 100644 --- a/.github/workflows/_build.yaml +++ b/.github/workflows/_build.yaml @@ -9,7 +9,7 @@ # # Even though we run the build in a matrix to check against different platforms, due to a known # limitation of reusable workflows that do not support setting strategy property from the caller -# workflow, we only generate artifacts for ubuntu-latest and Python 3.11, which can be used to +# workflow, we only generate artifacts for Ubuntu 24.04 and Python 3.11, which can be used to # create a release. For details see: # # https://docs.github.com/en/actions/using-workflows/reusing-workflows#limitations @@ -32,7 +32,7 @@ on: permissions: contents: read env: - ARTIFACT_OS: ubuntu-latest # The default OS for release. + ARTIFACT_OS: ubuntu-24.04 # The default OS for release. ARTIFACT_PYTHON: '3.11' # The default Python version for release. PACKAGE_PATH: src/macaron # The relative Python package path to the repo. @@ -45,9 +45,9 @@ jobs: strategy: fail-fast: false matrix: - # It is recommended to pin a Runner version specifically: - # https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners - os: [ubuntu-latest] + # Souffle 2.5 provides Ubuntu 22.04/24.04 packages, but none for 26.04. + # Pin the supported runner instead of following ubuntu-latest migrations. + os: [ubuntu-24.04] python: ['3.11'] steps: @@ -155,4 +155,4 @@ jobs: artifact-sha256: ${{ needs.build.outputs.artifacts-sha256 }} # TODO: use ${{ env.ARTIFACT_OS }} and ${{ env.ARTIFACT_PYTHON }} # when this issue is addressed: https://github.com/actions/runner/issues/2394. - artifact-name: artifact-ubuntu-latest-python-3.11 + artifact-name: artifact-ubuntu-24.04-python-3.11 diff --git a/.github/workflows/_build_docker.yaml b/.github/workflows/_build_docker.yaml index f4611d5a0..fa5a43d4e 100644 --- a/.github/workflows/_build_docker.yaml +++ b/.github/workflows/_build_docker.yaml @@ -21,7 +21,7 @@ permissions: jobs: build-docker: - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 permissions: packages: read steps: diff --git a/.github/workflows/_deploy-github-pages.yaml b/.github/workflows/_deploy-github-pages.yaml index a626a4b25..e986df6ef 100644 --- a/.github/workflows/_deploy-github-pages.yaml +++ b/.github/workflows/_deploy-github-pages.yaml @@ -26,7 +26,7 @@ jobs: environment: name: github-pages url: ${{ steps.deployment.outputs.page_url }} - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 steps: - name: Check out repository diff --git a/.github/workflows/_generate-rebase.yaml b/.github/workflows/_generate-rebase.yaml index c157a3d0b..80f063f2e 100644 --- a/.github/workflows/_generate-rebase.yaml +++ b/.github/workflows/_generate-rebase.yaml @@ -33,7 +33,7 @@ permissions: jobs: rebase: - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 timeout-minutes: 35 steps: diff --git a/.github/workflows/build_base_image.yaml b/.github/workflows/build_base_image.yaml index b2439bbb5..43ac5004f 100644 --- a/.github/workflows/build_base_image.yaml +++ b/.github/workflows/build_base_image.yaml @@ -13,7 +13,7 @@ permissions: jobs: build-base-image: name: Build base image - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 permissions: packages: write # To push the base Docker image. steps: diff --git a/.github/workflows/codeql-analysis.yaml b/.github/workflows/codeql-analysis.yaml index 946c15e5b..b18a9c458 100644 --- a/.github/workflows/codeql-analysis.yaml +++ b/.github/workflows/codeql-analysis.yaml @@ -22,7 +22,7 @@ permissions: jobs: analyze: name: Analyze - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 permissions: actions: read contents: read diff --git a/.github/workflows/dependabot-automerge.yaml b/.github/workflows/dependabot-automerge.yaml index 045c3cca4..81b97cbc7 100644 --- a/.github/workflows/dependabot-automerge.yaml +++ b/.github/workflows/dependabot-automerge.yaml @@ -1,4 +1,4 @@ -# Copyright (c) 2022 - 2022, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2022 - 2026, Oracle and/or its affiliates. All rights reserved. # Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/. # Automatically merge Dependabot PRs upon approval by leaving @@ -15,7 +15,7 @@ permissions: jobs: comment: if: ${{ github.event.review.state == 'approved' && github.event.pull_request.user.login == 'dependabot[bot]' }} - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 steps: - name: Merge Dependabot PR run: gh pr comment --body "@dependabot squash and merge" "$PR_URL" diff --git a/.github/workflows/macaron-analysis.yaml b/.github/workflows/macaron-analysis.yaml index 5cc03a877..2e4c6dcc2 100644 --- a/.github/workflows/macaron-analysis.yaml +++ b/.github/workflows/macaron-analysis.yaml @@ -21,7 +21,7 @@ permissions: jobs: run_macaron: - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 steps: diff --git a/.github/workflows/manual-deploy-github-pages.yaml b/.github/workflows/manual-deploy-github-pages.yaml index 73d054b12..23639642a 100644 --- a/.github/workflows/manual-deploy-github-pages.yaml +++ b/.github/workflows/manual-deploy-github-pages.yaml @@ -1,4 +1,4 @@ -# Copyright (c) 2025 - 2025, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2025 - 2026, Oracle and/or its affiliates. All rights reserved. # Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/. # Builds and deploys documentation to GitHub Pages on demand. @@ -11,7 +11,7 @@ on: workflow_dispatch permissions: contents: read env: - ARTIFACT_NAME: artifact-ubuntu-latest-python-3.11 + ARTIFACT_NAME: artifact-ubuntu-24.04-python-3.11 jobs: # Build the artifact. @@ -31,5 +31,5 @@ jobs: pages: write id-token: write with: - artifact-name: artifact-ubuntu-latest-python-3.11 + artifact-name: artifact-ubuntu-24.04-python-3.11 artifact-sha256: ${{ needs.build.outputs.artifacts-sha256 }} diff --git a/.github/workflows/pr-conventional-commits.yaml b/.github/workflows/pr-conventional-commits.yaml index ab9b46f34..0a41c006a 100644 --- a/.github/workflows/pr-conventional-commits.yaml +++ b/.github/workflows/pr-conventional-commits.yaml @@ -21,7 +21,7 @@ permissions: jobs: conventional-commits: - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 steps: - name: Check out repository diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index f2e379ca6..f93c457a7 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -13,7 +13,7 @@ on: permissions: contents: read env: - ARTIFACT_NAME: artifact-ubuntu-latest-python-3.11 + ARTIFACT_NAME: artifact-ubuntu-24.04-python-3.11 # This is the username and email for the user who commits and pushes the release # commit. In an organisation that should be a dedicated devops account. USER_NAME: behnazh-w @@ -33,7 +33,7 @@ jobs: bump: needs: check if: github.ref == 'refs/heads/release' - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 permissions: contents: write steps: @@ -108,7 +108,7 @@ jobs: release-url: ${{ steps.release-info.outputs.release-url }} image-name: ${{ steps.push-docker.outputs.image-name }} image-digest: ${{ steps.push-docker.outputs.image-digest }} - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 permissions: contents: write # To publish release notes. packages: write # To push the Docker image. @@ -299,7 +299,7 @@ jobs: # publish_provenance: # needs: [release, provenance] # name: Publish provenance - # runs-on: ubuntu-latest + # runs-on: ubuntu-24.04 # permissions: # contents: write # To publish release notes. # steps: @@ -331,5 +331,5 @@ jobs: with: # TODO: use ${{ env.ARTIFACT_NAME }} when this issue is addressed: # https://github.com/actions/runner/issues/2394. - artifact-name: artifact-ubuntu-latest-python-3.11 + artifact-name: artifact-ubuntu-24.04-python-3.11 artifact-sha256: ${{ needs.build.outputs.artifacts-sha256 }} diff --git a/.github/workflows/scorecards-analysis.yaml b/.github/workflows/scorecards-analysis.yaml index 54ccd73b4..304934aee 100644 --- a/.github/workflows/scorecards-analysis.yaml +++ b/.github/workflows/scorecards-analysis.yaml @@ -18,7 +18,7 @@ permissions: read-all jobs: analysis: name: Scorecards analysis - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 permissions: # Needed to upload the results to code-scanning dashboard. security-events: write diff --git a/.github/workflows/test_macaron_action.yaml b/.github/workflows/test_macaron_action.yaml index 85772f8c6..98050e11e 100644 --- a/.github/workflows/test_macaron_action.yaml +++ b/.github/workflows/test_macaron_action.yaml @@ -23,7 +23,7 @@ permissions: jobs: tutorial-commit-finder: name: Analyzing and comparing different versions of an artifact - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 env: MACARON_IMAGE_TAG: ${{ inputs.macaron_image_tag }} DOCKER_PULL: never @@ -73,7 +73,7 @@ jobs: tutorial-detect-malicious-package: name: Detecting malicious packages - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 env: MACARON_IMAGE_TAG: ${{ inputs.macaron_image_tag }} DOCKER_PULL: never @@ -138,7 +138,7 @@ jobs: tutorial-detect-vulnerable-actions: name: How to detect vulnerable GitHub Actions - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 env: MACARON_IMAGE_TAG: ${{ inputs.macaron_image_tag }} DOCKER_PULL: never @@ -218,7 +218,7 @@ jobs: tutorial-provenance: name: Provenance discovery, extraction, and verification - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 env: MACARON_IMAGE_TAG: ${{ inputs.macaron_image_tag }} DOCKER_PULL: never @@ -291,7 +291,7 @@ jobs: tutorial-detect-malicious-java-dep: name: Detecting Java dependencies manually uploaded to Maven Central - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 env: MACARON_IMAGE_TAG: ${{ inputs.macaron_image_tag }} DOCKER_PULL: never @@ -325,7 +325,7 @@ jobs: tutorial-exclude-include-checks: name: Exclude and include checks in Macaron - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 env: MACARON_IMAGE_TAG: ${{ inputs.macaron_image_tag }} DOCKER_PULL: never @@ -358,7 +358,7 @@ jobs: test-detect-vulnerable-actions: name: How to detect vulnerable GitHub Actions - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 env: MACARON_IMAGE_TAG: ${{ inputs.macaron_image_tag }} DOCKER_PULL: never @@ -399,7 +399,7 @@ jobs: test-github-actions-lockfiles: name: Recognizing workflow lockfile coverage - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 env: MACARON_IMAGE_TAG: ${{ inputs.macaron_image_tag }} DOCKER_PULL: never @@ -438,7 +438,7 @@ jobs: test-detect-potential-injection: name: How to detect vulnerable GitHub Actions - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 env: MACARON_IMAGE_TAG: ${{ inputs.macaron_image_tag }} DOCKER_PULL: never From 902b86e5db78e6cfebea969a06afaab46f4ac3cc Mon Sep 17 00:00:00 2001 From: behnazh-w Date: Fri, 20 Nov 2026 16:34:03 +1000 Subject: [PATCH 5/5] test: fix the failing tests Signed-off-by: behnazh-w --- .../test.yaml | 5 +++- .../repo_finder_remote_calls/repo_finder.py | 13 ++------ tests/repo_finder/test_repo_validator.py | 30 +++++++++++++++++++ 3 files changed, 37 insertions(+), 11 deletions(-) create mode 100644 tests/repo_finder/test_repo_validator.py diff --git a/tests/integration/cases/log4j_release_pipeline_deleted_run/test.yaml b/tests/integration/cases/log4j_release_pipeline_deleted_run/test.yaml index 2b33a0a24..f53f1cf20 100644 --- a/tests/integration/cases/log4j_release_pipeline_deleted_run/test.yaml +++ b/tests/integration/cases/log4j_release_pipeline_deleted_run/test.yaml @@ -1,4 +1,4 @@ -# Copyright (c) 2024 - 2024, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2024 - 2026, Oracle and/or its affiliates. All rights reserved. # Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/. description: | @@ -14,6 +14,9 @@ steps: command_args: - -purl - pkg:maven/org.apache.logging.log4j/log4j-core@2.19.0 + # The release POM uses Apache redirects, which can be unavailable. + - -rp + - https://github.com/apache/logging-log4j2 - name: Run macaron verify-policy to verify passed/failed checks kind: verify options: diff --git a/tests/integration/cases/repo_finder_remote_calls/repo_finder.py b/tests/integration/cases/repo_finder_remote_calls/repo_finder.py index e2dcb1d62..98dd48d81 100644 --- a/tests/integration/cases/repo_finder_remote_calls/repo_finder.py +++ b/tests/integration/cases/repo_finder_remote_calls/repo_finder.py @@ -1,4 +1,4 @@ -# Copyright (c) 2023 - 2025, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2023 - 2026, Oracle and/or its affiliates. All rights reserved. # Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/. """This script tests the functionality of the repo finder's remote API calls.""" @@ -10,11 +10,9 @@ from packageurl import PackageURL from macaron.config.defaults import defaults -from macaron.repo_finder import repo_validator from macaron.repo_finder.repo_finder import find_repo from macaron.repo_finder.repo_finder_deps_dev import DepsDevRepoFinder from macaron.repo_finder.repo_finder_enums import RepoFinderInfo -from macaron.slsa_analyzer.git_url import clean_url logger: logging.Logger = logging.getLogger(__name__) @@ -56,8 +54,8 @@ def test_repo_finder() -> int: return os.EX_UNAVAILABLE # Test Java package with SCM metadata in artifact's parent POM. - match, outcome = find_repo(PackageURL.from_string("pkg:maven/commons-cli/commons-cli@1.5.0")) - if not match or outcome != RepoFinderInfo.FOUND: + match, outcome = find_repo(PackageURL.from_string("pkg:maven/org.apache.logging.log4j/log4j-core@2.25.3")) + if match != "https://github.com/apache/logging-log4j2" or outcome != RepoFinderInfo.FOUND_FROM_PARENT: return os.EX_UNAVAILABLE # Test deps.dev API for a Python package. @@ -80,11 +78,6 @@ def test_repo_finder() -> int: if not match or outcome != RepoFinderInfo.FOUND: return os.EX_UNAVAILABLE - # Test redirecting URL from Apache commons-io package. - parsed_url = clean_url("https://git-wip-us.apache.org/repos/asf?p=commons-io.git") - if not parsed_url or not repo_validator.resolve_redirects(parsed_url): - return os.EX_UNAVAILABLE - # Test Java package whose SCM metadata only points to the repo in later versions than is provided here. purl = PackageURL.from_string("pkg:maven/io.vertx/vertx-auth-common@3.8.0") repo, outcome = find_repo(purl) diff --git a/tests/repo_finder/test_repo_validator.py b/tests/repo_finder/test_repo_validator.py new file mode 100644 index 000000000..1415e791f --- /dev/null +++ b/tests/repo_finder/test_repo_validator.py @@ -0,0 +1,30 @@ +# Copyright (c) 2026 - 2026, Oracle and/or its affiliates. All rights reserved. +# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/. + +"""Test repository redirects without depending on external redirect services.""" + +from urllib.parse import urlparse + +import pytest +from pytest_httpserver import HTTPServer + +from macaron.config.defaults import defaults +from macaron.repo_finder.repo_validator import resolve_redirects + + +@pytest.mark.parametrize("allowed", [True, False]) +@pytest.mark.parametrize("status", [302, 200, 404]) +def test_repository_redirects( + httpserver: HTTPServer, monkeypatch: pytest.MonkeyPatch, allowed: bool, status: int +) -> None: + """Only resolve redirects from configured hosts that return a Location header.""" + source = urlparse(httpserver.url_for("/repos/asf?p=commons-io.git")) + target = "https://github.com/apache/commons-io" + monkeypatch.setitem(defaults["repofinder"], "redirect_urls", source.netloc if allowed else "example.org") + headers = {"Location": target} if status == 302 else {} + if allowed: + httpserver.expect_request("/repos/asf", query_string="p=commons-io.git").respond_with_data( + "", status=status, headers=headers + ) + + assert resolve_redirects(source) == (target if allowed and status == 302 else None)