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

feat: use new verify workflow #373

Merged
merged 6 commits into from
Oct 18, 2022
Merged

Conversation

binbin-li
Copy link
Contributor

What?

Use the new verification workflow for the verify command. Therefore, we have to make some updates to support it.

  1. Remove all local verification related flags and arguments, including signatures, certs, certFiles, pull, local and mediaType.
  2. Add config flag so that users can set up verification plugin configs.
  3. Use the new verification workflow.
  4. Support both tag and digest reference.
  5. Format the result.

Signed-off-by: Binbin Li libinbin@microsoft.com

reference string
SecureFlagOpts
reference string
config string
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
config string
pluginConfig []string

Copy link
Contributor Author

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.

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")
Copy link
Contributor

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

tw := newTabWriter(w)

if resultErr == nil {
fmt.Fprintf(tw, "%s\n", digest)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
fmt.Fprintf(tw, "%s\n", digest)
fmt.Fprintf(tw, "Signature verification succeeded for %s\n", digest)

Copy link
Contributor

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.

https://github.com/notaryproject/notaryproject/blob/main/trust-store-trust-policy-specification.md#signature-verification-details

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Tracking it in #304

Comment on lines 71 to 81
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())
}
Copy link
Contributor

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}

Copy link
Contributor Author

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?

Copy link
Contributor

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

Copy link
Contributor

@priteshbandi priteshbandi Oct 17, 2022

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-commenter
Copy link

codecov-commenter commented Oct 14, 2022

Codecov Report

Merging #373 (8329127) into main (b9f1fb5) will increase coverage by 0.24%.
The diff coverage is 12.82%.

@@            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              
Impacted Files Coverage Δ
cmd/notation/verify.go 29.16% <12.82%> (+2.27%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Signed-off-by: Binbin Li <libinbin@microsoft.com>
Copy link
Contributor

@priteshbandi priteshbandi left a comment

Choose a reason for hiding this comment

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

LGTM

Comment on lines 71 to 81
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())
}
Copy link
Contributor

@priteshbandi priteshbandi Oct 17, 2022

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".
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Use: "verify [flags] <reference>",
Short: "Verifies OCI Artifacts",
Long: `Verifies OCI Artifacts:
notation verify [--config <key>=<value>,...] [--username <username>] [--password <password>] <reference>`,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
notation verify [--config <key>=<value>,...] [--username <username>] [--password <password>] <reference>`,
notation verify [--pluginConfig <key>=<value>,...] [--username <username>] [--password <password>] <reference>`,

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")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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")

Copy link
Contributor Author

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)

Copy link
Contributor

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>

Copy link
Contributor Author

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)
Copy link
Contributor

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.

@yizha1 yizha1 linked an issue Oct 18, 2022 that may be closed by this pull request
Copy link
Contributor

@patrickzheng200 patrickzheng200 left a 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>
}
if err := command.ParseFlags([]string{
expected.reference,
"--plain-http",
"--pull=false",
"--media-type=mediaT"}); err != nil {
"--pluginConfig", expected.pluginConfig}); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"--pluginConfig", expected.pluginConfig}); err != nil {
"--plugin-config", expected.pluginConfig}); err != nil {

Can we use kebab-case everywhere for command input?

@priteshbandi priteshbandi self-requested a review October 18, 2022 04:29

if resultErr == nil {
fmt.Fprintf(tw, "Signature verification succeeded for %s\n", digest)
// TODO: print out failed validations as warnings.
Copy link
Contributor

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>
@binbin-li binbin-li merged commit 20b9fa2 into notaryproject:main Oct 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Implementing verify command
8 participants