Browse code

added the registry API to the docker docs

Ken Cochrane authored on 2013/05/02 01:31:46
Showing 5 changed files
... ...
@@ -15,6 +15,7 @@ This documentation has the following resources:
15 15
    examples/index
16 16
    contributing/index
17 17
    commandline/index
18
+   registry/index
18 19
    faq
19 20
 
20 21
 
21 22
new file mode 100644
... ...
@@ -0,0 +1,464 @@
0
+===================
1
+Docker Registry API
2
+===================
3
+
4
+.. contents:: Table of Contents
5
+
6
+1. The 3 roles
7
+===============
8
+
9
+1.1 Index
10
+---------
11
+
12
+The Index is responsible for centralizing information about:
13
+- User accounts
14
+- Checksums of the images
15
+- Public namespaces
16
+
17
+The Index has different components:
18
+- Web UI
19
+- Meta-data store (comments, stars, list public repositories)
20
+- Authentication service
21
+- Tokenization
22
+
23
+The index is authoritative for those information.
24
+
25
+We expect that there will be only one instance of the index, run and managed by dotCloud.
26
+
27
+1.2 Registry
28
+------------
29
+- It stores the images and the graph for a set of repositories
30
+- It does not have user accounts data
31
+- It has no notion of user accounts or authorization
32
+- It delegates authentication and authorization to the Index Auth service using tokens
33
+- It supports different storage backends (S3, cloud files, local FS)
34
+- It doesn’t have a local database
35
+- It will be open-sourced at some point
36
+
37
+We expect that there will be multiple registries out there. To help to grasp the context, here are some examples of registries:
38
+
39
+- **sponsor registry**: such a registry is provided by a third-party hosting infrastructure as a convenience for their customers and the docker community as a whole. Its costs are supported by the third party, but the management and operation of the registry are supported by dotCloud. It features read/write access, and delegates authentication and authorization to the Index.
40
+- **mirror registry**: such a registry is provided by a third-party hosting infrastructure but is targeted at their customers only. Some mechanism (unspecified to date) ensures that public images are pulled from a sponsor registry to the mirror registry, to make sure that the customers of the third-party provider can “docker pull” those images locally.
41
+- **vendor registry**: such a registry is provided by a software vendor, who wants to distribute docker images. It would be operated and managed by the vendor. Only users authorized by the vendor would be able to get write access. Some images would be public (accessible for anyone), others private (accessible only for authorized users). Authentication and authorization would be delegated to the Index. The goal of vendor registries is to let someone do “docker pull basho/riak1.3” and automatically push from the vendor registry (instead of a sponsor registry); i.e. get all the convenience of a sponsor registry, while retaining control on the asset distribution.
42
+- **private registry**: such a registry is located behind a firewall, or protected by an additional security layer (HTTP authorization, SSL client-side certificates, IP address authorization...). The registry is operated by a private entity, outside of dotCloud’s control. It can optionally delegate additional authorization to the Index, but it is not mandatory.
43
+
44
+.. note::
45
+
46
+    Mirror registries and private registries which do not use the Index don’t even need to run the registry code. They can be implemented by any kind of transport implementing HTTP GET and PUT. Read-only registries can be powered by a simple static HTTP server. 
47
+
48
+.. note::
49
+
50
+    The latter implies that while HTTP is the protocol of choice for a registry, multiple schemes are possible (and in some cases, trivial):
51
+        - HTTP with GET (and PUT for read-write registries);
52
+        - local mount point;
53
+        - remote docker addressed through SSH.
54
+
55
+The latter would only require two new commands in docker, e.g. “registryget” and “registryput”, wrapping access to the local filesystem (and optionally doing consistency checks). Authentication and authorization are then delegated to SSH (e.g. with public keys).
56
+
57
+1.3 Docker
58
+----------
59
+
60
+On top of being a runtime for LXC, Docker is the Registry client. It supports:
61
+- Push / Pull on the registry
62
+- Client authentication on the Index
63
+
64
+2. Workflow
65
+===========
66
+
67
+2.1 Pull
68
+--------
69
+
70
+.. image:: /static_files/docker_pull_chart.png
71
+
72
+1. Contact the Index to know where I should download “samalba/busybox”
73
+2. Index replies:
74
+   a. “samalba/busybox” is on Registry A
75
+   b. here are the checksums for “samalba/busybox” (for all layers)
76
+   c. token
77
+3. Contact Registry A to receive the layers for “samalba/busybox” (all of them to the base image). Registry A is authoritative for “samalba/busybox” but keeps a copy of all inherited layers and serve them all from the same location.
78
+4. registry contacts index to verify if token/user is allowed to download images
79
+5. Index returns true/false lettings registry know if it should proceed or error out
80
+6. Get the payload for all layers
81
+
82
+It’s possible to run docker pull https://<registry>/repositories/samalba/busybox. In this case, docker bypasses the Index. However the security is not guaranteed (in case Registry A is corrupted) because there won’t be any checksum checks.
83
+
84
+Currently registry redirects to s3 urls for downloads, going forward all downloads need to be streamed through the registry. The Registry will then abstract the calls to S3 by a top-level class which implements sub-classes for S3 and local storage.
85
+
86
+Token is only returned when it is a private repo, public repos do not require tokens to be returned. The Registry will still contact the Index to make sure the pull is authorized (“is it ok to download this repos without a Token?”).
87
+
88
+API (pulling repository foo/bar):
89
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
90
+
91
+1. (Docker -> Index) GET /v1/repositories/foo/bar/images
92
+    **Headers**:
93
+        Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
94
+        X-Docker-Token: true
95
+    **Action**:
96
+        (looking up the foo/bar in db and gets images and checksums for that repo (all if no tag is specified, if tag, only checksums for those tags) see part 4.4.1)
97
+
98
+2. (Index -> Docker) HTTP 200 OK
99
+
100
+    **Headers**:
101
+        - Authorization: Token signature=123abc,repository=”foo/bar”,access=write
102
+        - X-Docker-Endpoints: registry.docker.io [, registry2.docker.io]
103
+    **Body**:
104
+        Jsonified checksums (see part 4.4.1)
105
+
106
+3. (Docker -> Registry) GET /v1/repositories/foo/bar/tags/latest
107
+    **Headers**: 
108
+        Authorization: Token signature=123abc,repository=”foo/bar”,access=write
109
+
110
+4. (Registry -> Index) GET /v1/repositories/foo/bar/images
111
+
112
+    **Headers**:
113
+        Authorization: Token signature=123abc,repository=”foo/bar”,access=read
114
+
115
+    **Body**:
116
+        <ids and checksums in payload>
117
+
118
+    **Action**:
119
+        ( Lookup token see if they have access to pull.)
120
+
121
+        If good: 
122
+            HTTP 200 OK
123
+            Index will invalidate the token
124
+        If bad: 
125
+            HTTP 401 Unauthorized
126
+
127
+5. (Docker -> Registry) GET /v1/images/928374982374/ancestry
128
+    **Action**:
129
+        (for each image id returned in the registry, fetch /json + /layer)
130
+
131
+.. note::
132
+
133
+    If someone makes a second request, then we will always give a new token, never reuse tokens.
134
+
135
+2.2 Push
136
+--------
137
+
138
+.. image:: /static_files/docker_push_chart.png
139
+
140
+1. Contact the index to allocate the repository name “samalba/busybox” (authentication required with user credentials)
141
+2. If authentication works and namespace available, “samalba/busybox” is allocated and a temporary token is returned (namespace is marked as initialized in index)
142
+3. Push the image on the registry (along with the token)
143
+4. Registry A contacts the Index to verify the token (token must corresponds to the repository name)
144
+5. Index validates the token. Registry A starts reading the stream pushed by docker and store the repository (with its images)
145
+6. docker contacts the index to give checksums for upload images
146
+
147
+.. note::
148
+
149
+    **It’s possible not to use the Index at all!** In this case, a deployed version of the Registry is deployed to store and serve images. Those images are not authentified and the security is not guaranteed.
150
+
151
+.. note::
152
+
153
+    **Index can be replaced!** For a private Registry deployed, a custom Index can be used to serve and validate token according to different policies.
154
+
155
+Docker computes the checksums and submit them to the Index at the end of the push. When a repository name does not have checksums on the Index, it means that the push is in progress (since checksums are submitted at the end).
156
+
157
+API (pushing repos foo/bar):
158
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^
159
+
160
+1. (Docker -> Index) PUT /v1/repositories/foo/bar/
161
+    **Headers**:
162
+        Authorization: Basic sdkjfskdjfhsdkjfh==
163
+        X-Docker-Token: true
164
+
165
+    **Action**::
166
+        - in index, we allocated a new repository, and set to initialized
167
+
168
+    **Body**::
169
+        (The body contains the list of images that are going to be pushed, with empty checksums. The checksums will be set at the end of the push)::
170
+
171
+        [{“id”: “9e89cc6f0bc3c38722009fe6857087b486531f9a779a0c17e3ed29dae8f12c4f”}]
172
+
173
+2. (Index -> Docker) 200 Created
174
+    **Headers**:
175
+        - WWW-Authenticate: Token signature=123abc,repository=”foo/bar”,access=write
176
+        - X-Docker-Endpoints: registry.docker.io [, registry2.docker.io]
177
+
178
+3. (Docker -> Registry) PUT /v1/images/98765432_parent/json
179
+    **Headers**:
180
+        Authorization: Token signature=123abc,repository=”foo/bar”,access=write
181
+
182
+4. (Registry->Index) GET /v1/repositories/foo/bar/images
183
+    **Headers**:
184
+        Authorization: Token signature=123abc,repository=”foo/bar”,access=write
185
+    **Action**::
186
+        - Index: 
187
+            will invalidate the token.
188
+        - Registry: 
189
+            grants a session (if token is approved) and fetches the images id
190
+
191
+5. (Docker -> Registry) PUT /v1/images/98765432_parent/json
192
+    **Headers**::
193
+        - Authorization: Token signature=123abc,repository=”foo/bar”,access=write
194
+        - Cookie: (Cookie provided by the Registry)
195
+
196
+6. (Docker -> Registry) PUT /v1/images/98765432/json
197
+    **Headers**:
198
+        Cookie: (Cookie provided by the Registry)
199
+
200
+7. (Docker -> Registry) PUT /v1/images/98765432_parent/layer
201
+    **Headers**:
202
+        Cookie: (Cookie provided by the Registry)
203
+
204
+8. (Docker -> Registry) PUT /v1/images/98765432/layer
205
+    **Headers**:
206
+        X-Docker-Checksum: sha256:436745873465fdjkhdfjkgh
207
+
208
+9. (Docker -> Registry) PUT /v1/repositories/foo/bar/tags/latest
209
+    **Headers**:
210
+        Cookie: (Cookie provided by the Registry)
211
+    **Body**:
212
+        “98765432”
213
+
214
+10. (Docker -> Index) PUT /v1/repositories/foo/bar/images
215
+
216
+    **Headers**:
217
+        Authorization: Basic 123oislifjsldfj==
218
+        X-Docker-Endpoints: registry1.docker.io (no validation on this right now)
219
+
220
+    **Body**:
221
+        (The image, id’s, tags and checksums)
222
+
223
+        [{“id”: “9e89cc6f0bc3c38722009fe6857087b486531f9a779a0c17e3ed29dae8f12c4f”, 
224
+        “checksum”: “b486531f9a779a0c17e3ed29dae8f12c4f9e89cc6f0bc3c38722009fe6857087”}]
225
+
226
+    **Return** HTTP 204
227
+
228
+.. note::
229
+
230
+     If push fails and they need to start again, what happens in the index, there will already be a record for the namespace/name, but it will be initialized. Should we allow it, or mark as name already used? One edge case could be if someone pushes the same thing at the same time with two different shells.
231
+
232
+     If it's a retry on the Registry, Docker has a cookie (provided by the registry after token validation). So the Index won’t have to provide a new token.
233
+
234
+3. How to use the Registry in standalone mode
235
+=============================================
236
+
237
+The Index has two main purposes (along with its fancy social features):
238
+
239
+- Resolve short names (to avoid passing absolute URLs all the time)
240
+   - username/projectname -> https://registry.docker.io/users/<username>/repositories/<projectname>/
241
+   - team/projectname -> https://registry.docker.io/team/<team>/repositories/<projectname>/
242
+- Authenticate a user as a repos owner (for a central referenced repository)
243
+
244
+3.1 Without an Index
245
+--------------------
246
+Using the Registry without the Index can be useful to store the images on a private network without having to rely on an external entity controlled by dotCloud.
247
+
248
+In this case, the registry will be launched in a special mode (--standalone? --no-index?). In this mode, the only thing which changes is that Registry will never contact the Index to verify a token. It will be the Registry owner responsibility to authenticate the user who pushes (or even pulls) an image using any mechanism (HTTP auth, IP based, etc...).
249
+
250
+In this scenario, the Registry is responsible for the security in case of data corruption since the checksums are not delivered by a trusted entity.
251
+
252
+As hinted previously, a standalone registry can also be implemented by any HTTP server handling GET/PUT requests (or even only GET requests if no write access is necessary).
253
+
254
+3.2 With an Index
255
+-----------------
256
+
257
+The Index data needed by the Registry are simple:
258
+- Serve the checksums
259
+- Provide and authorize a Token
260
+
261
+In the scenario of a Registry running on a private network with the need of centralizing and authorizing, it’s easy to use a custom Index.
262
+
263
+The only challenge will be to tell Docker to contact (and trust) this custom Index. Docker will be configurable at some point to use a specific Index, it’ll be the private entity responsibility (basically the organization who uses Docker in a private environment) to maintain the Index and the Docker’s configuration among its consumers.
264
+
265
+4. The API
266
+==========
267
+
268
+The first version of the api is available here: https://github.com/jpetazzo/docker/blob/acd51ecea8f5d3c02b00a08176171c59442df8b3/docs/images-repositories-push-pull.md
269
+
270
+4.1 Images
271
+----------
272
+
273
+The format returned in the images is not defined here (for layer and json), basically because Registry stores exactly the same kind of information as Docker uses to manage them.
274
+
275
+The format of ancestry is a line-separated list of image ids, in age order. I.e. the image’s parent is on the last line, the parent of the parent on the next-to-last line, etc.; if the image has no parent, the file is empty.
276
+
277
+GET /v1/images/<image_id>/layer
278
+PUT /v1/images/<image_id>/layer
279
+GET /v1/images/<image_id>/json
280
+PUT /v1/images/<image_id>/json
281
+GET /v1/images/<image_id>/ancestry
282
+PUT /v1/images/<image_id>/ancestry
283
+
284
+4.2 Users
285
+---------
286
+
287
+4.2.1 Create a user (Index)
288
+^^^^^^^^^^^^^^^^^^^^^^^^^^^
289
+
290
+POST /v1/users
291
+
292
+**Body**:
293
+    {"email": "sam@dotcloud.com", "password": "toto42", "username": "foobar"'}
294
+
295
+**Validation**:
296
+    - **username** : min 4 character, max 30 characters, all lowercase no special characters. 
297
+    - **password**: min 5 characters
298
+
299
+**Valid**: return HTTP 200
300
+
301
+Errors: HTTP 400 (we should create error codes for possible errors)
302
+- invalid json
303
+- missing field
304
+- wrong format (username, password, email, etc)
305
+- forbidden name
306
+- name already exists
307
+
308
+.. note::
309
+
310
+    A user account will be valid only if the email has been validated (a validation link is sent to the email address).
311
+
312
+4.2.2 Update a user (Index)
313
+^^^^^^^^^^^^^^^^^^^^^^^^^^^
314
+
315
+PUT /v1/users/<username>
316
+
317
+**Body**:
318
+    {"password": "toto"}
319
+
320
+.. note::
321
+
322
+    We can also update email address, if they do, they will need to reverify their new email address.
323
+
324
+4.2.3 Login (Index)
325
+^^^^^^^^^^^^^^^^^^^
326
+Does nothing else but asking for a user authentication. Can be used to validate credentials. HTTP Basic Auth for now, maybe change in future.
327
+
328
+GET /v1/users
329
+
330
+**Return**:
331
+    - Valid: HTTP 200
332
+    - Invalid login: HTTP 401
333
+    - Account inactive: HTTP 403 Account is not Active
334
+
335
+4.3 Tags (Registry)
336
+-------------------
337
+
338
+The Registry does not know anything about users. Even though repositories are under usernames, it’s just a namespace for the registry. Allowing us to implement organizations or different namespaces per user later, without modifying the Registry’s API.
339
+
340
+4.3.1 Get all tags
341
+^^^^^^^^^^^^^^^^^^
342
+
343
+GET /v1/repositories/<namespace>/<repository_name>/tags
344
+
345
+**Return**: HTTP 200
346
+    {
347
+    "latest": "9e89cc6f0bc3c38722009fe6857087b486531f9a779a0c17e3ed29dae8f12c4f",
348
+    “0.1.1”:  “b486531f9a779a0c17e3ed29dae8f12c4f9e89cc6f0bc3c38722009fe6857087”
349
+    }
350
+
351
+4.3.2 Read the content of a tag (resolve the image id)
352
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
353
+
354
+GET /v1/repositories/<namespace>/<repo_name>/tags/<tag>
355
+
356
+**Return**:
357
+    "9e89cc6f0bc3c38722009fe6857087b486531f9a779a0c17e3ed29dae8f12c4f"
358
+
359
+4.3.3 Delete a tag (registry)
360
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
361
+
362
+DELETE /v1/repositories/<namespace>/<repo_name>/tags/<tag>
363
+
364
+4.4 Images (Index)
365
+------------------
366
+
367
+For the Index to “resolve” the repository name to a Registry location, it uses the X-Docker-Endpoints header. In other terms, this requests always add a “X-Docker-Endpoints” to indicate the location of the registry which hosts this repository.
368
+
369
+4.4.1 Get the images
370
+^^^^^^^^^^^^^^^^^^^^^
371
+
372
+GET /v1/repositories/<namespace>/<repo_name>/images
373
+
374
+**Return**: HTTP 200
375
+    [{“id”: “9e89cc6f0bc3c38722009fe6857087b486531f9a779a0c17e3ed29dae8f12c4f”, “checksum”: “md5:b486531f9a779a0c17e3ed29dae8f12c4f9e89cc6f0bc3c38722009fe6857087”}]
376
+
377
+
378
+4.4.2 Add/update the images
379
+^^^^^^^^^^^^^^^^^^^^^^^^^^^
380
+
381
+You always add images, you never remove them.
382
+
383
+PUT /v1/repositories/<namespace>/<repo_name>/images
384
+
385
+**Body**:
386
+    [ {“id”: “9e89cc6f0bc3c38722009fe6857087b486531f9a779a0c17e3ed29dae8f12c4f”, “checksum”: “sha256:b486531f9a779a0c17e3ed29dae8f12c4f9e89cc6f0bc3c38722009fe6857087”} ]
387
+    
388
+**Return** 204
389
+
390
+5. Chaining Registries
391
+======================
392
+
393
+It’s possible to chain Registries server for several reasons:
394
+- Load balancing
395
+- Delegate the next request to another server
396
+
397
+When a Registry is a reference for a repository, it should host the entire images chain in order to avoid breaking the chain during the download.
398
+
399
+The Index and Registry use this mechanism to redirect on one or the other.
400
+
401
+Example with an image download:
402
+On every request, a special header can be returned:
403
+
404
+X-Docker-Endpoints: server1,server2
405
+
406
+On the next request, the client will always pick a server from this list.
407
+
408
+6. Authentication & Authorization
409
+=================================
410
+
411
+6.1 On the Index
412
+-----------------
413
+
414
+The Index supports both “Basic” and “Token” challenges. Usually when there is a “401 Unauthorized”, the Index replies this::
415
+
416
+    401 Unauthorized
417
+    WWW-Authenticate: Basic realm="auth required",Token
418
+
419
+You have 3 options:
420
+
421
+1. Provide user credentials and ask for a token
422
+
423
+    **Header**:
424
+        - Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
425
+        - X-Docker-Token: true
426
+
427
+    In this case, along with the 200 response, you’ll get a new token (if user auth is ok):
428
+
429
+    **Response**:
430
+        - 200 OK
431
+        - X-Docker-Token: Token signature=123abc,repository=”foo/bar”,access=read
432
+
433
+2. Provide user credentials only
434
+
435
+    **Header**:
436
+        Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
437
+
438
+3. Provide Token
439
+
440
+    **Header**:
441
+        Authorization: Token signature=123abc,repository=”foo/bar”,access=read
442
+
443
+6.2 On the Registry
444
+-------------------
445
+
446
+The Registry only supports the Token challenge::
447
+
448
+    401 Unauthorized
449
+    WWW-Authenticate: Token
450
+
451
+The only way is to provide a token on “401 Unauthorized” responses::
452
+
453
+    Authorization: Token signature=123abc,repository=”foo/bar”,access=read
454
+
455
+Usually, the Registry provides a Cookie when a Token verification succeeded. Every time the Registry passes a Cookie, you have to pass it back the same cookie.::
456
+
457
+    200 OK
458
+    Set-Cookie: session="wD/J7LqL5ctqw8haL10vgfhrb2Q=?foo=UydiYXInCnAxCi4=&timestamp=RjEzNjYzMTQ5NDcuNDc0NjQzCi4="; Path=/; HttpOnly
459
+
460
+Next request::
461
+
462
+    GET /(...)
463
+    Cookie: session="wD/J7LqL5ctqw8haL10vgfhrb2Q=?foo=UydiYXInCnAxCi4=&timestamp=RjEzNjYzMTQ5NDcuNDc0NjQzCi4="
0 464
new file mode 100644
... ...
@@ -0,0 +1,15 @@
0
+:title: docker Registry documentation
1
+:description: Documentation for docker Registry and Registry API
2
+:keywords: docker, registry, api, index
3
+
4
+
5
+
6
+Registry
7
+========
8
+
9
+Contents:
10
+
11
+.. toctree::
12
+   :maxdepth: 2
13
+
14
+   api
0 15
new file mode 100644
1 16
Binary files /dev/null and b/docs/sources/static_files/docker_pull_chart.png differ
2 17
new file mode 100644
3 18
Binary files /dev/null and b/docs/sources/static_files/docker_push_chart.png differ