Skip to content

Conversation

kannanjgithub
Copy link
Contributor

@kannanjgithub kannanjgithub commented Sep 24, 2025

When using xDS credentials make SNI for the Tls handshake to be configured via xDS, rather than use the channel authority as the SNI, and make SAN validation to be able to use the SNI sent when so instructed via xDS.

Implements A101.

…m-root-changes-needed

# Conflicts:
#	xds/src/main/java/io/grpc/xds/internal/security/SslContextProviderSupplier.java
#	xds/src/test/java/io/grpc/xds/CdsLoadBalancer2Test.java
#	xds/src/test/java/io/grpc/xds/internal/security/SslContextProviderSupplierTest.java
#	xds/src/test/java/io/grpc/xds/internal/security/certprovider/CertProviderClientSslContextProviderTest.java
@kannanjgithub
Copy link
Contributor Author

I have done the changes discussed, but am yet to fix tests including compilation errors in a few of them.

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.

About to get on a call, so sending what I have. This looks a lot better; I don't really have any reservations from what I've seen.

HostPort hostPort = parseAuthority(authority);
this.host = hostPort.host;
this.port = hostPort.port;
// TODO: For empty authority and fallback flag
Copy link
Member

Choose a reason for hiding this comment

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

Half-baked thought (I haven't double checked with the expected behavior): it seems we should just pass sni = null here instead of empty string when GRPC_USE_CHANNEL_AUTHORITY_IF_NO_SNI_APPLICABLE is set. If the XDS config is saying to validate the SAN from the SNI and it also dosen't have a hostname, then that's a rather minor case that might pass when it should fail.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could either pass empty SNI here and change it to null when fallback flag is set (which is what I was going to do), or we could do that in the calling site at ClientTlsProtocolNegotiator itself and pass a null SNI in that case. The bigger question is at the time of SAN validation do we get the xDS channel authority from the SsllParameters.getServerNames(), and if so we should not use it for the SAN validation, and that would require setting some state in the XdsX509TrustManager.

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.

Moving ATTR_ADDRESS_NAME out of InternalXdsAttributes looks to be main thing. Everything else is small.


private List<StringMatcher> getAutoSniSanMatchers(SSLParameters sslParams) {
List<StringMatcher> sniNamesToMatch = new ArrayList<>();
if (CertificateUtils.isXdsSniEnabled && autoSniSanValidation) {
Copy link
Member

Choose a reason for hiding this comment

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

FYI: we strongly want to avoid checks like this deep in the code. It is very easy to miss a spot and generally wrong because verification checks should be impacted (e.g., XdsClusterResource.validateUpstreamTlsContext()). Instead, we'd want to handle this when parsing (XdsClusterResource) and then force autoSniSanValidation = false when CertificateUtils.isXdsSniEnabled == false.

Given this code is already failing to copy into our own data structures, it is sort of annoying to fix here. But keep it in mind in general.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Acknowledged.

@kannanjgithub kannanjgithub merged commit 0567531 into grpc:master Sep 29, 2025
20 of 23 checks passed
@kannanjgithub kannanjgithub deleted the sni-san-changes branch September 29, 2025 16:22
*/
public static InternalProtocolNegotiator.ProtocolNegotiator tls(SslContext sslContext) {
return tls(sslContext, null, Optional.absent());
public static InternalProtocolNegotiator.ProtocolNegotiator tls(
Copy link
Member

Choose a reason for hiding this comment

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

Is this not an api breaking change? Should we do function overloading here?

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.

3 participants