pipeline: Missing validation when referencing unknown params with bracket notation
Expected Behavior
There are three ways to reference a parameter in task steps.
# dot notation
$(params.<name>)
# or bracket notation (wrapping <name> with either single or double quotes):
$(params['<name>'])
$(params["<name>"])
If task steps use an unknown <name> in any 3 reference forms (means the parameter name is not declared in params), the webhook should validate against it and report an error like the following when applying a taskrun.
Error from server (BadRequest): error when creating "validation-test.yaml": admission webhook "validation.webhook.pipeline.tekton.dev" denied the request: validation failed: non-existent variable in "set -e\necho $(params.fooo) | tee $(results.echo-output.path)\n": spec.taskSpec.steps[0].script
Actual Behavior
- Only validate against
$(params.<name>)dot notation reference - Not validate against
$(params['<name>'])$(params["<name>"])bracket notation reference. If I use wrong parameter name, the taskrun still succeeds, but the unknown param reference has some bad behaviour i.e. when echo to result.
Steps to Reproduce the Problem
- Apply the following taskrun in which the step
echo-paramsreferences an unknown parameter namefooousing the bracket notation.
apiVersion: tekton.dev/v1beta1
kind: TaskRun
metadata:
generateName: validation-
spec:
taskSpec:
params:
- name: foo
type: string
default: "bar"
results:
- name: echo-output
description: "see echo output"
steps:
- name: echo-params
image: bash
script: |
set -e
echo $(params["fooo"]) | tee $(results.echo-output.path)
- Then, you can see nothing is complaint and taskrun is applied successfully. But the expectation is that the taskrun should not be run and an error should be reported.
- Get the taskrun yaml
kubectl get tr <TASKRUN_NAME> -o yaml - You can see the
taskResultsecho-outputhas unexpected content because the parameterfooodoesn’t exits. And this should not happen.
...
taskResults:
- name: echo-output
value: |2+
...
Additional Info
Normal behaviour when using unknown name in dot notation $(params.<name>).
- Change the
echocommand in step1’s yaml toecho $(params.fooo) | tee $(results.echo-output.path) - apply that yaml file
- you can see the admission webhook will complaint, which is the expected behaviour when using unknown parameter names.
Error from server (BadRequest): error when creating "validation-test.yaml": admission webhook "validation.webhook.pipeline.tekton.dev" denied the request: validation failed: non-existent variable in "set -e\necho $(params.fooo) | tee $(results.echo-output.path)\n": spec.taskSpec.steps[0].script
Kubernetes version:
Output of kubectl version:
Client Version: version.Info{Major:"1", Minor:"23", GitVersion:"v1.23.1", GitCommit:"86ec240af8cbd1b60bcc4c03c20da9b98005b92e", GitTreeState:"clean", BuildDate:"2021-12-16T11:41:01Z", GoVersion:"go1.17.5", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"21", GitVersion:"v1.21.6-gke.1503", GitCommit:"2c7bbda09a9b7ca78db230e099cf90fe901d3df8", GitTreeState:"clean", BuildDate:"2022-02-18T03:17:45Z", GoVersion:"go1.16.9b7", Compiler:"gc", Platform:"linux/amd64"}
WARNING: version difference between client (1.23) and server (1.21) exceeds the supported minor version skew of +/-1
Tekton Pipeline version:
Output of tkn version or kubectl get pods -n tekton-pipelines -l app=tekton-pipelines-controller -o=jsonpath='{.items[0].metadata.labels.version}'
Client version: 0.21.0
Pipeline version: devel
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 15 (15 by maintainers)
After implementing the above fixes, I now get errors from the webhook if the names are inconsistent even with the bracket notation when I run this task:
To allow bracket notation to extract the variable properly, I think the regex pattern needs to be updated to
And line needs to be replaced by something like:
I’m happy to take a stab at this and add some unit tests if you are not working on it @chuangw6.
Proposed Solution
Modify the
extractVariablesFromStringfunction to enable it to extract variable names from bracket notation reference strings. Currently, it can only extract variable names from dot notation reference strings.Example:
current functionality
foofrom string$(params.foo)and extractfoo[*]from string$(params.foo[*]), but it cannot extractfoofrom string$(params["foo"])or$(params['foo'])expect functionality
foofrom string$(params["foo"])or$(params['foo'])