Skip to content

Commit 7199c26

Browse files
Scotttekton-robot
authored andcommitted
PullRequest PipelineResource expects root
When a user replaces the pullrequest-init image with their own it's possible that the default UID of the container is not 0. More generally, we've never tested PipelineResources as anything but the root user. Rather than attempt to improve a feature that's now deprecated by adding testing and support for non-root use-cases it makes more sense to simply encode this expectation in to their containers until they're removed. This commit updates the pullrequest pipelineresource to explicitly set its container `runAsUser` to `0`. It also updates the pullrequest-init image to use our default base of distroless' static:nonroot.
1 parent 92281d6 commit 7199c26

File tree

4 files changed

+31
-22
lines changed

4 files changed

+31
-22
lines changed

.ko.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,3 @@ baseImageOverrides:
33
# git-init uses a base image that includes Git, and supports running either
44
# as root or as user nonroot with UID 65532.
55
github.com/tektoncd/pipeline/cmd/git-init: gcr.io/tekton-nightly/github.com/tektoncd/pipeline/git-init-build-base:latest
6-
7-
# pullrequest-init supports running either as root or as user with UID 65532.
8-
github.com/tektoncd/pipeline/cmd/pullrequest-init: gcr.io/distroless/static

pkg/apis/resource/v1alpha1/pullrequest/pull_request_resource.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
resourcev1alpha1 "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1"
2727
"github.com/tektoncd/pipeline/pkg/names"
2828
corev1 "k8s.io/api/core/v1"
29+
"knative.dev/pkg/ptr"
2930
)
3031

3132
const (
@@ -174,5 +175,9 @@ func (s *Resource) getSteps(mode string, sourcePath string) []pipelinev1beta1.St
174175
Args: args,
175176
WorkingDir: pipeline.WorkspaceDir,
176177
Env: evs,
178+
SecurityContext: &corev1.SecurityContext{
179+
// The pullrequest pipeline resource only works when running as root.
180+
RunAsUser: ptr.Int64(0),
181+
},
177182
}}}
178183
}

pkg/apis/resource/v1alpha1/pullrequest/pull_request_resource_test.go

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"testing"
2121

2222
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23+
"knative.dev/pkg/ptr"
2324

2425
"github.com/google/go-cmp/cmp"
2526
"github.com/tektoncd/pipeline/pkg/apis/pipeline"
@@ -102,6 +103,9 @@ type testcase struct {
102103
const workspace = "/workspace"
103104

104105
func containerTestCases(mode string) []testcase {
106+
securityContext := &corev1.SecurityContext{
107+
RunAsUser: ptr.Int64(0),
108+
}
105109
return []testcase{{
106110
in: &pullrequest.Resource{
107111
Name: "nocreds",
@@ -110,12 +114,13 @@ func containerTestCases(mode string) []testcase {
110114
InsecureSkipTLSVerify: false,
111115
},
112116
out: []v1beta1.Step{{Container: corev1.Container{
113-
Name: "pr-source-nocreds-9l9zj",
114-
Image: "override-with-pr:latest",
115-
WorkingDir: pipeline.WorkspaceDir,
116-
Command: []string{"/ko-app/pullrequest-init"},
117-
Args: []string{"-url", "https://example.com", "-path", workspace, "-mode", mode},
118-
Env: []corev1.EnvVar{{Name: "TEKTON_RESOURCE_NAME", Value: "nocreds"}},
117+
Name: "pr-source-nocreds-9l9zj",
118+
Image: "override-with-pr:latest",
119+
WorkingDir: pipeline.WorkspaceDir,
120+
Command: []string{"/ko-app/pullrequest-init"},
121+
Args: []string{"-url", "https://example.com", "-path", workspace, "-mode", mode},
122+
Env: []corev1.EnvVar{{Name: "TEKTON_RESOURCE_NAME", Value: "nocreds"}},
123+
SecurityContext: securityContext,
119124
}}},
120125
}, {
121126
in: &pullrequest.Resource{
@@ -149,6 +154,7 @@ func containerTestCases(mode string) []testcase {
149154
},
150155
},
151156
}},
157+
SecurityContext: securityContext,
152158
}}},
153159
}, {
154160
in: &pullrequest.Resource{
@@ -158,12 +164,13 @@ func containerTestCases(mode string) []testcase {
158164
InsecureSkipTLSVerify: true,
159165
},
160166
out: []v1beta1.Step{{Container: corev1.Container{
161-
Name: "pr-source-nocreds-mssqb",
162-
Image: "override-with-pr:latest",
163-
WorkingDir: pipeline.WorkspaceDir,
164-
Command: []string{"/ko-app/pullrequest-init"},
165-
Args: []string{"-url", "https://example.com", "-path", workspace, "-mode", mode, "-insecure-skip-tls-verify=true"},
166-
Env: []corev1.EnvVar{{Name: "TEKTON_RESOURCE_NAME", Value: "nocreds"}},
167+
Name: "pr-source-nocreds-mssqb",
168+
Image: "override-with-pr:latest",
169+
WorkingDir: pipeline.WorkspaceDir,
170+
Command: []string{"/ko-app/pullrequest-init"},
171+
Args: []string{"-url", "https://example.com", "-path", workspace, "-mode", mode, "-insecure-skip-tls-verify=true"},
172+
Env: []corev1.EnvVar{{Name: "TEKTON_RESOURCE_NAME", Value: "nocreds"}},
173+
SecurityContext: securityContext,
167174
}}},
168175
}, {
169176
in: &pullrequest.Resource{
@@ -173,12 +180,13 @@ func containerTestCases(mode string) []testcase {
173180
DisableStrictJSONComments: true,
174181
},
175182
out: []v1beta1.Step{{Container: corev1.Container{
176-
Name: "pr-source-strict-json-comments-78c5n",
177-
Image: "override-with-pr:latest",
178-
WorkingDir: pipeline.WorkspaceDir,
179-
Command: []string{"/ko-app/pullrequest-init"},
180-
Args: []string{"-url", "https://example.com", "-path", workspace, "-mode", mode, "-disable-strict-json-comments=true"},
181-
Env: []corev1.EnvVar{{Name: "TEKTON_RESOURCE_NAME", Value: "strict-json-comments"}},
183+
Name: "pr-source-strict-json-comments-78c5n",
184+
Image: "override-with-pr:latest",
185+
WorkingDir: pipeline.WorkspaceDir,
186+
Command: []string{"/ko-app/pullrequest-init"},
187+
Args: []string{"-url", "https://example.com", "-path", workspace, "-mode", mode, "-disable-strict-json-comments=true"},
188+
Env: []corev1.EnvVar{{Name: "TEKTON_RESOURCE_NAME", Value: "strict-json-comments"}},
189+
SecurityContext: securityContext,
182190
}}},
183191
}}
184192
}

tekton/publish.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ spec:
110110
111111
# This matches values configured in .ko.yaml
112112
$(params.package)/cmd/git-init: ${CONTAINER_REGISTRY}/$(params.package)/git-init-build-base:latest
113-
$(params.package)/cmd/pullrequest-init: gcr.io/distroless/static
114113
EOF
115114
116115
cat ${PROJECT_ROOT}/.ko.yaml

0 commit comments

Comments
 (0)