Repository navigation
Conversation
Empty OPA findings / missing policies previously yielded globalComplianceStatus=true via Stream.noneMatch on an empty list. Add evaluationStatus + evaluationSummary and only mark quantum-safe when evaluation is complete and conclusive. Closes cbomkit#342 Signed-off-by: Ahmed Hassan <[email protected]> Co-authored-by: Cursor <[email protected]>
There was a problem hiding this comment.
Thanks for this PR, Ahmed! I appreciate the work 💙
I reviewed the backend, frontend, API response, and tests against #342. The empty-findings regression is fixed, but several paths still report a complete or green evaluation when the requested OPA policy did not cover the CBOM or failed. The inline comments have concrete cases and suggested fixes. Frontend lint and production build pass. I could not run the Java tests: Maven gets a 401 for the private cbomkit-lib package because this environment has no GitHub Packages Maven credentials.
This review was generated with AI assistance; please verify the findings.
| } | ||
| } | ||
|
|
||
| int evaluatedAssets = findings.size(); |
There was a problem hiding this comment.
Could we check coverage against the CBOM's actual bom-ref values instead of findings.size()? The bundled Rego policy can emit both an OID/name finding and a NIST-level finding for the same asset. With two components, two safe findings for A and none for B make this count 2/2 and set globalComplianceStatus=true. A malformed OPA finding with a safe result but no bom-ref can also satisfy a one-asset count. Pass the expected asset IDs into the factory, validate finding IDs, and add tests for duplicate and missing IDs.
| } else if (findings.isEmpty()) { | ||
| // Missing policy, empty OPA result, or no findings key — never quantum-safe. | ||
| status = EvaluationStatus.NOT_EVALUATED; | ||
| } else if (applicableAssets <= 0) { |
There was a problem hiding this comment.
Could we check incomplete coverage before choosing not_applicable? For a two-asset CBOM with one NA finding and no finding for the second asset, applicableAssets is zero, so this reports not_applicable and hides the unevaluated asset. That case should be partial; a test with one NA result and one missing asset would catch it.
| } | ||
|
|
||
| private static int countCryptographicAssets(@Nonnull CBOM cbom) { | ||
| return Optional.ofNullable(cbom.cycloneDXbom().getComponents()) |
There was a problem hiding this comment.
Could we count only components of type cryptographic-asset here and in the scanned-repository handler? This currently counts every CycloneDX component. With one evaluated crypto asset plus one ordinary library, the factory reports partial because it expects two findings, even though the policy covered every crypto asset. A library-only CBOM is likewise treated as unevaluated instead of having no applicable crypto assets.
| @Nonnull List<ComplianceLevel> complianceLevels, | ||
| int defaultComplianceLevel, | ||
| int totalCryptographicAssets) { | ||
| if (checkResult.error()) { |
There was a problem hiding this comment.
This only detects an error from the selected service. If OPA is configured but unreachable at startup, Configuration.getComplianceService() catches that failure and selects BasicQuantumSafeComplianceService instead. Its successful result reaches this factory as error=false and can become evaluationStatus=evaluated, globalComplianceStatus=true, although the configured OPA policy never ran. Could we carry that fallback state into the response and keep the requested policy's evaluation from appearing successful?
| evaluationStatus = "partial"; | ||
| } else if (vulnerableAssets === 0 && unknownAssets === 0) { | ||
| evaluationStatus = "evaluated"; | ||
| globalComplianceStatus = true; |
There was a problem hiding this comment.
A backend OPA error can still produce a green banner. getRemoteComplianceReport() in api.js treats {error:true,evaluationStatus:'error'} as invalid and replaces it with this local report; one asset with nistQuantumSecurityLevel: 1 makes this branch return evaluated/true, which the UI renders as Compliant. Could we preserve the failed remote evaluation status in the overall verdict instead of letting the fallback overwrite it? A frontend deployed before the new backend also takes this fallback path for responses lacking evaluationStatus.
|
|
||
| const globalComplianceStatus = findings.every(finding => finding.levelId !== 1 && finding.levelId !== 2); | ||
| const cryptoComponents = components.filter(component => component.type === "cryptographic-asset"); | ||
| const totalCryptographicAssets = cryptoComponents.length || components.length; |
There was a problem hiding this comment.
Could we use cryptoComponents.length directly? For a CBOM containing only an ordinary library component, the loop above emits no findings, but || components.length reports one cryptographic asset and chooses not_evaluated. There are zero crypto assets, so this should be not_applicable with a total of zero. I reproduced this with a library-only CBOM.
| false, | ||
| true, | ||
| EvaluationStatus.ERROR, | ||
| ComplianceEvaluationSummary.empty()); |
There was a problem hiding this comment.
Could the error result retain the CBOM's asset total? fromServiceResult() already receives totalCryptographicAssets, but this helper sets every summary count to zero. An OPA failure for a nonempty CBOM therefore reports totalCryptographicAssets: 0, which reads as an empty CBOM rather than an evaluation error.
|
Hi @AAH20 - Are you still interested it in PR? Here's another review in case you still want to go on. Requesting changesThis is a well-motivated fix. The Two correctness issues need to be addressed before merge. 1. Coverage is counted in findings, not assets, which allows a false
|
|
Hi, yes, I’m still interested in getting this merged. Thanks for the detailed repros. I pushed a follow-up that deduplicates findings by I’ve rechecked the remaining paths and don’t want to mark the review resolved yet. I still need to address the NA-plus-missing-asset case, preserve failed remote evaluation status instead of allowing the local fallback to show a green result, correct the library-only local count, retain asset totals on errors, and add coverage through the OPA response path. I checked the latest CI state. The frontend and backend workflows are awaiting maintainer approval, and DCO-2 failed because the latest commit is missing a sign-off. I’ll correct the sign-off on the follow-up commit. The Java test run is also blocked locally by the private |
Signed-off-by: Ahmed Hassan <[email protected]>
92620ad to
4dff3af
Compare
FYI: You need a GitHub Personal Access Token (see https://docs.github.com/en/[email protected]/packages/working-with-a-github-packages-registry/working-with-the-apache-maven-registry) and put it into your <settings>
<servers>
<server>
<id>github</id>
<username>YOUR_GITHUB_USERNAME</username>
<password>YOUR_GITHUB_TOKEN</password>
</server>
</servers>
</settings> |
Summary
Stream.noneMatchon an empty list was fail-open).evaluationStatus(evaluated|partial|not_evaluated|not_applicable|error) andevaluationSummaryasset counts to the compliance API response.globalComplianceStatus=trueonly when evaluation is complete and every applicable asset is conclusively quantum-safe.Test plan
ComplianceResultFactoryTestcovering: missing/empty findings, service error, empty CBOM, NA-only, partial coverage, unknown, mixed, fully evaluated safe positive control, and the empty-list fail-open regression../mvnw clean package(needs GitHub Packages auth fororg.pqca:cbomkit-lib)./mvnw test -Dtest=ComplianceResultFactoryTest/api/v1/compliance/checkwith a CBOM while OPA policy is missing →evaluationStatus=not_evaluated,globalComplianceStatus=falseevaluationStatus=evaluated,globalComplianceStatus=trueMade with Cursor