Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

catalog: correctly program shorthand service FQDN #1935

Merged
merged 1 commit into from
Oct 28, 2020

Conversation

shashankram
Copy link
Member

@shashankram shashankram commented Oct 27, 2020

Description:
Currently, while programming the service FQDNs for an
upstream service in the downstream envoy's virtual_host config
the shorthand service FQDN using the service name without the namespace
is always programmed. This is incorrect because the same service (name)
could exist in multiple namespaces. The service FQDN without the
namespace should only be programmed on downstream clients that are
in the same namespace. If the downstream client is in a different namespace,
then shorthand FQDNs without the namespace for the upstream service
should not be programmed.

Consider the following example:
Imagine the following 3 services of the form namespace/service:
foo/bookbuyer, foo/bookstore, bar/bookstore
bookbuyer is allowed to reach the bookstore service in both namespaces foo and bar.

Previously:

  • the virtual_host config on bookbuyer to reach foo/bookstore
    would be bookstore, bookstore.foo, bookstore.foo.svc.cluster.local ....
  • the virtual_host config on bookbuyer to reach bar/bookstore
    would be bookstore, bookstore.bar, bookstore.bar.svc.cluster.local ....

The above config would result in an error because the same hostname bookstore
is programmed for 2 different destinations in the outbound route.

With this change, the bookstore hostname will only be programmed for the
foo/bookstore destination because foo/bookbuyer is in the same namespace,
and is allowed to use shorthand FQDN to make a request of the form http://bookstore/,
without resulting in invalid virtual_host configurations on bookbuyer envoy.

This change addresses this bug and adds tests for the same. It also
removes a duplicated test copied into an unrelated package.

Resolves #951

Affected area:

  • New Functionality [ ]
  • Documentation [ ]
  • Install [ ]
  • Control Plane [X]
  • CLI Tool [ ]
  • Certificate Management [ ]
  • Networking [X]
  • Metrics [ ]
  • SMI Policy [ ]
  • Security [ ]
  • Tests [ ]
  • CI System [ ]
  • Performance [ ]
  • Other [ ]

Please answer the following questions with yes/no.

  • Does this change contain code from or inspired by another project? If so, did you notify the maintainers and provide attribution?
    No

Currently, while programming the service FQDNs for an
upstream service in the downstream envoy's virtual_host config
the shorthand service FQDN using the service name without the namespace
is always programmed. This is incorrect because the same service (name)
could exist in multiple namespaces. The service FQDN without the
namespace should only be programmed on downstream clients that are
in the same namespace.

This change addresses this bug and adds tests for the same. It also
removes a duplicated test copied into an unrelated package.

Resolves openservicemesh#951

Signed-off-by: Shashank Ram <shashank08@gmail.com>
@codecov-io
Copy link

Codecov Report

Merging #1935 into main will decrease coverage by 0.09%.
The diff coverage is 47.61%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1935      +/-   ##
==========================================
- Coverage   58.50%   58.40%   -0.10%     
==========================================
  Files         131      131              
  Lines        5270     5272       +2     
==========================================
- Hits         3083     3079       -4     
- Misses       2184     2190       +6     
  Partials        3        3              
Impacted Files Coverage Δ
pkg/catalog/mock_catalog.go 0.00% <0.00%> (ø)
pkg/envoy/rds/response.go 25.00% <0.00%> (ø)
pkg/catalog/routes.go 77.77% <60.00%> (ø)
pkg/kubernetes/util.go 95.00% <100.00%> (+0.55%) ⬆️
...ertificate/providers/tresor/certificate_manager.go 69.66% <0.00%> (-6.75%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 85a6597...acca2a1. Read the comment docs.

@shashankram shashankram marked this pull request as ready for review October 27, 2020 21:25
@shashankram shashankram requested a review from a team as a code owner October 27, 2020 21:25
Copy link
Contributor

@draychev draychev left a comment

Choose a reason for hiding this comment

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

Looks good to me!
Thanks for fixing this!

// GetHostnamesForService returns the hostnames for a service
GetHostnamesForService(service service.MeshService) (string, error)
// GetResolvableHostnamesForUpstreamService returns the hostnames over which an upstream service is accessible from a downstream service
GetResolvableHostnamesForUpstreamService(downstream, upstream service.MeshService) (string, error)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm starting to wonder if some of the mental overload of this could be decreased (or increased) if we had upstream.GetHostnamesFor(downstream) 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

That kind of semantic would work if the caller expects and API to simply return the hostnames, however the current API has more business logic of doing things differently for permissive mode, when traffic split isn't applicable, when traffic split is applied etc. Currently this is called in RDS which expects catalog to do the magic of returning all possible hostnames based on some business logic (permissive mode, traffic split etc.)

@shashankram shashankram merged commit 97a0720 into openservicemesh:main Oct 28, 2020
@shashankram shashankram deleted the svc-fqdn branch October 28, 2020 00:15
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prevent hostname conflicts for services in different namespaces when using k8s short form DNS names
4 participants