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

[TEP-0091] update taskrun and pipelinerun condition based on VerificationResult #6757

Merged
merged 1 commit into from
Jun 5, 2023

Conversation

Yongxuanzhang
Copy link
Member

@Yongxuanzhang Yongxuanzhang commented Jun 1, 2023

Changes

This commits updates taskrun and pipelinerun condition based on VerificationResult to add TrustedResourcesVerified condition. The condition will be marked as false if verification policy fails, or no matching policies when feature flag is set to fail. The condition will be set to true if verification passes. No condition is added when verification is skipped.

Last feature PR of #6665

/kind feature

Signed-off-by: Yongxuan Zhang [email protected]

Submitter Checklist

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

  • 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.
  • Release notes contains the string "action required" if the change requires additional action from users switching to the new release

Release Notes

TrustedResourcesVerified is added to TaskRun/PipelineRun status if trusted resources is enabled, the condition indicates the result of the verification.

@tekton-robot
Copy link
Collaborator

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@tekton-robot tekton-robot added release-note-none Denotes a PR that doesnt merit a release note. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. kind/feature Categorizes issue or PR as related to a new feature. labels Jun 1, 2023
@tekton-robot tekton-robot requested review from imjasonh and jerop June 1, 2023 22:53
@tekton-robot tekton-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jun 1, 2023
@Yongxuanzhang
Copy link
Member Author

/test all

@Yongxuanzhang Yongxuanzhang changed the title update taskrun condition based on VerificationResult [TEP-0091]update taskrun condition based on VerificationResult Jun 1, 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/taskrun/taskrun.go 84.6% 84.7% 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/taskrun/taskrun.go 84.6% 84.7% 0.1

@tekton-robot tekton-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-none Denotes a PR that doesnt merit a release note. labels Jun 1, 2023
@Yongxuanzhang Yongxuanzhang marked this pull request as ready for review June 1, 2023 23:07
@tekton-robot tekton-robot requested review from abayer and afrittoli June 1, 2023 23:07
@tekton-robot tekton-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jun 1, 2023
failNoMatchCondition := &apis.Condition{
Type: trustedresources.ConditionTrustedResourcesVerified,
Status: corev1.ConditionFalse,
Message: fmt.Sprintf("failed to get matched policies: %s: no matching policies are found for resource: %s against source: %s", trustedresources.ErrNoMatchedPolicies, ts.Name, ""),
Copy link
Member Author

@Yongxuanzhang Yongxuanzhang Jun 1, 2023

Choose a reason for hiding this comment

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

There are duplicate messages, will clean up the error handling when the feature is done, added an item #6356

@Yongxuanzhang Yongxuanzhang changed the title [TEP-0091]update taskrun condition based on VerificationResult [TEP-0091] update taskrun condition based on VerificationResult Jun 1, 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/taskrun/taskrun.go 84.6% 84.7% 0.1

Comment on lines +43 to +44
// ConditionTrustedResourcesVerified specifies that the resources pass trusted resources verification or not.
ConditionTrustedResourcesVerified apis.ConditionType = "TrustedResourcesVerified"
Copy link
Member Author

@Yongxuanzhang Yongxuanzhang Jun 1, 2023

Choose a reason for hiding this comment

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

this may not be the best place to put the ConditionType. But I don't know if there are any other places better than this

@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/taskrun/taskrun.go 84.6% 84.7% 0.1

@Yongxuanzhang Yongxuanzhang changed the title [TEP-0091] update taskrun condition based on VerificationResult [TEP-0091] update taskrun and pipelinerun condition based on VerificationResult Jun 2, 2023
@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/pipelinerun/pipelinerun.go 90.4% 90.5% 0.1
pkg/reconciler/taskrun/taskrun.go 84.6% 84.7% 0.1

Copy link
Member

@lbernick lbernick left a comment

Choose a reason for hiding this comment

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

coverage report shows all the trusted resources conditions are covered 👍

/meow

failNoKeysCondition := &apis.Condition{
Type: trustedresources.ConditionTrustedResourcesVerified,
Status: corev1.ConditionFalse,
Message: fmt.Sprintf("fails to get verifiers for resource %s from namespace %s: %s", ts.Name, ts.Namespace, verifier.ErrEmptyPublicKeys),
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Message: fmt.Sprintf("fails to get verifiers for resource %s from namespace %s: %s", ts.Name, ts.Namespace, verifier.ErrEmptyPublicKeys),
Message: fmt.Sprintf("failed to get verifiers for resource %s from namespace %s: %s", ts.Name, ts.Namespace, verifier.ErrEmptyPublicKeys),

@tekton-robot
Copy link
Collaborator

@lbernick: cat image

In response to this:

coverage report shows all the trusted resources conditions are covered 👍

/meow

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@tekton-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: lbernick

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 Jun 5, 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/pipelinerun/pipelinerun.go 90.4% 90.5% 0.1
pkg/reconciler/taskrun/taskrun.go 84.6% 84.7% 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/pipelinerun/pipelinerun.go 90.4% 90.5% 0.1
pkg/reconciler/taskrun/taskrun.go 84.6% 84.7% 0.1

Message: err.Error(),
})
return nil, controller.NewPermanentError(err)
case trustedresources.VerificationSkip:
Copy link
Contributor

Choose a reason for hiding this comment

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

can this not be the default?

Copy link
Member Author

Choose a reason for hiding this comment

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

Did you mean something like this?

switch verificationResult.VerificationResultType {
case trustedresources.VerificationError:
xxx
case trustedresources.VerificationWarn:
xxx
case trustedresources.VerificationPass:
xxx
default:

Copy link
Contributor

Choose a reason for hiding this comment

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

yes. Because that condition was not doing anything. However, it is clearer for readability compared to default so I'm ok with leaving this as is too.

Type: trustedresources.ConditionTrustedResourcesVerified,
Status: corev1.ConditionTrue,
})
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The same switch-case seems to be repeated. Can this be wrapped into a function to avoid repitition?

Copy link
Member Author

Choose a reason for hiding this comment

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

There are 3 places using the same switch, 2 on pipelinerun and 1 on taskrun. The 2 pipelinerun returns are different.
Do you have any suggestions? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

let me try out, I think we could wrap it into a function

Copy link
Contributor

Choose a reason for hiding this comment

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

The PipelineRuns returns only seem to be happening for the case of verificationError. In one case, you return controller.New... and in other case you return nil, controller.New....

What if this function returned error, conditionToSet? You could catch that and handle it in both cases?

Copy link
Contributor

@chitrangpatel chitrangpatel Jun 5, 2023

Choose a reason for hiding this comment

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

Something like?

func Verify(verificationResult <typeOfverificationResult>) (error, apis.Condition){
        var condition apis.Condition
        var err error
        
        switch verificationResult.VerificationResultType {
 		case trustedresources.VerificationError:
 			err := fmt.Errorf("PipelineRun %s/%s referred pipeline failed signature    verification: %w", pr.Namespace, pr.Name, verificationResult.Err)
 		 	
// add this line after the output of the function
// pr.Status.MarkFailed(ReasonResourceVerificationFailed, err.Error())
 			condition = &apis.Condition{
 				Type:    trustedresources.ConditionTrustedResourcesVerified,
 				Status:  corev1.ConditionFalse,
 				Message: err.Error(),
 			}
// add this line after the output of the function
 // return controller.NewPermanentError(err)
 		case trustedresources.VerificationSkip:
 			// do nothing
 		case trustedresources.VerificationWarn:
 			condition = &apis.Condition{
 				Type:    trustedresources.ConditionTrustedResourcesVerified,
 				Status:  corev1.ConditionFalse,
 				Message: verificationResult.Err.Error(),
 			}
// set the condition when you catch the output of the function
 		case trustedresources.VerificationPass:
 			condition = apis.Condition{
 				Type:   trustedresources.ConditionTrustedResourcesVerified,
 				Status: corev1.ConditionTrue,
 			}
 		}
 		return err, condition
}


err, cond := Verify(verificationResult)
pr.Status.SetCondition(&cond)
if err != nil {
    pr.Status.MarkFailed(ReasonResourceVerificationFailed, err.Error())
    return controller.NewPermanentError(err)
}

Copy link
Contributor

Choose a reason for hiding this comment

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

☝️ is how you would use it well.

Copy link
Contributor

Choose a reason for hiding this comment

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

Does that work?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah this should work, just pushed the code.

@chitrangpatel
Copy link
Contributor

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Jun 5, 2023
@tekton-robot tekton-robot removed the lgtm Indicates that a PR is ready to be merged. label Jun 5, 2023
@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/pipelinerun/pipelinerun.go 90.4% 90.5% 0.2
pkg/reconciler/taskrun/taskrun.go 84.6% 84.7% 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/pipelinerun/pipelinerun.go 90.4% 90.5% 0.1
pkg/reconciler/taskrun/taskrun.go 84.6% 84.7% 0.1

@chitrangpatel
Copy link
Contributor

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Jun 5, 2023
@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/pipelinerun/pipelinerun.go 90.4% 90.5% 0.1
pkg/reconciler/taskrun/taskrun.go 84.6% 84.7% 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/pipelinerun/pipelinerun.go 90.4% 90.5% 0.1
pkg/reconciler/taskrun/taskrun.go 84.6% 84.7% 0.1

This commits updates taskrun and pipelinerun condition based on VerificationResult to
add TrustedResourcesVerified condition. The condition will be marked as
false if verification policy fails, or no matching policies when
feature flag is set to fail. The condition will be set to true if
verification passes. No condition is added when verification is skipped.

Signed-off-by: Yongxuan Zhang [email protected]
@tekton-robot tekton-robot removed the lgtm Indicates that a PR is ready to be merged. label Jun 5, 2023
@chitrangpatel
Copy link
Contributor

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Jun 5, 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/pipelinerun/pipelinerun.go 90.4% 90.5% 0.2
pkg/reconciler/taskrun/taskrun.go 84.6% 84.7% 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/pipelinerun/pipelinerun.go 90.4% 90.5% 0.2
pkg/reconciler/taskrun/taskrun.go 84.6% 84.7% 0.1

@tekton-robot tekton-robot merged commit ee9a5e3 into tektoncd:main Jun 5, 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/feature Categorizes issue or PR as related to a new feature. 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/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants