Skip to content

ROX-31227: Add and store tailored profiles equivalence hash#19561

Draft
guzalv wants to merge 7 commits intomaster-base/gualvare/fix-compliance-custom-rules-gotchasfrom
master-base/gualvare/ROX-31227-add-tp-equivalence-hash
Draft

ROX-31227: Add and store tailored profiles equivalence hash#19561
guzalv wants to merge 7 commits intomaster-base/gualvare/fix-compliance-custom-rules-gotchasfrom
master-base/gualvare/ROX-31227-add-tp-equivalence-hash

Conversation

@guzalv
Copy link
Contributor

@guzalv guzalv commented Mar 24, 2026

Description

change me!

User-facing documentation

Testing and quality

  • the change is production ready: the change is GA, or otherwise the functionality is gated by a feature flag
  • CI results are inspected

Automated testing

  • added unit tests
  • added e2e tests
  • added regression tests
  • added compatibility tests
  • modified existing tests

How I validated my change

change me!

guzalv and others added 6 commits March 23, 2026 23:20
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>
@openshift-ci
Copy link

openshift-ci bot commented Mar 24, 2026

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 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.
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>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
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(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@rhacs-bot
Copy link
Contributor

rhacs-bot commented Mar 24, 2026

Images are ready for the commit at 545cc11.

To use with deploy scripts, first export MAIN_IMAGE_TAG=4.11.x-438-g545cc113bd.

@guzalv guzalv force-pushed the master-base/gualvare/fix-compliance-custom-rules-gotchas branch from f9bb406 to 8c838fb Compare March 24, 2026 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants