-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[ProtoApiScrubber] Add response scrubber to the filter. #42145
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
Conversation
Signed-off-by: Sumit Kumar <sumitkmr@google.com>
Signed-off-by: Sumit Kumar <sumitkmr@google.com>
Signed-off-by: Sumit Kumar <sumitkmr@google.com>
Signed-off-by: Sumit Kumar <sumitkmr@google.com>
| // vice-versa. | ||
| GrpcFieldExtraction::MessageConverterPtr request_msg_converter_{nullptr}; | ||
|
|
||
| // Response message converter which converts Envoy Buffer data to StreamMessage (for scrubbing) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
High-level comment:
looking at the request vs response related fields, it seems that there are the same group of objects needed for each of these. Using a generic struct with the relevant fields that is initialized differently for each of them may reduce the copy-paste between the two.
(not AI for this PR, just high-level observation to take into account).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that makes sense. I'll add that in the backlog for now, will pick it up once the current lined-up items are complete for the filter.
| if (stream_message->message() == nullptr) { | ||
| // Expect end_stream=true when the MessageConverter signals an stream end. | ||
| ASSERT(end_stream); | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style-nit: please remove empty lines that don't split logical code segments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
|
|
||
| auto buf_convert_status = | ||
| response_msg_converter_->convertBackToBuffer(std::move(stream_message)); | ||
| RELEASE_ASSERT(buf_convert_status.ok(), "failed to convert message back to envoy buffer"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pretty sure I had reservations about this RELEASE_ASSERT in the request path.
I'm worried this will create an attack vector that may crash the proxy.
If this is needed, can you add a comment before these lines describing why the release-assert is necessary here (say compared to sending local reply)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, you are right. Although, the message converter is designed to be very robust, it is still possible that it can fail due to a bug introduced later. I've replaced release_assert() with rejectResponse which sends a local reply with appropriate error details. I'll make the change for request path in a separate PR.
|
|
||
| using ProtoApiScrubberResponsePassThroughTest = ProtoApiScrubberFilterTest; | ||
|
|
||
| TEST_F(ProtoApiScrubberResponsePassThroughTest, UnaryResponseSingleBuffer) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add one-liner comments describing these tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Signed-off-by: Sumit Kumar <sumitkmr@google.com>
sumitkmr2
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed comments, thanks!
| // vice-versa. | ||
| GrpcFieldExtraction::MessageConverterPtr request_msg_converter_{nullptr}; | ||
|
|
||
| // Response message converter which converts Envoy Buffer data to StreamMessage (for scrubbing) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that makes sense. I'll add that in the backlog for now, will pick it up once the current lined-up items are complete for the filter.
| if (stream_message->message() == nullptr) { | ||
| // Expect end_stream=true when the MessageConverter signals an stream end. | ||
| ASSERT(end_stream); | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
|
|
||
| using ProtoApiScrubberResponsePassThroughTest = ProtoApiScrubberFilterTest; | ||
|
|
||
| TEST_F(ProtoApiScrubberResponsePassThroughTest, UnaryResponseSingleBuffer) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
|
|
||
| auto buf_convert_status = | ||
| response_msg_converter_->convertBackToBuffer(std::move(stream_message)); | ||
| RELEASE_ASSERT(buf_convert_status.ok(), "failed to convert message back to envoy buffer"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, you are right. Although, the message converter is designed to be very robust, it is still possible that it can fail due to a bug introduced later. I've replaced release_assert() with rejectResponse which sends a local reply with appropriate error details. I'll make the change for request path in a separate PR.
adisuissa
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks
Commit Message: Add response scrubber to the filter.
Additional Description:
Risk Level: None.
Testing: UTs are added. Integration tests will be added in a separate PR once IT setup PR ([ProtoApiScrubber] Add Integration Tests #42121) gets submitted.
Docs Changes: None.
Release Notes: None.
Platform Specific Features:
[Optional Runtime guard:]
[Optional Fixes #Issue]
[Optional Fixes commit #PR or SHA]
[Optional Deprecated:]
[Optional API Considerations:]