Fix MethodDescriptor lookup in ManualGrpcSecurityMetadataSource for gRPC 1.75.0+ #1190
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix MethodDescriptor lookup in ManualGrpcSecurityMetadataSource for gRPC 1.75.0+
Problem
With gRPC 1.75.0+,
MethodDescriptorinstances fromProtoReflectionServicedon't match instances fromServiceDescriptor.getMethods()when used as HashMap keys. This causes security configuration lookups to fail, resulting in ServerReflection and other services requiring authentication even when configured withAccessPredicate.permitAll().Symptoms
source.set(ServerReflectionGrpc.getServiceDescriptor(), AccessPredicate.permitAll())Root Cause
gRPC 1.75.0 changed
MethodDescriptorequality/identity behavior. WhenProtoReflectionServicecreatesMethodDescriptorinstances, they are not the same object instances returned byServerReflectionGrpc.getServiceDescriptor(), causing HashMap lookups by object identity to fail.The issue occurs in this lookup chain:
GrpcSecurityConfigurationcallssource.set(ServerReflectionGrpc.getServiceDescriptor(), AccessPredicate.permitAll())ServiceDescriptor.getMethods()ProtoReflectionServiceuses different MethodDescriptor instancesdefaultAttributes(deny all)Solution
Use
method.getFullMethodName()(String) as the HashMap key instead of relying on MethodDescriptor object identity. This provides stable, reliable lookups across all MethodDescriptor instances for the same method.Changes Made
Added name-based lookup map:
Updated
getAttributes()method:Updated all mutation methods:
set(ServiceDescriptor, AccessPredicate)- populates both mapsset(MethodDescriptor, AccessPredicate)- populates both mapsremove(ServiceDescriptor)- removes from both mapsremove(MethodDescriptor)- removes from both mapsUpdated
getAllConfigAttributes():Backward Compatibility
✅ Fully backward compatible - The fix maintains both lookup mechanisms (name-based and object-based) to ensure existing code continues to work. The name-based lookup is attempted first as it's more reliable with gRPC 1.75.0+, with fallback to object-based lookup.
Testing
Verified with gRPC 1.75.0 that:
permitAll()Test Case
Impact
Who is affected?
grpc-spring-boot-starter3.1.0.RELEASEManualGrpcSecurityMetadataSourcewith method-level security configurationBenefits
Risks
Related Issues
This issue is related to the gRPC 1.75.0 release and ProtoReflectionService deprecation:
ProtoReflectionServicein favor ofProtoReflectionServiceV1Checklist
Screenshots/Logs
Before fix - ServerReflection requires authentication:
After fix - ServerReflection works without authentication: