Skip to content

Update ServerInterceptors.java to support different marshallers for Request and Response messages. #9870

@ioanbsu

Description

@ioanbsu

Is your feature request related to a problem?

I'm trying to enable e2e encryption in grpc sever side using Marshallers. There is a very handy ServerInterceptors#useMarshalledMessages(ServerServiceDefinition, MethodDescriptor.Marshaller) that allows me to specify marshaller that can intercept request and response and modify it before passing bytes to serialization and actual sever processing logic. The problem that I have is that for e2e encryption I need to perform different actions: for request it is decryption and for response it is encryption. Thus I need to separate marshallers: one for requests(doing decryption) and another one for responses(doing encryption).

Describe the solution you'd like

Add(aka override) existing method ServerInterceptors#useMarshalledMessages(ServerServiceDefinition, MethodDescriptor.Marshaller) to be ServerInterceptors#useMarshalledMessages(ServerServiceDefinition, MethodDescriptor.Marshaller, MethodDescriptor.Marshaller).

Describe alternatives you've considered

There are couple alternatives to enable e2e encryption in grpc server, how ever they all have drawbacks:

  1. Use Compressors with custom codecs to do encryption/decryption.
    Drawback: it is not what compressors are meant to be used for and they fit the e2e encryption use case poorly, despite the fact there is a way to make e2e encryption to work with codecs.
  2. Shift all the code to generate needed ServerServiceDefinition outside of the grpc.io library. In other words, don't change ServerInterceptors.java in grpc.io, but instead create ServerServiceDefinition with e2e encryption marshallers in the code that uses grpc.io and just just pass this ServerServiceDefinition to server builder when grpc server is built.
    Drawback: unlike with ServerInterceptors.java case, creation of such ServerServiceDefinition outside of ServerInterceptors.java will require significant amount of code to be written. The ServerInterceptors.java has a lot of helper methods that are not public and will have to be almost fully copy-pasted(including several of non public methods and classes outside of ServerInterceptors.java that available to ServerInterceptors.java but not to the code that uses grpc.io) to the code of application that wants to enable e2e encryption for grpc server.

Additional context

n/a

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions