Skip to content
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 basic syntactical parsing of CEL filters and expressions. #745

Conversation

bigkevmcd
Copy link
Member

@bigkevmcd bigkevmcd commented Sep 7, 2020

Changes

This does basic syntax checking of CEL interceptor Filters and Overlays.

This would fix this https://tektoncd.slack.com/archives/CKUSJ2A5D/p1599486079009700

Submitter Checklist

These are the criteria that every PR should meet, please check them off as you
review them:

See the contribution guide for more details.

Release Notes

Perform simple syntax checking of CEL filter and overlays in the Webhook validator.

This performs perfunctory syntax validation of the expressions in the interceptor, it won't detect logical errors (expressions that rely on JSON bodies).

@tekton-robot tekton-robot added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label Sep 7, 2020
@tekton-robot tekton-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Sep 7, 2020
@tekton-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-tekton-triggers-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/triggers/v1alpha1/event_listener_validation.go 93.4% 91.7% -1.8

Copy link
Contributor

@savitaashture savitaashture left a comment

Choose a reason for hiding this comment

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

PR looks good to me
Thank you 👍

Few minor comments

for _, v := range i.CEL.Overlays {
_, issues := env.Parse(v.Expression)
if issues != nil && issues.Err() != nil {
return apis.ErrInvalidValue(fmt.Errorf("failed to parse the CEL filter: %s", issues.Err()), "cel.filter")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return apis.ErrInvalidValue(fmt.Errorf("failed to parse the CEL filter: %s", issues.Err()), "cel.filter")
return apis.ErrInvalidValue(fmt.Errorf("failed to parse the CEL overlays: %s", issues.Err()), "cel.overlays")

bldr.EventListenerTrigger("tt", "v1alpha1",
bldr.EventListenerTriggerBinding("tb", "", "tb", "v1alpha1"),
bldr.EventListenerCELInterceptor("body.value == 'test')"),
))),
}, {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add a test case for invalid overlays also

Comment on lines 167 to 168
_, issues := env.Parse(i.CEL.Filter)
if issues != nil && issues.Err() != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
_, issues := env.Parse(i.CEL.Filter)
if issues != nil && issues.Err() != nil {
if_, issues := env.Parse(i.CEL.Filter); issues != nil && issues.Err() != nil {

Comment on lines 173 to 174
_, issues := env.Parse(v.Expression)
if issues != nil && issues.Err() != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
_, issues := env.Parse(v.Expression)
if issues != nil && issues.Err() != nil {
if _, issues := env.Parse(v.Expression); issues != nil && issues.Err() != nil {

@bigkevmcd bigkevmcd force-pushed the basic-validation-cel-expression-webhook branch from 2a3b374 to 5faaff9 Compare September 7, 2020 16:47
@tekton-robot tekton-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Sep 7, 2020
@tekton-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-tekton-triggers-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/triggers/v1alpha1/event_listener_validation.go 93.4% 92.9% -0.6

@sravankumar777
Copy link
Contributor

Added the reported github issue :)

#746

Copy link
Contributor

@savitaashture savitaashture left a comment

Choose a reason for hiding this comment

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

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Sep 8, 2020
Copy link
Contributor

@khrm khrm left a comment

Choose a reason for hiding this comment

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

/lgtm

@khrm
Copy link
Contributor

khrm commented Sep 8, 2020

/approve

@tekton-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: khrm

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

@tekton-robot tekton-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 8, 2020
@tekton-robot tekton-robot merged commit 8c3090c into tektoncd:master Sep 8, 2020
@dibyom dibyom added this to the Triggers v0.8.0 milestone Sep 8, 2020
@bigkevmcd bigkevmcd deleted the basic-validation-cel-expression-webhook branch September 24, 2020 19:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants