Skip to content

Commit ece5326

Browse files
theakshaypantchmouel
authored andcommitted
fix(resolve): restore relative task path resolution for repository paths
Commit 6e36620 broke relative task path resolution for repository file paths by only allowing HTTP(S) URLs. This caused paths containing '..' to be passed unresolved to the GitHub API, which rejects them with "path must not contain '..' due to auth vulnerability issue". This fix restores the original behavior by allowing both HTTP(S) URLs and repository file paths (e.g., .tekton/pipelines/build.yaml) to have their relative paths resolved, while still excluding catalog/hub references (catalog://, hub://). Fixes: #2549 Signed-off-by: Akshay Pant <akpant@redhat.com>
1 parent 439e536 commit ece5326

File tree

5 files changed

+51
-4
lines changed

5 files changed

+51
-4
lines changed

pkg/resolve/remote.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,14 @@ func assembleTaskFQDNs(pipelineURL string, tasks []string) ([]string, error) {
3333
return tasks, nil // no pipeline URL, return tasks as is
3434
}
3535

36-
// Only HTTP(S) URLs can serve as base for relative task resolution.
36+
// Only HTTP(S) URLs and repository file paths can serve as base for relative task resolution.
3737
// Hub catalog references (e.g., "catalog://resource:version") use a
3838
// different scheme where relative paths are meaningless.
3939
lowered := strings.ToLower(pipelineURL)
40-
if !strings.HasPrefix(lowered, "http://") && !strings.HasPrefix(lowered, "https://") {
40+
isHTTP := strings.HasPrefix(lowered, "http://") || strings.HasPrefix(lowered, "https://")
41+
isRepoPath := strings.Contains(lowered, "/") && !strings.Contains(lowered, "://")
42+
43+
if !isHTTP && !isRepoPath {
4144
return tasks, nil
4245
}
4346

pkg/resolve/remote_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,10 +562,10 @@ func TestAssembleTaskFQDNs(t *testing.T) {
562562
expected: []string{"https://example.com/repo/task.yaml"},
563563
},
564564
{
565-
name: "repository file path URL returns tasks unchanged",
565+
name: "repository file path URL resolves relative tasks",
566566
pipelineURL: "share/pipelines/build.yaml",
567567
tasks: []string{"../tasks/t.yaml", "tasks/other-task.yaml"},
568-
expected: []string{"../tasks/t.yaml", "tasks/other-task.yaml"},
568+
expected: []string{"share/tasks/t.yaml", "share/pipelines/tasks/other-task.yaml"},
569569
},
570570
}
571571
for _, tt := range tests {

test/gitea_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,25 @@ func TestGiteaPullRequestPipelineAnnotations(t *testing.T) {
103103
defer f()
104104
}
105105

106+
// TestGiteaPullRequestRemotePipelineRelativeTask verifies that relative task paths
107+
// in a Pipeline's annotations are resolved correctly when the pipeline is
108+
// fetched from a repository path.
109+
func TestGiteaPullRequestRemotePipelineRelativeTask(t *testing.T) {
110+
topts := &tgitea.TestOpts{
111+
Regexp: successRegexp,
112+
TargetEvent: triggertype.PullRequest.String(),
113+
YAMLFiles: map[string]string{
114+
".tekton/pr.yaml": "testdata/pipelinerun_remote_pipeline_repo_path.yaml",
115+
".pipelines/pipeline.yaml": "testdata/pipeline_relative_task.yaml",
116+
".tasks/task-referenced-internally.yaml": "testdata/task_referenced_internally.yaml",
117+
},
118+
ExpectEvents: false,
119+
CheckForStatus: "success",
120+
}
121+
_, f := tgitea.TestPR(t, topts)
122+
defer f()
123+
}
124+
106125
func TestGiteaPullRequestResolvePipelineOnlyAssociatedWithPipelineRunFilterted(t *testing.T) {
107126
topts := &tgitea.TestOpts{
108127
Regexp: successRegexp,
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
apiVersion: tekton.dev/v1beta1
3+
kind: Pipeline
4+
metadata:
5+
name: pipeline-relative-task
6+
annotations:
7+
pipelinesascode.tekton.dev/task: "[../.tasks/task-referenced-internally.yaml]"
8+
spec:
9+
tasks:
10+
- name: task-referenced-internally
11+
taskRef:
12+
name: task-referenced-internally
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
apiVersion: tekton.dev/v1beta1
3+
kind: PipelineRun
4+
metadata:
5+
name: "pipelinerun-remote-pipeline-relative-task"
6+
annotations:
7+
pipelinesascode.tekton.dev/target-namespace: "\\ .TargetNamespace //"
8+
pipelinesascode.tekton.dev/on-target-branch: "[\\ .TargetBranch //]"
9+
pipelinesascode.tekton.dev/on-event: "[\\ .TargetEvent //]"
10+
pipelinesascode.tekton.dev/pipeline: "[../.pipelines/pipeline.yaml]"
11+
spec:
12+
pipelineRef:
13+
name: pipeline-relative-task

0 commit comments

Comments
 (0)