Distribution and Trust - Dockerlabs
Distribution and Trust - Dockerlabs
This lab focuses on understanding and securing image distribution. We’ll start with a simple docker pull and build up to using Docker Content Trust (DCT).
Prerequisites
You will need all of the following to complete this lab:
A Docker Host running Docker 1.10 or higher (preferably Docker 1.12 or higher).
This lab uses environment variables which can be clunky when working with sudo. Therefore none of the Docker commands in this particular lab are preceded
with sudo.
This command will pull the Alpine image tagged as edge. The corresponding image can be found here on Docker Store.
If no tag is specified, Docker will pull the image with the latest tag.
$ docker images
/ # ping www.docker.com
PING www.docker.com (104.239.220.248): 56 data bytes
64 bytes from 104.239.220.248: seq=0 ttl=40 time=94.424 ms
64 bytes from 104.239.220.248: seq=1 ttl=40 time=94.549 ms
64 bytes from 104.239.220.248: seq=2 ttl=40 time=94.455 ms
^C
file:///C:/Users/oloco/Desktop/README.html 1/5
6/4/24, 19:53 Distribution and Trust
In this step you pulled an image by tag and verified the pull by running a container from it.
This is why pulling by digest is such a powerful operation. Thanks to the content-addressable storage model used by Docker images, we can target pulls to specific
image contents by pulling by digest. In this step you’ll see how to pull by digest.
Notice that there are now two Alpine images in the Docker Hosts local repository. One lists the edge tag. The other lists <none> as the tag along with the
b7233daf... digest.
The content addressable storage model used by Docker images means that any changes made to an image will result in a new digest for the updated image. This
means it is not possible for two images with different contents to have the same digest.
In this step you learned how to pull images by digest and list image digests using the docker images command. For more information about the docker pull
command, see the documentation.
Enter Docker Content Trust: a system currently in the Docker Engine that verifies the publisher of images without sacrificing usability. Docker Content Trust
implements The Update Framework (TUF), an NSF-funded research project succeeding Thandy of the Tor project. TUF uses a key hierarchy to ensure recoverable
key compromise and robust freshness guarantees.
Under the hood, Docker Content Trust handles name resolution from IMAGE tags to IMAGE digests by signing its own metadata – when Content Trust is enabled,
docker will verify the signatures and expiration dates in the metadata before rewriting a pull by tag command to a pull by digest.
In this step you will enable Docker Content Trust, sign images as you push them, and pull signed and unsigned images.
$ export DOCKER_CONTENT_TRUST=1
Note: If you are using sudo with your Docker commands, you will need to preceded the above command so that it looks like thissudo export
DOCKER_CONTENT_TRUST=1
It is worth nothing that although Docker Content Trust is now enabled, all Docker commands remain the same. Docker Content Trust will work silently in the
background.
Look closely at the output of the docker pull command and take particular notice of the name translation - how the command is translated to the digest as
shown below:
You cannot pull unsigned images with Docker Content Trust enabled. Once Docker Content Trust is enabled you can only pull, run, or build with trusted images.
1. Tag and push your own signed image with Docker Content Trust.
$ docker tag alpine:edge <your-docker-id>/alpine:trusted
$ docker push <your-docker-id>/alpine:trusted
file:///C:/Users/oloco/Desktop/README.html 2/5
6/4/24, 19:53 Distribution and Trust
The push refers to a repository [docker.io/nigelpoulton/alpine]
4fe15f8d0ae6: Pushed
trusted: digest: sha256:dc89ce8401da81f24f7ba3f0ab2914ed9013608bdba0b7e7e5d964817067dc06 size: 528
Signing and pushing trust metadata
You are about to create a new root signing key passphrase. This passphrase
will be used to protect the most sensitive key in your signing system. Please
choose a long, complex passphrase and be careful to keep the password and the
key file itself secure and backed up. It is highly recommended that you use a
password manager to generate the passphrase and keep it safe. There will be no way to recover this key. You can find the key in your config directo
Enter passphrase for new root key with ID fef644e:
Repeat passphrase for new root key with ID fef644e:
Enter passphrase for new repository key with ID b4fd76d (docker.io/nigelpoulton/alpine):
Repeat passphrase for new repository key with ID b4fd76d (docker.io/nigelpoulton/alpine):
Finished initializing "docker.io/nigelpoulton/alpine"
Successfully signed "docker.io/nigelpoulton/alpine":trusted
This command will prompt you for passphrases. This is because Docker Content Trust is generating a hierarchy of keys with different signing roles. Each key is
encrypted with a passphrase, and it is best practice is to provide different passphrases for each key.
The root key is the most important key in TUF as it can rotate any other key in the system. The root key should be kept offline, ideally in hardware crypto device. It
is stored in ~/.docker/trust/private/root_keys by default.
The tagging key is the only local key required to push new tags to an existing repo, and is stored in ~/.docker/trust/private/tuf_keys by default.
Feel free to explore the ~/.docker/trust directory to view the internal metadata and key information that Docker Content Trust generates.
$ export DOCKER_CONTENT_TRUST=0
Take note of the difference between the pull of a signed image with Docker Content Trust enabled and disabled. With Docker Content Trust enabled the image
pull is converted from a tagged image pull to a digest image pull.
In this step you have seen how to enable and disable Docker Content Trust. You have also seen how to sign images that you push. For more information about
Docker Content Trust, see the documentation.
Official images can be pulled with just their name and tag. You do not have to precede the image name with library/ or any other repository name.
This can be done by downloading a binary directly from the releases page, or by cloning the notary repository into a valid Go repository structure (instructions at the
end of the README) and building a client by running make binaries. If you build the notary binary yourself, it will be placed in the bin subdirectory within the
notary git repo directory.
1. Use the notary client to inspect the existing Alpine repository on Docker Hub.
file:///C:/Users/oloco/Desktop/README.html 3/5
6/4/24, 19:53 Distribution and Trust
Note that docker.io/ must be prepended to the image name for hub images. You should also try your own image you pushed to hub earlier!
You will need to run this command from inside the root folder of the notary repository. The operation may take a minute or two to complete.
$ docker-compose up -d
Pulling mysql (mariadb:10.1.10)...
10.1.10: Pulling from library/mariadb
03e1855d4f31: Pull complete
a3ed95caeb02: Pull complete
ea9cb3d7d346: Pull complete
e47839e262bb: Pull complete
f568a56c1fd0: Pull complete
cc98c1dfbf81: Pull complete
98a99d2efdc4: Pull complete
0b304232c8e6: Pull complete
d65a44f4573e: Pull complete
Digest: sha256:10d0179f08a4fb0c785142ca73367921f46a93c2ee7c84831ae3543522156a6c
Status: Downloaded newer image for mariadb:10.1.10
<SNIP>
Creating notary_mysql_1
Creating notary_signer_1
Creating notary_server_1
2. Add 127.0.0.1 notary-server to /etc/hosts (or if using docker-machine, add $(docker-machine ip) notary-server).
3. Copy the config and certificate required to talk to your local Notary server.
$ mkdir -p ~/.notary && cp cmd/notary/config.json cmd/notary/root-ca.crt ~/.notary
You will be prompted for passphrases for the root and repository keys. This is for the same reasons as it was when you first pushed a repo with Docker Content Trust
enabled.
1. Add content to your trusted collection by running a sequence of notary add example.com/scripts <NAME> <FILE>, notary publish example.com/scripts, and
notary list example.com/scripts. This is a the sequence, in order:
Stages adding a target with notary add
Attempts to publish this target to the server with notary publish
Fetches and displays all trust data for example.com (verifying output as it is downloaded)
To remove targets, you can make use of the notary remove example.com/scripts <NAME> command, followed by a notary publish example.com/scripts.
Please note that this docker-compose setup will persist notary’s database data in a volume; if you’d like to wipe out all state when running this lab running multiple
times, you will have to remove this volume in addition to restarting the notary server, signer, and database containers.
In the event of key-compromise, it’s a simple procedure to rotate keys with notary. Simply determine which key you wish to rotate, and run notary key rotate.
2. Rotate a key.
file:///C:/Users/oloco/Desktop/README.html 4/5
6/4/24, 19:53 Distribution and Trust
3. Confirm that the targets key ID has changed.
$ notary key list
For more information about keys, please see the this section of the Notary Service Architecture documentation
This is done by default when creating new Content Trust repositories in Docker 1.10+.
This is so that delegation roles will only require their own delegation’s private key to publish to trusted collections.
2. Have your delegate generate an x509 certificate + private key pair with openssl - instructions here.
This command will allow the collaborator to push any target (from --all-paths) to the targets/releases role if they can sign with their private key
delegation.key in order to produce a valid signature that can be verified by delegation.crt’s public key material.
Be aware that this commmand only stages the delegation role addition.
Your collaborator should now be able to publish content (docker push) with Docker Content Trust enabled, or with a notary add example.com/scripts <NAME>
<FILE> -r targets/releases. You can verify their pushes by running a notary list example.com/scripts -r targets/releases
You can add additional keys to the same role with additional delegation add commands, like so: notary delegation add example.com/scripts targets/releases
delegation2.crt delegation3.crt, followed by a publish
For more commands over delegation roles, please consult the notary advanced usage documentation.
Summary
Congratulations. You now know the advantages of image digests over image tags. You have also seen how to enable Docker Content Trust and push signed images.
Finally you have seen how to perform some advanced tasks using the notary server and client.
free Ubuntu VM
This page was generated by GitHub Pages.
No Result Website Carbon
file:///C:/Users/oloco/Desktop/README.html 5/5