Skip to content

Prevent fallback to v1 registry for digest pulls#12881

Merged
tiborvass merged 1 commit intomoby:masterfrom
nakedible:patch-1
May 26, 2015
Merged

Prevent fallback to v1 registry for digest pulls#12881
tiborvass merged 1 commit intomoby:masterfrom
nakedible:patch-1

Conversation

@nakedible
Copy link
Contributor

Prevent fallback to v1 registry when pull is for a digest. The intention of the user is to download a verified image if explicitly pulling with a digest and falling back to v1 registry circumvents that protection.

Fixes #12879.

@nakedible
Copy link
Contributor Author

The change made here is the simplest one - there would be room for refactoring and improvement altogether, but that might better be done separately?

Also, should I write tests which fail if digest pulls ever fall back to v1 registry?

Copy link
Contributor

Choose a reason for hiding this comment

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

This may not be a strong enough guarantee. Its probably better to use digest.ParseDigest and catch the error or digest.DigestRegexp.Match. Arguably, utils.DigestReference should not exist. The most reliable way to tell if something is a reference is to test whether it came after the @.

@dmcgowan

Copy link
Member

Choose a reason for hiding this comment

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

While utils.DigestReference is a fragile function, it is strong enough in this case. It is only intended to test for digest given a reference (digest or tag). Reference should be made a stronger type with explicit digest or ref, but that is a different refactor which is not necessary to implement this fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I used utils.DigestReference because that exact function is used inside the v2 pull functions to check if loadManifest should attempt to verify that the manifest digest matches or not - the check should be identical. This should be safe as the tag has already been parsed, so the only way it can contain a colon is if it has been specified by the digest format.

I dislike mixing tags and digests in the tag argument to Pull, but fixing that is a bigger refactoring effort and I do not know enough Go.

Copy link
Contributor

Choose a reason for hiding this comment

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

@stevvooe @dmcgowan IIRC, docker/distribution wasn't vendored in when I originally wrote utils.DigestReference. +1 to removing it, now that we can call digest.ParseDigest.

Copy link
Contributor

Choose a reason for hiding this comment

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

@nakedible Discussed with @dmcgowan and we think this is okay for this PR.

@ncdc We'll clean this up in the future.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed, thanks.

@stevvooe
Copy link
Contributor

@nakedible This is looking good although I am a little worried about how we are detecting pull by digest. I commented above. This approach should work but we may want to make this more explicit. Its up to you if you'd like to explore fixing this up.

Also, should I write tests which fail if digest pulls ever fall back to v1 registry?

Yes, please do.

@dmcgowan
Copy link
Member

dmcgowan commented May 1, 2015

@nakedible if you are going to add a test, you can add one to the integration cli tests which attempts to pull a non-existent digest and checks the error output. Use a locally running v2 registry though, we are trying to avoid tests which rely on hitting the central repository.

@nakedible
Copy link
Contributor Author

Added a simple test case, which only checks that the correct error message is shown. Ideally the test case should set up a working v1 registry and ensure that no v1 uris are accessed, but this is probably good enough for now.

@nakedible nakedible force-pushed the patch-1 branch 2 times, most recently from 05a9e92 to 82986c5 Compare May 1, 2015 10:49
@nakedible
Copy link
Contributor Author

Rebased as single commit and cleaned up commit message.

@stevvooe
Copy link
Contributor

stevvooe commented May 2, 2015

LGMT.

@dmcgowan PTAL.

@dmcgowan
Copy link
Member

dmcgowan commented May 2, 2015

LGTM

@thaJeztah
Copy link
Member

Is this ready to merge?

@nakedible
Copy link
Contributor Author

I'm new here so I'm not sure of the process here (considering this is still labeled as needs design review), but this is ready to merge from my side. No documentation changes as not falling back to an insecure download for a digest pull is kinda obvious.

@dmcgowan
Copy link
Member

dmcgowan commented May 4, 2015

Just saw it was tagged as design review, updated. It is ready for merge after one more LGTM.

@nakedible-p
Copy link

Again, not sure of the policy for this sort of thing, but is it a possibility that this could get baked in to 1.6.1 or similar (once merged to master)? This is a security vulnerability, but it is a security vulnerability in a part that is explicitly marked as "do not trust this yet".

@thaJeztah
Copy link
Member

@nakedible-p not sure if there will be a 1.6.1 release, or directly 1.7.0

I'll include @ewindisch for the security part, and @jfrazelle to check if there are any plans to release a 1.6.1

@jlhawn
Copy link
Contributor

jlhawn commented May 5, 2015

LGTM

graph/pull.go Outdated
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Seems odd to tell users we're not falling back to v1. I don't think users care and it's confusing.

Choose a reason for hiding this comment

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

I agree in general, but this is surrounded by log messages such as:

logrus.Errorf("Error from V2 registry: %s", err)
logrus.Debug("image does not exist on v2 registry, falling back to v1")
logrus.Debugf("pulling v1 repository with local name %q", repoInfo.LocalName)

However, would this be a reasonable error message:

secure pull with digest reference failed

Or should I just remove everything after the comma in the original message?

Copy link
Contributor

Choose a reason for hiding this comment

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

@nakedible-p Just remove the post-comma content. No reason to hold this PR up on a minor nit.

@ewindisch
Copy link
Contributor

LGTM; left a nit on an error message.

@ewindisch
Copy link
Contributor

@nakedible-p I'd say that because fallback exists in the first place and because this isn't a baked feature, we will hold off until the next scheduled release. This is not severe enough to warrant tagging a new release.

@jessfraz
Copy link
Contributor

jessfraz commented May 7, 2015

@nakedible-p please update the error message then we can merge

@nakedible-p
Copy link

Added a comment about the error message 7 days ago, nothing has happened since.

@stevvooe
Copy link
Contributor

@nakedible-p Reiterating my LGTM. This can merge with or without the error message fix.

@nakedible-p
Copy link

@stevvooe Thanks.

I hope someone give feedback on the comment I made about the error message though - I'd love to fix it if I knew which would be the right direction. I'm also fine with merging without any changes.

@dmp42 dmp42 added this to the 1.7.0 milestone May 16, 2015
@nakedible-p
Copy link

Fixed error message, no other changes.

The intention of the user is to download a verified image if explicitly
pulling with a digest and falling back to v1 registry circumvents that
protection.

Signed-off-by: Nuutti Kotivuori <[email protected]>
@nakedible-p
Copy link

@jfrazelle Not sure if I need to ping you separately...

@tiborvass tiborvass self-assigned this May 22, 2015
@tiborvass
Copy link
Contributor

LGTM

tiborvass added a commit that referenced this pull request May 26, 2015
Prevent fallback to v1 registry for digest pulls
@tiborvass tiborvass merged commit 54b5147 into moby:master May 26, 2015
@tiborvass tiborvass removed their assignment Nov 3, 2015
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.

Pull with digest revision falls back to v1 registry