Skip to content

Mutual TLS: Update port to address as listener identity.#570

Merged
mattklein123 merged 13 commits intoenvoyproxy:masterfrom
wattli:dev
Mar 18, 2017
Merged

Mutual TLS: Update port to address as listener identity.#570
mattklein123 merged 13 commits intoenvoyproxy:masterfrom
wattli:dev

Conversation

@wattli
Copy link
Copy Markdown
Contributor

@wattli wattli commented Mar 14, 2017

fixes #507

@wattli
Copy link
Copy Markdown
Contributor Author

wattli commented Mar 14, 2017

@mattklein123 , please take a look, this PR fixes #507, please take a look. thanks.

Copy link
Copy Markdown
Member

@lizan lizan left a comment

Choose a reason for hiding this comment

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

test cases for 0.0.0.0?

}
}

TcpListenSocket::TcpListenSocket(std::string address, bool bind_to_port) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: const std::string&

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.

done

local_address_.reset(new Address::Ipv4Instance(port));
}

TcpListenSocket::TcpListenSocket(int fd, std::string address) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ditto

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.

done


RpcGetListenSocketRequest rpc;
rpc.port_ = port;
memcpy(rpc.address_, address.c_str(), address.length() + 1);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

make sure address.length() < 256?

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.

Good point. Done.

ReadFilter(TestDnsServerQuery& parent) : parent_(parent) {}

// Network::ReadFilter
// Network::ReadFilter'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

?

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.

Removed.

@wattli
Copy link
Copy Markdown
Contributor Author

wattli commented Mar 14, 2017

@myidpt , FYI

@mattklein123
Copy link
Copy Markdown
Member

@htuch can you possibly take the first pass on this?

@htuch
Copy link
Copy Markdown
Member

htuch commented Mar 14, 2017

wattli@ I can take a look at this. Before beginning, it would be helpful if you can you rebase from master, squash all the commits down to a single commit and provide a descriptive commit message? Thanks.

@htuch
Copy link
Copy Markdown
Member

htuch commented Mar 14, 2017

Also, Travis CI tests are failing as this isn't building. I think rebasing from master might fix it if it's working locally for you.

@wattli
Copy link
Copy Markdown
Contributor Author

wattli commented Mar 15, 2017

@htuch please take a look. Thanks.

@htuch
Copy link
Copy Markdown
Member

htuch commented Mar 15, 2017

@wattli Travis CI is still failing. Also, you haven't rebased from master, squashed down the commits and put together a descriptive comment. You should squash locally with "git rebase -i" until you have a single commit, and then "git push -f" to this branch. This will kill the working history and leave us with a single commit to start the review with. It's fine to later push smaller fixup commits, but I'd like to begin with a base that is most of the way there.

If you're new to git and need some help, I'll be available most of tomorrow EDT on https://gitter.im/lyft/envoy and can assist with the git flow.

@wattli wattli force-pushed the dev branch 4 times, most recently from ab673ba to 5daa5c4 Compare March 15, 2017 04:23
@wattli
Copy link
Copy Markdown
Contributor Author

wattli commented Mar 15, 2017

@htuch , it should be ready for review now. Thanks.

* the address returned by getOriginalDst() match the listener address. In this case the
* listener handles the connection directly and does not hand it off.
*/
if (listener->socket_.localAddress()->asString() != final_local_address->asString()) {
Copy link
Copy Markdown
Contributor

@kyessenov kyessenov Mar 14, 2017

Choose a reason for hiding this comment

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

I wonder if we want to have address wildcards. For ingress on Kubernetes pods, what's the IP address in the listener? Is it pod IP, service IP, or 127.0.0.1? If it can be either pod IP or service IP, then we need to have a list of addresses in the listener spec.

Copy link
Copy Markdown
Member

@htuch htuch Mar 15, 2017

Choose a reason for hiding this comment

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

Is this instead of 0.0.0.0 which is too broad? E.g. you're after just {pod IP, 127.0.0.1} but not service IP? Then yeah, a list might make sense. This seems like it's beyond the scope of this PR though - you can use 0.0.0.0 for backwards compatibility with Envoy today with the current PR. It would make sense to file a PR for extending to a list once this PR is in though.

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.

Agree with htuch's point. We can start from one address with 0.0.0.0 as the wild card. And then extend to a list if necessary.

Copy link
Copy Markdown
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

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

In general, looks great. In addition to the comments below, I agree with @lizan that we should have some tests for 0.0.0.0 wildcard matching, in particular given the new logic in ConnectionHandlerImpl::findListenerByPort().

Can you also add some tests for use_original_dst that deal with different addresses?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Either sizeof(rpc.address_) (which should work, as this is an explicitly sized array) or use a named constant both here and in hot_restart.h.

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.

Good point, done.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Addresses have overloaded == operator, so should be comparable directly without having to convert to strings.

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.

Great, done.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ditto, shouldn't need to be performing direct string comparisons here.

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.

Done.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This was a problem in the original code - we shouldn't use single letter variables like l, too easy to confuse with 1. can we rename to "auto listener" ?

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.

Updated here and everywhere else in this file.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe we should have an attribute on Address that lets us know if it's 0.0.0.0 without having to do string compares?

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.

Good point, i added a member function isWildcard().

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do you want to EXPECT on the return value for listen? Same above, I know this was an issue in the original test.

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.

Done.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you comment on why we have this test as well as the socket2? In general, all these socket cases could do with a one line comment explaining the intent.

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.

done.

@wattli
Copy link
Copy Markdown
Contributor Author

wattli commented Mar 15, 2017

@htuch , wildcard test case is covered as well as use_original_dst. Thanks.

@htuch
Copy link
Copy Markdown
Member

htuch commented Mar 15, 2017

@wattli I'll take a look, but tests are failing, so please look into them as well.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

address

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

isAllHostsWildcard()?

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.

I was thinking of adding helpers for creating the ANY address instances, equivalent to (but with shared instances):

namespace Network {
namespace Address {
InstancePtr anyIpv4() { return InstancePtr(new Ipv4Instance(0)); }
InstancePtr anyIpv6() { return InstancePtr(new Ipv6Instance(0)); }
} // Address
} // Network

That should make the impl a bit easier.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't know if this solves the problem that isWildcard() is being used for though - the idea is you have an address that is something like 0.0.0.0:443 and want to know if just the IP part (ignoring the port) is wildcard.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Wouldn't this be :: ?

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.

Why return false? As Harvey indicates, the IPv6 equivalent of IPv4's "0.0.0.0" is "::", which is short for "0:0:0:0:0:0:0:0".

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this might be a source of compile errors?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

According to man (2) listen: "On success, zero is returned. On error, -1 is returned, and errno is set appropriately."

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Shouldn't need to explicitly construct a std::string?

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.

Otherwise it will complain 'ambiguous message type'.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Isn't the idea here that we're trying to test findListenerByAddress? But instead it seems that this method is mocked, so it doesn't get exercised..

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.

The unit test of findlistenerbyaddress is in connection_handler_test.cc. This here is for use_original_dst, which can't be tested there.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sorry, my bad, this looks good.

@jamessynge
Copy link
Copy Markdown
Contributor

This PR seems to have strayed away from the original goal, listen on the loopback address, and into the territory of "Update Envoy to use Network::Address::InstancePtr instead of port number". Can we separate these? I've been doing a bit of the latter as part of working on #351, which could be split into separate issues as appropriate.

@wattli
Copy link
Copy Markdown
Contributor Author

wattli commented Mar 15, 2017 via email

@jamessynge
Copy link
Copy Markdown
Contributor

Well, if we use the word "any" in the functions I suggested (rather than saying "all hosts wild"), then we should probably call the predicate function something like "isAny" or "isAnyAddress".

@wattli
Copy link
Copy Markdown
Contributor Author

wattli commented Mar 15, 2017 via email

@htuch
Copy link
Copy Markdown
Member

htuch commented Mar 15, 2017

I'd strongly prefer not to be matching on strings. I just spoke with @jamessynge and he is fine with you adding isAnyAddress(), as long as tests are added as well.

@wattli
Copy link
Copy Markdown
Contributor Author

wattli commented Mar 16, 2017

@htuch , the comments are addressed. Thanks.

Copy link
Copy Markdown
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Overall great work. Some comments.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we get an example of what a TCP listener address looks like, and how to specify wildcard vs. specific.

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.

Done.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

const Network::Address::Instance&

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.

Done.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

const std::string&

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.

done.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

const std::string& (or potentially have this just return AddressPtr directly).

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.

done

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

const std::string& address

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.

done

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please use strlcpy here

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.

done

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

const

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.

done

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You are comparing pointers here. This is almost definitely not what you want. Please make sure you have tests that catch this. (Though if you fix per other comment to const Instance& it will be obvious)

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.

done and more tests are added

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It would be kind of nice to not have to do 2 searches here. I think this was commented on elsewhere, but wondering if we should do this in follow up. I wonder if we should have different options, "use_original_port" and "use_original_address". Not a huge deal, but throwing it out there.

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.

Yes, it is mentioned above we can use a map to improve efficiency. I prefer leaving a TODO here and get rid of this big PR. :)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You have made it work for UDS, you can remove this TODO. :)

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.

removed 👍

Copy link
Copy Markdown
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

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

A few more minor comments then I think it's good to hand over to mattklein123@ for approval. Thanks for your patience with the nits.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Best to use // C++ comment style for method internal comments. I think the Javadoc style is only for stuff that Doxygen processes.

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.

done

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sorry, my bad, this looks good.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do you also want to verify that newConnection isn't called on listenerDst?

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.

done

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The name of this test is a bit confusing, since use_original_dst is set false. Shouldn't it be UseActualDst?

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.

done

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can TcpListenSocket::TcpListenSocket(uint32_t port, bool bind_to_port) below be implemented in terms of this method? That would reduce the amount of code duplication.

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.

Matt raised similar issue above. In config, admin still uses port. So we can have a follow up PR to update admin from using port to address and make corresponding change later. I will let him decide

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes we can do in follow up. Please add TODO somewhere.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ditto but with TcpListenSocket::TcpListenSocket(int fd, uint32_t port).

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.

Same as above.

@wattli
Copy link
Copy Markdown
Contributor Author

wattli commented Mar 16, 2017

@mattklein123 , all checks have passed. Please take a look, thanks.

return -1;
}
StringUtil::strlcpy(rpc.address_, address.c_str(), address.length());
StringUtil::strlcpy(rpc.address_, address.c_str(), address.length() + 1);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The last param is the max length of the target buffer, which is why it didn't work before.

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.

I misunderstood what you meant. Updated

@wattli
Copy link
Copy Markdown
Contributor Author

wattli commented Mar 16, 2017 via email

@wattli
Copy link
Copy Markdown
Contributor Author

wattli commented Mar 16, 2017

@mattklein123 , do you have more comments on this PR?

@mattklein123
Copy link
Copy Markdown
Member

I haven't looked yet. Can you fix the thing I just mentioned? The last param should be sizeof(rpc.address_)

@wattli
Copy link
Copy Markdown
Contributor Author

wattli commented Mar 16, 2017

@mattklein123 , checks passed, please take a look when available, thanks :)

{# TCP listener for external port 443 (SSL). Assumes a TCP LB in front such as ELB which
supports proxy proto. #}
{{ listener(9300,True,True) }},
{{ listener("tcp://127.0.0.1:9300",True,True) }},
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

0.0.0.0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please add TODO somewhere

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.

Done

{# TCP listener for external port 80 (non-SSL). Assumes a TCP LB in front such as ELB which
supports proxy proto. #}
{{ listener(9301,False,True) }}
{{ listener("tcp://127.0.0.1:9301",False,True) }}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

0.0.0.0

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.

Done

supports proxy proto. #}
{{ listener(9300, ssl=True, proxy_proto=True, router_file='envoy_router.template.json') }},
{{ listener(9301, ssl=False, proxy_proto=True, router_file='envoy_router.template.json') }},
{{ listener("tcp://127.0.0.1:9300", ssl=True, proxy_proto=True, router_file='envoy_router.template.json') }},
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

0.0.0.0

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.

Done

{{ listener(9300, ssl=True, proxy_proto=True, router_file='envoy_router.template.json') }},
{{ listener(9301, ssl=False, proxy_proto=True, router_file='envoy_router.template.json') }},
{{ listener("tcp://127.0.0.1:9300", ssl=True, proxy_proto=True, router_file='envoy_router.template.json') }},
{{ listener("tcp://127.0.0.1:9301", ssl=False, proxy_proto=True, router_file='envoy_router.template.json') }},
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

0.0.0.0

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.

Done

{# TCP listener for backhaul traffic from the double proxy.
See envoy_double_proxy.template.json #}
{{ listener(9400, ssl=True, proxy_proto=False, pin_double_proxy_client=True,
{{ listener("tcp://127.0.0.1:9400", ssl=True, proxy_proto=False, pin_double_proxy_client=True,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

0.0.0.0

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.

Done

*/
virtual Network::Listener* findListenerByPort(uint32_t port) PURE;
virtual Network::Listener*
findListenerByAddress(const Network::Address::InstancePtr& address) PURE;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

const Network::Address::Instance& (not InstancePtr)

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.

I tried, it does not work in testing file because no comparison of Address::Instance is defined.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That doesn't make sense, as you end up comparing them in the end. https://github.com/lyft/envoy/blob/master/include/envoy/network/address.h#L80

You had some other compiler error. Please try again or ask someone for an over the shoulder check.

struct IpHelper : public Ip {
const std::string& addressAsString() const override { return friendly_address_; }
bool isAnyAddress() const override {
return memcmp(&ipv6_.address_.sin6_addr, &in6addr_any, sizeof(struct in6_addr));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think you actually want 0 == memcmp(...). Please add test for this.

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.

Done

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes we can do in follow up. Please add TODO somewhere.


RpcGetListenSocketRequest rpc;
rpc.port_ = port;
if (address.length() >= sizeof(rpc.address_)) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

not sure if I would bother with this check. strlcpy() will protect. I would just put in an ASSERT(address.length() < sizeof(rpc.address_))

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.

Done


int InstanceImpl::getListenSocketFd(uint32_t port) {
int InstanceImpl::getListenSocketFd(const std::string& address) {
Network::Address::InstancePtr addr = Network::Utility::resolveUrl(address);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No point in resolving this, just do the string compare directly. Either it matches or it doesn't.

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.

I have to, address is in format 'tcp://address:port' while localAddress()->asString() is in format 'address:port'

# optional external service ports: built from external_virtual_hosts above. Each external host
# that Envoy proxies to listens on its own port.
# optional mongo ports: built from mongos_servers above.
# TODO(wattli): investigate why a bad config (with port but not address) can
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sorry this is not an acceptable TODO, it will cause production issues.

The issue is that you are returning an std::string from the configuration, and it doesn't get bound to an address until the listeners actually start running on the workers. I mentioned this a while ago, but please have the configuration return an Address::InstancePtr instead of a string. This will cause an exception to be thrown if the address cannot be resolved at config load time.


// TODO(wattli): remove this once the admin port is updated with address.
TcpListenSocket::TcpListenSocket(const std::string& address, bool bind_to_port) {
TcpListenSocket::TcpListenSocket(const Address::InstancePtr& address, bool bind_to_port) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just pass Address::InstancePtr here (passing by const& can lead to subtle bugs). Same below.

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.

Done

* @return std::string the address.
*/
virtual uint64_t port() PURE;
virtual const std::string& address() PURE;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@wattli this is where you need to return Address::InstancePtr. Resolve it inside the configuration. Otherwise https://github.com/lyft/envoy/blob/master/test/example_configs_test.cc#L32 will still potentially pass, since you first resolve it when the server starts running.

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.

Done

@wattli
Copy link
Copy Markdown
Contributor Author

wattli commented Mar 17, 2017

@mattklein123 @htuch , please take a look.

Network::FilterChainFactory& filterChainFactory() override { return *this; }
const std::string& address() override { return address_; }
Network::Address::InstancePtr address() override {
return Network::Utility::resolveUrl(address_);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Still not right. It doesn't help you if you don't resolve until you access. Resolve at construction time and change address_ to Address::InstancePtr

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.

Done, thanks.

@mattklein123 mattklein123 merged commit fb42918 into envoyproxy:master Mar 18, 2017
@wattli wattli changed the title Update port to address as listener identity. Mutual TLS: Update port to address as listener identity. Sep 16, 2018
lambdai pushed a commit to lambdai/envoy-dai that referenced this pull request Jul 21, 2020
Signed-off-by: John Plevyak <jplevyak@gmail.com>
jpsim pushed a commit that referenced this pull request Nov 28, 2022
Description: I believe this was probably a bad copy paste.
Risk Level: low
Testing: builds.

Signed-off-by: Jose Nino <jnino@lyft.com>
Signed-off-by: JP Simard <jp@jpsim.com>
jpsim pushed a commit that referenced this pull request Nov 29, 2022
Description: I believe this was probably a bad copy paste.
Risk Level: low
Testing: builds.

Signed-off-by: Jose Nino <jnino@lyft.com>
Signed-off-by: JP Simard <jp@jpsim.com>
mathetake pushed a commit that referenced this pull request Mar 3, 2026
…pha.0 in the k8s-io group across 1 directory (#570)
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.

Bind listener to 0.0.0.0 or 127.0.0.1

6 participants