Skip to content

Commit c1bbe00

Browse files
vdemeestertekton-robot
authored andcommitted
Cleanup resolved object before validating through dry-run
This ensure that we are not going to fail during validation with dry-run. An example of such a failure would be the following scenario. - A task in a namespace has `ownerReferences` with `blockOwnerDeletion: true` - A user uses the `cluster` resolver to fetch that task - That user doesn't have a lot of rights in that namespace (only listing Tasks for example). /kind bug Signed-off-by: Vincent Demeester <vdemeest@redhat.com> (cherry picked from commit d3b18ea) (cherry picked from commit a89b964)
1 parent 8a7ccf4 commit c1bbe00

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

pkg/reconciler/pipelinerun/resources/pipelineref.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ func resolvePipeline(ctx context.Context, resolver remote.Resolver, name string,
136136
func readRuntimeObjectAsPipeline(ctx context.Context, namespace string, obj runtime.Object, k8s kubernetes.Interface, tekton clientset.Interface, refSource *v1.RefSource, verificationPolicies []*v1alpha1.VerificationPolicy) (*v1.Pipeline, *trustedresources.VerificationResult, error) {
137137
switch obj := obj.(type) {
138138
case *v1beta1.Pipeline:
139+
// Cleanup object from things we don't care about
140+
// FIXME: extract this in a function
141+
obj.ObjectMeta.OwnerReferences = nil
139142
// Verify the Pipeline once we fetch from the remote resolution, mutating, validation and conversion of the pipeline should happen after the verification, since signatures are based on the remote pipeline contents
140143
vr := trustedresources.VerifyResource(ctx, obj, k8s, refSource, verificationPolicies)
141144
// Issue a dry-run request to create the remote Pipeline, so that it can undergo validation from validating admission webhooks
@@ -154,6 +157,9 @@ func readRuntimeObjectAsPipeline(ctx context.Context, namespace string, obj runt
154157
}
155158
return p, &vr, nil
156159
case *v1.Pipeline:
160+
// Cleanup object from things we don't care about
161+
// FIXME: extract this in a function
162+
obj.ObjectMeta.OwnerReferences = nil
157163
vr := trustedresources.VerifyResource(ctx, obj, k8s, refSource, verificationPolicies)
158164
// Issue a dry-run request to create the remote Pipeline, so that it can undergo validation from validating admission webhooks
159165
// without actually creating the Pipeline on the cluster

pkg/reconciler/taskrun/resources/taskref.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ func GetTaskFuncFromTaskRun(ctx context.Context, k8s kubernetes.Interface, tekto
8484
// a remote image to fetch the reference. It will also return the "kind" of the task being referenced.
8585
// OCI bundle and remote resolution tasks will be verified by trusted resources if the feature is enabled
8686
func GetTaskFunc(ctx context.Context, k8s kubernetes.Interface, tekton clientset.Interface, requester remoteresource.Requester,
87-
owner kmeta.OwnerRefable, tr *v1.TaskRef, trName string, namespace, saName string, verificationPolicies []*v1alpha1.VerificationPolicy) GetTask {
87+
owner kmeta.OwnerRefable, tr *v1.TaskRef, trName string, namespace, saName string, verificationPolicies []*v1alpha1.VerificationPolicy,
88+
) GetTask {
8889
kind := v1.NamespacedTaskKind
8990
if tr != nil && tr.Kind != "" {
9091
kind = tr.Kind
@@ -172,6 +173,9 @@ func resolveStepAction(ctx context.Context, resolver remote.Resolver, name, name
172173
}
173174
switch obj := obj.(type) { //nolint:gocritic
174175
case *v1alpha1.StepAction:
176+
// Cleanup object from things we don't care about
177+
// FIXME: extract this in a function
178+
obj.ObjectMeta.OwnerReferences = nil
175179
if err := apiserver.DryRunValidate(ctx, namespace, obj, tekton); err != nil {
176180
return nil, nil, err
177181
}
@@ -192,6 +196,9 @@ func resolveStepAction(ctx context.Context, resolver remote.Resolver, name, name
192196
func readRuntimeObjectAsTask(ctx context.Context, namespace string, obj runtime.Object, k8s kubernetes.Interface, tekton clientset.Interface, refSource *v1.RefSource, verificationPolicies []*v1alpha1.VerificationPolicy) (*v1.Task, *trustedresources.VerificationResult, error) {
193197
switch obj := obj.(type) {
194198
case *v1beta1.Task:
199+
// Cleanup object from things we don't care about
200+
// FIXME: extract this in a function
201+
obj.ObjectMeta.OwnerReferences = nil
195202
// Verify the Task once we fetch from the remote resolution, mutating, validation and conversion of the task should happen after the verification, since signatures are based on the remote task contents
196203
vr := trustedresources.VerifyResource(ctx, obj, k8s, refSource, verificationPolicies)
197204
// Issue a dry-run request to create the remote Task, so that it can undergo validation from validating admission webhooks
@@ -210,6 +217,9 @@ func readRuntimeObjectAsTask(ctx context.Context, namespace string, obj runtime.
210217
}
211218
return t, &vr, nil
212219
case *v1beta1.ClusterTask:
220+
// Cleanup object from things we don't care about
221+
// FIXME: extract this in a function
222+
obj.ObjectMeta.OwnerReferences = nil
213223
t, err := convertClusterTaskToTask(ctx, *obj)
214224
// Issue a dry-run request to create the remote Task, so that it can undergo validation from validating admission webhooks
215225
// without actually creating the Task on the cluster
@@ -218,6 +228,9 @@ func readRuntimeObjectAsTask(ctx context.Context, namespace string, obj runtime.
218228
}
219229
return t, nil, err
220230
case *v1.Task:
231+
// Cleanup object from things we don't care about
232+
// FIXME: extract this in a function
233+
obj.ObjectMeta.OwnerReferences = nil
221234
vr := trustedresources.VerifyResource(ctx, obj, k8s, refSource, verificationPolicies)
222235
// Issue a dry-run request to create the remote Task, so that it can undergo validation from validating admission webhooks
223236
// without actually creating the Task on the cluster

0 commit comments

Comments
 (0)