ROX-31227: Add and store tailored profiles equivalence hash#19561
Conversation
This solves the issue but injects fake data - custom rules don't have the annotation. Let's implement this in the central converter instead - we have all the data required there. This reverts commit 4cd180b.
- Remove else branch (idiomatic early-assignment style) - Add permanent link to CO's IDToDNSFriendlyName in comment (importing compliance-operator/pkg/utils would pull in unrelated transitive deps) - Add idToDNSFriendlyName test case for xccdf_org.ssgproject.rule_abc (no content_ segment: prefix not stripped) - Fix ambiguous regular-rule test: RuleId now produces a different value from idToDNSFriendlyName so that the test proves parentRule comes from the annotation, not from the RuleId transformation - Add explicit (wrong) annotation to custom rule test to confirm it is ignored in favour of idToDNSFriendlyName(RuleId) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
This change is part of the following stack:
Change managed by git-spice. |
|
Skipping CI for Draft Pull Request. |
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- The tests assume that the V2 profile message is always at index 1 in
ForwardMessages, which is a bit brittle; consider asserting on message type or filtering for theComplianceOperatorProfileV2message instead of relying on a fixed position. computeProfileEquivalenceHashmanually threadsname,namespace,description,title, and rule names; consider accepting aTailoredProfile(or its spec) directly so that any future additions to the equivalence criteria are harder to forget and easier to maintain.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The tests assume that the V2 profile message is always at index 1 in `ForwardMessages`, which is a bit brittle; consider asserting on message type or filtering for the `ComplianceOperatorProfileV2` message instead of relying on a fixed position.
- `computeProfileEquivalenceHash` manually threads `name`, `namespace`, `description`, `title`, and rule names; consider accepting a `TailoredProfile` (or its spec) directly so that any future additions to the equivalence criteria are harder to forget and easier to maintain.
## Individual Comments
### Comment 1
<location path="sensor/kubernetes/complianceoperator/dispatchers/complianceoperatortailoredprofiles.go" line_range="138" />
<code_context>
+ ruleNames = append(ruleNames, rule.GetName())
}
+ protoProfileV2.EquivalenceHash = computeProfileEquivalenceHash(
+ tailoredProfile.GetName(),
+ tailoredProfile.GetNamespace(),
</code_context>
<issue_to_address>
**issue (bug_risk):** Equivalence hash ignores values/variables, which may cause distinct tailored profiles to collide
Since the hash only uses name, namespace, description, title, and rule names, two tailored profiles that differ only in variable/value settings will produce the same EquivalenceHash and be treated as equivalent despite differing behavior. Consider including a canonicalized representation of these values/variables in the hash input to distinguish such profiles.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| ruleNames = append(ruleNames, rule.GetName()) | ||
| } | ||
|
|
||
| protoProfileV2.EquivalenceHash = computeProfileEquivalenceHash( |
There was a problem hiding this comment.
issue (bug_risk): Equivalence hash ignores values/variables, which may cause distinct tailored profiles to collide
Since the hash only uses name, namespace, description, title, and rule names, two tailored profiles that differ only in variable/value settings will produce the same EquivalenceHash and be treated as equivalent despite differing behavior. Consider including a canonicalized representation of these values/variables in the hash input to distinguish such profiles.
|
Images are ready for the commit at 545cc11. To use with deploy scripts, first |
f9bb406 to
8c838fb
Compare
Description
change me!
User-facing documentation
Testing and quality
Automated testing
How I validated my change
change me!