Skip to content

Commit 8ab86ef

Browse files
committed
chore: add descriptions for each existing policy and a test to verify the .description file
Signed-off-by: Demolus13 <[email protected]>
1 parent 4496570 commit 8ab86ef

File tree

8 files changed

+57
-6
lines changed

8 files changed

+57
-6
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Policies
2+
=======
3+
4+
This directory contains policy resources used by Macaron. Policies in this folder are packaged as templates that the verify-policy command can use.
5+
6+
Common files and conventions
7+
---------------------------
8+
- `*.dl.template` - datalog policy templates.
9+
- `*.description` - short descriptions that explain the policy's intent.
10+
- `*.cue.template` - CUE-based expectation templates used by the GDK.
11+
12+
Example policies are exposed to the user via Macaron commands `verify-policy --existing-policy <policy-name>`.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Datalog policy templates
2+
=========================
3+
4+
- This folder contains Datalog-based policy templates and accompanying `.description` files used by Macaron's policy engine.
5+
6+
- These `.dl.template` templates are intended as examples and starting points. They can be used by name using `--existing-policy` flag.
7+
8+
- `*.description` - descriptions for each template. These are intended to be shown in UIs or documentation to help users choose an appropriate example policy.
9+
10+
Extending or adding templates
11+
-----------------------------
12+
- Add a new `.dl.template` file and a matching `.description` file.
13+
- Update documentation or the tutorials page if you add new example policies that should be exposed to users.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Detects whether a component was built using GitHub Actions that are known to be vulnerable or otherwise unsafe. The policy evaluates a check named `mcn_githubactions_vulnerabilities_1` and reports a passed/failed result for the component when applied.
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#include "prelude.dl"
22

33
Policy("github_actions_vulns", component_id, "GitHub Actions Vulnerability Detection") :-
4-
check_passed(component_id, "mcn_githubactions_vulnerabilities_1").
4+
check_passed(component_id, "mcn_githubactions_vulnerabilities_1").
55

66
apply_policy_to("github_actions_vulns", component_id) :-
7-
is_component(component_id, purl),
8-
match("<PACKAGE_PURL>", purl).
7+
is_component(component_id, purl),
8+
match("<PACKAGE_PURL>", purl).

src/macaron/resources/policies/datalog/malware-detection-dependencies.description

Whitespace-only changes.

src/macaron/resources/policies/datalog/malware-detection-dependencies.dl.template

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#include "prelude.dl"
22

33
Policy("check-dependencies", component_id, "Check the dependencies of component.") :-
4-
transitive_dependency(component_id, dependency),
5-
check_passed(component_id, "mcn_detect_malicious_metadata_1"),
6-
check_passed(dependency, "mcn_detect_malicious_metadata_1").
4+
transitive_dependency(component_id, dependency),
5+
check_passed(component_id, "mcn_detect_malicious_metadata_1"),
6+
check_passed(dependency, "mcn_detect_malicious_metadata_1").
77

88
apply_policy_to("check-dependencies", component_id) :-
99
is_component(component_id, purl),
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Checks a component for indicators of malicious or suspicious content. The policy evaluates a check named mcn_detect_malicious_metadata_1 and reports a passed/failed result for the component when applied.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copyright (c) 2025 - 2025, Oracle and/or its affiliates. All rights reserved.
2+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/.
3+
4+
"""Tests that every Datalog template has a matching .description file."""
5+
6+
from pathlib import Path
7+
8+
import macaron
9+
10+
11+
def test_datalog_templates_have_descriptions() -> None:
12+
"""Verify each ``*.dl.template`` has a corresponding ``*.description``."""
13+
datalog_dir = Path(macaron.__file__).resolve().parent.joinpath("resources", "policies", "datalog")
14+
templates = sorted(datalog_dir.glob("*.dl.template"))
15+
16+
missing = []
17+
for tmpl in templates:
18+
expected_desc = datalog_dir.joinpath(tmpl.name.replace(".dl.template", ".description"))
19+
if not expected_desc.exists():
20+
missing.append((tmpl.name, expected_desc))
21+
22+
if templates and missing:
23+
missing_list = ", ".join(f"{t} -> {d}" for t, d in missing)
24+
raise AssertionError("Missing .description files for the following templates: " + missing_list)

0 commit comments

Comments
 (0)