Fix ClassCastException for otherName SAN entries during inter-cluster handshake#6137
Fix ClassCastException for otherName SAN entries during inter-cluster handshake#6137sashetov wants to merge 2 commits intoopensearch-project:mainfrom
Conversation
… handshake (opensearch-project#6090) Signed-off-by: sashetov <alexander@vassilevski.com>
Signed-off-by: sashetov <alexander@vassilevski.com>
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
Description
Bug fix.
DefaultInterClusterRequestEvaluator#isInterClusterRequestthrewClassCastExceptionduring the transport handshake whenever a peer's certificate contained anotherNameSAN (e.g. UPN, OID1.3.6.1.4.1.311.20.2.3, common on Windows-CA-issued certs), preventing affected nodes from joining the cluster. The parser walked each inner SAN list with anIteratorand cast every even-indexed element toint, which works for two-element entries but breaks onotherNameentries that return three or more elements with an OID String at index 2. The fix reads each entry as a single[typeId, value]pair viaian.get(0)/ian.get(1)with aninstanceof Integerguard, matching the Java API contract and the existing pattern inSPIFFEPrincipalExtractor.Before
DefaultInterClusterRequestEvaluatorTest#testIsInterClusterRequest_upnOtherNameInSan_doesNotThrowconstructs anX509Certificatewhose SAN list contains a UPN-shapedotherNameentry:[0, "user@example.com", "1.3.6.1.4.1.311.20.2.3"]. With the parser reverted to its pre-fix state, the test reproduces the exact exception from the bug report:The exception message and class are identical to the one originally reported in #6090.
After
Restore the fix and re-run the full test class:
All four cases pass
Checkstyle is also clean:
Issues Resolved
Closes #6090
This is not a backport.
These changes do not introduce new permissions and require no companion PR in the security dashboards plugin.
Testing
Adds a new unit test class
DefaultInterClusterRequestEvaluatorTest(Mockito-based, mirroring the pattern inSPIFFEPrincipalExtractorTest) with four cases:testIsInterClusterRequest_upnOtherNameInSan_doesNotThrow— direct repro of [BUG] OS handshake fails on certificate containing UPN in the Subject Alternative Names #6090; SAN list contains a 3-elementotherNameentry. Previously threwClassCastException; now returnsfalsecleanly.testIsInterClusterRequest_oidSanMatchesNodeOid_returnsTrue— sanity: aregisteredID(typeId 8) SAN with the configured node OID still returnstrue.testIsInterClusterRequest_oidSanAlongsideUpn_returnsTrue— mixed list (UPN otherName + DNS + matching OID) still resolves correctly without throwing.testIsInterClusterRequest_nullSan_returnsFalse— null SAN list is handled gracefully.No integration or manual testing was performed; the bug surface is fully covered by the unit-level repro because
getSubjectAlternativeNames()is the only entry point.Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.