Skip to content

Commit 355e530

Browse files
committed
Fix panic in v1beta1 matrix validation for invalid result refs
This fix applies the same safety check that was added to v1 pipelines in PR #8089. The validateMatrixedPipelineTaskConsumed function was panicking when encountering invalid variable substitutions like $(tasks)-$(tasks.echo-result.results.output) because it tried to access subExpressions[1] without first checking if the expression was a valid result reference. The fix adds a check to skip expressions that don't look like result references before attempting to parse them, preventing the panic and allowing the webhook to return a proper validation error instead. Fixes: SRVKP-9204 Related: #8089
1 parent c3c6299 commit 355e530

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

pkg/apis/pipeline/v1beta1/pipeline_validation.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,10 @@ func findAndValidateResultRefsForMatrix(tasks []PipelineTask, taskMapping map[st
811811
func validateMatrixedPipelineTaskConsumed(expressions []string, taskMapping map[string]PipelineTask) (resultRefs []*ResultRef, errs *apis.FieldError) {
812812
var filteredExpressions []string
813813
for _, expression := range expressions {
814+
// if it is not matrix result ref expression, skip
815+
if !resultref.LooksLikeResultRef(expression) {
816+
continue
817+
}
814818
// ie. "tasks.<pipelineTaskName>.results.<resultName>[*]"
815819
subExpressions := strings.Split(expression, ".")
816820
pipelineTask := subExpressions[1] // pipelineTaskName

pkg/apis/pipeline/v1beta1/pipeline_validation_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,56 @@ func TestPipeline_Validate_Success(t *testing.T) {
167167
}},
168168
},
169169
},
170+
}, {
171+
name: "param with different type of values with matrix and invalid result ref",
172+
p: &Pipeline{
173+
ObjectMeta: metav1.ObjectMeta{
174+
Name: "pipelinelinename",
175+
},
176+
Spec: PipelineSpec{
177+
Tasks: []PipelineTask{{
178+
Name: "echo-result",
179+
TaskSpec: &EmbeddedTask{TaskSpec: TaskSpec{
180+
Results: []TaskResult{{
181+
Name: "output",
182+
Type: ResultsTypeString,
183+
}},
184+
Steps: []Step{{
185+
Name: "emit-a-result",
186+
Image: "mirror.gcr.io/bash",
187+
Script: "#!/usr/bin/env bash\necho -n \"some data\" | tee $(results.output.path)",
188+
}},
189+
}},
190+
}, {
191+
Name: "consume-result",
192+
Matrix: &Matrix{
193+
Params: Params{{
194+
Name: "version", Value: ParamValue{ArrayVal: []string{"1", "2"}},
195+
}},
196+
},
197+
Params: Params{
198+
{
199+
Name: "bad-input",
200+
Value: ParamValue{
201+
Type: ParamTypeString,
202+
StringVal: "$(tasks)-$(tasks.echo-result.results.output)",
203+
},
204+
},
205+
},
206+
TaskSpec: &EmbeddedTask{TaskSpec: TaskSpec{
207+
Params: []ParamSpec{{
208+
Name: "bad-input",
209+
Type: ParamTypeString,
210+
}},
211+
Steps: []Step{{
212+
Name: "consume-the-result",
213+
Image: "mirror.gcr.io/bash",
214+
Script: "#!/usr/bin/env bash\necho -n \"input: $(params.bad-input)\"",
215+
}},
216+
}},
217+
}},
218+
},
219+
},
170220
}, {
171221
name: "valid pipeline with pipeline task and final task referencing artifacts in task params with enable-artifacts flag true",
172222
p: &Pipeline{

0 commit comments

Comments
 (0)