Skip to content

Content trust for swarm services#29156

Merged
tiborvass merged 3 commits intomoby:masterfrom
aaronlehmann:trusted-service-create
Dec 15, 2016
Merged

Content trust for swarm services#29156
tiborvass merged 3 commits intomoby:masterfrom
aaronlehmann:trusted-service-create

Conversation

@aaronlehmann
Copy link

@aaronlehmann aaronlehmann commented Dec 6, 2016

  • Refactor cli trust code to split generally useful functions and variables out of cli/command/image.
  • Implement digest pinning using notary for "service create" and "service update".

cc @nishanttotla @diogomonica @cyli @endophage

@aaronlehmann aaronlehmann force-pushed the trusted-service-create branch 4 times, most recently from fe3cc04 to 0e22fe8 Compare December 6, 2016 01:29
Copy link
Contributor

@cyli cyli Dec 6, 2016

Choose a reason for hiding this comment

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

Non-blocking: It looks likeWithDefaultTag checks IsNameOnly before adding the default tag, so possibly this extra reference.IsNameOnly(ref) check is not necessary? (Update: apologies I forgot to delete the first half of this comment - I originally thought this was in distribution's code)

Copy link
Author

Choose a reason for hiding this comment

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

Fixed

Copy link
Contributor

@cyli cyli Dec 6, 2016

Choose a reason for hiding this comment

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

Should service create fail if the image fails to resolve the reference against DCT (similarly to docker run?)

Copy link
Author

Choose a reason for hiding this comment

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

Hmm. That's a tough one. I can see the security argument for doing it, since otherwise a denial of service can cause a downgrade to non-trusted resolution (by making it happen on the daemon). However, there are valid use cases that involve specifying images that have never been pushed to a registry, and the client won't be able to know if the images already exist on the worker nodes.

Should we require content trust to be turned off to support local image use cases?

Copy link
Contributor

Choose a reason for hiding this comment

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

That's true - and it's not a great experience on non-swarm docker atm, where you can't run images that are are built but not pushed. I lean towards requiring content trust to be turned off, just because it seems like it'd be easier to go from tighter security down, and also because it'd be consistent with docker run behavior, and we probably need to work out a better model for the local image case anyway.

Out of curiosity, docker build happens on a single worker node at a time, right? Does scheduling take into account which nodes have the image locally, or replicate the local images if the service needs to scale?

Copy link
Author

Choose a reason for hiding this comment

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

Out of curiosity, docker build happens on a single worker node at a time, right? Does scheduling take into account which nodes have the image locally, or replicate the local images if the service needs to scale?

No, none of this is automatic. Typically a scenario using an image that's not pushed to a registry would be a single node swarm, or a few nodes where the image was manually copied in advance.

Copy link
Author

Choose a reason for hiding this comment

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

Changed to fail the "service create" or "service update" command if digest resolution fails when using content trust.

@aaronlehmann
Copy link
Author

Added integration tests. PTAL.

@aaronlehmann aaronlehmann changed the title [WIP] Content trust for swarm services Content trust for swarm services Dec 6, 2016
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we leave this as it is? Maybe it is worthwhile to have a log message specifying which digest the service was pinned to upon creation, even if the client provided a digest to begin with.

Copy link
Author

Choose a reason for hiding this comment

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

I noticed this message while testing and found it quite strange and misleading. It's of the form:

pinning image busybox:latest@sha256:29f5d56d12684887bdfa50dcd29fc31eea4aaf4ad3bec43daf19026a7ce69912 by digest: busybox:latest@sha256:29f5d56d12684887bdfa50dcd29fc31eea4aaf4ad3bec43daf19026a7ce69912

I think it would be okay to have a debug log message noting that pinning by digest is being skipped because the image reference already has a digest. But saying that we're doing digest pinning when we're actually not touching the image reference is misleading.

"service update" already skips this log message when there is no change to the reference. I thought it was an oversight that "service create" logs it anyway.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see your point. I had deliberately kept the log message on create but didn't consider how it can look misleading.

Perhaps it's reasonable to add a separate message when no pinning happens, such as creating service with image digest busybox:latest@sha256:29f5d56d12684887bdfa50dcd29fc31eea4aaf4ad3bec43daf19026a7ce69912, and leave the existing message for the default case.

Either way, I don't feel too strongly about it.

Copy link
Author

Choose a reason for hiding this comment

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

Perhaps it's reasonable to add a separate message when no pinning happens

Added a debug log message in this case for create and update.

Copy link
Author

Choose a reason for hiding this comment

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

... but it's not showing up because GitHub is broken

remote: Unexpected system error after push was received.
remote: These changes may not be reflected on github.com!
remote: Your unique error code: ...

Copy link
Author

Choose a reason for hiding this comment

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

Resolved the GitHub issue by force-pushing.

Copy link
Contributor

Choose a reason for hiding this comment

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

Non-blocking question regarding this comment: by image ID do you mean image name? If not, what is the syntax for passing the ID?

Copy link
Author

Choose a reason for hiding this comment

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

It's what you see under Id in docker inspect. An example is:

sha256:a95d886ecdf2cda6a61eef160ca61be49c56d005c7b5fec048706e4a12e53eb7

In other words, if the digest package validates it as a digest, we treat it as a content-addressable image ID. Since neither notary nor registry can fetch images by their ID, this avoids talking to notary/registry to query it. Images referenced in this way will only work if the image already exists locally.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah ok, so not the truncated hex displayed by docker images. I had interpreted "digest reference" to mean something like sha256:a95d886ecdf2cda6a61eef160ca61be49c56d005c7b5fec048706e4a12e53eb7, so I though image ID was something else.

Does "digest reference" instead mean distribution/reference.Named, which can have a digest?

Copy link
Author

Choose a reason for hiding this comment

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

Does "digest reference" instead mean distribution/reference.Named, which can have a digest?

Correct. An example is busybox@sha256:29f5d56d12684887bdfa50dcd29fc31eea4aaf4ad3bec43daf19026a7ce69912

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the explanation!

@cyli
Copy link
Contributor

cyli commented Dec 6, 2016

LGTM! Thanks for the very quick turnaround on this!

@aaronlehmann aaronlehmann force-pushed the trusted-service-create branch from b86f543 to 0182c9a Compare December 6, 2016 23:54
@tonistiigi
Copy link
Member

LGTM

2 similar comments
@diogomonica
Copy link
Contributor

LGTM

@nishanttotla
Copy link
Contributor

LGTM

@nishanttotla
Copy link
Contributor

nishanttotla commented Dec 7, 2016

Btw, we should document this behavior as well, since it's slightly different from when content trust is not being used. Without content trust, service create/update will not fail even if digest resolution doesn't work, only a warning will be returned. With content trust, it'll fail.

cc @mstanleyjones @thaJeztah

@diogomonica
Copy link
Contributor

@aluzzardi @vieux can you put this on the 1.13 milestone? It's fixing a bug where service create/update doesn't respect DCT if enabled.

@aaronlehmann aaronlehmann force-pushed the trusted-service-create branch from 0182c9a to 39e70a1 Compare December 8, 2016 18:19
@aaronlehmann
Copy link
Author

Rebased

@diogomonica
Copy link
Contributor

@thaJeztah can we move forward with merging this bug-fix?

@aaronlehmann aaronlehmann force-pushed the trusted-service-create branch 2 times, most recently from c9ceb91 to a9ee110 Compare December 13, 2016 02:14
@aaronlehmann
Copy link
Author

Rebased again.

Can this PR be considered for the 1.13 milestone as suggested above?

Also, review ping. 4 LGTMs, but only one comes from an actual maintainer :(. Not sure who else should review this. @tiborvass @LK4D4 @vdemeester ?

Aaron Lehmann added 3 commits December 14, 2016 10:49
Split these into cli/trust so that other commands can make use of them.

Signed-off-by: Aaron Lehmann <[email protected]>
Implement notary-based digest lookup in the client when
DOCKER_CONTENT_TRUST=1.

Signed-off-by: Aaron Lehmann <[email protected]>
@aaronlehmann aaronlehmann force-pushed the trusted-service-create branch from a9ee110 to 62cd3b3 Compare December 14, 2016 18:50
@aaronlehmann
Copy link
Author

Rebased

@tiborvass
Copy link
Contributor

LGTM

@tiborvass tiborvass merged commit ba368ba into moby:master Dec 15, 2016
@GordonTheTurtle GordonTheTurtle added this to the 1.14.0 milestone Dec 15, 2016
@tiborvass
Copy link
Contributor

FYI @vieux @thaJeztah

@aaronlehmann aaronlehmann deleted the trusted-service-create branch December 15, 2016 00:43
@thaJeztah
Copy link
Member

@tiborvass 1.13 milestone?

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants