Skip to content

Add a foreign layer URL host whitelist - #1829

Merged
RichardScothern merged 1 commit into
distribution:masterfrom
nwt:foreign-layer-host-whitelist
Jul 21, 2016
Merged

RichardScothern merged 1 commit into
distribution:masterfrom
nwt:foreign-layer-host-whitelist

Conversation

@nwt

@nwt nwt commented Jul 11, 2016

Copy link
Copy Markdown
Contributor

Until we have some experience hosting foreign layer manifests, the Hub
operators wish to limit foreign layers on Hub to those hosted by
Microsoft. To that end, this change adds a registry configuration option
to whitelist hosts that may appear in foreign layer URLs of pushed
manifests, and it modifies manifest validation to reject pushes
containing foreign layer URLs whose host is not whitelisted.

Signed-off-by: Noah Treuhaft [email protected]

@codecov-io

codecov-io commented Jul 11, 2016 •

Copy link
Copy Markdown

Current coverage is 52.47%

Merging #1829 into master will decrease coverage by 6.95%

@@             master      #1829   diff @@
==========================================
  Files           120        120          
  Lines         10506      10499     -7   
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
- Hits           6243       5509   -734   
- Misses         3429       4249   +820   
+ Partials        834        741    -93   

Sunburst

Powered by Codecov. Last updated by 7b59587...61e5803

@dmp42

dmp42 commented Jul 11, 2016

Copy link
Copy Markdown
Contributor

cc @runcom @docker/core-distribution-maintainers

and related to #1825

@runcom

runcom commented Jul 11, 2016 •

Copy link
Copy Markdown
Contributor

seems inline with #1825 so 👍 (haven't done code-review yet)

Comment thread docs/configuration.md Outdated
foreignlayer:
hostwhitelist: [EXAMPLE.COM, .example.net]

Set `hostwhitelist` to an empty list (`[]`) to reject all foreign-layer

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

could you just add an enabled: <bool> under the foreignlayer section instead? (more explicit and easier for testing)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Certainly. And in that case, panicking on an empty whitelist seems appropriate.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Let's use the term allowed.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Or better yet:

foreignlayer:
  hosts:
    allow:
      - www.foo.com
      - example.com

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Happy to follow either this proposal or @RichardScothern's proposal of whitelist.

@stevvooe

Copy link
Copy Markdown
Collaborator

This feature shouldn't be called "Foreign Layers". The concept of a foreign layer is reserved to the docker engine, as the layer is foreign to docker. The registry doesn't care. This just influences the valid urls that a registry will accept in the manifest.

@runcom

runcom commented Jul 12, 2016 •

Copy link
Copy Markdown
Contributor

Can we take care of enabling/disabling the whole foreign layer story/feature as part of this PR? Related to point 3) in #1825

Is it feasible in this PR? seems likely to me, just an enabled flag under foreignLayers: opt (or whatever it'll be called)
If not, I'll take care of it as a follow up (but I don't see issues in doing this here)

Quoting poing 3) from #1825:

  1. provide a way to opt-in for such a feature at the registry level
    Since there may be the need to defer this support on some deployment, we can have an explicit setting which opt-in for this new behavior.

@dmp42 @stevvooe wdyt?

Comment thread registry/storage/registry.go Outdated

// ForeignLayerHostWhitelist tests whether the host is allowed in foreign layer URLs.
func (reg *registry) ForeignLayerHostAllowed(host string) bool {
if reg.foreignLayerHostWhitelist == nil {

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.

the knob I'm talking about can cleanly take care of this check also - instead of checking for the presence of a whitelist, we can check if foreign layers are enabled at all and exit early here

@nwt

nwt commented Jul 12, 2016

Copy link
Copy Markdown
Contributor Author

This feature shouldn't be called "Foreign Layers".

I'm happy follow maintainer guidance on an appropriate name. I don't think I have enough perspective to propose an alternative. Except for "Not Foreign Layers". 💥

@nwt

nwt commented Jul 12, 2016

Copy link
Copy Markdown
Contributor Author

Is it feasible in this PR? seems likely to me, just an enabled flag under foreignLayers: opt (or whatever it'll be called)

@RichardScothern proposed the same and I'm planning to implement it.

@runcom

runcom commented Jul 12, 2016

Copy link
Copy Markdown
Contributor

Is it feasible in this PR? seems likely to me, just an enabled flag under foreignLayers: opt (or whatever it'll be called)
@RichardScothern proposed the same and I'm planning to implement it.

ty

@stevvooe

Copy link
Copy Markdown
Collaborator

@nwt This is validating manifest urls:

validation:
  disabled: false
  manifests:
    urls:
      allowed:
        - https://foo.com

A few things:

  1. This is configuring how we validate incoming manifests. While this is on storage configuration, let's consider pulling the validation above storage.
  2. We should also think about prevention of serving manifests with disallowed urls. For example, if it doesn't pass url validation, should we serve it at all? This is important since we don't block these at all now.
  3. We should be validating URLs, not hosts and domains.

@nwt

nwt commented Jul 15, 2016

Copy link
Copy Markdown
Contributor Author

@stevvooe: I implemented this:

validation:
  manifests:
    urls:
      disabled: false
      allowed: regexp

I changed allowed to a regular expression because Hub needs more control than a list of strings can provide, and I moved disabled under urls since that's the only validation it influences.

@runcom

runcom commented Jul 15, 2016

Copy link
Copy Markdown
Contributor

I meant to have disabled (or enabled) as a way to fully opt-out this features. It seems what you did doesn't cleanly achieve that, does it?

@nwt

nwt commented Jul 15, 2016

Copy link
Copy Markdown
Contributor Author

@runcom: All pushes of foreign layer manifests will be rejected with this in your config:

validation:
  manifests:
    urls:
      disabled: true

Were you asking for something different?

@runcom

runcom commented Jul 15, 2016

Copy link
Copy Markdown
Contributor

That's somehow fine ti me, i was hoping for such a flag to be more global but if it still accomplishes fully opt-out than I'll leave those decisions to others about where that disable flag should be.

Comment thread configuration/configuration.go Outdated
Validation struct {
Manifests struct {
URLs struct {
Allowed *string `yaml:"allowed,omitempty"`

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why not a list?

@runcom

runcom commented Jul 16, 2016

Copy link
Copy Markdown
Contributor

@stevvooe +1

@nwt

nwt commented Jul 18, 2016

Copy link
Copy Markdown
Contributor Author

@stevvooe: 153c2f2 should be closer to what you had in mind than 2e37629 was, with enabled immediately below validation, deny as well as allow, and lists for both.

Comment thread docs/configuration.md Outdated
disabled: false
manifests:
urls:
allow: ^https?://([^/]+\.)*example\.com/

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think these examples need to be a list.

@stevvooe

Copy link
Copy Markdown
Collaborator

LGTM

There are a few nits about getting the defaults backwards compatible.

Great addition, @nwt!

Until we have some experience hosting foreign layer manifests, the Hub
operators wish to limit foreign layers on Hub. To that end, this change
adds registry configuration options to restrict the URLs that may appear
in pushed manifests.

Signed-off-by: Noah Treuhaft <[email protected]>
@nwt

nwt commented Jul 19, 2016 •

Copy link
Copy Markdown
Contributor Author

@stevvooe: 61e5803 addresses comments on 153c2f2.

  1. Documentation examples properly show allow and deny as lists.
  2. Configuration.Validation.Enabled replaces ….Disabled.
  3. If allow and deny are empty, all manifests with URLs are rejected.

I'm not thrilled with how I handled for that last one, both becausedeny is no longer useful without allow and because storage.ManifestURLsAllowRegexp(regexp.MustCompile("^$")) in app.go is a bit magical, so let me know if you think either of those edges needs filing.

@stevvooe

Copy link
Copy Markdown
Collaborator

@nwt

I'm not thrilled with how I handled for that last one, both becausedeny is no longer useful without allow and because storage.ManifestURLsAllowRegexp(regexp.MustCompile("^$")) in app.go is a bit magical, so let me know if you think either of those edges needs filing.

Will it still allow manifests without urls? That is somewhat the purpose. For example, if one configures the following:

validation:
  enabled: true

All manifests with urls would be blocked, while others would be allowed.

Let's say we unrolled these into an ordered set of operations. By default, with all empy allow and deny, it would look like this:

DENY ALL

This would give us default closed operation when the URL is empty.

We insert all allows before denies:

ALLOW foo.com
DENY ALL

ALLOW always has precedent:

ALLOW foo.com
DENY foo.com
DENY ALL

These are matched such that if the rule matches, we return the operation. For foo.com, we'd match an ALLOW rule first and the URL would be allowed.

This only becomes problematic when we have a more specific deny than an allow:

ALLOW .*
DENY foo.com
DENY ALL

So, even though we deny foo.com, allow has precedent and is match before the deny. We can fix this by ordering DENY before allow, but we get the same issue, except we have allow that is more specific than a deny:

DENY .*
ALLOW foo.com
DENY ALL

Typically, this issue is dealt with using priorities, but that is overbuilt for this purpose. It is probably better to favor ALLOW for this purpose but arguments can go either way.

TL; DR Having ^$ as a "magic" deny entry is an okay bit of magic. That defines the default operation on the match chain.

@nwt

nwt commented Jul 19, 2016

Copy link
Copy Markdown
Contributor Author

@stevvooe:

Will it still allow manifests without urls?

Yes, manifests without URLs are always allowed regardless of what appears under validation.

@nwt nwt closed this Jul 21, 2016
@nwt
nwt deleted the foreign-layer-host-whitelist branch July 21, 2016 19:51
@nwt
nwt restored the foreign-layer-host-whitelist branch July 21, 2016 19:53
@nwt nwt reopened this Jul 21, 2016
@RichardScothern

Copy link
Copy Markdown

LGTM

2 similar comments
@stevvooe

Copy link
Copy Markdown
Collaborator

LGTM

@dmcgowan

Copy link
Copy Markdown
Collaborator

LGTM

@RichardScothern

Copy link
Copy Markdown

Holding off on merging while we discuss a missing API test..

@RichardScothern

Copy link
Copy Markdown

Fixes a pre-existing condition and coming in a PR.

@RichardScothern
RichardScothern merged commit 2b72dd3 into distribution:master Jul 21, 2016
@nwt
nwt deleted the foreign-layer-host-whitelist branch July 21, 2016 23:10
@RichardScothern RichardScothern added this to the Registry/2.6 milestone Jul 28, 2016
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.

9 participants