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 20 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
address comments
shivaspeaks committed Mar 18, 2025
commit ca5bb140a421fc1a5e760f47aeb619934f254bc5
6 changes: 6 additions & 0 deletions xds/src/main/java/io/grpc/xds/XdsListenerResource.java
Original file line number Diff line number Diff line change
@@ -165,6 +165,12 @@
if (proto.getAddress().hasSocketAddress()) {
SocketAddress socketAddress = proto.getAddress().getSocketAddress();
address = socketAddress.getAddress();
if (address.trim().isEmpty()) {
throw new ResourceInvalidException("Invalid address: Empty address is not allowed.");

Check warning on line 169 in xds/src/main/java/io/grpc/xds/XdsListenerResource.java

Codecov / codecov/patch

xds/src/main/java/io/grpc/xds/XdsListenerResource.java#L169

Added line #L169 was not covered by tests
}
if (socketAddress.hasNamedPort()) {
throw new ResourceInvalidException("NAMED_PORT is not supported in gRPC.");

Check warning on line 172 in xds/src/main/java/io/grpc/xds/XdsListenerResource.java

Codecov / codecov/patch

xds/src/main/java/io/grpc/xds/XdsListenerResource.java#L172

Added line #L172 was not covered by tests
}
switch (socketAddress.getPortSpecifierCase()) {
case NAMED_PORT:
address = address + ":" + socketAddress.getNamedPort();
15 changes: 12 additions & 3 deletions xds/src/main/java/io/grpc/xds/XdsServerWrapper.java
Original file line number Diff line number Diff line change
@@ -387,12 +387,21 @@
}
logger.log(Level.FINEST, "Received Lds update {0}", update);
if (update.listener() == null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Add unit test for this case as well.

onResourceDoesNotExist("Non-API");
return;

Check warning on line 391 in xds/src/main/java/io/grpc/xds/XdsServerWrapper.java

Codecov / codecov/patch

xds/src/main/java/io/grpc/xds/XdsServerWrapper.java#L390-L391

Added lines #L390 - L391 were not covered by tests
}

boolean isUdpListener = false;
for (FilterChain filterChain : update.listener().filterChains()) {
String transportProtocol = filterChain.filterChainMatch().transportProtocol();
if (transportProtocol != null && !"raw_buffer".equals(transportProtocol)) {
isUdpListener = true;
break;
}
}

String ldsAddress = update.listener().address();
if (ldsAddress != null && !ipAddressesMatch(ldsAddress)) {
if (!isUdpListener && ldsAddress != null && !ipAddressesMatch(ldsAddress)) {
handleConfigNotFoundOrMismatch(
Status.UNKNOWN.withDescription(
String.format(
@@ -454,9 +463,9 @@

InetAddress listenerIp = InetAddresses.forString(listenerAddressHnP.getHost());
InetAddress ldsIp = InetAddresses.forString(ldsAddressHnP.getHost());
if (ldsAddressHnP.hasPort() && listenerAddressHnP.hasPort()
&& ldsAddressHnP.getPort() != listenerAddressHnP.getPort()) {
if (!ldsAddressHnP.hasPort() || !listenerAddressHnP.hasPort()
|| ldsAddressHnP.getPort() != listenerAddressHnP.getPort()) {
return false;

Check warning on line 468 in xds/src/main/java/io/grpc/xds/XdsServerWrapper.java

Codecov / codecov/patch

xds/src/main/java/io/grpc/xds/XdsServerWrapper.java#L468

Added line #L468 was not covered by tests
}

return listenerIp.equals(ldsIp);
2 changes: 1 addition & 1 deletion xds/src/test/java/io/grpc/xds/XdsServerWrapperTest.java
Original file line number Diff line number Diff line change
@@ -1862,7 +1862,7 @@ private static FilterChainMatch createMatch() {
EnvoyServerProtoData.ConnectionSourceType.ANY,
ImmutableList.of(),
ImmutableList.of(),
"");
"raw_buffer");
}

private static FilterChainMatch createMatchSrcIp(String srcCidr) {