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

Verification helpers #72

Merged
merged 9 commits into from
Jul 7, 2022
Merged

Conversation

rgnote
Copy link
Contributor

@rgnote rgnote commented Jun 30, 2022

Changes:

  1. Changed trustPolicy.TrustStore to trustPolicy.TrustStores
  2. Added Type field to X509TrustStore to be able to filter trust stores based on their type
  3. Added verification workflow errors and helper methods to load policies and trust stores
  4. Added VerificationResult and SignatureVerificationOutsome types to encapsulate verification results.
  5. Associated unit tests for above changes

Signed-off-by: rgnote <[email protected]>
@rgnote rgnote requested a review from a team June 30, 2022 21:55
Signed-off-by: rgnote <[email protected]>
verification/helpers.go Outdated Show resolved Hide resolved
verification/types.go Outdated Show resolved Hide resolved
notation.go Outdated Show resolved Hide resolved
verification/helpers.go Outdated Show resolved Hide resolved
Comment on lines +35 to +36
// TrustStores this policy statement uses
TrustStores []string `json:"trustStores,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we update the spec first then the code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We discussed this change in yesterday's call. Made the code update as it is minor. If the spec deviates, I can come back and make those changes.

Copy link

Choose a reason for hiding this comment

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

@shizhMSFT I'll be submitting a spec PR for this, we discussed the change and use case in Thursday call . Rakesh has been working on verification workflow logic and it was simpler to update it in a single pass.

Copy link

Choose a reason for hiding this comment

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

Related spec update PR.

verification/helpers.go Outdated Show resolved Hide resolved
verification/helpers.go Outdated Show resolved Hide resolved
func getArtifactDigestFromUri(artifactUri string) (string, error) {
i := strings.LastIndex(artifactUri, ":")
if i < 0 {
return "", fmt.Errorf("artifact URI %q could not be parsed, make sure it is the fully qualified OCI artifact URI without the scheme/protocol. e.g domain.com:80/my/repository:digest", artifactUri)
Copy link
Contributor

Choose a reason for hiding this comment

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

digest is digest like sha256:xxx or a tag like v1?

Copy link
Contributor Author

@rgnote rgnote Jul 1, 2022

Choose a reason for hiding this comment

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

Spec is not supporting tags yet. We can come back and update this code when we support tags.

Copy link
Contributor

Choose a reason for hiding this comment

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

domain.com:80/my/repository:digest this reference string makes me confused. If it is for digest, it should be in the form of domain.com:80/my/repository@digest. That is, @ instead of :.

verification/verifier_helpers.go Show resolved Hide resolved
Signed-off-by: rgnote <[email protected]>
Signed-off-by: rgnote <[email protected]>
notation.go Outdated Show resolved Hide resolved
verification/errors.go Outdated Show resolved Hide resolved
verification/errors.go Show resolved Hide resolved
verification/helpers.go Outdated Show resolved Hide resolved
Comment on lines +35 to +36
// TrustStores this policy statement uses
TrustStores []string `json:"trustStores,omitempty"`
Copy link

Choose a reason for hiding this comment

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

@shizhMSFT I'll be submitting a spec PR for this, we discussed the change and use case in Thursday call . Rakesh has been working on verification workflow logic and it was simpler to update it in a single pass.

verification/types.go Outdated Show resolved Hide resolved
verification/verifier_helpers.go Show resolved Hide resolved
verification/verifier_helpers.go Show resolved Hide resolved
Signed-off-by: rgnote <[email protected]>
Copy link

@gokarnm gokarnm left a comment

Choose a reason for hiding this comment

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

LGTM!

@binbin-li
Copy link
Contributor

lgtm

verification/types.go Outdated Show resolved Hide resolved
func getArtifactDigestFromUri(artifactUri string) (string, error) {
i := strings.LastIndex(artifactUri, ":")
if i < 0 {
return "", fmt.Errorf("artifact URI %q could not be parsed, make sure it is the fully qualified OCI artifact URI without the scheme/protocol. e.g domain.com:80/my/repository:digest", artifactUri)
Copy link
Contributor

Choose a reason for hiding this comment

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

domain.com:80/my/repository:digest this reference string makes me confused. If it is for digest, it should be in the form of domain.com:80/my/repository@digest. That is, @ instead of :.

digest string
wantErr bool
}{
{"domain.com:80/repository:digest", "digest", false},
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 set wantErr: true for this case.

Copy link
Contributor Author

@rgnote rgnote Jul 6, 2022

Choose a reason for hiding this comment

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

Updated the code to accept domain.com:80/repository@<alg>:<digest>

My understanding is that <alg> is not included when querying manifests from the registry, is that correct? Or the entire thing <alg>:<digest> is considered a digest and we need to use that when resolving?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

NVM. Alg is needed to query with a digest. I addressed it in the latest revision

verification/policy.go Show resolved Hide resolved
verification/verifier_helpers.go Show resolved Hide resolved
Signed-off-by: rgnote <[email protected]>
Copy link
Contributor

@shizhMSFT shizhMSFT 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 +84
func getArtifactDigestFromUri(artifactUri string) (string, error) {
invalidUriErr := fmt.Errorf("artifact URI %q could not be parsed, make sure it is the fully qualified OCI artifact URI without the scheme/protocol. e.g domain.com:80/my/repository@sha256:digest", artifactUri)
i := strings.LastIndex(artifactUri, "@")
if i < 0 || i+1 == len(artifactUri) {
return "", invalidUriErr
}

j := strings.LastIndex(artifactUri[i+1:], ":")
if j < 0 || j+1 == len(artifactUri[i+1:]) {
return "", invalidUriErr
}

return artifactUri[i+1:], nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This block of code is workable but fragile. Try registry.ParseReference().

Copy link
Contributor

Choose a reason for hiding this comment

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

Note: A digest is usually with the algorithm, not just the hash value.

@gokarnm gokarnm merged commit 3d22fbc into notaryproject:main Jul 7, 2022
JeyJeyGao pushed a commit to JeyJeyGao/notation-go that referenced this pull request Jul 22, 2022
* Add verification helpers
* fix build

Signed-off-by: rgnote <[email protected]>
Signed-off-by: Junjie Gao <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants