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

Notation library baseline #5

Merged
merged 12 commits into from
Sep 15, 2021
Merged

Notation library baseline #5

merged 12 commits into from
Sep 15, 2021

Conversation

shizhMSFT
Copy link
Contributor

This notation library is based on the prototype-3 of the notary v2 library, which is based on prototype-2.
The underlying artifact specification and registry referrer API are alighed to oras-project/artifacts-spec.

@sajayantony
Copy link
Contributor

LGTM as this is based on prototype 2 and JWS refactoring will bring in more changes.

@imjasonh
Copy link

imjasonh commented Sep 8, 2021

Hello! 👋

This PR seems to implement a fair bit of the registry protocol in Go, in addition to implementing the new not-yet-standard bits necessary to store signatures. I happen to have some experience writing and maintaining a fairly widely used registry protocol client in Go, which you might be interested in reusing: go-containerregistry; specifically the low-level HTTP transport in pkg/v1/remote/transport, which is well-contained and doesn't depend on any specific API data types. This, along with pkg/authn, implements HTTP and auth (including parsing Docker config, and invoking credential helpers).

This package ends up being used by a number of tools, including buildpacks, kaniko, ko, Tekton, Knative, and probably a dozen others. This means it's pretty well battle-tested in real world scenarios, and with more users it should have any bugs or vulnerabilities discovered and fixed more quickly than new single-use clients.

This comment shouldn't block this PR, but I think it'd be worth discussing reusing an existing client instead of writing and maintaining your own, and (call me biased) I think go-containerregistry would be a good one. 😄

@sajayantony
Copy link
Contributor

sajayantony commented Sep 8, 2021

@imjasonh that's great feedback and we should consider reusing an existing registry client. I believe a lot of changes are done into oras-go to support the new signature manifest format with local cache store similar to how helm is working and also has dependency on and quite heavily used. Another aspect is move of the entire graph of signatures.

@shizhMSFT shizhMSFT changed the title Notation Alpha Library Notation library baseline Sep 13, 2021
@sajayantony
Copy link
Contributor

Tracking refactoring in #8

@sajayantony
Copy link
Contributor

Tracking signature format update in #9

Signed-off-by: Shiwei Zhang <[email protected]>
Signed-off-by: Shiwei Zhang <[email protected]>
Signed-off-by: Shiwei Zhang <[email protected]>
Signed-off-by: Shiwei Zhang <[email protected]>
Signed-off-by: Shiwei Zhang <[email protected]>
Signed-off-by: Shiwei Zhang <[email protected]>
Signed-off-by: Shiwei Zhang <[email protected]>
Signed-off-by: Shiwei Zhang <[email protected]>
@shizhMSFT shizhMSFT requested a review from a team September 15, 2021 02:20
@SteveLasker SteveLasker merged commit 484c01c into notaryproject:main Sep 15, 2021
example/basicauth.go Show resolved Hide resolved
example/basicauth.go Show resolved Hide resolved
example/example.go Show resolved Hide resolved
go.mod Show resolved Hide resolved
example/example.go Show resolved Hide resolved
Comment on lines +87 to +90
case len(params.X5c) > 0:
return v.getVerificationKeyPairFromX5c(params.X5c)
case params.KeyID != "":
return v.getVerificationKeyPairFromKeyID(params.KeyID)
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of giving x5c priority over keyId, in my opinion it would be better to fail the verification if both signature and keyId are present in signature.

Comment on lines +96 to +106
func (v *verifier) getVerificationKeyPairFromKeyID(keyID string) (libtrust.PublicKey, *x509.Certificate, error) {
key, found := v.keys[keyID]
if !found {
return nil, nil, errors.New("key not found: " + keyID)
}
cert, found := v.certs[keyID]
if !found {
return nil, nil, errors.New("cert not found: " + keyID)
}
return key, cert, nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

For future updates: the keyid mechanism doesn't need to return X509Cert, keyId can even refer to a raw private key.

if err != nil {
return err
}
if err := key.Verify(strings.NewReader(signed), params.Algorithm, sig); 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.

We should add validation for list of supported algorithms(to avoid algorithm substitution and signature bypass attacks).

signing.go Show resolved Hide resolved
registry/descriptor.go Show resolved Hide resolved
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.

5 participants