Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: allow direct access to message binary #19321

Closed
wants to merge 2 commits into from
Closed

Feature request: allow direct access to message binary #19321

wants to merge 2 commits into from

Conversation

adamkewley
Copy link

A gRPC-based project I'm working on requires signing requests (with RSA or HMAC). In our implementation, we concatenate the method name, relevant headers, and the message binary to create a digest (inspiration stole from this RFC draft). However, I couldn't find an easy way of accessing the message binary server-side (interceptors only give access to method + headers), so I had to hack this in.

I understand that this may not be suitable for streaming messages, etc. but I thought I'd contribute this PR to open a discussion on the idea. Overall, this change increases the lifetime of a message's binary buffer to be the same as the lifetime of the context, which will increase the overall (on-average) memory usage of a gRPC server because it gives the GC less to play with across the lifetime of one gRPC request.

@thelinuxfoundation
Copy link

Thank you for your pull request. Before we can look at your contribution, we need to ensure all contributors are covered by a Contributor License Agreement.

After the following items are addressed, please respond with a new comment here, and the automated system will re-verify.

Regards,
CLA GitHub bot

@gnossen
Copy link
Contributor

gnossen commented Jun 13, 2019

I haven't taken the time to fully digest the implications of this change yet, but I have two initial observations:

  1. It's not sufficient to just add a method to _server.py. The method will also need to be added to the Server ServicerContext interface in __init__.py
  2. Since this is a user-facing API change, it is going to require a gRFC.

@gnossen gnossen self-assigned this Jun 13, 2019
@adamkewley
Copy link
Author

@gnossen the method has been added to the Context's API, which is a user-facing API change that will apply on a per-message basis.

If any python devs know a way to get access to the gRPC message binary pre deserialization then that's my main requirement: the signing procedure being used requires direct access to those bytes.

@gnossen
Copy link
Contributor

gnossen commented Jun 13, 2019

@adamkewley Would it be possible to accomplish your use case with a custom deserializer?

@adamkewley
Copy link
Author

@gnossen possibly, but the deserializers that are currently matched against each gRPC method are generated using protobuf. I guess I could decorate a (hopefully non-generated) class with methods that do the signing step. However, anything further downstream (e.g. the implementation methods that override the stub) are already too late in the process :(

@thelinuxfoundation
Copy link

Thank you for your pull request. Before we can look at your contribution, we need to ensure all contributors are covered by a Contributor License Agreement.

After the following items are addressed, please respond with a new comment here, and the automated system will re-verify.

Regards,
CLA GitHub bot

@adamkewley
Copy link
Author

So, for my purposes (signing/encrypting a gRPC message), I needed to mod in the latest push I made. Essentially, it required adding a request_mapper and response_mapper to the outer API, so that our codebase could use those to map requests/responses hitting our gRPC server

@gnossen
Copy link
Contributor

gnossen commented Jun 15, 2019

I can't help but wonder if this use case wouldn't be better served by a complete set of client-side and server-side interceptors. The client-side support is already there, but server-side support is pending.

@adamkewley
Copy link
Author

Yes, something like that is pretty much exactly what's needed for this particular use-case. I wasn't sure what that type of feature would be called (the existing api already uses "interceptors"), so I missed this existing work. Thanks for pointing it out: I'll look into it.

@stale
Copy link

stale bot commented Dec 12, 2019

This issue/PR has been automatically marked as stale because it has not had any update (including commits, comments, labels, milestones, etc) for 180 days. It will be closed automatically if no further update occurs in 1 day. Thank you for your contributions!

@stale stale bot closed this Dec 19, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Mar 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants