Skip to content

Comments

Added certificate management commands to the docker nv2 plugin.#70

Closed
sajayantony wants to merge 1 commit intonotaryproject:prototype-2from
sajayantony:manage-certs
Closed

Added certificate management commands to the docker nv2 plugin.#70
sajayantony wants to merge 1 commit intonotaryproject:prototype-2from
sajayantony:manage-certs

Conversation

@sajayantony
Copy link
Contributor

Currently adding and removing certificates from the verification list is really error prone.
Providing an ability to add and remove the certificates would improve the user experience

❯ docker nv2 certificates --help
NAME:
   docker nv2 certificates - Manage certificates used for signing and verification

USAGE:
   docker nv2 certificates command [command options] [arguments...]

COMMANDS:
   add         Add certificate to verification list
   list, ls    List cerificates used for verification
   remove, rm  Remove certificate from verification list
   help, h     Shows a list of commands or help for one command

OPTIONS:
   --help, -h  show help (default: false)
❯ docker nv2 certificates ls
/home/sajay/.notary/keys/wabbit-networks.crt
/home/sajay/code/src/github.com/notaryproject/nv2/cmd/nv2/cert/wabbit-networks.crt
❯ docker nv2 certificates add /home/sajay/.notary/keys/wabbit-networks.crt
Added /home/sajay/.notary/keys/wabbit-networks.crt to verification certificates
❯ docker nv2 certificates rm /home/sajay/code/src/github.com/notaryproject/nv2/cmd/nv2/cert/wabbit-networks.crt
Removed /home/sajay/code/src/github.com/notaryproject/nv2/cmd/nv2/cert/wabbit-networks.crt from list of verification certificates

Signed-off-by: Sajay Antony sajaya@microsoft.com

Fixes #69

Currently adding and removing certificates from the verification list is really error prone.
Providing an ability to add and remove the certificates would improve the user experience

```
❯ docker nv2 certificates --help
NAME:
   docker nv2 certificates - Manage certificates used for signing and verification

USAGE:
   docker nv2 certificates command [command options] [arguments...]

COMMANDS:
   add         Add certificate to verification list
   list, ls    List cerificates used for verification
   remove, rm  Remove certificate from verification list
   help, h     Shows a list of commands or help for one command

OPTIONS:
   --help, -h  show help (default: false)
```

```
❯ docker nv2 certificates ls
/home/sajay/.notary/keys/wabbit-networks.crt
/home/sajay/code/src/github.com/notaryproject/nv2/cmd/nv2/cert/wabbit-networks.crt
```

```
❯ docker nv2 certificates add /home/sajay/.notary/keys/wabbit-networks.crt
Added /home/sajay/.notary/keys/wabbit-networks.crt to verification certificates
```

```
❯ docker nv2 certificates rm /home/sajay/code/src/github.com/notaryproject/nv2/cmd/nv2/cert/wabbit-networks.crt
Removed /home/sajay/code/src/github.com/notaryproject/nv2/cmd/nv2/cert/wabbit-networks.crt from list of verification certificates
```

Signed-off-by: Sajay Antony <sajaya@microsoft.com>
@sajayantony
Copy link
Contributor Author

/cc @shizhMSFT

@shizhMSFT shizhMSFT self-requested a review August 24, 2021 07:43
)

var certsCommand = &cli.Command{
Name: "certificates",
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we shorten the command to cert or certs?

Copy link
Contributor

Choose a reason for hiding this comment

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

Or just add an alias.

Copy link
Contributor Author

@sajayantony sajayantony Aug 25, 2021

Choose a reason for hiding this comment

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

I think we can start with one and enhance along the way. Also regarding shortening, is there a convention among othere tools to use certs or cert that we can reference here. I was also debating with short names but the full certificates is always less ambiguous.

if !ctx.Args().Present() {
return errors.New("Required argument, certificate path not specified")
}
cert := ctx.Args().First()
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 add multiple certs at once?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Similar to above if we can start with one then we can support multiple as a additive issue.

fmt.Printf("Added %s to verification certificates\n", cert)
}

return nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Should return error if there is an error on cfg.Save().

}

for _, s := range cfg.VerificationCerts {
fmt.Printf("%s\n", s)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: fmt.Println(s)


cfg, err := config.Load()
if err != nil {
if !os.IsNotExist(err) {
Copy link
Contributor

Choose a reason for hiding this comment

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

if it is os.IsNotExist(err), we return nil. Otherwise, we should return err.

if !ctx.Args().Present() {
return errors.New("Required argument, certificate path not specified")
}
cert := ctx.Args().First()
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 remove multiple certs at once?

fmt.Printf("Removed %s from list of verification certificates\n", cert)
}

return nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Should return error if there is an error on cfg.Save().

@SteveLasker
Copy link
Contributor

From a refactoring to the notation-go-lib, how much should be reflected there?

@SteveLasker
Copy link
Contributor

Please see: #78 for some cli commands.
I'm actually wondering if we should capture a set of commands, in a single doc. Like the output of notation --help

@SteveLasker SteveLasker mentioned this pull request Aug 28, 2021
@sajayantony sajayantony marked this pull request as draft August 31, 2021 07:15
@SteveLasker SteveLasker added the cli Issue or PR released to Notation CLI label Sep 1, 2021
var certsAddCommand = &cli.Command{
Name: "add",
Usage: "Add certificate to verification list",
ArgsUsage: "[cert]",
Copy link
Contributor

Choose a reason for hiding this comment

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

should this be certificate path?

Comment on lines +45 to +56
func uniqueAppend(entries []string, e string) []string {
entries = append(entries, e)
keys := make(map[string]bool)
list := []string{}
for _, item := range entries {
if _, value := keys[item]; !value {
keys[item] = true
list = append(list, item)
}
}
return list
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Since the input to function is slice, this method created a map from slice with slice values as keys thus removing duplicate but won't it be more efficient(both memory and compute) to just iterate over slice i.e., entries and check for duplicate and add e if none is found?

Also, by not creating intermediate map we will be preserving the order of certificates thus every invocation of certificates ls will provide predictable output to customer.

Before:
certificates add path1
certificates add path2
certificates add path3
certificates ls
> [path2, path1, path3]
certificates add path4
certificates ls
> [path2, path4, path1, path3]

After
certificates add path1
certificates add path2
certificates add path3
certificates ls
> [path1, path2, path3]
certificates add path4
certificates ls
> [path1, path2, path3, path4]

}

func uniqueRemove(entries []string, e string) ([]string, error) {
keys := make(map[string]bool)
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto


cfg, err := config.Load()
if err != nil {
if !os.IsNotExist(err) {
Copy link
Contributor

Choose a reason for hiding this comment

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

if config doesnt exists then we can short circuit here(no need to create config) and display proper error message to customer saying that it’s an invalid operation as there is zero verification certificate stored.

@shizhMSFT shizhMSFT mentioned this pull request Sep 3, 2021
@sajayantony
Copy link
Contributor Author

@priteshbandi #83 PR adds all this capability into notation alpha.
I will close this draft PR and we should be now trying to get this all into one alpha release which we can iterate on is my thinking.

@shizhMSFT - can see if there are inputs here you might not have already considered in your PR?

@sajayantony
Copy link
Contributor Author

Closing since #83 supersedes this.

@sajayantony sajayantony closed this Sep 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli Issue or PR released to Notation CLI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add certificate management to nv2 docker plugin

4 participants