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

Provide error for invalid bindings #1049

Merged

Conversation

jmcshane
Copy link
Contributor

Changes

TriggerBinding values do not yet have any validation on their values, but we have situations, as
discussed in #385, where the binding value is somewhat nonsensical. In templates, it is possible that
a nesting situation may take place within a TaskRun script, but for a binding parameter value it makes
sense to avoid these types of situations.

This PR currently only avoids the situations where expressions are directly nested, meaning
dollar-parens immediately followed by dollar-parens. This would not detect a situation where they are
separated by some characters

Submitter Checklist

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

  • Includes tests (if functionality changed/added)
  • Includes docs (if user facing)
  • Commit messages follow commit message best practices
  • Release notes block has been filled in or deleted (only if no user facing changes)

See the contribution guide for more details.

Release Notes

TriggerBinding error on invalid Tekton template values

@tekton-robot tekton-robot added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label Apr 14, 2021
@tekton-robot tekton-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Apr 14, 2021
@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/template/event.go 100.0% 97.8% -2.2
pkg/template/jsonpath.go 93.3% 93.8% 0.4

@dibyom
Copy link
Member

dibyom commented Apr 14, 2021

Looks like build test is failing with:

pkg/template/jsonpath.go:187:11: `if` block ends with a `return` statement, so drop this `else` and outdent its block (golint)
			} else {
			       ^

@jmcshane
Copy link
Contributor Author

So, this happens at processing time, but I wonder if we want to change this to a validation error? It might be an issue in existing installs, but an error at triggerbinding creation time might make more sense than during the HTTP request.

@jmcshane jmcshane force-pushed the bugfix/error-message-on-nesting branch from 53aad97 to 3d385f0 Compare April 15, 2021 13:44
@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/template/event.go 100.0% 97.8% -2.2
pkg/template/jsonpath.go 93.3% 93.8% 0.4

@dibyom
Copy link
Member

dibyom commented Apr 15, 2021

So, this happens at processing time, but I wonder if we want to change this to a validation error? It might be an issue in existing installs, but an error at triggerbinding creation time might make more sense than during the HTTP request.

Agreed. That makes more sense.

@jmcshane jmcshane force-pushed the bugfix/error-message-on-nesting branch from 3d385f0 to daac875 Compare April 15, 2021 18:16
@jmcshane
Copy link
Contributor Author

Updated tests and Validation function (as well as validation error messages). The HTTP request processing remains completely the same, we will just reject binding values that have nested tekton expressions within them.

@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/trigger_binding_validation.go 100.0% 93.5% -6.5

@jmcshane jmcshane force-pushed the bugfix/error-message-on-nesting branch from daac875 to 633476f Compare April 15, 2021 18:19
This eliminates the concern about nested Tekton expressions that could possibly be parsed in sink processing.
@jmcshane jmcshane force-pushed the bugfix/error-message-on-nesting branch from 633476f to 3e2476d Compare April 15, 2021 18:26
terminated := true
for _, e := range maybeExpressions[1:] { // Split always returns at least one element
// Iterate until we find the first unbalanced )
numOpenBrackets := 0
Copy link
Member

Choose a reason for hiding this comment

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

question: is it possible to reuse this bit from the jsonpath.go? Maybe this bit could be extracted to its own function? If that's too much for this PR, I'm happy to merge this as is.

@tekton-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dibyom

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 Apr 16, 2021
@dibyom
Copy link
Member

dibyom commented Apr 23, 2021

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Apr 23, 2021
@tekton-robot tekton-robot merged commit 7e52b44 into tektoncd:main Apr 23, 2021
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.

3 participants