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

network: support interface binding on Android #1897

Merged
merged 8 commits into from
Nov 1, 2021
Merged

Conversation

goaway
Copy link
Contributor

@goaway goaway commented Oct 22, 2021

Description: SO_BINDTODEVICE will generally only be useable by an Android app running as root, so the present interface-binding approach on Android is mostly a non-starter. Instead, this change binds the interface indirectly by finding the local IP of the interface and setting that as the source IP of the socket.

To do so, it passes a "synthetic" socket option through to the internal connection API. When applied, instead of setting an actual socket option on the socket, this object sets the source IP property on the connection before bind() is called.
Risk Level: Moderate
Testing: Local & On Device

Signed-off-by: Mike Schore mike.schore@gmail.com

Signed-off-by: Mike Schore <mike.schore@gmail.com>
Signed-off-by: Mike Schore <mike.schore@gmail.com>
Signed-off-by: Mike Schore <mike.schore@gmail.com>
@goaway
Copy link
Contributor Author

goaway commented Oct 27, 2021

Depends on envoyproxy/envoy#18769.

@goaway goaway marked this pull request as ready for review October 27, 2021 09:36
@goaway goaway requested a review from snowp October 27, 2021 09:41
Copy link
Contributor

@snowp snowp 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, just a few comments

library/common/engine.cc Show resolved Hide resolved
* This is a "synthetic" socket option implementation, which sets the source IP/port of a socket
* using a provided IP address (and maybe port) during bind.
*
* Based on the OriginalSrcSocketOption extension.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this exactly the same? Or are there any key differences to call out?

If it's the same, would it be worthwhile to try to reuse the upstream one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is the same, and I almost did just that. However, the original source code is part of a larger extension that appears to be intended to allow Envoy to transparently pretend to be the origin of the connection. The socket option just happened to allow us to bind an arbitrary local address, which is what we wanted.

My concern about re-using this upstream code was that the SocketOption piece of it could change in support of the different upstream intent. If it were to change, it could break us in a way that stopped the feature from working or worse, could lead to runtime failures. If this occurred, there's a real risk that such failures wouldn't be detected until they hit production.

The risk of hard-to-detect runtime failures, and the fact that we'd be pulling in a larger extension with an unrelated purpose, swayed me towards just including the code we need. This also enables us to modify it to better suit our purpose as needed.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think perhaps ideally we'd lift this up to a generic socket option (so it's not in extension code) and have EM tests that it works the right way for EM's use case so we catch any regression

That said I'm not gonna block on this, if you think it's easier to copy this I would just do that (and maybe note that at the time of writing it's the same as the OriginalSrc one)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What still gives me pause is that I'm not sure this is so much a case of shared inherent behavior, so much as shared incidental behavior.

My preference right now is to move forward, but I'm open to continuing the discussion.

library/common/network/configurator.cc Show resolved Hide resolved
Signed-off-by: Mike Schore <mike.schore@gmail.com>
Signed-off-by: Mike Schore <mike.schore@gmail.com>
Signed-off-by: Mike Schore <mike.schore@gmail.com>
Signed-off-by: Mike Schore <mike.schore@gmail.com>
Signed-off-by: Mike Schore <mike.schore@gmail.com>
@goaway goaway requested a review from snowp November 1, 2021 13:16
Copy link
Contributor

@snowp snowp left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@goaway
Copy link
Contributor Author

goaway commented Nov 1, 2021

Thanks @snowp!

@goaway goaway merged commit 41eba57 into main Nov 1, 2021
@goaway goaway deleted the ms/android-addr-binding branch November 1, 2021 17:45
junr03 pushed a commit that referenced this pull request Dec 2, 2021
Description: Both v4_interfaces and v6_interfaces were using V4 interfaces likely due to a typo. This is a follow-up to #1897.
Risk Level: Low, just fixing a log.

Signed-off-by: JP Simard <jp@jpsim.com>
junr03 pushed a commit that referenced this pull request Dec 15, 2021
Description: Both v4_interfaces and v6_interfaces were using V4 interfaces likely due to a typo. This is a follow-up to #1897.
Risk Level: Low, just fixing a log.

Signed-off-by: JP Simard <jp@jpsim.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.

2 participants