Skip to content

Commit cf22bd5

Browse files
committed
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 6e36620 commit cf22bd5

5 files changed

Lines changed: 51 additions & 4 deletions

File tree

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
@@ -515,10 +515,10 @@ func TestAssembleTaskFQDNs(t *testing.T) {
515515
expected: []string{"https://example.com/repo/task.yaml"},
516516
},
517517
{
518-
name: "repository file path URL returns tasks unchanged",
518+
name: "repository file path URL resolves relative tasks",
519519
pipelineURL: "share/pipelines/build.yaml",
520520
tasks: []string{"../tasks/t.yaml", "tasks/other-task.yaml"},
521-
expected: []string{"../tasks/t.yaml", "tasks/other-task.yaml"},
521+
expected: []string{"share/tasks/t.yaml", "share/pipelines/tasks/other-task.yaml"},
522522
},
523523
}
524524
for _, tt := range tests {

test/gitea_test.go

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

132+
// TestGiteaPullRequestRemotePipelineRelativeTask verifies that relative task paths
133+
// in a Pipeline's annotations are resolved correctly when the pipeline is
134+
// fetched from a repository path.
135+
func TestGiteaPullRequestRemotePipelineRelativeTask(t *testing.T) {
136+
topts := &tgitea.TestOpts{
137+
Regexp: successRegexp,
138+
TargetEvent: triggertype.PullRequest.String(),
139+
YAMLFiles: map[string]string{
140+
".tekton/pr.yaml": "testdata/pipelinerun_remote_pipeline_repo_path.yaml",
141+
".pipelines/pipeline.yaml": "testdata/pipeline_relative_task.yaml",
142+
".tasks/task-referenced-internally.yaml": "testdata/task_referenced_internally.yaml",
143+
},
144+
ExpectEvents: false,
145+
CheckForStatus: "success",
146+
}
147+
_, f := tgitea.TestPR(t, topts)
148+
defer f()
149+
}
150+
132151
func TestGiteaPullRequestResolvePipelineOnlyAssociatedWithPipelineRunFilterted(t *testing.T) {
133152
topts := &tgitea.TestOpts{
134153
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)