Create a trust policy and verify artifacts
As part of the process to verify a container image with Notation, you need to configure the trust policy to specify trusted identities that sign the artifacts, and the level of signature verification to use. For more details, see trust policy spec.
This tutorial shows you how to create a trust policy with different trusted identities and levels of signature verification.
Create an example registry with an image
Warning
The following example creates a registry with oras-project/registry. This registry should only be used for development purposes. When using other registries, ensure the registry is compatible with OCI Image specification v1.1.0. Starting withv1.0.0-rc.1
of notation
, by default, signatures are stored using OCI Artifact Manifest, which is defined in OCI Image spec v1.1.0).
Note
For Apple silicon, add the--platform linux/arm64
parameter.
Use docker buildx build
and docker push
to build and push a sample image to your registry.
Save the digest value of the image from the output of docker push
. For example:
In the above example, the digest value of the image is sha256:1111111111111111111111111111111111111111111111111111111111111111
.
Create example certificates and sign the image
Use notation cert generate-test
to generate three example certificates and trust stores for signing the image.
- The valid-example certificate and trust store will be used to sign the image with a valid signature.
- The expired-example certificate and trust store will be used to sign the image with an expired signature.
- The missing-example certificate and trust store will not be used to sign the image, but will be used to demonstrate the trust policy.
Use notation ls
to list the current signatures for your image. The following example sets the value of $IMAGE to the name of the image and its digest value.
Warning
Always use the digest value of an image when signing since they are immutable. Tag values are mutable and can reference a different container image than the original signed container image.Confirm there are no signatures listed.
Use notation sign
to sign the image with two different signatures.
Use notation ls
to confirm there are two signatures.
Create a trust policy
Create a trustpolicy.json
with the following trust policy in the notation configuration directory.
Note
For Linux, the notation configuration directory is${HOME}/.config/notation/
. For macOS, the notation configuration directory is ${HOME}/Library/Application\ Support/notation/
. For Windows, the notation configuration folder is %USERPROFILE%\AppData\Roaming\notation\
.
The above example has a verification level of strict and uses the valid-example trust store.
Verify image signatures using the trust policy
The trust policy you created in the previous step uses a verification level of strict but there’s also permissive, audit, and skip. For more details on see trust policy spec.
Use notation verify
to verify the image using the strict verification level and valid-example trust store and confirm it succeeds.
Update the trust store to use the expired-example trust store.
Use notation verify
to verify the image using the strict verification level and expired-example trust store and confirm it fails.
This example fails because the strict verification level does not allow expired certificates. When creating the expired-example certificate and trust store, the certificate’s expiration was set for 30 seconds.
Update the trust policy to use the permissive verification level, which only logs if there is an expired certificate.
Use notation verify
to verify the image using the permissive verification level and expired-example trust store and confirm it succeeds while logging the expired certificate.
Update the trust policy to use the missing-example trust store.
Use notation verify
to verify the image using the permissive verification level and missing-example trust store and confirm it fails.
This example fails because the permissive verification level does not allow missing certificates. When creating the missing-example certificate and trust store, the certificate was not used to sign the image.
Update the trust store to use the audit verification level.
Use notation verify
to verify the image using the audit verification level and missing-example trust store and confirm it succeeds while logging the missing certificate.
Cleanup
Remove the notation configuration
To remove local keys, self-signed certificates, and notation configurations, remove the notation configuration directory.
For linux:
For macOS:
For Windows, delete the directory %USERPROFILE%\AppData\Roaming\notation\
Remove the registry
To remove the registry running on your development computer: