-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
xds: listener type validation #11933
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I didn't mean to approve
InetAddress listenerIp = InetAddresses.forString(listenerAddressHnP.getHost()); | ||
InetAddress ldsIp = InetAddresses.forString(ldsAddressHnP.getHost()); | ||
|
||
if (listenerIp.isAnyLocalAddress()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I said before, remove the wildcard handling. IPv4 and IPv6 wildcards behave differently, and you aren't checking the port here. And if we need to be comparing wildcards, we would really need to spell out how that is done in the gRFC to be consistent cross-language.
return; | ||
} | ||
|
||
String ldsAddress = update.listener().address(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For my education: what would be the "best/most appropriate" behaviour if the String ldsAddress
is the empty string or null
?
Currently, if ldsAddress
is null
, we skip ipAddressesMatch
entirely and proceed with the remaining logic. Would this still be fine?
Likewise, if ldsAddress
is the empty string, we check ipAddressesMatch
, AFAIK, this would throw an exception and would this be fine? HostAndPort.fromString
would return a HostAndPort(host="", port=-1, hasBracketlessColons=false)
then InetAddresses.forString
would throw an IllegalArgumentException
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm. Good point. I couldn't find any mention about this case in gRFC A36.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ldsAddress == null
means (based on XdsListenerResource) that the address type was not a SocketAddress, which is covered in the gRFC.
In most NR/LB logic, exceptions cause the channel to go into panic mode. NR/LB should only throw in case of a bug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Empty address is disallowed in the proto, but is not in our validation so we should add validation. The ip matching logic here should also be checking that it is a TCP listener, which is not being communicated through EnvoyServerData.Address.
And the validation should probably be NACKing (throw ResourceInvalidException
) NAMED_PORT as gRPC does not support resolver_name
, which is mentioned as being required to use it in its documentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do we check if it is a TCP listener?
if ("raw_buffer".equals(update.listener().filterChains().get(0).filterChainMatch().transportProtocol()))
this could tell us but I'm not very sure about this. I could have pasted the above condition with default filter chain but that is a Nullable field.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This gRPC code is always TCP. So we need to not match when xDS tells us to use UDP.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The transport protocol doesn't seem to be about TCP vs UDP. That's raw_buffer
or tls
: the higher-level protocol. And that is part of filter chain matches; used to select which filter chain to use. You should never loop through all the matchers and then copy details about it to other matchers.
We were talking about the address, and SocketAddress has a TCP vs UDP protocol
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it.
You said we need not match addresses when it's UDP, so I assume we don't call handleConfigNotFoundOrMismatch
when it's UDP and continue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand. If you don't call handleConfigNotFoundOrMismatch
, that's the same as matching... If !ipAddressesMatch()
you call handleConfigNotFoundOrMismatch
. Why would you not call it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep. I was thinking right at first before editing the comment and then I messed up with thoughts.
@Override | ||
public void onResourceDoesNotExist(final String resourceName) { | ||
if (stopped) { | ||
return; | ||
} | ||
StatusException statusException = Status.UNAVAILABLE.withDescription( | ||
String.format("Listener %s unavailable, xDS node ID: %s", resourceName, | ||
String.format("%s listener unavailable, xDS node ID: %s", resourceName, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: what would be the reason to switch the order of the error format here? I think Listener %s
is slightly more common in the code base. Consistent formatting helps with searching when debugging issues.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found these comments laying around. I don't know why I didn't send it out earlier.
|
||
InetAddress listenerIp = InetAddresses.forString(listenerAddressHnP.getHost()); | ||
InetAddress ldsIp = InetAddresses.forString(ldsAddressHnP.getHost()); | ||
if (ldsAddressHnP.hasPort() && listenerAddressHnP.hasPort() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the address doesn't have a port, fail the match.
return; | ||
} | ||
|
||
String ldsAddress = update.listener().address(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This gRPC code is always TCP. So we need to not match when xDS tells us to use UDP.
@@ -165,6 +165,12 @@ static EnvoyServerProtoData.Listener parseServerSideListener( | |||
if (proto.getAddress().hasSocketAddress()) { | |||
SocketAddress socketAddress = proto.getAddress().getSocketAddress(); | |||
address = socketAddress.getAddress(); | |||
if (address.trim().isEmpty()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the trim()
.
throw new ResourceInvalidException("Invalid address: Empty address is not allowed."); | ||
} | ||
if (socketAddress.hasNamedPort()) { | ||
throw new ResourceInvalidException("NAMED_PORT is not supported in gRPC."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this to the switch
? Or delete the NAMED_PORT case in the switch; it is dead code and misleading.
return; | ||
} | ||
|
||
String ldsAddress = update.listener().address(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The transport protocol doesn't seem to be about TCP vs UDP. That's raw_buffer
or tls
: the higher-level protocol. And that is part of filter chain matches; used to select which filter chain to use. You should never loop through all the matchers and then copy details about it to other matchers.
We were talking about the address, and SocketAddress has a TCP vs UDP protocol
.
cronet/build.gradle
Outdated
@@ -57,7 +57,7 @@ dependencies { | |||
|
|||
task javadocs(type: Javadoc) { | |||
source = android.sourceSets.main.java.srcDirs | |||
classpath += files(android.getBootClasspath()) | |||
// classpath += files(android.getBootClasspath()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll uncomment this in the next commit.
} | ||
|
||
String ldsAddress = update.listener().address(); | ||
if (ldsAddress != null && update.listener().protocol() == Protocol.TCP |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From gRFC A36:
To be useful, the xDS-returned Listener must have an address that matches the listening address provided. The Listener's address would be a TCP SocketAddress with matching address and port_value. The XdsServer must be "not serving" if the address does not match.
If ldsAddress == null
, then there was not a (supported) address and it should not be serving. If the protocol is not TCP then it should not be serving.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This means that every place in our tests that calls Listener.newBuilder()
needs to set the address.
While it is in the gRFC, why is it really important to enforce a returned address being non-null? This doesn't seem to really provide value as the address was already known for communicating to the xds server in the first place. |
Fixes #11737