Skip to content

xds: Add SNI related field in handshake info#8965

Open
eshitachandwani wants to merge 6 commits intogrpc:masterfrom
eshitachandwani:add_field_in_handshake_info
Open

xds: Add SNI related field in handshake info#8965
eshitachandwani wants to merge 6 commits intogrpc:masterfrom
eshitachandwani:add_field_in_handshake_info

Conversation

@eshitachandwani
Copy link
Member

@eshitachandwani eshitachandwani commented Mar 9, 2026

This PR is part of A101 implementation.

This PR does the following changes:

  1. Add sni and autoSniSanValidation field to handshake info.
  2. Change the TLS config building to add SNI if env variable is true (currently false by default so will not be set), and sni is present (currently set as empty in handshake so will not be set).
  3. Change verify function to match SANs against SNI if set and env variable and autoSniSanValidation is true (currently set to false by default).
  4. Set sni to empty and autoSniSanValidation to false by default when creating handshake info in clusterimpl
  5. Adds tests to verify the happy and failure cases of handshake.

In the next PR :

  1. Will decide between hostname and SNI from CDS update in clusterimpl balancer.
  2. Add end to end tests to verify the SNI flow.

RELEASE NOTES: None

@eshitachandwani eshitachandwani added this to the 1.81 Release milestone Mar 9, 2026
@eshitachandwani eshitachandwani added Type: Feature New features or improvements in behavior Area: xDS Includes everything xDS related, including LB policies used with xDS. labels Mar 9, 2026
@codecov
Copy link

codecov bot commented Mar 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.10%. Comparing base (fd53961) to head (7f99e03).
⚠️ Report is 9 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8965      +/-   ##
==========================================
- Coverage   83.26%   83.10%   -0.16%     
==========================================
  Files         410      411       +1     
  Lines       32576    32744     +168     
==========================================
+ Hits        27123    27213      +90     
- Misses       4062     4151      +89     
+ Partials     1391     1380      -11     
Files with missing lines Coverage Δ
internal/credentials/xds/handshake_info.go 93.71% <100.00%> (+0.46%) ⬆️
internal/xds/balancer/clusterimpl/clusterimpl.go 86.34% <100.00%> (-1.48%) ⬇️
internal/xds/server/conn_wrapper.go 76.27% <100.00%> (ø)

... and 34 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@easwars easwars self-assigned this Mar 17, 2026
@easwars
Copy link
Contributor

easwars commented Mar 17, 2026

Change the environment variable to true

We probably don't want to do that until interop tests pass.

sanMatchers []matcher.StringMatcher // Only on the client side.
requireClientCert bool // Only on server side.
sni string // Only on client side, used for Server Name Indication in TLS handshake.
autoSniSanValidation bool // Only on client side, indicates whether to perform validation of SANs based on SNI value.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: In autoSniSanValidation, the Sni and San need to all caps. But that will make the field name be autoSNISANValidation which is not very readable. So, I think you need to get a little creative here.

Maybe sanValidationUsingSNI or something better?

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed to validateSANUsingSNI. Let me know if this sounds good.

// NewHandshakeInfo returns a new handshake info configured with the provided
// options.
func NewHandshakeInfo(rootProvider certprovider.Provider, identityProvider certprovider.Provider, sanMatchers []matcher.StringMatcher, requireClientCert bool) *HandshakeInfo {
func NewHandshakeInfo(rootProvider certprovider.Provider, identityProvider certprovider.Provider, sanMatchers []matcher.StringMatcher, requireClientCert bool, sni string, autoSniSanValidation bool) *HandshakeInfo {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here with the autoSniSanValidation parameter?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

}
return fmt.Errorf("xds: received DNS SANs: %v do not match the SNI: %v", certs[0].DNSNames, hi.sni)
}
// The SANs sent by the MeshCA are encoded as SPIFFE IDs. We need to
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: While you are here, could you please remove mentions of MeshCA. That is not something that we use anymore. The SANs are sent to us by the xDS control plane.

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed the comment to say that.

return nil
}
}
return fmt.Errorf("xds: received DNS SANs: %v do not match the SNI: %v", certs[0].DNSNames, hi.sni)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please ensure that these %vs actually are readable in the error message.

Copy link
Member Author

Choose a reason for hiding this comment

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

verified that it is readable

if _, err := certs[0].Verify(opts); err != nil {
return err
}
if envconfig.XDSSNIEnabled && hi.autoSniSanValidation && hi.sni != "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is the sentence from the gRFC:

Server SAN validation against SNI used: If auto_sni_san_validation is true in the UpstreamTlsContext gRPC client will perform matching for a SAN against the SNI used for the handshake if any. If auto_sni_san_validation is true but no SNI was sent, then validation will use any SAN matchers specified in the validation context instead. While XdsChannelCredentials without auto_sni_san_validation performs matching using any of DNS / URI / IPA SAN matchers specified in the validation context, when auto_sni_san_validation is set, validation will be performed using exact DNS matcher.

Based on the above, it is not clear to me whether we should perform matching against any of DNS/URI/IP SAN matchers specified in the validation context or should the validation be performed against exact DNS matcher, when auto_sni_san_validation is true but no SNI was sent.

Could you please confirm what other implementations do?

Copy link
Member Author

Choose a reason for hiding this comment

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

From my discussion with Kannan , we should fallback to the matchers provided and continue doing what was being done earlier, and so does Envoy as mentioned here in chat

Comment on lines +509 to +510
autoSniSanValidation bool
enableSniFlag bool
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Go initialisms here as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@easwars easwars assigned eshitachandwani and unassigned easwars Mar 17, 2026
@eshitachandwani
Copy link
Member Author

Change the environment variable to true

We probably don't want to do that until interop tests pass.

Got it! Changed the description too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: xDS Includes everything xDS related, including LB policies used with xDS. Type: Feature New features or improvements in behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants