Skip to content

Add a 'docker fingerprint' command for signing images - #6070

Closed
wking wants to merge 10 commits into
moby:masterfrom
wking:2700-fingerprint
Closed

wking wants to merge 10 commits into
moby:masterfrom
wking:2700-fingerprint

Conversation

@wking

@wking wking commented May 28, 2014

Copy link
Copy Markdown

The "should we do this" discussion starts in #2700 [1](where it still
hasn't reached a consensus). The goal here is to implement:

 $ docker fingerprint <namespace>/<name>[:<tag>]
 <namespace>/<name>:<tag>
 <metadata>
 <own tarsums> 

The tarsum should be the tarsum of the assembled image (squashing all
layers), not the tarsum of the tip layer.

The current implementation is a work in progress. I'm still not clear
on how the whole server/job API is supposed to get wired together, and
have been basically pattern-matching off 'git grep -i history'. I'm
posting the WIP branch because I won't have time to work on it for the
next few days, and wanted to open it up in case anyone else wanted to
chip in.

#2700 (comment)

@cyphar

cyphar commented May 28, 2014

Copy link
Copy Markdown
Contributor

Do we need to ensure that the entire "stack" of layers has the same hash, or just the topmost? Since only the topmost is ever run (and the final filesystem image is technically independent of the previous images), is it necessary to hash all of the parent images? (I would personally prefer to hash everything, just playing devil's advocate). If we do need to, we could potentially hash together each of the filesystem hashes. Otherwise, we can just get the md5sum of the topmost filesystem layer. My only question is whether the dependent layers need to be verified, since the topmost layer contains all of the dependencies.

@wking

wking commented May 28, 2014

Copy link
Copy Markdown
Author

On Tue, May 27, 2014 at 09:28:23PM -0700, Aleksa Sarai wrote:

Do we need to ensure that the entire "stack" of layers has the same
hash, or just the topmost?

I want hashes of every file in the assembled (squashed) filesystem.

Since only the topmost is ever run (and the final filesystem image
is technically independent of the previous images),

I don't think this is true. For example, in several of my tagged
images, the last layer is an empty layer touching some metadata
(e.g. from an EXPOSE call). I don't care about signing the history,
so I don't need to take the “deterministic image ID route”, but I do
care about the entire assembled image (including files added by layers
before the final EXPOSE). I don't care about how those files are
distributed among layers, or how those layers are compressed, etc.
Besides the file contents, I also care about ownership, permissions,
and other metadata. Since the signing program (e.g. gpg) already
handles hashing the input data, I see no reason to pre-hash the
filesystem data. Unfortunately, encoding all of the file metadata
(uid, mode, devmajor, atime, …) would basically involve re-inventing
the tar file format in text. In order to avoid that, I'm happy to
hash the layer tarballs themselves:

/:
<metadata (as dumped by 'docker inspect')>
<name of tarball hash (e.g. sha1)>


…

So the file section would look something like:

sha1
106129d53f5a10cfe681b6879eea91a031e52e0a 64a9aa8a64c688e103c235c8e8cf6ac6d178658bb49cd0ee32a3600dfa5c8470
2663fdea02ada5fc267bcf060617ddf58a29595f d7cbc965ae6a6fc75668197f01cf6369bdfe6fae364004f4c1a4ea27d704dfef
f2acf0ebde752b5b7643155819694a610fb7c28c 5e36dce9af247f8ec656fc024f77b9055cc0c4cd2cf54d4037ef321cf554682f
…

with images in the same order as they stand in the 'docker history'
output. This assumes that the layer tarballs are conserved (e.g. not
regenerated with different timestamps or compression algorithms).
I think that's accurate, but I don't completely understand the
Image.TarLayer code.

@vbatts

vbatts commented Jun 21, 2014

Copy link
Copy Markdown
Contributor

I would hope that we get deterministic image IDs, so then we could tarsum/fingerprint each layer. Then assuming you've validated each layer, you could not arrive at the ID of the next layer without sum checking out.

@vbatts

vbatts commented Jun 21, 2014

Copy link
Copy Markdown
Contributor

Also, I'm glad to see you working on this, and I hope to review this soon.

@SvenDowideit

Copy link
Copy Markdown
Contributor

Docs LGTM - though I presume they may change during the implementation discussions

@vbatts

vbatts commented Jul 1, 2014

Copy link
Copy Markdown
Contributor

@wking Can you rebase on master and fix the code so it compiles?

TarSum of a layer is a presently a fixed-time checksum of that filesystem + the json metadata, and does account for uid, gid, etc. Since the current image-id (layer + json) is not a deterministic id, but a random 32byte hex value, it only provides so_much assurance that the referenced parent image-id is the exact parent (pretty-good, but not content-addressable-good). In the meantime, calculating a squashed checksum for an image, is effectively the same as a set of tarsums, of that image and all of its ancestors. It would be just as expensive, unless the actual image is being flattened to have no parent layers.

Also, since the current /: is somewhat arbitrary, and could point to a new image-id momentarily, and the Metadata (json) is already accounted for in the TarSum, the mostly critical pieces of what is being signed is an image-id and its corresponding TarSum. Then when you load or pull an image, and even if you must re-tag it for a local-registry, then the image would still validate. Make sense?

@shykes I realize this is thick in the identity trust model, but thoughts on this?

@vbatts vbatts added the Trust label Jul 1, 2014
Comment thread api/server/server.go

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe be more explicit about the parameter you're expecting.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Wed, Jul 02, 2014 at 11:10:23AM -0700, Johan Euphrosine wrote:

@@ -251,6 +251,20 @@ func getEvents(eng *engine.Engine, version version.Version, w http.ResponseWrite
return job.Run()
}

+func getImagesFingerprint(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {

  • if vars == nil {
  •   return fmt.Errorf("Missing parameter")
    

maybe be more explicit about the parameter you're expecting.

That's just copy-pasted from getImagesHistory. I'm fine changing it
(it seems like we only use vars["name"]), but I think consistency in
the Docker source is also important.

wking added 10 commits July 9, 2014 13:30
Docker-DCO-1.1-Signed-off-by: W. Trevor King <[email protected]> (github: wking)
Modeled on getImagesHistory.

Docker-DCO-1.1-Signed-off-by: W. Trevor King <[email protected]> (github: wking)
Docker-DCO-1.1-Signed-off-by: W. Trevor King <[email protected]> (github: wking)
This needs a better output example and a way to specify tags.

Docker-DCO-1.1-Signed-off-by: W. Trevor King <[email protected]> (github: wking)
Just pass the server-side response through unchanged.  We want the
output to match the user's locale, but also have an option to spit out
canonical UTF-8 for consistent signatures.  Unfortunately, I don't
know how to do any of that in Go yet :p.

Docker-DCO-1.1-Signed-off-by: W. Trevor King <[email protected]> (github: wking)
Docker-DCO-1.1-Signed-off-by: W. Trevor King <[email protected]> (github: wking)
Docker-DCO-1.1-Signed-off-by: W. Trevor King <[email protected]> (github: wking)
Docker-DCO-1.1-Signed-off-by: W. Trevor King <[email protected]> (github: wking)
Docker-DCO-1.1-Signed-off-by: W. Trevor King <[email protected]> (github: wking)
Docker-DCO-1.1-Signed-off-by: W. Trevor King <[email protected]> (github: wking)
@wking

wking commented Jul 9, 2014

Copy link
Copy Markdown
Author

On Tue, Jul 01, 2014 at 11:54:27AM -0700, Vincent Batts wrote:

Can you rebase on master and fix the code so it compiles?

Rebased. Sorry about the delay :p. I think getting it to compile may
require further tweaks, but the whole “building in a container”
business makes it harder for me to test this ;). I'll try and figure
out the appropriate invocation to build against my system libraries.

TarSum of a layer is a presently a fixed-time checksum of that
filesystem + the json metadata, and does account for uid, gid,
etc. Since the current image-id (layer + json) is not a
deterministic id, but a random 32byte hex value, it only provides
so_much assurance that the referenced parent image-id is the exact
parent (pretty-good, but not content-addressable-good).

But I don't think users really care about validating the history. In
lots of situations (e.g. builds based off remote images), it's also
hard for the signer to ensure that the history is accurate. What they
can ensure is that the squashed filesystem is what they built. Users
who are interested in verifying the history can find and validate
history-agnostic signatures for each image in the chain.

In the meantime, calculating a squashed checksum for an image, is
effectively the same as a set of tarsums, of that image and all of
its ancestors. It would be just as expensive, unless the actual
image is being flattened to have no parent layers.

It would be cheaper, because you no longer have to calculate tarsums
for ancestor files that have been modified/removed in the final image.
It's only cheaper if you trust the image ids sufficiently to only have
to sign the final filesystem layer (and can skip stuff inherited from
previous layers).

Also, since the current /: is somewhat
arbitrary, and could point to a new image-id momentarily, and the
Metadata (json) is already accounted for in the TarSum, the mostly
critical pieces of what is being signed is an image-id and its
corresponding TarSum. Then when you load or pull an image, and even
if you must re-tag it for a local-registry, then the image would
still validate. Make sense?

I don't want it to validate if it's been re-tagged. For example, if
I tag some nefarious image as 'ubuntu', but I have a valid signature
on my nefarious image, I don't want that validating. The point of the
signature is to say “this (mostly) unforgable content fingerprint
belongs to this tag”.

Of course, I'm not a big fan of forced renames when pushing to
alternative registries, because it makes mirroring hard. However, you
can get around this by pulling from your local registry, retagging to
the original name, and then checking the signature.

@wking

wking commented Jul 9, 2014

Copy link
Copy Markdown
Author

On Sun, Jun 29, 2014 at 09:52:38PM -0700, Sven Dowideit wrote:

Docs LGTM - though I presume they may change during the
implementation discussions

Definitely, although so far there hasn't been all that much discussion
;). The more consensus we can build up-front about what this should
look like, the more efficiently we can write the implementation. It's
certainly easier for me to talk about what this should look like than
it is for me to stumble through the Go ;).

@tiborvass

Copy link
Copy Markdown
Contributor

@dmcgowan @jlhawn can you comment on the design of this?

@dmcgowan

Copy link
Copy Markdown
Member

The implementation for #8093 should cover what this PR is trying to accomplish. The implementation we are working on is farther reaching as it effects the image format and the registry, but it achieves image verification through cryptographic hashes along with chain of trust.

@wking

wking commented Sep 26, 2014

Copy link
Copy Markdown
Author

On Wed, Sep 24, 2014 at 09:19:53AM -0700, Derek McGowan wrote:

The implementation we are working on is farther reaching as it
effects the image format and the registry, but it achieves image
verification through cryptographic hashes along with chain of trust.

This proposal also provides image verification and tag association
through crypographic hashes and webs of trust, it's just that the
hashing and trust distribution is offloaded to whichever tool the
signer and verified choose to use. I already trust GnuPG (and have a
web of other OpenPGP I trust), but maybe you prefer OpenSSL? Docker
shouldn't care. Some registry-side support for distributing opaque
signatures would be nice, but isn't required. Other than that the
fingerprint command outlined here and optional registry endpoints for
distributing signatures, I don't think Docker needs to get involved in
the image-signing business at all. I can use the external
cryptography infrastructure I trust, and Docker gets to be less
complicated. Wins all around.

@crosbymichael

Copy link
Copy Markdown
Contributor

This functionality is being addressed in #8093 and the initial work has already been starting with the first features being included in docker 1.3.

Sorry for the late response and please submit feedback on #8093

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants