Skip to content

CMP-2868: Add scannerType field, CustomRule CRD, and 'kind' property for rule #686

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Vincent056
Copy link

Added changes needed to CRDs to enable CEL scanner.

  • Introduce scannerType to ComplianceScan and ComplianceSuite CRDs for specifying OpenSCAP or CEL.
  • Add CustomRule CRD and types.
  • Extend TailoredProfile references with a 'kind' field to differentiate between Rule and CustomRule.

@openshift-ci openshift-ci bot requested review from mrogers950 and rhmdnd February 19, 2025 06:20
Copy link

openshift-ci bot commented Feb 19, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Vincent056

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link

🤖 To deploy this PR, run the following command:

make catalog-deploy CATALOG_IMG=ghcr.io/complianceascode/compliance-operator-catalog:686-0e1b9b6f1bbc3a6778b9958178de5819f7578cdb

@Vincent056
Copy link
Author

/retest

Copy link

@rhmdnd rhmdnd left a comment

Choose a reason for hiding this comment

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

A few suggestions inline. Thanks!

kind:
description: |-
Type of the rule reference, either "Rule" or "CustomRule"
We will use "Rule" by default if not specified
Copy link

Choose a reason for hiding this comment

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

Nit: Suggest using passive voice here to be consistent with the rest of the properties.

Type of rule, either "Rule" or "CustomRule". "Rule" is the default if not specified.

kind:
description: |-
Type of the rule reference, either "Rule" or "CustomRule"
We will use "Rule" by default if not specified
Copy link

Choose a reason for hiding this comment

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

Similar comment as above.

kind:
description: |-
Type of the rule reference, either "Rule" or "CustomRule"
We will use "Rule" by default if not specified
Copy link

Choose a reason for hiding this comment

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

Similar comment as above.

type: object
spec:
properties:
availableFixes:
Copy link

Choose a reason for hiding this comment

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

Is this carry over from Rules? Do we want to open this up right away?

checkType:
description: |-
What type of check will this rule execute:
Platform, Node or none (represented by an empty string)
Copy link

Choose a reason for hiding this comment

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

This can only be Platform initially, right? Do we want to state that explicitly?

minLength: 1
type: string
id:
description: The XCCDF ID
Copy link

Choose a reason for hiding this comment

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

Does this have to be an XCCDF ID? Or does it just have to be an ID?

Copy link
Author

Choose a reason for hiding this comment

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

I made some changes to the descriptions here, I tried to move the common part together, but it looks like we have rulePayLoad referenced in other part of the code that prevents from doing so, I wonder if we should keep the minimal changes and make the documentation clear

const (
ScannerTypeCEL ScannerType = "CEL"
ScannerTypeOpenSCAP ScannerType = "OpenSCAP"
ScannerTypeUnknown ScannerType = "Unknown"
Copy link

Choose a reason for hiding this comment

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

Based on the code above - we'd never use this, right?

Copy link
Author

Choose a reason for hiding this comment

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

no, we will not use that until later in the reconciler loop

Copy link

Choose a reason for hiding this comment

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

Ok - so we will use it, just not now?

Copy link
Author

Choose a reason for hiding this comment

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

that's right

@Vincent056 Vincent056 changed the title Add scannerType field, CustomRule CRD, and 'kind' property for rule CMP-2868: Add scannerType field, CustomRule CRD, and 'kind' property for rule Feb 25, 2025
@openshift-ci-robot
Copy link
Collaborator

@Vincent056: This pull request references CMP-2868 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "4.19.0" version, but no target version was set.

In response to this:

Added changes needed to CRDs to enable CEL scanner.

  • Introduce scannerType to ComplianceScan and ComplianceSuite CRDs for specifying OpenSCAP or CEL.
  • Add CustomRule CRD and types.
  • Extend TailoredProfile references with a 'kind' field to differentiate between Rule and CustomRule.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@Vincent056 Vincent056 force-pushed the cel-scanner-crd branch 2 times, most recently from 1fed741 to f10057f Compare February 25, 2025 10:57
Copy link

🤖 To deploy this PR, run the following command:

make catalog-deploy CATALOG_IMG=ghcr.io/complianceascode/compliance-operator-catalog:686-f10057fa1740738ef4dab488e72ae3f0bd63986d

Copy link

🤖 To deploy this PR, run the following command:

make catalog-deploy CATALOG_IMG=ghcr.io/complianceascode/compliance-operator-catalog:686-866bd41b109c994cdd0a2697db929d83d69352e9

@xiaojiey
Copy link
Collaborator

Still failed to list customrule crd with the latest version. More permission needed from the apiGroups. Refer to #671 for info.

% oc project openshift-compliance
Already on project "openshift-compliance" on server "https://api.xiyuan-18b.qe.devcluster.openshift.com:6443".
% oc get csv
 NAME                             DISPLAY               VERSION     REPLACES   PHASE
compliance-operator.v1.6.2-dev   Compliance Operator   1.6.2-dev              Succeeded
% oc get customrule                                     
error: the server doesn't have a resource type "customrule"
% oc get crd | grep -i compliancescan
compliancescans.compliance.openshift.io                           2025-02-27T02:10:54Z

@rhmdnd rhmdnd added the CEL CEL features and functionality label Feb 27, 2025
@Vincent056 Vincent056 force-pushed the cel-scanner-crd branch 2 times, most recently from ce487a5 to 4446db3 Compare February 27, 2025 19:26
Copy link

🤖 To deploy this PR, run the following command:

make catalog-deploy CATALOG_IMG=ghcr.io/complianceascode/compliance-operator-catalog:686-4446db38df6d58b67d9d6ef582c2dd8565b889ef

@Vincent056
Copy link
Author

2025/02/27 21:48:56 CronJob test-suspend-scan-setting-binding-rerunner is active
    main_test.go:1790: Put "https://api.ci-op-infhdffw-f837a.quay.devcluster.openshift.com:6443/apis/compliance.openshift.io/v1alpha1/namespaces/osdk-e2e-66ae43a3-80d7-4fdd-8ef9-a53f1fdc5faa/scansettings/test-suspend-scan-setting-scansetting": read tcp 10.129.192.153:45824->54.151.38.0:6443: read: connection reset by peer
--- FAIL: TestSuspendScanSetting (55.93s)
=== RUN   TestRemoveProfileScan

api transient issue

@Vincent056
Copy link
Author

/retest

@xiaojiey
Copy link
Collaborator

Verification pass:

  1. creat customrule with correct configration, customrules created correctly.
% oc get customrule
NAME                                                    AGE
custom-rule-configure-network-policies-namespaces-cel   6s
custom-rule-enable-nonroot-feature-gate-cel             7s
custom-rule-etcd-cert-file-cel                          5s
custom-rule-motd-exists-cel                             36s
  1. When creating customrule with wrong scannertype, the customrule will be failed to created.
% oc apply -f customrules_motd_error_scannertype.yaml 
The CustomRule "custom-rule-motd-error-scannertype-cel" is invalid: spec.scannerType: Unsupported value: "OpenSCAP": supported values: "CEL"

@xiaojiey
Copy link
Collaborator

/label qe-approved

Copy link

🤖 To deploy this PR, run the following command:

make catalog-deploy CATALOG_IMG=ghcr.io/complianceascode/compliance-operator-catalog:686-c1f92b2dd19b9538e752ea9d77928804fb5f05ff


type CELPayload struct {

// ScannerType specifies what type of check this rule performs
Copy link

Choose a reason for hiding this comment

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

This bit is a little confusing to me since we also have the concept of platform and node checks.

Perhaps something like:

// ScannerType denotes the scanning implementation to use when evaluating rules

// ScannerType specifies what type of check this rule performs
// +kubebuilder:validation:Required
// +kubebuilder:validation:Enum=CEL
ScannerType ScannerType `json:"scannerType"`
Copy link

Choose a reason for hiding this comment

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

I wonder if ScannerType should be defined outside the CELPayload. What happens if/when we add another implementation along side CEL? Will we need to define ScannerType in its payload, too?

Copy link
Author

Choose a reason for hiding this comment

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

that's a really good point!

const (
ScannerTypeCEL ScannerType = "CEL"
ScannerTypeOpenSCAP ScannerType = "OpenSCAP"
ScannerTypeUnknown ScannerType = "Unknown"
Copy link

Choose a reason for hiding this comment

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

Ok - so we will use it, just not now?

@@ -367,6 +372,19 @@ func (cs *ComplianceScan) GetScanTypeIfValid() (ComplianceScanType, error) {
return "", ErrUnkownScanType
}

// GetScanerTypeIfValid returns scanner type we will be using if the scan has a valid one, else it returns
// an error
func (cs *ComplianceScan) GetScanerTypeIfValid() (ScannerType, error) {
Copy link

Choose a reason for hiding this comment

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

nit: GetScannerTypeIfValid

@@ -50,6 +50,8 @@ const DefaultStorageRotation = 3

var ErrUnkownScanType = errors.New("Unknown scan type")

var ErrUnkownScanerType = errors.New("Unknown scanner type")
Copy link

Choose a reason for hiding this comment

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

Similar comment here as below (e.g., Scanner instead of Scaner)

@@ -367,6 +372,19 @@ func (cs *ComplianceScan) GetScanTypeIfValid() (ComplianceScanType, error) {
return "", ErrUnkownScanType
}

// GetScanerTypeIfValid returns scanner type we will be using if the scan has a valid one, else it returns
// an error
func (cs *ComplianceScan) GetScanerTypeIfValid() (ScannerType, error) {
Copy link

Choose a reason for hiding this comment

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

nit: Could steal a leaf from the kubeclient book and name if GetScannerTypeOrDie) - or we could use OrFail if we remove the panic(err) eventually.

name:
description: Name of the rule that's being referenced
type: string
rationale:
description: Rationale of why this rule is being selected/deselected
type: string
required:
- kind
Copy link

Choose a reason for hiding this comment

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

Does this mean it's possible to have a CustomRule named foo and a Rule named foo?

I'm trying to think through a case where someone would want to disable a CustomRule. In that case, wouldn't they just not include it in the tailored profile?

Copy link
Author

@Vincent056 Vincent056 Mar 3, 2025

Choose a reason for hiding this comment

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

In that case, wouldn't they just not include it in the tailored profile?

no, they would not be included in the tailored profile in that case

name:
description: Name of the rule that's being referenced
type: string
rationale:
description: Rationale of why this rule is being selected/deselected
type: string
required:
- kind
Copy link

Choose a reason for hiding this comment

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

This one makes sense to me.

name:
description: Name of the rule that's being referenced
type: string
rationale:
description: Rationale of why this rule is being selected/deselected
type: string
required:
- kind
Copy link

Choose a reason for hiding this comment

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

Similar comment here as above. Does it makes sense to support CustomRules from a manual rule perspective in a tailored profile?

Copy link
Author

Choose a reason for hiding this comment

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

I can write a check later in tailoredProfile controller to check for that

@rhmdnd rhmdnd added this to the 1.7.0 milestone Feb 28, 2025
@Vincent056 Vincent056 force-pushed the cel-scanner-crd branch 2 times, most recently from cb3392e to 401c06c Compare March 3, 2025 16:10
Copy link

github-actions bot commented Mar 3, 2025

🤖 To deploy this PR, run the following command:

make catalog-deploy CATALOG_IMG=ghcr.io/complianceascode/compliance-operator-catalog:686-401c06c0874f1a16ff23c3760bb6c9889942fd07

@Vincent056
Copy link
Author

/retest

@xiaojiey
Copy link
Collaborator

xiaojiey commented Mar 4, 2025

/label qe-approved

% oc get customrules
NAME                                                    AGE
custom-rule-configure-network-policies-namespaces-cel   88m
custom-rule-enable-nonroot-feature-gate-cel             88m
custom-rule-etcd-cert-file-cel                          88m
custom-rule-motd-exists-cel                             12m
% oc apply -f customrules_motd_error_scannerType.yaml 
The CustomRule "custom-rule-motd-error-scannertype-cel" is invalid: spec.scannerType: Unsupported value: "OpenSCAP": supported values: "CEL"
% oc apply -f customrules_motd_scannerType_empty.yaml 
The CustomRule "custom-rule-motd-error-scannertype-cel" is invalid: spec.scannerType: Unsupported value: "": supported values: "CEL"

Copy link

@rhmdnd rhmdnd left a comment

Choose a reason for hiding this comment

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

Overall this is on the right track, but I feel we should remove the things we're not going to support initially so it's a simpler feature and less testing surface.

kind:
description: Type of rule, either "Rule" or "CustomRule". "Rule"
is the default if not specified.
type: string
Copy link

Choose a reason for hiding this comment

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

I don't understand why we would support disabling a CustomRule. The use case for CustomRule is that:

  1. User creates a CustomRule for a check that doesn't exist in the default profiles
  2. User creates a TailoredProfile with the CustomRule from step 1 in the enabledRules

Are you able to walk me through the use case for adding a CustomRule to the disabledRules?

@@ -97,13 +107,18 @@ spec:
description: RuleReferenceSpec specifies a rule to be selected/deselected,
as well as the reason why
properties:
kind:
description: Type of rule, either "Rule" or "CustomRule". "Rule"
is the default if not specified.
Copy link

Choose a reason for hiding this comment

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

Same comment here as the disabledRules above. Do we need to support CustomRules here initially? Or can we add that in later?

availableFixes:
description: |-
The Available fixes
This is not supported with CustomRule
Copy link

Choose a reason for hiding this comment

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

I feel if we're not going to support it - we should remove it from the CRD so it's not confusing to users, and not creating additional API surface area for us to test.

We could always add this in later.

Copy link

🤖 To deploy this PR, run the following command:

make catalog-deploy CATALOG_IMG=ghcr.io/complianceascode/compliance-operator-catalog:686-482271b1ccf2da0fe6083fca8e6a6cb501ba68f5

// Expression is the CEL expression to evaluate
// +kubebuilder:validation:Required
// +kubebuilder:validation:MinLength=1
Expression string `json:"expression"`
Copy link

Choose a reason for hiding this comment

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

Evaluation (struct):
  // CELEvaluation
  Expression:
  Inputs:

  // BashEvaluation
  Commands: (list of command strings or reference to config map)

  // AnsibleEvaluation
  Tasks: (reference to config map or CRDs)

  // SomeNewThingWeDoNotKnowAboutYetEvaluation

Perhaps we can learn from https://github.com/openshift/cluster-logging-operator/blob/master/api/observability/v1/output_types.go

@Vincent056 Vincent056 force-pushed the cel-scanner-crd branch 2 times, most recently from 51a25a6 to f7e5add Compare March 10, 2025 16:30
Copy link

🤖 To deploy this PR, run the following command:

make catalog-deploy CATALOG_IMG=ghcr.io/complianceascode/compliance-operator-catalog:686-f7e5add53de9c428332e87aca435978fe777e985

- Introduce scannerType to ComplianceScan and ComplianceSuite for specifying OpenSCAP or CEL.
- Add custom rule CRD (compliance.openshift.io_customrules.yaml) and types.
- Extend TailoredProfile with addtional EnableCustomRule field.
Copy link

🤖 To deploy this PR, run the following command:

make catalog-deploy CATALOG_IMG=ghcr.io/complianceascode/compliance-operator-catalog:686-e5265d453ffe2aee0123f1bd52441420de7dc22b

Copy link

openshift-ci bot commented Mar 10, 2025

@Vincent056: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/images e5265d4 link true /test images
ci/prow/e2e-aws-parallel-arm e5265d4 link true /test e2e-aws-parallel-arm
ci/prow/e2e-aws-serial e5265d4 link true /test e2e-aws-serial

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@Vincent056
Copy link
Author

/retest

@Vincent056 Vincent056 requested a review from rhmdnd March 11, 2025 14:36
@rhmdnd rhmdnd removed this from the 1.7.0 milestone Apr 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants