Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add webhook validation for remote Tasks #6942

Merged
merged 1 commit into from
Aug 16, 2023

Conversation

lbernick
Copy link
Member

@lbernick lbernick commented Jul 19, 2023

A prior commit (#6887) added validation for remote Pipelines by issuing dry-run create requests to the kubernetes API server, allowing validating admission webhooks to accept or reject remote pipelines without actually creating them. This commit adds the same logic for remote Tasks, and moves common logic into a shared package.

/kind misc

Submitter Checklist

As the author of this PR, please check off the items in this checklist:

  • n/a Has Docs if any changes are user facing, including updates to minimum requirements e.g. Kubernetes version bumps
  • Has Tests included if any functionality added or changed
  • Follows the commit message standard
  • Meets the Tekton contributor standards (including functionality, content, code)
  • Has a kind label. You can add one by adding a comment on this PR that contains /kind <type>. Valid types are bug, cleanup, design, documentation, feature, flake, misc, question, tep
  • Release notes block below has been updated with any user facing changes (API changes, bug fixes, changes requiring upgrade notices or deprecation warnings). See some examples of good release notes.
  • n/a Release notes contains the string "action required" if the change requires additional action from users switching to the new release

Release Notes

Remote tasks are now validated by any validating admission webhooks.

@tekton-robot tekton-robot added kind/misc Categorizes issue or PR as a miscellaneuous one. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 19, 2023
@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/reconciler/apiserver/apiserver.go Do not exist 96.3%
pkg/reconciler/pipelinerun/resources/pipelineref.go 89.1% 93.2% 4.1
pkg/reconciler/taskrun/resources/taskref.go 88.4% 89.0% 0.6
pkg/reconciler/taskrun/taskrun.go 84.8% 84.9% 0.1

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage-df to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/reconciler/apiserver/apiserver.go Do not exist 96.3%
pkg/reconciler/pipelinerun/resources/pipelineref.go 89.1% 93.2% 4.1
pkg/reconciler/taskrun/resources/taskref.go 88.4% 89.0% 0.6
pkg/reconciler/taskrun/taskrun.go 84.8% 84.9% 0.1

@lbernick lbernick force-pushed the validate-remote-pipelines-2 branch from aad013f to e8ff288 Compare July 19, 2023 13:45
@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage-df to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/reconciler/apiserver/apiserver.go Do not exist 96.3%
pkg/reconciler/pipelinerun/resources/pipelineref.go 89.1% 93.2% 4.1
pkg/reconciler/taskrun/resources/taskref.go 88.4% 89.0% 0.6
pkg/reconciler/taskrun/taskrun.go 84.8% 84.9% 0.1

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/reconciler/apiserver/apiserver.go Do not exist 96.3%
pkg/reconciler/pipelinerun/resources/pipelineref.go 89.1% 93.2% 4.1
pkg/reconciler/taskrun/resources/taskref.go 88.4% 89.0% 0.6
pkg/reconciler/taskrun/taskrun.go 84.8% 84.9% 0.1

@lbernick
Copy link
Member Author

/retest: #6943

@lbernick
Copy link
Member Author

/retest
same flake

Copy link
Member

@Yongxuanzhang Yongxuanzhang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm
thanks! Learned a lot from reading the pr

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Jul 21, 2023
@afrittoli
Copy link
Member

@lbernick Thanks for this. My only doubt about this approach was the extra load it generates on the k8s API server. However, considering that it will only call the API once per TaskRun, it shouldn't be an issue.

Copy link
Member

@QuanZhang-William QuanZhang-William left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Lee! Changes look good to me!

pkg/pod/status.go Show resolved Hide resolved
@@ -448,14 +451,6 @@ func TestGetTaskFunc_RemoteResolution(t *testing.T) {
taskYAMLString,
}, "\n"),
wantTask: parse.MustParseV1Task(t, taskYAMLString),
}, {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious why do we remove these tests?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The webhook will now validate that beta features aren't used in v1 tasks unless enable-api-fields is set to beta. This replaces the existing hard-coded check for this specific bit of validation (

// Validation of beta fields must happen before the V1 Task is converted into the storage version of the API.
// TODO(#6592): Decouple API versioning from feature versioning
if err := obj.Spec.ValidateBetaFields(ctx); err != nil {
return nil, nil, fmt.Errorf("invalid Task %s: %w", obj.GetName(), err)
}
). I could mock the tests to return a BadRequestError specifically when beta features are used in v1 crds with enable-api-fields set to "stable", but I think the newly added tests that return BadRequestError are sufficient coverage and less brittle.

@lbernick lbernick force-pushed the validate-remote-pipelines-2 branch from e8ff288 to 9b9cdeb Compare July 27, 2023 20:39
@tekton-robot tekton-robot removed the lgtm Indicates that a PR is ready to be merged. label Jul 27, 2023
@lbernick
Copy link
Member Author

@lbernick Thanks for this. My only doubt about this approach was the extra load it generates on the k8s API server. However, considering that it will only call the API once per TaskRun, it shouldn't be an issue.

Thanks @afrittoli! I also think this should be fine-- we already call the webhook to update every taskrun and our k8s clients are rate limited. Are there any changes I can make to this PR that would help alleviate concerns about extra api calls?

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/reconciler/apiserver/apiserver.go Do not exist 96.3%
pkg/reconciler/pipelinerun/resources/pipelineref.go 89.1% 93.2% 4.1
pkg/reconciler/taskrun/resources/taskref.go 91.3% 91.8% 0.5
pkg/reconciler/taskrun/taskrun.go 85.2% 85.3% 0.1

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage-df to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/reconciler/apiserver/apiserver.go Do not exist 96.3%
pkg/reconciler/pipelinerun/resources/pipelineref.go 89.1% 93.2% 4.1
pkg/reconciler/taskrun/resources/taskref.go 91.3% 91.8% 0.5
pkg/reconciler/taskrun/taskrun.go 85.2% 85.3% 0.1

@vdemeester
Copy link
Member

Thanks @afrittoli! I also think this should be fine-- we already call the webhook to update every taskrun and our k8s clients are rate limited. Are there any changes I can make to this PR that would help alleviate concerns about extra api calls?

This call is conditionned though (aka it won't happen for all PipelineRun or TaskRun), but ok.

@lbernick
Copy link
Member Author

Thanks @afrittoli! I also think this should be fine-- we already call the webhook to update every taskrun and our k8s clients are rate limited. Are there any changes I can make to this PR that would help alleviate concerns about extra api calls?

This call is conditionned though (aka it won't happen for all PipelineRun or TaskRun), but ok.

My understanding (from #5146) is this function is actually what does all our status updates for TaskRuns, so it'll be called multiple times per TaskRun.

Do you have any suggestions for changes I could make to this PR, or concerns about merging it?

@lbernick
Copy link
Member Author

/retest
since #6992 is fixed

@vdemeester
Copy link
Member

/hold
See #7015

@tekton-robot tekton-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Aug 2, 2023
@lbernick lbernick force-pushed the validate-remote-pipelines-2 branch from 9b9cdeb to 309c650 Compare August 3, 2023 19:05
@tekton-robot tekton-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Aug 3, 2023
@lbernick lbernick force-pushed the validate-remote-pipelines-2 branch from 309c650 to f39cd22 Compare August 3, 2023 19:06
@lbernick
Copy link
Member Author

lbernick commented Aug 3, 2023

/hold cancel

@tekton-robot tekton-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Aug 3, 2023
@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/reconciler/apiserver/apiserver.go Do not exist 96.9%
pkg/reconciler/pipelinerun/resources/pipelineref.go 89.5% 93.2% 3.7
pkg/reconciler/taskrun/resources/taskref.go 91.3% 91.8% 0.5
pkg/reconciler/taskrun/taskrun.go 85.3% 85.4% 0.1

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage-df to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/reconciler/apiserver/apiserver.go Do not exist 96.9%
pkg/reconciler/pipelinerun/resources/pipelineref.go 89.5% 93.2% 3.7
pkg/reconciler/taskrun/resources/taskref.go 91.3% 91.8% 0.5
pkg/reconciler/taskrun/taskrun.go 85.3% 85.4% 0.1

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage-df to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/reconciler/apiserver/apiserver.go Do not exist 96.9%
pkg/reconciler/pipelinerun/resources/pipelineref.go 89.5% 93.2% 3.7
pkg/reconciler/taskrun/resources/taskref.go 91.3% 91.8% 0.5
pkg/reconciler/taskrun/taskrun.go 85.3% 85.4% 0.1

A prior commit added validation for remote Pipelines by issuing dry-run
create requests to the kubernetes API server, allowing validating admission
webhooks to accept or reject remote pipelines without actually creating them.
This commit adds the same logic for remote Tasks, and moves common logic
into a shared package.
@lbernick lbernick force-pushed the validate-remote-pipelines-2 branch from f39cd22 to 0ad1bc8 Compare August 4, 2023 13:42
@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/reconciler/apiserver/apiserver.go Do not exist 96.8%
pkg/reconciler/pipelinerun/resources/pipelineref.go 89.5% 93.2% 3.7
pkg/reconciler/taskrun/resources/taskref.go 91.3% 91.8% 0.5
pkg/reconciler/taskrun/taskrun.go 85.3% 85.4% 0.1

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage-df to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/reconciler/apiserver/apiserver.go Do not exist 96.8%
pkg/reconciler/pipelinerun/resources/pipelineref.go 89.5% 93.2% 3.7
pkg/reconciler/taskrun/resources/taskref.go 91.3% 91.8% 0.5
pkg/reconciler/taskrun/taskrun.go 85.3% 85.4% 0.1

@lbernick lbernick added this to the Pipelines v0.51 milestone Aug 8, 2023
@afrittoli afrittoli self-assigned this Aug 8, 2023
Copy link
Member

@Yongxuanzhang Yongxuanzhang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Aug 15, 2023
@dibyom
Copy link
Member

dibyom commented Aug 16, 2023

/approve

@tekton-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dibyom, Yongxuanzhang

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@tekton-robot tekton-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 16, 2023
@tekton-robot tekton-robot merged commit 445734d into tektoncd:main Aug 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/misc Categorizes issue or PR as a miscellaneuous one. lgtm Indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants