Skip to content

feat: Add CEL validation to OperatorConfig CRD#1911

Open
bernot-dev wants to merge 4 commits into
mainfrom
operatorconfig-cel-validation-10161733801110130447
Open

feat: Add CEL validation to OperatorConfig CRD#1911
bernot-dev wants to merge 4 commits into
mainfrom
operatorconfig-cel-validation-10161733801110130447

Conversation

@bernot-dev
Copy link
Copy Markdown
Collaborator

Implement CEL-based validation and OpenAPIv3 defaulting for OperatorConfig CRD. This moves validation logic out of the webhook server and embeds it directly into the Custom Resource Definitions, improving reliability by avoiding startup races and zero-node issues.


PR created automatically by Jules for task 10161733801110130447 started by @bernot-dev

@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces CEL-based validations and kubebuilder markers to the OperatorConfig CRD and its corresponding Go types to enforce stricter validation for labels, URLs, GCP project IDs, and Kubernetes resource names. The feedback identifies that the validation for Secret names is overly restrictive, as it currently limits names to 63 characters and excludes dots, which violates the DNS subdomain standard (RFC 1123) used by Kubernetes. It is recommended to update these regex patterns and size constraints to allow up to 253 characters and include dots.

// Struct containing the client cert file for the targets.
Cert *SecretOrConfigMap `json:"cert,omitempty"`
// Secret containing the client key file for the targets.
// +kubebuilder:validation:XValidation:rule="has(self.name) && self.name.matches('^[a-z0-9]([-a-z0-9]*[a-z0-9])?$') && size(self.name) <= 63"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

The CEL validation for the Secret name is too restrictive. Kubernetes Secret names follow the DNS subdomain standard (RFC 1123), which allows dots (.) and can be up to 253 characters long. The current regex and size constraint only allow a single DNS label of up to 63 characters, which will reject valid secret names like my-secret.v1.

Additionally, to fully move validation logic out of the webhook as intended, this validation should be applied consistently to all other SecretKeySelector fields in the API (e.g., CollectionSpec.Credentials, RuleEvaluatorSpec.Credentials, and ManagedAlertmanagerSpec.ConfigSecret).

Suggested change
// +kubebuilder:validation:XValidation:rule="has(self.name) && self.name.matches('^[a-z0-9]([-a-z0-9]*[a-z0-9])?$') && size(self.name) <= 63"
// +kubebuilder:validation:XValidation:rule="has(self.name) && self.name.matches('^[a-z0-9]([-a-z0-9.]*[a-z0-9])?$') && size(self.name) <= 253"

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@jules make this change, but escape the . properly with a backslash so it doesn't match "any character."

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I've escaped the . correctly using double backslashes in the Go string, and updated the pattern to properly match an RFC 1123 sub-domain format.

Comment on lines +474 to +475
- rule: has(self.name) && self.name.matches('^[a-z0-9]([-a-z0-9]*[a-z0-9])?$')
&& size(self.name) <= 63
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

The regex and size limit for the Secret name are too restrictive. Kubernetes Secrets use DNS subdomain names, which allow dots and up to 253 characters. The current rule restricts names to a single DNS label of 63 characters.

                              - rule: has(self.name) && self.name.matches('^[a-z0-9]([-a-z0-9.]*[a-z0-9])?$')
                                  && size(self.name) <= 253

google-labs-jules Bot and others added 4 commits April 10, 2026 12:45
Adds kubebuilder CEL validations to `OperatorConfig` fields based on the migration away from webhook validation, per the provided design doc requirements.

- Validates prometheus label keys in `externalLabels`
- Validates `queryProjectID` constraints (length and regex pattern)
- Adds `isURL` checks for `generatorUrl`, `exports.url`, `externalURL`
- Implements RFC 1123 label constraints for AlertmanagerEndpoints namespace and name
- Validates TLSConfig KeySecret name
- Enforces HTTP/HTTPS scheme for AlertmanagerEndpoints

Co-authored-by: bernot-dev <34751694+bernot-dev@users.noreply.github.com>
Addresses code review feedback to properly escape the `.` character in the CEL
regex validation for the KeySecret name, so it correctly matches literal dots
instead of "any character". Also correctly implemented the full RFC1123
subdomain rules `^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$`

Co-authored-by: bernot-dev <34751694+bernot-dev@users.noreply.github.com>
Addresses code review feedback to properly escape the `.` character in the CEL
regex validation for the KeySecret name, so it correctly matches literal dots
instead of "any character". Also correctly implemented the full RFC1123
subdomain rules `^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$`

Co-authored-by: bernot-dev <34751694+bernot-dev@users.noreply.github.com>
Updates commit messages to conform to conventional commits standards.

Co-authored-by: bernot-dev <34751694+bernot-dev@users.noreply.github.com>
@bernot-dev bernot-dev force-pushed the operatorconfig-cel-validation-10161733801110130447 branch from e3df1a4 to 64f16ce Compare April 10, 2026 19:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant