Skip to content

ROX-31226: Add compliance operator custom rule protos#19032

Open
guzalv wants to merge 6 commits intomasterfrom
master-base/gualvare/ROX-31226-custom-rules-protos
Open

ROX-31226: Add compliance operator custom rule protos#19032
guzalv wants to merge 6 commits intomasterfrom
master-base/gualvare/ROX-31226-custom-rules-protos

Conversation

@guzalv
Copy link
Contributor

@guzalv guzalv commented Feb 13, 2026

Description

This PR prepares the proto definitions for upcoming support of Compliance Operator custom rules by adding a new enum field called ComplianceOperatorRuleKind to the existing ComplianceOperatorRuleV2 definition. This field will be CUSTOM_RULE for custom rules (CEL based), and RULE for regular XDCC rules. Details about custom rules can be found in this Red Hat developer blog post.

Note on the naming of the new field: The compliance_operator_ prefix on the field and enum name distinguishes them from the existing rule_type field and reflects that this classification belongs to the Compliance Operator domain, not StackRox's own rule model.

While whether a rule is custom or not could possibly be inferred by looking at other fields, an explicit enum is preferred:

  • Prevents having to add similar logic to tell whether a rule is custom in several places.
  • Prevents having to handle null v empty situations.
  • Straightforward based on Compliance Operator’s CR kind (in Compliance Operator, rules and custom rules are different CRDs:
    • kind: Rule -> ComplianceOperatorRuleKind: RULE
    • kind: CustomRule -> ComplianceOperatorRuleKind: CUSTOM_RULE

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

CI

@openshift-ci
Copy link

openshift-ci bot commented Feb 13, 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

@guzalv
Copy link
Contributor Author

guzalv commented Feb 13, 2026

/test all

@rhacs-bot
Copy link
Contributor

rhacs-bot commented Feb 13, 2026

Images are ready for the commit at bdaa47c.

To use with deploy scripts, first export MAIN_IMAGE_TAG=4.11.x-264-gbdaa47cd10.

@codecov
Copy link

codecov bot commented Feb 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 49.64%. Comparing base (5e9f675) to head (bdaa47c).
⚠️ Report is 5 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #19032      +/-   ##
==========================================
- Coverage   49.65%   49.64%   -0.01%     
==========================================
  Files        2689     2689              
  Lines      202505   202505              
==========================================
- Hits       100548   100541       -7     
- Misses      94463    94470       +7     
  Partials     7494     7494              
Flag Coverage Δ
go-unit-tests 49.64% <ø> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@guzalv guzalv force-pushed the master-base/gualvare/ROX-31226-custom-rules-protos branch 2 times, most recently from 563ac1e to 51b14e8 Compare February 15, 2026 23:30
@guzalv
Copy link
Contributor Author

guzalv commented Feb 15, 2026

/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 left some high level feedback:

  • Consider documenting CustomRuleDetails directly in the proto comment (e.g., explicitly stating it is only populated for CEL-based custom rules and nil for XDCC rules) so downstream consumers don’t need to rely on external docs to understand the semantics.
  • Since CustomRuleDetails is added to both internalapi and storage protos, double-check any conversion/mapping code between these layers is updated to correctly populate and persist the new field for custom rules to avoid silent data loss.
  • If CustomRuleDetails is effectively acting as a discriminator between custom and non-custom rules, you might want to consider a oneof or an explicit enum/flag instead of using presence vs. absence of the message to signal rule type, which can make the API contract clearer and less error-prone.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider documenting `CustomRuleDetails` directly in the proto comment (e.g., explicitly stating it is only populated for CEL-based custom rules and nil for XDCC rules) so downstream consumers don’t need to rely on external docs to understand the semantics.
- Since `CustomRuleDetails` is added to both internalapi and storage protos, double-check any conversion/mapping code between these layers is updated to correctly populate and persist the new field for custom rules to avoid silent data loss.
- If `CustomRuleDetails` is effectively acting as a discriminator between custom and non-custom rules, you might want to consider a `oneof` or an explicit enum/flag instead of using presence vs. absence of the message to signal rule type, which can make the API contract clearer and less error-prone.

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.

@guzalv guzalv force-pushed the master-base/gualvare/ROX-31226-custom-rules-protos branch 4 times, most recently from 0117848 to 12ef7d0 Compare March 2, 2026 09:45
@guzalv guzalv added ai-review and removed ai-review labels Mar 2, 2026
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 reviewed your changes and they look great!


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.

@guzalv guzalv marked this pull request as ready for review March 2, 2026 12:09
@guzalv guzalv requested a review from a team as a code owner March 2, 2026 12:09
@guzalv guzalv requested review from a team and mtodor and removed request for a team March 2, 2026 12:10
string instructions = 13;

enum ComplianceOperatorRuleKind {
RULE = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

one consideration (not sure if it applies in this case): Usually = 0 is used for UNSET. I'm not sure if this is relevant in this case or not. Also if we would start with UNSET = 0 - probably migration is required, where in this case not, since default 0 will be mapped to provided rules.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I used 0 for RULE because I found it the most convenient for the reason you wrote, but I was not aware of the UNSPECIFIED best practice, I will implement that. @rukletsov also highlighted this in another comment. I have not dealt with migrations here yet, so if that is needed I will learn something new :).

I will look around and figure this out. Thanks!

string instructions = 17;

enum ComplianceOperatorRuleKind {
RULE = 0;
Copy link
Member

Choose a reason for hiding this comment

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

Make 0 a sentinel value. I know our codebase is inconsistent but let's not add to it. See https://protobuf.dev/programming-guides/style/#enums . So — OPERATOR_KIND_UNSPECIFIED = 0;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the pointer, I was not aware of this and since I saw both styles in this file I went with the one that seemed simplest. Done:

  enum OperatorKind {
    OPERATOR_KIND_UNSPECIFIED = 0;
    OPERATOR_KIND_RULE = 1;
    OPERATOR_KIND_CUSTOM_RULE = 2;
  }
  OperatorKind operator_kind = 18;

string parent_rule = 16;
string instructions = 17;

enum ComplianceOperatorRuleKind {
Copy link
Member

Choose a reason for hiding this comment

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

If enum is nested, no need to repeat the message name. Enums (contrary to enum values) are already scoped. Just call it RuleKind.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The intent was to show that this reflects the kind of a rule at the compliance operator side, and avoid confusion with the existing rule_type field. But it is clear that what it says is "author thought prefix is needed" :D.

I liked your suggestion below "operator_kind", so I have used it here:

  enum OperatorKind {
    OPERATOR_KIND_UNSPECIFIED = 0;
    OPERATOR_KIND_RULE = 1;
    OPERATOR_KIND_CUSTOM_RULE = 2;
  }
  OperatorKind operator_kind = 18;

guzalv added 6 commits March 6, 2026 14:03
I had to do:

  docker run --platform linux/amd64 --rm -v "$(pwd):/src" -w /src quay.io/stackrox-io/apollo-ci:stackrox-test-0.5.2 bash -c "rm -rf .gotools && go mod tidy && make proto-generated-srcs"
@guzalv guzalv force-pushed the master-base/gualvare/ROX-31226-custom-rules-protos branch from c3bf9b9 to bdaa47c Compare March 6, 2026 13:28
Copy link
Member

@rukletsov rukletsov left a comment

Choose a reason for hiding this comment

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

Only checked two .proto files.

Comment on lines +92 to +93
OPERATOR_KIND_RULE = 1;
OPERATOR_KIND_CUSTOM_RULE = 2;
Copy link
Member

Choose a reason for hiding this comment

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

You don't have to prefix any fields except the first one. They will be scoped to the message so if the chance that another enum in this message would use the same enum value, you can skip the prefix. The sentinel 0 is important because it's collide with any enum in the message.

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.

5 participants