Commit d6b0c35
authored
CMP-2870, CMP-2869, CMP-2870, CMP-2872, CMP-2868: Compliance SDK Compliance Operator Implementation (#811)
* feat: Add CustomRule CRD for custom compliance rules
Adds a new CustomRule CRD to support user-defined compliance rules with CEL expressions
* Enhance TailoredProfile to support CustomRules
Add CustomRule handling logic
Validate rule types consistency
Update ownership management logic
Ensure correct product type annotation for CustomRUle
Ensure correct scannerType annotation is set
* feat: Add initial CEL expression scanner pod implmentation
* Fix CustomRule api verify-bundle error
Fix an issues that fails verify-bundle make target, we need to move rulepayload under Spec
* Skip not used component for CEL scan
We are going to disable the raw stroage related resources as well as runtime kubeletconfig for CEL as those are not going to be used
* Skip aggregator for cel scanner based Scan
* Handle CustomRule in ScanSettingBinding Controller
We are modifying the ScanSettingBinding controller so that if tailoredProfile is referencing CustomRule will be handled accordingly, we are also removing the not used scannerImage field in ComplianceScan CRD
* Update ScanHandler to support CEL
We are updating the Platform ScanHandler to be able to process CEL based CustomRule.
* Add CCR generation in CEL-Scanner
We are adding the ability to generate ComplianceCheckResult directly in CEL scanner
* Update TailoredProfile status for CustomRule
* Fix tailoredProfile controller annotation generation for Custom CEL Rule
* Add custom rule annotation for ComplianceSuite Controller
* Add CEL-scanner cmd
* Fix UUID generation for CustomRule
* Add CEL demo files
* Fix issues in cel scanner cmd
* Fill correct tp information for CustomRule in the Scan
* Add rbac for CEL Scanner
* Fix cmd flag and client creation for CEL scanner
* Adjust demo, add rbac for kubevirt rule
* Fix issue with CEl scanner
Use correct resouce as input for cel scanner
* Add necessary permission so scanner can set ownership to CCR
* Make KubeResource Input as inline config
This will align with enhancement, make input KubeResource as inline config under input instead
of having it under input.KubeResource
* Add more demo files for CEL
* Update tailoredProfile controller to watch for CustomRule changes
* Fix the CEL aggregation phase
Updating platformScanTypeHandler to handle compliance result
for CEL correctly during aggregator phase so that we can move to
Done state.
* Change check status to Fail for not fetched resource
We are switching the ComplianceCheckStatus to Fail
Instead of error for resource that we are not able to fetch. We will only set it to error when we were having other issues evaluating the rule.
This matches the openscap default behavior.
* Fix duplicated scanner pod for OpenScap scan
This is to revert changes made to scanner pod config, so that OpenScap can run without issues.
* Add support for custom variables in CEL scanner and tailored profile
* Add README for writing and running CEL rules in Compliance Operator
* remove unwanted changes
* Make OpenSCAP as default value for scannerType
This makes changes backward compatible and will also address some e2e failures with rerunner
* Updating scanner field description
* Add CEL scanner module with comprehensive architecture and input handling
This commit introduces a new CEL scanner module designed for compliance checking using Google's Common Expression Language (CEL). Key features include:
- A flexible architecture supporting multiple input types (Kubernetes, filesystem, system commands).
- Comprehensive test coverage with unit, integration, and benchmark tests.
- Detailed documentation including usage guides and architecture principles.
- New input fetchers for Kubernetes and filesystem resources, along with system command execution capabilities.
This implementation enhances the compliance operator's ability to evaluate rules against various data sources, ensuring a robust compliance scanning solution.
* Update go.sum to remove unused dependencies and update existing ones from mergy conflict with master
* Install compliance-sdk go1.23 dependency
* Remove deprecated cel-scanner-refactored.go and eliminate unused components.
* Refactor KubeResource structure in customrule_types.go to integrate KubernetesInputSpec from compliance-sdk
This update modifies the KubeResource type to include a KubernetesInputSpec field, enhancing the input handling for compliance rules. The InputPayload structure has also been adjusted to reflect this change, improving the overall architecture for compliance scanning.
* Add custom rule controller and unit tests for validation
This commit introduces a new controller for managing custom rules within the compliance operator. It includes the implementation of the `add_customrule.go` file, which registers the custom rule controller with the manager. Additionally, comprehensive unit tests have been added in `customrule_controller_test.go` to validate the reconciliation logic and structure of custom rules, ensuring proper handling of various scenarios including valid and invalid rules.
* Update compliance-sdk dependency and enhance CustomRule CRD with validation features
This commit updates the compliance-sdk dependency to a newer version, improving compatibility and functionality. Additionally, it enhances the CustomRule Custom Resource Definition (CRD) by adding additional printer columns for better visibility of rule status and severity. The validation structure for CustomRule inputs has been refined, ensuring more robust error handling and validation during rule processing. Unit tests have been updated to reflect these changes, ensuring comprehensive coverage of the new features.
* Add support for deprecated tailored profile notifications in ComplianceScan for CustomRule
This commit enhances the ComplianceScan controller to notify users when a deprecated tailored profile is in use for CEL scanner types.
* Refactor CEL scanner to integrate compliance-sdk and enhance logging
This commit refactors the CEL scanner implementation to utilize the compliance-sdk for improved resource fetching and scanning capabilities.
* Remove deprecated CEL demo rules and associated resources; add new custom rule for pod security context as for the demo.
* Add e2e tests for customRule
This commit adds tests for CustomRule functionality, including tests for tailored profiles, validation of CEL expressions, and handling of multiple inputs.
* Revert image registry cleanup in Makefile
* Remove unused DeriveResourcePath function and clean up imports in common.go
* Move end-to-end tests for CustomRule functionality to Parallel
* Refactor CustomRule validation tests to improve error handling
This commit updates the error handling in the CustomRule validation tests, it was asserting the wrong result
* Update CustomRule and TailoredProfile descriptions for clarity
This commit refines the descriptions in the CustomRule and TailoredProfile CRDs to enhance clarity, specifically changing references from "XCCDF ID" to "ID of the Rule" and improving the wording of scanner type descriptions. Additionally, it updates the CustomRule validation logic to use the new CustomRulePayload structure, ensuring consistency across the codebase. Unit tests have been adjusted accordingly to reflect these changes.
* Clean Up not used CRD and RBAC config
* Add checkType to CustomRule examples.
* Refactor CustomRule to replace ErrorMessage with FailureReason
* Enhance ScanSettingBinding status handling in controller
This commit introduces logic to transition the ScanSettingBinding status from Invalid to Ready when the associated TailoredProfile is fixed. It updates the status check function to account for this transition and adds corresponding unit tests to verify the behavior.
* Remove unused label from custom security checks profile in pod security configuration
* Update CustomRule descriptions for improved clarity
* Revert the id field of Rule and TailoredProfile to be XCCDF ID
* Enhance descriptions for rule reference in TailoredProfiles and CRDs to improve clarity. Specify the type of rule reference as "Rule" or "CustomRule" and clarify default behavior.
* Update ComplianceScanSpec and CustomRule definitions for improved clarity and validation.
Enhance ScannerType description and add validation enum for ScannerType.
Remove unused Severity column from CustomRule resource definition.
* Rename getCelScannerClient to getRuntimeClient for improved clarity in client creation function.
* Refactor CelScanner configuration to use ApiResourceCacheDir instead of ApiResourcePath for API resources are cached
ApiResourceCacheDir unambiguously refers to a local filesystem directory where API resources are cached
* Update failure reason in CustomRule for pod security context validation
* Enhance error logging and refactor variable handling in CelScanner.
Improved log messages to include additional context for profile and tailored profile errors.
* Change scan result output format from XML to JSON in CelScanner and update serialization error messages for clarity.
* Add error handling for ComplianceCheckResult operations in CelScanner
Implement os.Exit with CelExitCodeError for error scenarios when listing, creating/updating, and deleting ComplianceCheckResults to ensure proper termination on failure.
* Refactor object retrieval logic in CelScanner and introduce utility function for improved error handling
Replace the existing getObjectIfFoundCEL function with a new utility function GetObjectIfFound in the utils package,
which implements retry logic with exponential backoff for retrieving Kubernetes objects. Additionally, correct
spelling errors in method names related to scanner type validation in ComplianceScan.
* Update CustomRuleProfileAnnotation to clarify its purpose as tailored profile containing custom rules
* Refactor CustomRule validation logic to remove redudent checks performed by kubebuilder
* Update CustomRule ID in TestCustomRuleTailoredProfile to just use customRuleName
* Fix TestCustomRuleTailoredProfile e2e test
* Add readiness check for ScanSettingBinding in TestCustomRuleWithMultipleInputs
* Fix spelling error in scanner type validation method in ComplianceScan
* Add TestCustomRuleCascadingStatusUpdate to validate cascading status changes
This test checks the behavior of CustomRule, TailoredProfile, and ScanSettingBinding when a CustomRule is updated with an invalid expression. It verifies that the resources transition to error states and subsequently recover when the expression is fixed. Additionally, it updates the ID fields in existing tests to use consistent naming conventions.
* Refactor TestCustomRuleTailoredProfile to improve pod creation logic and update compliance expectations.
The test now verifies that a pod without the test label is ignored, while a pod with the label is expected to be non-compliant due to the absence of a security context.
* Add validation to prevent mixing CustomRules and regular Rules in TailoredProfile
* Add FailureReason to warnings in ComplianceCheckResult for failed scans
* Adjusted the rule in TestTailoredProfileRejectsMixedRuleTypes to fix error in tailoredProfile states caused by node rule platform mixing.
* Refactor TailoredProfile controller logic and enhance test validations. Updated condition for custom rules check and improved error messaging for unsupported rule types. Enhanced tests to validate CustomRule results, ensuring accurate compliance status reporting.
* Update scan name assignment in CustomRule tests to use TailoredProfile name.
This change clarifies the expected behavior for TailoredProfiles in the tests, ensuring accurate compliance check results.
* Added validation to ensure CustomRules only use 'Platform' as the check type and 'CEL' as the scanner type. Updated descriptions in CRDs for clarity on rule ID and check type restrictions.
* Update error logging in CelScanner to use TailoredProfile name for improved clarity in scan failure messages.
* Refactor error handling in TestCustomRuleCheckTypeAndScannerTypeValidation to improve clarity on invalid scannerType creation. Removed unnecessary status checks and streamlined test logic for better readability.1 parent 8277b8d commit d6b0c35
File tree
420 files changed
+99376
-18958
lines changed- bundle/manifests
- cel-demo
- cmd/manager
- config
- crd
- bases
- manifests/bases
- rbac
- pkg
- apis/compliance/v1alpha1
- controller
- compliancescan
- compliancesuite
- customrule
- scansettingbinding
- tailoredprofile
- utils
- tests/e2e
- framework
- parallel
- vendor
- cel.dev/expr
- github.com
- ComplianceAsCode/compliance-sdk
- pkg
- fetchers
- scanner
- antlr4-go/antlr/v4
- google/cel-go
- cel
- checker
- decls
- common
- ast
- containers
- debug
- decls
- functions
- operators
- overloads
- runes
- stdlib
- types
- pb
- ref
- traits
- interpreter
- parser
- gen
- stoewer/go-strcase
- golang.org/x
- crypto
- cryptobyte
- internal/poly1305
- exp/slices
- mod
- modfile
- module
- semver
- net
- html
- atom
- http2
- trace
- sync/errgroup
- sys
- cpu
- unix
- windows
- registry
- term
- tools
- go
- analysis
- passes/buildssa
- gcexportdata
- packages
- ssa
- types
- objectpath
- typeutil
- internal
- event
- keys
- label
- gcimporter
- gocommand
- packagesinternal
- pkgbits
- stdlib
- typeparams
- typesinternal
- google.golang.org
- genproto/googleapis/api/expr/v1alpha1
- protobuf/types
- dynamicpb
- known/wrapperspb
- k8s.io/kube-openapi/pkg/spec3
- sigs.k8s.io/randfill
- bytesource
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
420 files changed
+99376
-18958
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
1 | 5 | | |
2 | 6 | | |
3 | 7 | | |
| |||
61 | 65 | | |
62 | 66 | | |
63 | 67 | | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
64 | 76 | | |
Lines changed: 37 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
206 | 206 | | |
207 | 207 | | |
208 | 208 | | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
209 | 215 | | |
210 | 216 | | |
211 | 217 | | |
| |||
1034 | 1040 | | |
1035 | 1041 | | |
1036 | 1042 | | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
1037 | 1050 | | |
1038 | 1051 | | |
1039 | 1052 | | |
1040 | 1053 | | |
| 1054 | + | |
1041 | 1055 | | |
1042 | 1056 | | |
| 1057 | + | |
| 1058 | + | |
| 1059 | + | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
1043 | 1068 | | |
1044 | 1069 | | |
1045 | 1070 | | |
1046 | 1071 | | |
| 1072 | + | |
| 1073 | + | |
| 1074 | + | |
| 1075 | + | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
| 1083 | + | |
1047 | 1084 | | |
1048 | 1085 | | |
1049 | 1086 | | |
| |||
Lines changed: 8 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
273 | 273 | | |
274 | 274 | | |
275 | 275 | | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
276 | 284 | | |
277 | 285 | | |
278 | 286 | | |
| |||
Lines changed: 8 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
292 | 292 | | |
293 | 293 | | |
294 | 294 | | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
295 | 303 | | |
296 | 304 | | |
297 | 305 | | |
| |||
Lines changed: 204 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| 57 | + | |
57 | 58 | | |
58 | 59 | | |
59 | 60 | | |
60 | 61 | | |
61 | 62 | | |
62 | | - | |
| 63 | + | |
63 | 64 | | |
64 | 65 | | |
65 | 66 | | |
| |||
Lines changed: 18 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
60 | 66 | | |
61 | 67 | | |
62 | 68 | | |
| |||
75 | 81 | | |
76 | 82 | | |
77 | 83 | | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
78 | 90 | | |
79 | 91 | | |
80 | 92 | | |
| |||
97 | 109 | | |
98 | 110 | | |
99 | 111 | | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
100 | 118 | | |
101 | 119 | | |
102 | 120 | | |
| |||
0 commit comments