Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upstream: add transparency options #5035

Closed
wants to merge 19 commits into from

Conversation

klarose
Copy link
Contributor

@klarose klarose commented Nov 14, 2018

Description:
This adds two options to the upstream cluster definition:

  • mark
  • src_transparent

Mark is a 32-bit unsigned integer whose non-zero value indicates that all packets originating from envoy to the configured upstream cluster should be marked with the provided value.

src_transparent is a boolean where true indicates that L3/L4 source transparency should be enabled for this upstream cluster. That is, connections to the cluster will have the same IP address (and possibly port) as the original downstream connection.

Mark will just work as-is. However, src_transparent still needs implementation to work properly.

The options are implemented by adding socket options to the upstream cluster. Consequently, when an upstream connection is made, the socket options are applied. This infrastructure already existed.

The implementation applies SO_MARK in response to the mark configuration. This option seems to only exist on Linux. It requires CAP_NET_ADMIN privileges.

src_transparent applies IP_TRANSPARENT. The socket option code for this already exists. This change simply invokes it in the context of the upstream cluster. It also requires CAP_NET_ADMIN.

This is part of the infrastructure for #4128.

Risk Level: Low
This is an optional feature which is disabled by default. The only new logic is in choosing whether or not to add the socket options, called from existing code.

Testing:
Unit tests were added for the configuration options at every level. I ran the full unit test suite (which I think runs the integration tests.. If it doesn't, let me know, and I'll run them).

I manually tested that the mark socket option worked by running envoy in a container connected to a simple http upstream. With the required iptables rules in place, I could see the mark using conntrack -L.

Docs Changes:
I documented the API in the protobuf specification. The overall feature will need a proper blurb when it's done.

You can now set a "mark" unsigned integer value in a cluster. This will
mark any upstream packets originating from envoy on this cluster with
the given value.

You can also configure a cluster to be "src_transparent". This will
cause the cluster to use the downstream connection's remote address as
the source address for the upstream connection.

Signed-off-by: Kyle Larose <kyle@agilicus.com>
We can use this to control whether or not a packet is marked when
emitted by Envoy.

Signed-off-by: Kyle Larose <kyle@agilicus.com>
The cluster config supports the mark and src_transparent properties in
the upstream cluster. The upstream cluster now reads these properties.
It sets the corresponding socket options if the properties are present.

Signed-off-by: Kyle Larose <kyle@agilicus.com>
api/envoy/api/v2/cds.proto Outdated Show resolved Hide resolved
SO_MARK and IP_TRANSPARENT may not be supported on all platforms. Skip
tests testing those if they aren't supported.

Signed-off-by: Kyle Larose <kyle@agilicus.com>
@klarose
Copy link
Contributor Author

klarose commented Nov 14, 2018

@lyft/network-team Can somebody take a look at this please?

Thanks!

Edit: I'm not sure the above actually worked... Are the contribution guidelines out of date?

@mattklein123
Copy link
Member

@zuercher do you mind taking a first pass on this?

@stale
Copy link

stale bot commented Nov 22, 2018

This pull request has been automatically marked as stale because it has not had activity in the last 7 days. It will be closed in 7 days if no further activity occurs. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions!

@stale stale bot added the stale stalebot believes this issue/PR has not been touched recently label Nov 22, 2018
@klarose
Copy link
Contributor Author

klarose commented Nov 22, 2018

poke. Please review when back from holidays!

@stale stale bot removed the stale stalebot believes this issue/PR has not been touched recently label Nov 22, 2018
Copy link
Member

@zuercher zuercher left a comment

Choose a reason for hiding this comment

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

Sorry it took so long for me to get to this. The overall approach seems solid.

You'll probably want to merge master as well, just to make sure things haven't drifted too far.

api/envoy/api/v2/cds.proto Outdated Show resolved Hide resolved
api/envoy/api/v2/cds.proto Outdated Show resolved Hide resolved
api/envoy/api/v2/cds.proto Outdated Show resolved Hide resolved
source/common/config/cds_json.cc Outdated Show resolved Hide resolved
test/common/upstream/upstream_impl_test.cc Show resolved Hide resolved
test/common/upstream/upstream_impl_test.cc Outdated Show resolved Hide resolved
Signed-off-by: Kyle Larose <kyle@agilicus.com>
 - Removed json updates; json config is deprecated
 - Use scalar types for protobufs
 - Update new upstream_impl_tests to use yaml rather than json.

Signed-off-by: Kyle Larose <kyle@agilicus.com>
Signed-off-by: Kyle Larose <kyle@agilicus.com>
api/envoy/api/v2/cds.proto Outdated Show resolved Hide resolved
api/envoy/api/v2/cds.proto Outdated Show resolved Hide resolved
Signed-off-by: Kyle Larose <kyle@agilicus.com>
No need to pollute the already large Cluster definition when there's a
perfectly appropriate message to hold the source transparency config!

Signed-off-by: Kyle Larose <kyle@agilicus.com>
Signed-off-by: Kyle Larose <kyle@agilicus.com>
Signed-off-by: Kyle Larose <kyle@agilicus.com>
Copy link
Member

@zuercher zuercher left a comment

Choose a reason for hiding this comment

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

This is looking good. At this point, the only thing left is resolving the complexity of the unit tests. My vote is to promote SocketOptionName to include and make it accessible so the test can just check the right options are set.

@klarose
Copy link
Contributor Author

klarose commented Nov 28, 2018

/retest

@repokitteh-read-only
Copy link

🔨 rebuilding ci/circleci: ipv6_tests (failed build)

🐱

Caused by: a #5035 (comment) was created by @klarose.

see: more, trace.

@klarose
Copy link
Contributor Author

klarose commented Nov 28, 2018

/retest

@repokitteh-read-only
Copy link

🔨 rebuilding ci/circleci: ipv6_tests (failed build)

🐱

Caused by: a #5035 (comment) was created by @klarose.

see: more, trace.

Signed-off-by: Kyle Larose <kyle@agilicus.com>
We want to be able to introspect the options being passed around without
needing to actually apply them. The simplest way to do this is to have
them return the values they would set. Since the values may differ based
on who they are visiting, this introspection takes into account the
socket and state passed in.

Signed-off-by: Kyle Larose <kyle@agilicus.com>
This changes some tests I added a while back for the source transparency
socket options to use the new Option:getOptionInformation API. This
is nicer since it decouples the higher level tests from the low level
implementation of the socket API.

Signed-off-by: Kyle Larose <kyle@agilicus.com>
Signed-off-by: Kyle Larose <kyle@agilicus.com>
Having some issues running some IPv6 option tests.

Signed-off-by: Kyle Larose <kyle@agilicus.com>
Ugh. Sucks to not be able to reproduce locally.

Signed-off-by: Kyle Larose <kyle@agilicus.com>
zuercher
zuercher previously approved these changes Dec 8, 2018
Copy link
Member

@zuercher zuercher left a comment

Choose a reason for hiding this comment

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

I think this looks good. Thanks for figuring out the testing!

include/envoy/network/listen_socket.h Outdated Show resolved Hide resolved
Suggestions from review.

Signed-off-by: Kyle Larose <kyle@agilicus.com>
@zuercher
Copy link
Member

@mattklein123 or @htuch not sure about your availability this week, but I think this is ready for one of you to take a look

@htuch
Copy link
Member

htuch commented Dec 13, 2018

@zuercher will defer to @mattklein123 on this one, as I have limited bandwidth at present.

@klarose
Copy link
Contributor Author

klarose commented Dec 14, 2018

We may want to wait for the conversation in #5255 to be resolved before merging. We may end up changing the config model.

There is still some stuff in here I'd like -- namely, the socket option introspection. I can always do that in a separate PR if we decide to ditch this.

@mattklein123
Copy link
Member

We may want to wait for the conversation in #5255 to be resolved before merging. We may end up changing the config model.

I need to catch up on all of this. @klarose should I bother reviewing this now? Or just look at #5255 first?

@klarose
Copy link
Contributor Author

klarose commented Dec 16, 2018

@mattklein123 At least read the conversation we've been having in that PR. We've been discussing an alternative design. I'd like your feedback on it. TL;DR: try to use a filter rather than changing the core components.

@klarose
Copy link
Contributor Author

klarose commented Dec 20, 2018

Cancelling this as it has been subsumed by the work for another approach (#5337)

@klarose klarose closed this Dec 20, 2018
zuercher pushed a commit that referenced this pull request Dec 22, 2018
IP Source transparency involves non-local IP addresses being routed as though they were local. This requires some magic in the stack to ensure that those flows are sent back to envoy from the upstream host, rather than back to the original source IP address. We plan on using SO_MARK to do this. So, add it into the socket option factory. My intention is for it to be used by a follow-up PR to #5337.

This was cherry-picked from PR #5035 where it was already reviewed. I plan on closing that PR.

Risk Level: Low. No code invoked in production yet.
Testing: Ran newly added UT and other UT in network.
Docs Changes: None until we expose this through config.
Release Notes: None

Signed-off-by: Kyle Larose <kyle@agilicus.com>
fredlas pushed a commit to fredlas/envoy that referenced this pull request Mar 5, 2019
IP Source transparency involves non-local IP addresses being routed as though they were local. This requires some magic in the stack to ensure that those flows are sent back to envoy from the upstream host, rather than back to the original source IP address. We plan on using SO_MARK to do this. So, add it into the socket option factory. My intention is for it to be used by a follow-up PR to envoyproxy#5337.

This was cherry-picked from PR envoyproxy#5035 where it was already reviewed. I plan on closing that PR.

Risk Level: Low. No code invoked in production yet.
Testing: Ran newly added UT and other UT in network.
Docs Changes: None until we expose this through config.
Release Notes: None

Signed-off-by: Kyle Larose <kyle@agilicus.com>
Signed-off-by: Fred Douglas <fredlas@google.com>
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.

4 participants