-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Conversation
Skipping CI for Draft Pull Request. |
/test all |
The following is the coverage report on the affected files.
|
The following is the coverage report on the affected files.
|
ee36af9
to
f95fa03
Compare
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, ""), |
There was a problem hiding this comment.
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
The following is the coverage report on the affected files.
|
// ConditionTrustedResourcesVerified specifies that the resources pass trusted resources verification or not. | ||
ConditionTrustedResourcesVerified apis.ConditionType = "TrustedResourcesVerified" |
There was a problem hiding this comment.
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
The following is the coverage report on the affected files.
|
f95fa03
to
1fe170b
Compare
1fe170b
to
62318c9
Compare
The following is the coverage report on the affected files.
|
There was a problem hiding this 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), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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), |
In response to this:
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. |
[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 |
62318c9
to
f4e05d7
Compare
The following is the coverage report on the affected files.
|
The following is the coverage report on the affected files.
|
Message: err.Error(), | ||
}) | ||
return nil, controller.NewPermanentError(err) | ||
case trustedresources.VerificationSkip: |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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:
There was a problem hiding this comment.
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, | ||
}) | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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? 🤔
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)
}
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does that work?
There was a problem hiding this comment.
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.
f4e05d7
to
d080cf3
Compare
/lgtm |
d080cf3
to
4840463
Compare
4840463
to
a60e8b0
Compare
The following is the coverage report on the affected files.
|
The following is the coverage report on the affected files.
|
/lgtm |
The following is the coverage report on the affected files.
|
The following is the coverage report on the affected files.
|
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]
a60e8b0
to
97f37ca
Compare
/lgtm |
The following is the coverage report on the affected files.
|
The following is the coverage report on the affected files.
|
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:
/kind <type>
. Valid types are bug, cleanup, design, documentation, feature, flake, misc, question, tepRelease Notes