dotcloud/docker-registry — pull request #266 by wking (2014-03-01 18:39:33+00:00)
Title: index: Whitelist 'id' and 'checksum' keys for image data

The image data behind the "repository images" endpoints is documented as only
having these two keys [1], but on my existing docker-registry instance, I see
additional keys:

# cat /var/lib/docker-registry/repositories/wking/gentoo/_index_images | jq
.
[
{
"id": "9917ba282bd23e78d1caa25aac74fb9d5d305aee10db0ef84f3230ef7fc93c59",
"Tag": "latest"
}
]

Instead of storing any image-specific data that the user sends up, this commit
restricts the set of allowed keys. This avoids interfering with the
Server.pullRepository code in the Docker source, which uses the presence of
img.Tag to decide whether or not to download the image [2]. It also avoids
trouble with the Docker server trying to store auxiliary tags in the
hard-coded ImgData struct [3]. The drawback to this extra protection against
over-eager clients pushing undocumented keys is that we'll have to update the
whitelist if new keys are added to ImgData. This commit also doesn't cull
undocumented keys from existing image index files. Folks with existing
registries can use jq [4] to remove them by hand. In POSIX shell:

JQ='[.[] | {"id": .id, "checksum": .checksum}] | del(.[][] | select(. ==
null))'
for FILE in $(find /var/lib/docker-registry/repositories/ -name
_index_images)
do
FILTERED=$(jq "${JQ}" < "${FILE}")
echo "${FILTERED}" > "${FILE}"
done

[1]:
http://docs.docker.io/en/latest/reference/api/index_api/#repository-images
PUT /v1/repositories/(namespace)/(repo_name)/images
GET /v1/repositories/(namespace)/(repo_name)/images
PUT /v1/repositories/(repo_name)/images
GET /v1/repositories/(repo_name)/images
[2]: https://github.com/dotcloud/docker/blob/v0.8.1/server.go#L1179
[3]: https://github.com/dotcloud/docker/blob/v0.8.1/registry/registry.go#L673
[4]: http://stedolan.github.io/jq/