-
Notifications
You must be signed in to change notification settings - Fork 86
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
feat: use new verify workflow #373
Conversation
cmd/notation/verify.go
Outdated
reference string | ||
SecureFlagOpts | ||
reference string | ||
config string |
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.
config string | |
pluginConfig []string |
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 reason for using string
instead of slice is to be consistent with sign
and key
commands, https://github.com/notaryproject/notation/blob/main/cmd/notation/sign.go#L27 so that I can utilize https://github.com/notaryproject/notation/blob/main/internal/cmd/flags.go#L91 to parse the configs.
cmd/notation/verify.go
Outdated
opts.ApplyFlags(command.Flags()) | ||
command.Flags().StringVarP(&opts.config, "config", "c", "", "list of comma-separated {key}={value} pairs that are passed as is to the plugin") |
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.
We need to refine this after #371
internal/ioutil/print.go
Outdated
tw := newTabWriter(w) | ||
|
||
if resultErr == nil { | ||
fmt.Fprintf(tw, "%s\n", digest) |
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.
fmt.Fprintf(tw, "%s\n", digest) | |
fmt.Fprintf(tw, "Signature verification succeeded for %s\n", digest) |
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.
Depending upon the enforcement level in the trust policy configuration, the signature verification might succeed but some validations might have failed(where the enforcement level is logged). In such cases, we want to display the failed validations as warnings.
The signature that passed signature verification would be last signature in SignatureVerificationOutcome
array.
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.
right, I was thinking to print out the digest for failed signatures with the error for user experience. But seems the returned outcome doesn't contain it. Please correct me if I miss something.
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.
Tracking it in #304
internal/ioutil/print.go
Outdated
func printOutcomes(tw *tabwriter.Writer, outcomes []*verification.SignatureVerificationOutcome) { | ||
if len(outcomes) == 1 { | ||
fmt.Println("1 signature failed verification, error is listed as below:") | ||
} else { | ||
fmt.Printf("%d signatures failed verification, errors are listed as below:\n", len(outcomes)) | ||
} | ||
|
||
for _, outcome := range outcomes { | ||
// TODO: print out the signature digest once the outcome contains it. | ||
fmt.Printf("%s\n\n", outcome.Error.Error()) | ||
} |
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.
IMO this error message is not really helpful and should only be printed in debug level.
In non-debug mode, we should display some generic message like:
Signature verification failed for all the xx signatures associated with ${reference}.
In debug mode
Signature verification failed for all the xx signatures associated with ${reference}. ` The failure reasons for each signature are as follows:
1. ${signature-reference}: ${error message}
2. ${signature-reference}: ${error message}
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.
@yizha1 Could you help check if you need to update the spec?
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.
I can update verify CLI spec for this accordingly
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.
Tracking UX improvements in #304
Signed-off-by: Binbin Li <libinbin@microsoft.com>
Signed-off-by: Binbin Li <libinbin@microsoft.com>
Codecov Report
@@ Coverage Diff @@
## main #373 +/- ##
==========================================
+ Coverage 32.03% 32.28% +0.24%
==========================================
Files 26 26
Lines 1670 1623 -47
==========================================
- Hits 535 524 -11
+ Misses 1122 1086 -36
Partials 13 13
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
Signed-off-by: Binbin Li <libinbin@microsoft.com>
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.
LGTM
internal/ioutil/print.go
Outdated
func printOutcomes(tw *tabwriter.Writer, outcomes []*verification.SignatureVerificationOutcome) { | ||
if len(outcomes) == 1 { | ||
fmt.Println("1 signature failed verification, error is listed as below:") | ||
} else { | ||
fmt.Printf("%d signatures failed verification, errors are listed as below:\n", len(outcomes)) | ||
} | ||
|
||
for _, outcome := range outcomes { | ||
// TODO: print out the signature digest once the outcome contains it. | ||
fmt.Printf("%s\n\n", outcome.Error.Error()) | ||
} |
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.
Tracking UX improvements in #304
Signed-off-by: Binbin Li <libinbin@microsoft.com>
Short: "Verify OCI artifacts", | ||
Long: `Verify OCI artifacts | ||
|
||
Prerequisite: a trusted certificate needs to be generated or added using the command "notation cert". |
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.
Do we need to delete it?
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.
I'll keep the Prerequisite
comment.
cmd/notation/verify.go
Outdated
Use: "verify [flags] <reference>", | ||
Short: "Verifies OCI Artifacts", | ||
Long: `Verifies OCI Artifacts: | ||
notation verify [--config <key>=<value>,...] [--username <username>] [--password <password>] <reference>`, |
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.
notation verify [--config <key>=<value>,...] [--username <username>] [--password <password>] <reference>`, | |
notation verify [--pluginConfig <key>=<value>,...] [--username <username>] [--password <password>] <reference>`, |
cmd/notation/verify.go
Outdated
opts.ApplyFlags(command.Flags()) | ||
command.Flags().StringVarP(&opts.pluginConfig, "config", "c", "", "list of comma-separated {key}={value} pairs that are passed as is to the plugin") |
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.
command.Flags().StringVarP(&opts.pluginConfig, "config", "c", "", "list of comma-separated {key}={value} pairs that are passed as is to the plugin") | |
command.Flags().StringVarP(&opts.pluginConfig, "pluginConfig", "pc", "", "list of comma-separated {key}={value} pairs that are passed as is to the plugin") |
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.
Actually Cobra doesn't support shorthand with more than one character.
|
||
func printOutcomes(tw *tabwriter.Writer, outcomes []*verification.SignatureVerificationOutcome, digest string) { | ||
fmt.Printf("Signature verification failed for all the %d signatures associated with digest: %s\n", len(outcomes), digest) | ||
|
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.
I understand that we are working on a spec to describe the CLI inputs and outputs, but we should print the error messages associated with the individual outcomes in the short-term to make this command more useful. Can you print the outcomes like below in the interim?
Signature verification failed for all the 3 signatures associated with digest: asdf....asdfasdf
Signature #1 : <Error>
Signature #2 : <Error>
Signature #3 : <Error>
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.
Good call, I'll add error messages.
outcomes, err := verifier.Verify(ctx, ref.String()) | ||
|
||
// write out. | ||
return ioutil.PrintVerificationResults(os.Stdout, outcomes, err, ref.Reference) |
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.
We should return the error from verifier.Verify()
here so that CLI can throw a non-zero error code when signature verification fails.
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.
LGTM
Signed-off-by: Binbin Li <libinbin@microsoft.com>
cmd/notation/verify_test.go
Outdated
} | ||
if err := command.ParseFlags([]string{ | ||
expected.reference, | ||
"--plain-http", | ||
"--pull=false", | ||
"--media-type=mediaT"}); err != nil { | ||
"--pluginConfig", expected.pluginConfig}); err != nil { |
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.
"--pluginConfig", expected.pluginConfig}); err != nil { | |
"--plugin-config", expected.pluginConfig}); err != nil { |
Can we use kebab-case everywhere for command input?
internal/ioutil/print.go
Outdated
|
||
if resultErr == nil { | ||
fmt.Fprintf(tw, "Signature verification succeeded for %s\n", digest) | ||
// TODO: print out failed validations as warnings. |
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 you please also add issue with TODO: #304
Would allow easier tracking.
Signed-off-by: Binbin Li <libinbin@microsoft.com>
What?
Use the new verification workflow for the
verify
command. Therefore, we have to make some updates to support it.signatures
,certs
,certFiles
,pull
,local
andmediaType
.config
flag so that users can set up verification plugin configs.Signed-off-by: Binbin Li libinbin@microsoft.com