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

xds: listener type validation #11933

Open
wants to merge 18 commits into
base: master
Choose a base branch
from

Conversation

shivaspeaks
Copy link
Member

Fixes #11737

@shivaspeaks shivaspeaks changed the title Listener type validation xds: listener type validation Mar 3, 2025
@shivaspeaks shivaspeaks requested a review from ejona86 March 3, 2025 15:25
@ejona86 ejona86 self-requested a review March 5, 2025 21:20
Copy link
Member

@ejona86 ejona86 left a 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

@shivaspeaks shivaspeaks added the kokoro:run Add this label to a PR to tell Kokoro the code is safe and tests can be run label Mar 6, 2025
@grpc-kokoro grpc-kokoro removed the kokoro:run Add this label to a PR to tell Kokoro the code is safe and tests can be run label Mar 6, 2025
@shivaspeaks shivaspeaks requested a review from ejona86 March 6, 2025 20:52
InetAddress listenerIp = InetAddresses.forString(listenerAddressHnP.getHost());
InetAddress ldsIp = InetAddresses.forString(ldsAddressHnP.getHost());

if (listenerIp.isAnyLocalAddress()) {
Copy link
Member

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();
Copy link
Collaborator

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

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member

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.

Copy link
Member Author

@shivaspeaks shivaspeaks Mar 19, 2025

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?

Copy link
Member

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?

Copy link
Member Author

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,
Copy link
Collaborator

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.

Copy link
Member

@ejona86 ejona86 left a 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()
Copy link
Member

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();
Copy link
Member

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.

@shivaspeaks shivaspeaks requested a review from ejona86 March 18, 2025 17:03
@@ -165,6 +165,12 @@ static EnvoyServerProtoData.Listener parseServerSideListener(
if (proto.getAddress().hasSocketAddress()) {
SocketAddress socketAddress = proto.getAddress().getSocketAddress();
address = socketAddress.getAddress();
if (address.trim().isEmpty()) {
Copy link
Member

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.");
Copy link
Member

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();
Copy link
Member

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.

@shivaspeaks shivaspeaks requested a review from ejona86 March 19, 2025 15:58
@@ -57,7 +57,7 @@ dependencies {

task javadocs(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += files(android.getBootClasspath())
// classpath += files(android.getBootClasspath())
Copy link
Member Author

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
Copy link
Member

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.

Copy link
Contributor

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.

@shivaspeaks shivaspeaks requested a review from ejona86 March 19, 2025 18:07
@larry-safran
Copy link
Contributor

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.

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.

XdsNameResolver and XdsServerWrapper don't check listener type
5 participants