close
Skip to content

docker trust inspect - #694

Merged
thaJeztah merged 3 commits into
docker:masterfrom
riyazdf:trust-inspect
Nov 29, 2017
Merged

docker trust inspect#694
thaJeztah merged 3 commits into
docker:masterfrom
riyazdf:trust-inspect

Conversation

@riyazdf

@riyazdf riyazdf commented Nov 16, 2017

Copy link
Copy Markdown

Introduces a docker trust inspect command for JSON output with the same information presented in the human-readable docker trust view.

I refactored some of the existing view code so that it could be shared with inspect and added a docs page.

cc @ashfall @eiais for additional review, and @rn to confirm that this information is what he was looking for from the original issue (#659)

shortened and modified example here:

🐳 $ docker trust inspect my-image:purple
[
  {
    "Name": "my-image:purple",
    "SignedTags": [
      {
        "SignedTag": "purple",
        "Digest": "941d3dba358621ce3c41ef67b47cf80f701ff80cdf46b5cc86587eaebfe45557",
        "Signers": [
          "alice",
          "bob",
          "carol"
        ]
      }
    ],
    "Signers": [
      {
        "Name": "alice",
        "Keys": [
                {     
                          "ID": "04dd031411ed671ae1e12f47ddc8646d98f135090b01e54c3561e843084484a3"
                },
                {
                          "ID": "6a11e4898a4014d400332ab0e096308c844584ff70943cdd1d6628d577f45fd8"
                }
        ]
      },
      {
        "Name": "bob",
        "Keys": [
                {
                          "ID": "433e245c656ae9733cdcc504bfa560f90950104442c4528c9616daa45824ccba"
                }
        ]
      },
      {
        "Name": "carol",
        "Keys": [
                {
                          "ID": "d32fa8b5ca08273a2880f455fcb318da3dc80aeae1a30610815140deef8f30d9"
                },
                {
                          "ID":  "9a8bbec6ba2af88a5fad6047d428d17e6d05dbdd03d15b4fc8a9a0e8049cd606"
                }
        ]
      }
    ],
    "AdminstrativeKeys": [
      {
        "Name": "Repository",
        "Keys": [
                {
                          "ID": "27df2c8187e7543345c2e0bf3a1262e0bc63a72754e9a7395eac3f747ec23a44"
                }
        ]
      },
      {
        "Name": "Root",
        "Keys": [
                {
                          "ID": "40b66ccc8b176be8c7d365a17f3e046d1c3494e053dd57cfeacfe2e19c4f8e8f"
                }
        ]
      }
    ]
  }
]

Closes #659

@rn

rn commented Nov 16, 2017

Copy link
Copy Markdown

Thanks. the output looks good to me

Args: cli.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
return inspectTrustInfo(dockerCli, args[0])
},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I believe all other inspect commands support multiple args for inspecting multiple objects at once, so they return a list instead of a single JSON object.

Other inspect commands also use a formatter in cli/command/formatter to support the --format flag.

I think it might be good to be consistent here.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

sounds good. I've added multiple args support. I'd like to hold off on the --format flag for now until we've stabilized the JSON format



```bash
$ docker trust inspect alpine:latest | jq

@eiais eiais Nov 16, 2017

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

None of the other inspect command's docs show piping to jq

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Agreed: can you remove the | jq? We can keep the output as-is (it's documentation, so should be reasonable to output for readability - we may need to add a note / "conventions" section about that somewhere central)

@dnephin dnephin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@vdemeester vdemeester left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM 🐸
cc @thaJeztah for docs

@thaJeztah thaJeztah left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks! See my comments inline 😄

Comment thread cli/command/trust/inspect.go Outdated
}, nil
}

// trustRepo represents consumable information about a trusted repository

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: can you move these types to the top of this file? (looks like we do so in the other trust commands)

"SignedTag": "latest",
"Digest": "d6bfc3baf615dc9618209a8d607ba2a8103d9c8a405b3bd8741d88b4bef36478",
"Signers": [
"Repo Admin"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm wondering if more information about signers is available, or will be available/needed at some point; basically, I love the simplicity of a []string, but if we anticipate more information is needed at some point, perhaps a []sometype{} ?

Definitely open to input here 👍

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

if there's more info it will be specified in the top level Signers key struct - do you think that's ok? Let me know if I'm misinterpreting your comment.

{
"Name": "Repository",
"Keys": [
"5a46c9aaa82ff150bb7305a2d17d0c521c2d784246807b2dc611f436a69041fd"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same for keys ([]string vs []sometype{})

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I'm happy to make the change but don't think we'll need it - notary only exposes []string for Key IDs in its role structs

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

updated to use a custom type!

ex:

"Signers": [
            {
                "Name": "bob",
                "Keys": [
                    {
                        "ID": "B"
                    }
                ]
            },
...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You forgot to update the examples in the docs 😅

Comment thread cli/command/trust/view.go Outdated

// lookupTrustInfo returns processed signature and role information about a notary repository.
// This information is to be pretty printed or serialized into a machine-readable format.
func lookupTrustInfo(cli command.Cli, remote string) (trustTagRowList, []client.RoleWithSignatures, []data.Role, error) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lookupTrustInfo() is now shared between inspect and view; perhaps it (and the tests) should be moved to a separate file common.go ? I see there's a helpers.go, but not sure this qualifies as a "helper".

Same for:

  • getDelegationRoleToKeyMap()
  • matchReleasedSignatures()

(Possibly same for trustTagKey and the other types defined at the top of this file)

If signers are set up for the repository via other `docker trust` commands, `docker trust inspect` includes a `Signers` key:

```bash

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you remove this line?

### Get details about signatures for multiple images

```bash
$ docker trust inspect alpine ubuntu | jq

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

drop | jq

```

### Get details about signatures for all image tags in a repository

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you add a short introduction here? Just to lead in the example

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

👍 added!



### Get details about signatures for multiple images

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you add a short introduction here? Just to lead in the example

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

added!

cmd := &cobra.Command{
Use: "inspect IMAGE[:TAG] [IMAGE[:TAG]...]",
Short: "Return low-level information about keys and signatures",
Args: cli.RequiresMinArgs(1),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should either disallow specifying multiple repositories, or add the repository name to the output. The output as it is, is not useful if you specify multiple repositories;

$ docker trust inspect alpine hello-world | jq

Produces (removed some entries to keep it short):

[
  {
    "SignedTags": [
      {
        "SignedTag": "2.6",
        "Digest": "9ace551613070689a12857d62c30ef0daa9a376107ec0fff0e34786cedb3399b",
        "Signers": [
          "Repo Admin"
        ]
      },
      {
        "SignedTag": "latest",
        "Digest": "d6bfc3baf615dc9618209a8d607ba2a8103d9c8a405b3bd8741d88b4bef36478",
        "Signers": [
          "Repo Admin"
        ]
      }
    ],
    "AdminstrativeKeys": [
      {
        "Name": "Root",
        "Keys": [
          "a2489bcac7a79aa67b19b96c4a3bf0c675ffdf00c6d2fabe1a5df1115e80adce"
        ]
      },
      {
        "Name": "Repository",
        "Keys": [
          "5a46c9aaa82ff150bb7305a2d17d0c521c2d784246807b2dc611f436a69041fd"
        ]
      }
    ]
  },
  {
    "SignedTags": [
      {
        "SignedTag": "latest",
        "Digest": "0e06ef5e1945a718b02a8c319e15bae44f47039005530bc617a5d071190ed3fc",
        "Signers": [
          "Repo Admin"
        ]
      },
      {
        "SignedTag": "linux",
        "Digest": "452733afb5319f624b88aec51006a077bccf036a87167fd657057e2e31f42736",
        "Signers": [
          "Repo Admin"
        ]
      },
    ],
    "AdminstrativeKeys": [
      {
        "Name": "Root",
        "Keys": [
          "ff544c7f4ffa0a61b2fb836fb581182181c971acd58a7023c9a3b049dc952edd"
        ]
      },
      {
        "Name": "Repository",
        "Keys": [
          "8d2aaa7461b4305f74dc80bb946ccad962829a57bd0412a480e17a2413b18ec9"
        ]
      }
    ]
  }
]

With that information alone, I don't know which repository the :latest tag belongs to

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

sounds good, I added Name as the first field 👍

Comment thread cli/command/trust/inspect.go Outdated

// trustRepo represents consumable information about a trusted repository
type trustRepo struct {
SignedTags trustTagRowList `json:",omitempty"`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this type needs a property for the repo-name (see my comment for "multiple repositories")

@thaJeztah thaJeztah left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Left some notes for the docs, but LGTM otherwise

{
"Name": "Repository",
"Keys": [
"5a46c9aaa82ff150bb7305a2d17d0c521c2d784246807b2dc611f436a69041fd"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You forgot to update the examples in the docs 😅

]
},
{
"SignedTag": "3.6",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

When updating for the new format, can you also shorten the output of this example a bit? Only 1 .. 2 tags should be needed to show what it does 😄

@thaJeztah thaJeztah left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, but may need some squashing 👍

Signed-off-by: Riyaz Faizullabhoy <riyaz.faizullabhoy@docker.com>
Signed-off-by: Riyaz Faizullabhoy <riyaz.faizullabhoy@docker.com>
Signed-off-by: Riyaz Faizullabhoy <riyaz.faizullabhoy@docker.com>

@thaJeztah thaJeztah left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thanks!

@thaJeztah
thaJeztah merged commit d921d5c into docker:master Nov 29, 2017
@GordonTheTurtle GordonTheTurtle added this to the 17.12.0 milestone Nov 29, 2017
@riyazdf
riyazdf deleted the trust-inspect branch November 29, 2017 19:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants