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