-
Notifications
You must be signed in to change notification settings - Fork 42
Add a Conforma rule to check RPM origin for build deps of RPM builds #1578
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
* NOTE: This check is only a warning right now. It will be upgraded to deny once we are confident the rule and the data is correct and not blocking valid builds JIRA: ROK-814
Codecov Report✅ All modified and coverable lines are covered by tests.
... and 16 files with indirect coverage changes 🚀 New features to boost your workflow:
|
|
Tests Generated by Claude |
| # Test with another invalid download location | ||
| test_invalid_download_location_wrong_domain if { | ||
| invalid_location := "https://malicious.org/package.rpm" | ||
| att := _sbom_attestation_with_download_location(invalid_location) | ||
| expected_locations := array.concat(["NOASSERTION"], _mock_allowed_locations) | ||
| expected := {{ | ||
| "code": "rpm_build_deps.download_location_valid", | ||
| "msg": sprintf("Download Location is %s which is not in %v", [invalid_location, expected_locations]), | ||
| }} | ||
| lib.assert_equal_results(expected, rpm_build_deps.warn) with input.attestations as [att] | ||
| with data.rule_data.allowed_rpm_build_dependency_sources as _mock_allowed_locations | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
duplicate of test_invalid_download_location, can be removed
| # Test with location that doesn't match the patterns | ||
| test_invalid_download_location_no_pattern_match if { | ||
| # This location doesn't match any of the allowed patterns | ||
| invalid_location := "https://example.com/package.rpm" | ||
| att := _sbom_attestation_with_download_location(invalid_location) | ||
| results := rpm_build_deps.warn with input.attestations as [att] | ||
| with data.rule_data.allowed_rpm_build_dependency_sources as _mock_allowed_locations | ||
| count(results) > 0 | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
duplicate of test_invalid_download_location, can be removed
| # description: Builds have valid download locations for RPM build dependencies | ||
| # custom: | ||
| # short_name: download_location_valid | ||
| # failure_msg: Download Location is %s which is not in %v |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| # failure_msg: Download Location is %s which is not in %v | |
| # failure_msg: RPM build dependency source %s is not in the allowed list: %v. | |
| # solution: >- | |
| # The list of allowed RPM build dependency sources can be set via the | |
| # `allowed_rpm_build_dependency_sources` rule data. |
st3penta
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm. @conforma/devs can we merge it?
| result := lib.result_helper(rego.metadata.chain(), [pkg.downloadLocation, valid_locations]) | ||
| } | ||
|
|
||
| matches_any(branch, valid_locations) if { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a blocker, but I'd suggest making the params more generic. "Branch" seems confusing in this context.
| matches_any(branch, valid_locations) if { | |
| matches_any(value, patterns) if { |
And maybe we flip the order so it's consistent with regex.match:
| matches_any(branch, valid_locations) if { | |
| matches_any(patterns, value) if { |
| some pkg in s.packages | ||
|
|
||
| # NOASSERTION is displayed in the SBOM for the RPMS that have been built | ||
| valid_locations := array.concat(["NOASSERTION"], lib.rule_data("allowed_rpm_build_dependency_sources")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also not a blocker, but it might be tidier and perhaps more efficient to move the concat outside the rule. It's a pattern we follow elsewhere
warn ... {
...
not matches_any(pkg.downloadLocation, _valid_locations)
}
# NOASSERTION is displayed in the SBOM for the RPMS that have been built
_valid_locations := array.concat(["NOASSERTION"], lib.rule_data("allowed_rpm_build_dependency_sources"))
deny once we are confident the rule and the data is correct and not
blocking valid builds
JIRA: ROK-814