github.com/hustcat/docker@v1.3.3-0.20160314103604-901c67a8eeab/docs/security/trust/content_trust.md (about)

     1  <!--[metadata]>
     2  +++
     3  title = "Content trust in Docker"
     4  description = "Enabling content trust in Docker"
     5  keywords = ["content, trust, security, docker,  documentation"]
     6  [menu.main]
     7  parent= "smn_content_trust"
     8  weight=-1
     9  +++
    10  <![end-metadata]-->
    11  
    12  # Content trust in Docker
    13  
    14  When transferring data among networked systems, *trust* is a central concern. In
    15  particular, when communicating over an untrusted medium such as the internet, it
    16  is critical to ensure the integrity and publisher of all the data a system
    17  operates on. You use Docker to push and pull images (data) to a registry. Content trust
    18  gives you the ability to both verify the integrity and the publisher of all the
    19  data received from a registry over any channel.
    20  
    21  Content trust is currently only available for users of the public Docker Hub. It
    22  is currently not available for the Docker Trusted Registry or for private
    23  registries.
    24  
    25  ## Understand trust in Docker
    26  
    27  Content trust allows operations with a remote Docker registry to enforce
    28  client-side signing and verification of image tags. Content trust provides the
    29  ability to use digital signatures for data sent to and received from remote
    30  Docker registries. These signatures allow client-side verification of the
    31  integrity and publisher of specific image tags.
    32  
    33  Currently, content trust is disabled by default. You must enabled it by setting
    34  the `DOCKER_CONTENT_TRUST` environment variable. Refer to the
    35  [environment variables](../../reference/commandline/cli.md#environment-variables)
    36  and [Notary](../../reference/commandline/cli.md#notary) configuration
    37  for the docker client for more options.
    38  
    39  Once content trust is enabled, image publishers can sign their images. Image consumers can
    40  ensure that the images they use are signed. publishers and consumers can be
    41  individuals alone or in organizations. Docker's content trust supports users and
    42  automated processes such as builds.
    43  
    44  ### Image tags and content trust
    45  
    46  An individual image record has the following identifier:
    47  
    48  ```
    49  [REGISTRY_HOST[:REGISTRY_PORT]/]REPOSITORY[:TAG]
    50  ```
    51  
    52  A particular image `REPOSITORY` can have multiple tags. For example, `latest` and
    53   `3.1.2` are both tags on the `mongo` image. An image publisher can build an image
    54   and tag combination many times changing the image with each build.
    55  
    56  Content trust is associated with the `TAG` portion of an image. Each image
    57  repository has a set of keys that image publishers use to sign an image tag.
    58  Image publishers have discretion on which tags they sign.
    59  
    60  An image repository can contain an image with one tag that is signed and another
    61  tag that is not. For example, consider [the Mongo image
    62  repository](https://hub.docker.com/r/library/mongo/tags/). The `latest`
    63  tag could be unsigned while the `3.1.6` tag could be signed. It is the
    64  responsibility of the image publisher to decide if an image tag is signed or
    65  not. In this representation, some image tags are signed, others are not:
    66  
    67  ![Signed tags](images/tag_signing.png)
    68  
    69  Publishers can choose to sign a specific tag or not. As a result, the content of
    70  an unsigned tag and that of a signed tag with the same name may not match. For
    71  example, a publisher can push a tagged image `someimage:latest` and sign it.
    72  Later, the same publisher can push an unsigned `someimage:latest` image. This second
    73  push replaces the last unsigned tag `latest` but does not affect the signed `latest` version.
    74  The ability to choose which tags they can sign, allows publishers to iterate over
    75  the unsigned version of an image before officially signing it.
    76  
    77  Image consumers can enable content trust to ensure that images they use were
    78  signed. If a consumer enables content trust, they can only pull, run, or build
    79  with trusted images. Enabling content trust is like wearing a pair of
    80  rose-colored glasses. Consumers "see" only signed images tags and the less
    81  desirable, unsigned image tags are "invisible" to them.
    82  
    83  ![Trust view](images/trust_view.png)
    84  
    85  To the consumer who does not enabled content trust, nothing about how they
    86  work with Docker images changes. Every image is visible regardless of whether it
    87  is signed or not.
    88  
    89  
    90  ### Content trust operations and keys
    91  
    92  When content trust is enabled, `docker` CLI commands that operate on tagged images must
    93  either have content signatures or explicit content hashes. The commands that
    94  operate with content trust are:
    95  
    96  * `push`
    97  * `build`
    98  * `create`
    99  * `pull`
   100  * `run`
   101  
   102  For example, with content trust enabled a `docker pull someimage:latest` only
   103  succeeds if `someimage:latest` is signed. However, an operation with an explicit
   104  content hash always succeeds as long as the hash exists:
   105  
   106  ```bash
   107  $ docker pull someimage@sha256:d149ab53f8718e987c3a3024bb8aa0e2caadf6c0328f1d9d850b2a2a67f2819a
   108  ```
   109  
   110  Trust for an image tag is managed through the use of signing keys. A key set is
   111  created when an operation using content trust is first invoked. Docker's content
   112  trust makes use of four different keys:
   113  
   114  | Key                 | Description                                                                                                                                                                                                                                                                                                                                                                         |
   115  |---------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|
   116  | root key         | Root of content trust for a image tag. When content trust is enabled, you create the root key once. |
   117  | target and snapshot | These two keys are known together as the "repository" key. When content trust is enabled, you create this key when you add a new image repository. If you have the root key, you can export the repository key and allow other publishers to sign the image tags.    |
   118  | timestamp           | This key applies to a repository. It allows Docker repositories to have freshness security guarantees without requiring periodic content refreshes on the client's side.                                                                                                              |
   119  
   120  With the exception of the timestamp, all the keys are generated and stored locally
   121  client-side. The timestamp is safely generated and stored in a signing server that
   122  is deployed alongside the Docker registry. All keys are generated in a backend
   123  service that isn't directly exposed to the internet and are encrypted at rest.
   124  
   125  The following image depicts the various signing keys and their relationships:
   126  
   127  ![Content trust components](images/trust_components.png)
   128  
   129  >**WARNING**: Loss of the root key is **very difficult** to recover from.
   130  >Correcting this loss requires intervention from [Docker
   131  >Support](https://support.docker.com) to reset the repository state. This loss
   132  >also requires **manual intervention** from every consumer that used a signed
   133  >tag from this repository prior to the loss.
   134  
   135  You should backup the root key somewhere safe. Given that it is only required
   136  to create new repositories, it is a good idea to store it offline. Make sure you
   137  read [Manage keys for content trust](trust_key_mng.md) information
   138  for details on securing, and backing up your keys. 
   139  
   140  ## Survey of typical content trust operations
   141  
   142  This section surveys the typical trusted operations users perform with Docker
   143  images.
   144  
   145  ### Enable and disable content trust per-shell or per-invocation
   146  
   147  In a shell, you can enable content trust by setting the `DOCKER_CONTENT_TRUST`
   148  environment variable. Enabling per-shell is useful because you can have one
   149  shell configured for trusted operations and another terminal shell for untrusted
   150  operations. You can also add this declaration to your shell profile to have it
   151  turned on always by default.
   152  
   153  To enable content trust in a `bash` shell enter the following command:
   154  
   155  ```bash
   156  export DOCKER_CONTENT_TRUST=1
   157  ```
   158  
   159  Once set, each of the "tag" operations requires a key for a trusted tag.
   160  
   161  In an environment where `DOCKER_CONTENT_TRUST` is set, you can use the
   162  `--disable-content-trust` flag to run individual operations on tagged images
   163  without content trust on an as-needed basis.
   164  
   165  ```bash
   166  $  docker pull --disable-content-trust docker/trusttest:untrusted
   167  ```
   168  
   169  To invoke a command with content trust enabled regardless of whether or how the `DOCKER_CONTENT_TRUST` variable is set:
   170  
   171  ```bash
   172  $  docker build --disable-content-trust=false -t docker/trusttest:testing .
   173  ```
   174  
   175  All of the trusted operations support the `--disable-content-trust` flag.
   176  
   177  
   178  ### Push trusted content
   179  
   180  To create signed content for a specific image tag, simply enable content trust
   181  and push a tagged image. If this is the first time you have pushed an image
   182  using content trust on your system, the session looks like this:
   183  
   184  ```bash
   185  $ docker push docker/trusttest:latest
   186  The push refers to a repository [docker.io/docker/trusttest] (len: 1)
   187  9a61b6b1315e: Image already exists
   188  902b87aaaec9: Image already exists
   189  latest: digest: sha256:d02adacee0ac7a5be140adb94fa1dae64f4e71a68696e7f8e7cbf9db8dd49418 size: 3220
   190  Signing and pushing trust metadata
   191  You are about to create a new root signing key passphrase. This passphrase
   192  will be used to protect the most sensitive key in your signing system. Please
   193  choose a long, complex passphrase and be careful to keep the password and the
   194  key file itself secure and backed up. It is highly recommended that you use a
   195  password manager to generate the passphrase and keep it safe. There will be no
   196  way to recover this key. You can find the key in your config directory.
   197  Enter passphrase for new root key with id a1d96fb:
   198  Repeat passphrase for new root key with id a1d96fb:
   199  Enter passphrase for new repository key with id docker.io/docker/trusttest (3a932f1):
   200  Repeat passphrase for new repository key with id docker.io/docker/trusttest (3a932f1):
   201  Finished initializing "docker.io/docker/trusttest"
   202  ```
   203  When you push your first tagged image with content trust enabled, the  `docker`
   204  client recognizes this is your first push and:
   205  
   206   - alerts you that it will create a new root key
   207   - requests a passphrase for the key
   208   - generates a root key in the `~/.docker/trust` directory
   209   - generates a repository key for in the `~/.docker/trust` directory
   210  
   211  The passphrase you chose for both the root key and your content key-pair
   212  should be randomly generated and stored in a *password manager*.
   213  
   214  > **NOTE**: If you omit the `latest` tag, content trust is skipped. This is true
   215  even if content trust is enabled and even if this is your first push.
   216  
   217  ```bash
   218  $ docker push docker/trusttest
   219  The push refers to a repository [docker.io/docker/trusttest] (len: 1)
   220  9a61b6b1315e: Image successfully pushed
   221  902b87aaaec9: Image successfully pushed
   222  latest: digest: sha256:a9a9c4402604b703bed1c847f6d85faac97686e48c579bd9c3b0fa6694a398fc size: 3220
   223  No tag specified, skipping trust metadata push
   224  ```
   225  
   226  It is skipped because as the message states, you did not supply an image `TAG`
   227  value. In Docker content trust, signatures are associated with tags.
   228  
   229  Once you have a root key on your system, subsequent images repositories
   230  you create can use that same root key:
   231  
   232  ```bash
   233  $ docker push docker.io/docker/seaside:latest
   234  The push refers to a repository [docker.io/docker/seaside] (len: 1)
   235  a9539b34a6ab: Image successfully pushed
   236  b3dbab3810fc: Image successfully pushed
   237  latest: digest: sha256:d2ba1e603661a59940bfad7072eba698b79a8b20ccbb4e3bfb6f9e367ea43939 size: 3346
   238  Signing and pushing trust metadata
   239  Enter key passphrase for root key with id a1d96fb:
   240  Enter passphrase for new repository key with id docker.io/docker/seaside (bb045e3):
   241  Repeat passphrase for new repository key with id docker.io/docker/seaside (bb045e3):
   242  Finished initializing "docker.io/docker/seaside"
   243  ```
   244  
   245  The new image has its own repository key and timestamp key. The `latest` tag is signed with both of
   246  these.
   247  
   248  
   249  ### Pull image content
   250  
   251  A common way to consume an image is to `pull` it. With content trust enabled, the Docker
   252  client only allows `docker pull` to retrieve signed images.
   253  
   254  ```
   255  $  docker pull docker/seaside
   256  Using default tag: latest
   257  Pull (1 of 1): docker/trusttest:latest@sha256:d149ab53f871
   258  ...
   259  Tagging docker/trusttest@sha256:d149ab53f871 as docker/trusttest:latest
   260  ```
   261  
   262  The `seaside:latest` image is signed. In the following example, the command does not specify a tag, so the system uses
   263  the `latest` tag by default again and the `docker/cliffs:latest` tag is not signed.
   264  
   265  ```bash
   266  $ docker pull docker/cliffs
   267  Using default tag: latest
   268  no trust data available
   269  ```
   270  
   271  Because the tag `docker/cliffs:latest` is not trusted, the `pull` fails.
   272  
   273  
   274  ### Disable content trust for specific operations
   275  
   276  A user that wants to disable content trust for a particular operation can use the
   277  `--disable-content-trust` flag. **Warning: this flag disables content trust for
   278  this operation**. With this flag, Docker will ignore content-trust and allow all
   279  operations to be done without verifying any signatures. If we wanted the
   280  previous untrusted build to succeed we could do:
   281  
   282  ```
   283  $  cat Dockerfile
   284  FROM docker/trusttest:notrust
   285  RUN echo
   286  $  docker build --disable-content-trust -t docker/trusttest:testing .
   287  Sending build context to Docker daemon 42.84 MB
   288  ...
   289  Successfully built f21b872447dc
   290  ```
   291  
   292  The same is true for all the other commands, such as `pull` and `push`:
   293  
   294  ```
   295  $  docker pull --disable-content-trust docker/trusttest:untrusted
   296  ...
   297  $  docker push --disable-content-trust docker/trusttest:untrusted
   298  ...
   299  ```
   300  
   301  ## Related information
   302  
   303  * [Manage keys for content trust](trust_key_mng.md)
   304  * [Automation with content trust](trust_automation.md)
   305  * [Play in a content trust sandbox](trust_sandbox.md)