|
| 1 | +# METADATA |
| 2 | +# title: All maven artifacts have known repository URLs |
| 3 | +# description: >- |
| 4 | +# Each Maven package listed in an SBOM must specify the repository URL that it |
| 5 | +# comes from, and that URL must be present in the list of known and permitted |
| 6 | +# Maven repositories. If no URL is specified, the package is assumed to come |
| 7 | +# from Maven Central. |
| 8 | +# custom: |
| 9 | +# short_name: urls_known |
| 10 | +# failure_msg: 'Maven repo URL check failed: %s' |
| 11 | +# solution: >- |
| 12 | +# Ensure every maven artifact comes from a known and permitted repository URL. |
| 13 | +# collections: |
| 14 | +# - redhat |
| 15 | +# - redhat_maven |
| 16 | +# effective_on: "2026-05-10T00:00:00Z" |
| 17 | +# |
| 18 | +package release.maven_repos |
| 19 | + |
| 20 | +import future.keywords.contains |
| 21 | +import future.keywords.if |
| 22 | +import future.keywords.in |
| 23 | + |
| 24 | +import data.lib |
| 25 | +import data.lib.sbom.maven |
| 26 | + |
| 27 | +# METADATA |
| 28 | +# title: Missing Policy Data |
| 29 | +# scope: rule |
| 30 | +# custom: |
| 31 | +# short_name: policy_data_missing |
| 32 | +# failure_msg: 'Policy data is missing the required %q list' |
| 33 | +deny contains result if { |
| 34 | + some key in _rule_data_errors |
| 35 | + result := lib.result_helper(rego.metadata.chain(), [key]) |
| 36 | +} |
| 37 | + |
| 38 | +# METADATA |
| 39 | +# title: Known Repository URLs |
| 40 | +# scope: rule |
| 41 | +# custom: |
| 42 | +# short_name: deny_unpermitted_urls |
| 43 | +# failure_msg: '%s' |
| 44 | +deny contains result if { |
| 45 | + some purl, msg in _repo_url_errors |
| 46 | + base := lib.result_helper(rego.metadata.chain(), [msg]) |
| 47 | + result := object.union(base, {"term": purl}) |
| 48 | +} |
| 49 | + |
| 50 | +_repo_url_errors[purl] := msg if { |
| 51 | + some pkg in maven.packages |
| 52 | + purl := pkg.purl |
| 53 | + source := _get_effective_url(pkg.repository_url) |
| 54 | + not _url_is_permitted(source) |
| 55 | + msg := sprintf("Package %q (source: %q) is not in the permitted list", [purl, source]) |
| 56 | +} |
| 57 | + |
| 58 | +_get_effective_url(url) := url if { |
| 59 | + url != "" |
| 60 | +} else := "https://repo.maven.apache.org/maven2/" |
| 61 | + |
| 62 | +_url_is_permitted(url) if { |
| 63 | + permitted := lib.rule_data("allowed_maven_repositories") |
| 64 | + url in permitted |
| 65 | +} |
| 66 | + |
| 67 | +_rule_data_errors contains key if { |
| 68 | + key := "allowed_maven_repositories" |
| 69 | + data_list := object.get(data.rule_data, key, "UNDEFINED_IN_DATA") |
| 70 | + _is_invalid_data(data_list) |
| 71 | +} |
| 72 | + |
| 73 | +_is_invalid_data(val) if { |
| 74 | + val == "UNDEFINED_IN_DATA" |
| 75 | + print("") # workaround for code coverage |
| 76 | +} |
| 77 | + |
| 78 | +_is_invalid_data(val) if not is_array(val) |
| 79 | + |
| 80 | +_is_invalid_data(val) if { |
| 81 | + is_array(val) |
| 82 | + count(val) == 0 |
| 83 | +} |
0 commit comments