-
Notifications
You must be signed in to change notification settings - Fork 252
Add CEL template #1012
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
Add CEL template #1012
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like there is some AI-generated code in this PR. That's fine but I'd advice to add a note in the description about that .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice and compact, I'm a fan!
I understand that due to being an expression language, a CEL check is a bit limited compared to a check in some procedural language, where you can accumulate state. I'm not sure how important this limitation will be so I'm in favor of merging CEL support.
We can then try to implement open requests for checks using this CEL template and see how far we can go.
Signed-off-by: Tomasz Janiszewski <[email protected]>
Signed-off-by: Tomasz Janiszewski <[email protected]>
Signed-off-by: Tomasz Janiszewski <[email protected]>
Signed-off-by: Tomasz Janiszewski <[email protected]>
Signed-off-by: Tomasz Janiszewski <[email protected]>
Signed-off-by: Tomasz Janiszewski <[email protected]>
This dangling service can accumulate state, which means it can basically do anything we've done with Go. The issue is that it can get messy for big projects, especially since we're keeping it all in one YAML file. Moving forward, we should make CEL development easier by:
|
Add CEL Template for Custom Expression-Based Checks
This PR introduces a new
cel-expression
template that enables users to write custom checks using the Common Expression Language (CEL). This powerful addition allows for flexible, expression-based validation of Kubernetes resources without requiring Go code changes.🚀 Features
cel-expression
template inpkg/templates/cel/template.go:18
objectkinds.Any
🔧 How It Works
The template provides two variables to CEL expressions:
subject
: The current Kubernetes resource being evaluatedobjects
: Array of all Kubernetes resources in the current contextCEL expressions should return:
""
if the check passes📝 Usage Examples
Replace complex template logic with simple CEL expressions:
Example 1: Forbidden Annotation Check
Example 2: IRSA Role Validation
🧪 Testing
e2etests/bats-tests.sh
demonstrates the CEL template replacing traditional forbidden annotation checkspkg/templates/cel/template_test.go
e2etests/testdata/cel-config.yaml
andtests/checks/cel.yml
💡 Benefits
🔄 Migration Path
This template can replace many existing specialized templates. For example, the forbidden annotation functionality previously requiring a dedicated template can now be implemented with a simple CEL expression (as shown in the e2e tests).
📚 Resources
🤖 Generated with Claude Code
Co-Authored-By: Claude [email protected]