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

doc: update spec for feature sign/verify local images #601

Merged
merged 11 commits into from
Apr 17, 2023
28 changes: 27 additions & 1 deletion specs/commandline/list.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Aliases:
Flags:
-d, --debug debug mode
-h, --help help for list
--local-artifact [Preview] list signatures associated with the artifact in OCI layout directory
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. Can we considering inferring that its a file path? @priteshbandi also brought this up.
  2. Secondly if the flag is needed can we call it something like --file or --path etc. --local is quite subjective.

Copy link
Contributor

Choose a reason for hiding this comment

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

For the option, what if we considered something more flexible than just a boolean. If we use something like --type (maybe this isn't the best name, but I think the concept is interesting) we could specify through the option that it is a directory. That would allow us to easily incorporate new modes for tarballs, SBOMs, or other files that could be added in the future.


Example:

notation sign $IMAGE
notation sign --type dir /path/to/registry.acme-rockets.io/net-monitor:v2
notation sign --type tar hello-world.tar
...

Copy link
Contributor Author

@yizha1 yizha1 Mar 28, 2023

Choose a reason for hiding this comment

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

@shizhMSFT @patrickzheng200 @qweeah @priteshbandi @vaninrao10 @FeynmanZhou @toddysm @sajayantony please take a look at Kody's comment above. Now we have these options:

  1. --local-content
  2. --local-artifact
  3. --path <file path | dir path>
  4. --file
  5. --use-oci-layout
  6. --oci-dir
  7. --offline
  8. file://./
  9. --dirpath
  10. --target-path
  11. --type <dir|tar|other types>

Copy link
Contributor

Choose a reason for hiding this comment

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

In fact, if @yizha1 could remember, the very first version of my design was pretty similar to Kody's suggestion, i.e. specifying type of the user input. So personally speaking, I think it's a good idea as long as there's no usability concern (users need to know what options are available in Notation, and what type their input belong to).

Copy link
Contributor Author

@yizha1 yizha1 Mar 28, 2023

Choose a reason for hiding this comment

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

I vote for option 3: --path <file path | dir path>

Copy link
Member

Choose a reason for hiding this comment

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

Agree with adding --target type=... flag in v1.0.0. There is only one target type oci-layout in RC.4, it's reasonable to use --oci-layout as a shorthand for --target type=oci-layout.

Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure having shorthand is a good idea. Having too many switches pollutes the CLI and makes its use hard to use.

Copy link
Contributor Author

@yizha1 yizha1 Apr 1, 2023

Choose a reason for hiding this comment

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

@toddysm We will consider adding --target type= if the time allows for 1.0. For RC.4 it is a good start, since we only have one type now, compared to --target type=oci-layout, --oci-layout is short and convenient. Shorthand could be a good practice for some scenarios, if we have multiple choice, and we know what option 80% users will choose, then shorthand will be convenient for them, since it is short. In the meantime, we could also support 20% scenarios with the full flag. In our cases, OCI image layout could be the most choice, since it is the only standard now OCI images and other OCI artifacts can be stored in a directory structure under filesystem (could be completely offline), and easy to copy to remote registry.

Copy link
Contributor

Choose a reason for hiding this comment

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

My problem is that the main scenario is not that one. People do not want to create the layout before signing. A good user experience will be to reference the docker image and do all the work behind the scenes. Also, another local signing scenario is just signing a blob, like file for example, which doesn't require OCI layout at all. The current experience to ask the user to expand the image in OCI layout is suboptimal. If this is the only option then yes - this will be > 80% of the cases but it is a very little percentage of what people really want to do.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As discussed, --oci-layout and --scope will be experimental feature which requires system variable NOTATION_EXPERIMENTAL to be set.

-p, --password string password for registry operations (default to $NOTATION_PASSWORD if not specified)
--plain-http registry access via plain HTTP
-u, --username string username for registry operations (default to $NOTATION_USERNAME if not specified)
Expand All @@ -39,7 +40,7 @@ Flags:

### List all the signatures of the signed container image

```text
```shell
notation list <registry>/<repository>:<tag>
```

Expand All @@ -51,3 +52,28 @@ localhost:5000/net-monitor:v1
├── sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
└── sha256:bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
```

### [Preview] List all the signatures associated with the image in OCI layout directory

The following example lists the signatures associated with the image in OCI layout directory named `hello-world`.

Reference an image in OCI layout directory using tags:

```shell
notation list --local-artifact ./hello-world:v1
```

Reference an image in OCI layout directory using exact digest:

```shell
notation list --local-artifact ./hello-world@sha256:xxx
```

An example output:

```shell
./hello-world@sha256:a08753c0c7bcdaaf5c2fdb375f68e860c34bffb146368982c201d41769e1763c
yizha1 marked this conversation as resolved.
Show resolved Hide resolved
└── application/vnd.cncf.notary.signature
├── sha256:647039638efb22a021f59675c9449dd09956c981a44b82c1ff074513c2c9f273
└── sha256:6bfb3c4fd485d6810f9656ddd4fb603f0c414c5f0b175ef90eeb4090ebd9bfa1
```
32 changes: 32 additions & 0 deletions specs/commandline/sign.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Flags:
-h, --help help for sign
--id string key id (required if --plugin is set). This is mutually exclusive with the --key flag
-k, --key string signing key name, for a key previously added to notation's key list. This is mutually exclusive with the --id and --plugin flags
--local-artifact [Preview] sign artifact on local disk
-p, --password string password for registry operations (default to $NOTATION_PASSWORD if not specified)
--plain-http registry access via plain HTTP
--plugin string signing plugin name. This is mutually exclusive with the --key flag
Expand Down Expand Up @@ -166,6 +167,37 @@ Successfully signed localhost:5000/net-monitor@sha256:b94d27b9934d3e08a52e52d7da
notation sign --signature-manifest artifact <registry>/<repository>@<digest>
```

### [Preview] Sign local OCI image

A local OCI image means an OCI image Layout on local disk. OCI image layout is defined by spec [OCI image layout][oci-image-layout]. It is a directory structure that contains files and folders. Users can reference an image in the layout using either tags, or the exact digest. The OCI image layout could be a tarball or a directory. Notation only supports signing OCI layout directory for now.

Tools like `docker buildx` support building an OCI image layout on local disk. The following example creates a tarball named `hello-world.tar` with tag `v1`, which is an OCI layout tarball on local disk. Please note that the digest can be found in the output messages of `docker buildx build`.

```shell
docker buildx create --use
docker buildx build . -f Dockerfile -o type=oci,dest=hello-world.tar -t hello-world:v1
```

Users need to extract the tarball into a directory first. The following command creates the OCI layout directory, and the image can be referenced by `./hello-world:v1` or `./hello-world@sha256:xxx`.

```shell
mkdir hello-world
tar -xf ./hello-world.tar -C hello-world
yizha1 marked this conversation as resolved.
Show resolved Hide resolved
```

Use flag `--local-artifact` for signing local OCI images. For example:

```shell
notation sign --local-artifact ./hello-world@sha256:xxx
```

Upon successful signing, the signature is stored in the same layout directory and associated with the image. Use `notation list` command to list the signatures, for example:

```shell
notation list ./hello-world@sha256:xxx
```

[oci-artifact-manifest]: https://github.com/opencontainers/image-spec/blob/v1.1.0-rc2/artifact.md
[oci-image-spec]: https://github.com/opencontainers/image-spec/blob/v1.1.0-rc2/spec.md
[oci-referers-api]: https://github.com/opencontainers/distribution-spec/blob/v1.1.0-rc1/spec.md#listing-referrers
[oci-image-layout]: https://github.com/opencontainers/image-spec/blob/v1.1.0-rc2/image-layout.md
24 changes: 24 additions & 0 deletions specs/commandline/verify.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ Usage:
Flags:
-d, --debug debug mode
-h, --help help for verify
--local-artifact [Preview] verify artifact on local disk
-p, --password string password for registry operations (default to $NOTATION_PASSWORD if not specified)
--plain-http registry access via plain HTTP
--plugin-config stringArray {key}={value} pairs that are passed as it is to a plugin, if the verification is associated with a verification plugin, refer plugin documentation to set appropriate values
--scope string [Preview] trust policy scope for local artifact verification.
yizha1 marked this conversation as resolved.
Show resolved Hide resolved
-u, --username string username for registry operations (default to $NOTATION_USERNAME if not specified)
-m, --user-metadata stringArray user defined {key}={value} pairs that must be present in the signature for successful verification if provided
-v, --verbose verbose mode
Expand Down Expand Up @@ -168,3 +170,25 @@ An example of output messages for a successful verification:
Warning: Always verify the artifact using digest(@sha256:...) rather than a tag(:v1) because resolved digest may not point to the same signed artifact, as tags are mutable.
Successfully verified signature for localhost:5000/net-monitor@sha256:b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9
```

### [Preview] Verify local OCI image

Users should configure trust policy properly before verifying local OCI image. According to trust policy specification, `registryScopes` property determines which trust policy is applicable for the given artifact. The value of `registryScopes` should be a fully qualified URL for both local and remote images. For example, a remote image is referenced by "localhost:5000/net-monitor:v1", thus the value of `registryScopes` should contain "localhost:5000/net-monitor", which is the repository URL of the image. Local OCI image is in the form of OCI layout directory, the reference is different from a remote image, for example "./hello-world:v1". Besides flag `--local-artifact`, users need to specify which `registryScopes` is used to verify the local image using flag `--scope`. Here is an example of trust policy configured for local image `./hello-world:v1`:
yizha1 marked this conversation as resolved.
Show resolved Hide resolved

```jsonc
{
"name": "local-images",
"registryScopes": [ "local/hello-world" ],
yizha1 marked this conversation as resolved.
Show resolved Hide resolved
"signatureVerification": {
"level" : "strict"
},
"trustStores": [ "ca:hello-world" ],
"trustedIdentities": ["*"]
}
```

To verify local image `./hello-world:v1`, use the following command:

```shell
notation verify --local-artifact --scope "local/hello-world" ./hello-world:v1
```