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: add sign blob commands #856

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

rrsemlani
Copy link

@rrsemlani rrsemlani commented Dec 26, 2023

Adding sign blob commands.
Spec Pr used for ref: #811

Signed-off-by: Rishab Semlani <rrsemlani@gmail.com>
@codecov-commenter
Copy link

codecov-commenter commented Dec 26, 2023

Codecov Report

Attention: Patch coverage is 88.54167% with 11 lines in your changes are missing coverage. Please review.

Project coverage is 64.45%. Comparing base (31c9e84) to head (2ed55c6).
Report is 74 commits behind head on main.

❗ Current head 2ed55c6 differs from pull request most recent head 696d4a4. Consider uploading reports for the commit 696d4a4 to get more accurate results

Files Patch % Lines
cmd/notation/blob.go 88.29% 11 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #856      +/-   ##
==========================================
+ Coverage   64.09%   64.45%   +0.35%     
==========================================
  Files          40       46       +6     
  Lines        2284     2788     +504     
==========================================
+ Hits         1464     1797     +333     
- Misses        698      835     +137     
- Partials      122      156      +34     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -35,6 +35,7 @@ func main() {
}
cmd.AddCommand(
signCommand(nil),
blobSignCommand(nil),
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: put all blob commends at one place for readability

"github.com/spf13/cobra"
)

func blobSignCommand(opts *signOpts) *cobra.Command {
Copy link
Contributor

Choose a reason for hiding this comment

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

signOpts defined in sign.go has more flags than what is needed for notation blob sign command. Can we have a separate signOpts for blob signing?

func blobSignCommand(opts *signOpts) *cobra.Command {
if opts == nil {
opts = &signOpts{
inputType: inputTypeRegistry, // remote registry by default
Copy link
Contributor

Choose a reason for hiding this comment

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

Registries do not apply to blobs. Lets remove this.

inputType: inputTypeRegistry, // remote registry by default
}
}
longMessage := `Sign artifacts
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 use the log message as is from notation blob sign section in https://github.com/notaryproject/notation/pull/811/files?diff=unified&w=0?

`

command := &cobra.Command{
Use: "blob sign [flags] <reference>",
Copy link
Contributor

Choose a reason for hiding this comment

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

reference?

longMessage := `Inspect all signatures associated with the signed artifact.

Example - Inspect signatures on an BLOB artifact identified by a digest:
notation blob inspect <registry>/<repository>@<digest>
Copy link
Contributor

Choose a reason for hiding this comment

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

?

Signed-off-by: Rishab Semlani <rrsemlani@gmail.com>
@@ -0,0 +1,232 @@
// Copyright The Notary Project Authors.
Copy link
Contributor

Choose a reason for hiding this comment

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

Please move this inside blob directory similar to cert, plugin etc. Also, rename file to sign.go.

type blobOpts struct {
cmd.LoggingFlagOpts
cmd.SignerFlagOpts
SecureFlagOpts
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 SecureFlagOpts ?

pluginConfig []string
userMetadata []string
blobPath string
signaturePath 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
signaturePath string
signatureDirectory string

Long: longMessage,
Args: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
return errors.New("missing blob_path")
Copy link
Contributor

Choose a reason for hiding this comment

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

What is blob_path ? How will user interpret it?

Comment on lines 39 to 40
desc ocispec.Descriptor
sigRepo registry.Repository
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need this ?

userMetadata []string
blobPath string
signaturePath string
outputFormat string
Copy link
Contributor

Choose a reason for hiding this comment

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

are we missing option for some flags like --force ?


func blobSignCommand(opts *blobOpts) *cobra.Command {
if opts == nil {
opts = &blobOpts{}
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this correct ?

return blobOpts, nil
}

func blobInspectCommand(opts *blobOpts) *cobra.Command {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please create new .go file for inspect.


output := inspectOutput{MediaType: opts.desc.MediaType, Signatures: []signatureOutput{}}

sigBlob, _, _ := opts.sigRepo.FetchSignatureBlob(ctx, opts.desc)
Copy link
Contributor

Choose a reason for hiding this comment

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

we dont have sigRepo in case of blob signing.

Copy link
Contributor

Choose a reason for hiding this comment

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

nit:
We should not include the go build notation binary in the PR.

@Two-Hearts Two-Hearts changed the title Adding sign and inspect blob commands feat: add sign and inspect blob commands Jan 30, 2024
Comment on lines 126 to 127
var errorPushSignatureFailed notation.ErrorPushSignatureFailed
if errors.As(err, &errorPushSignatureFailed) && strings.Contains(err.Error(), referrersTagSchemaDeleteError) {
Copy link
Contributor

Choose a reason for hiding this comment

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

For blob signing, there's no more notation.ErrorPushSignatureFailed and referrersTagSchemaDeleteError because they are OCI specific errors.

cmd/notation/blob/cmd.go Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove binary

Copy link
Author

Choose a reason for hiding this comment

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

Will remove in new rev

@@ -45,6 +46,7 @@ func main() {
logoutCommand(nil),
versionCommand(),
inspectCommand(nil),
blob.SignCommand(nil),
Copy link
Contributor

Choose a reason for hiding this comment

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

Please follow pattern likecert.Cmd, policy.Cmd().

Copy link
Author

Choose a reason for hiding this comment

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

Will update in new rev

@rrsemlani rrsemlani changed the title feat: add sign and inspect blob commands feat: add sign blob commands Feb 13, 2024
Signed-off-by: Rishab Semlani <rrsemlani@gmail.com>
Long: longMessage,
Args: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
return errors.New("missing blob file path to the artifact: use `notation blob sign --help` to see what parameters are required")
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
return errors.New("missing blob file path to the artifact: use `notation blob sign --help` to see what parameters are required")
return errors.New("missing file path use `notation blob sign --help` to see what parameters are required")

Comment on lines +103 to +104
// Todo: we will need to replace signer with actual blob signer implementation in notation-go
// initialize
Copy link
Contributor

Choose a reason for hiding this comment

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

As discussed on Monday, for signing we dont need a TODO as code has already been merged on notation-go.


// Todo: we will need to replace signer with actual blob signer implementation in notation-go
// initialize
signer, err := cmd.GetSigner(ctx, &cmdOpts.SignerFlagOpts)
Copy link
Contributor

Choose a reason for hiding this comment

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

cmd.GetSigner returns notation.Signer which doesnt supports for BlobSigning.

Comment on lines +139 to +145
blobOpts := notation.SignOptions{
SignerSignOptions: notation.SignerSignOptions{
SignatureMediaType: mediaType,
ExpiryDuration: opts.expiry,
PluginConfig: pluginConfig,
},
UserMetadata: userMetadata,
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use blob related opts

if err != nil {
return err
}
contents, err := os.ReadFile(cmdOpts.blobPath)
Copy link
Contributor

Choose a reason for hiding this comment

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

Dont read file; pass the reader to SignBlob.

return err
}
// core process
_, _, err = notation.SignBlob(ctx, signer, strings.NewReader(string(contents)), blobOpts) //PlaceHolder
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we please add implementation to write signature file?

Copy link

This PR is stale because it has been opened for 45 days with no activity. Remove stale label or comment. Otherwise, it will be closed in 30 days.

@github-actions github-actions bot added Stale and removed Stale labels May 12, 2024
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.

None yet

5 participants