Skip to content

[ProtoApiScrubber] Fixing header and trailer propagation in field checker #42293

Merged
adisuissa merged 31 commits intoenvoyproxy:mainfrom
sumitkmr2:it2
Dec 17, 2025
Merged

[ProtoApiScrubber] Fixing header and trailer propagation in field checker #42293
adisuissa merged 31 commits intoenvoyproxy:mainfrom
sumitkmr2:it2

Conversation

@sumitkmr2
Copy link
Copy Markdown
Contributor

@sumitkmr2 sumitkmr2 commented Nov 27, 2025

Commit Message: Fixing header and trailer propagation in field checker
Additional Description: The headers and trailers were not properly propagated to the field checker and hence, the match tree couldn't use these inputs. Rest of the envoy attributes (https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/advanced/attributes) are automatically available for matching and hence, additional plumbing is not required.
Risk Level: None
Testing: UTs and ITs added.
Docs Changes: None.
Release Notes: None.
Platform Specific Features: None.
[Optional Runtime guard:]
[Optional Fixes #Issue]
[Optional Fixes commit #PR or SHA]
[Optional Deprecated:]
[Optional API Considerations:]

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>
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: sumitkmr2 <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>
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>
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>
Signed-off-by: Sumit Kumar <sumitkmr@google.com>
@repokitteh-read-only
Copy link
Copy Markdown

As a reminder, PRs marked as draft will not be automatically assigned reviewers,
or be handled by maintainer-oncall triage.

Please mark your PR as ready when you want it to be reviewed!

🐱

Caused by: #42293 was opened by sumitkmr2.

see: more, trace.

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>
@sumitkmr2 sumitkmr2 changed the title Fixing header and trailer propagation in field checker [ProtoApiScrubber] Fixing header and trailer propagation in field checker Dec 12, 2025
@sumitkmr2
Copy link
Copy Markdown
Contributor Author

/retest

@sumitkmr2 sumitkmr2 marked this pull request as ready for review December 12, 2025 11:54
@sumitkmr2 sumitkmr2 requested a review from adisuissa as a code owner December 12, 2025 11:54
@sumitkmr2
Copy link
Copy Markdown
Contributor Author

@adisuissa I'm working on fixing the Envoy/Check failure. It's taking time as the tests pass but the envoy step fails. Request you to please review the code and test changes in the meantime.

@phlax
Copy link
Copy Markdown
Member

phlax commented Dec 12, 2025

@sumitkmr2 gcc failure looks real (even if flaking)

Copy link
Copy Markdown
Contributor

@adisuissa adisuissa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, overall LGTM

FieldChecker(const ScrubberContext scrubber_context,
const Envoy::StreamInfo::StreamInfo* stream_info, const std::string& method_name,
const Envoy::StreamInfo::StreamInfo* stream_info,
const Http::RequestHeaderMap* request_headers,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OOC why is there a need to move between OptRef and pointers (for al the headers maps)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use of pointers here was intended to handle the optional nature of the headers and trailers, as the matching_data_ setters require valid references (so I needed a way to check for existence before dereferencing). I used pointers as a mechanism for nullable checks.

However, I agree that passing OptRef directly is more idiomatic for Envoy and avoids converting between types. I have updated the constructor signature to accept OptRef instead of raw pointers.

public:
// Validates whether the input type for the matcher is in the list of supported input types.
// Currently, only CEL input type (i.e., HttpAttributesCelMatchInput) is supported.
// ProtoApiScrubber filter supports all types of data inputs and hence, it returns
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. So what will the behavior (during a request processing by the ProtoApiScrubber filter) be if the matcher type is DestinationIPInput?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would result in a no-match. This is documented nicely in matching API documentation but I couldn't find it as of now. Right now, I can only find this: https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/advanced/matching/matching_api#inputs-and-matching-algorithms
I'll try to find the documentation which clearly stated that if you use response type inputs in the request flow, it would result in a no-match.
In essence, if someone is using matching API, we can be assured that they are aware of such nuances as it's clearly documented in envoy documentation.

: scrubber_context_(scrubber_context), matching_data_(*stream_info),
method_name_(method_name), filter_config_ptr_(filter_config) {}
method_name_(method_name), filter_config_ptr_(filter_config) {
// Populate matching data with whatever is available.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, the design here seems a bit leaky (a single field checker for both request and response, but used differently for each). I guess that is ok for now, but if further divergence from behavior needs to be done for request/response, it may be best to divide the two paths to different classes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are right. Although around 90-95% of the code is common for request and response, there's one part where they diverge. I'll keep that in mind in case that divergence becomes bigger but in principle, it would most probably not diverge as it's core job is to do scrubbing given a protobuf message. In case, the divergence becomes bigger, we might try to make it configurable instead.

Also, please note that it's not like request headers are only for request path, request headers can very well be utilized by response path.

Signed-off-by: Sumit Kumar <sumitkmr@google.com>
Copy link
Copy Markdown
Contributor Author

@sumitkmr2 sumitkmr2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed comments ,thanks!

: scrubber_context_(scrubber_context), matching_data_(*stream_info),
method_name_(method_name), filter_config_ptr_(filter_config) {}
method_name_(method_name), filter_config_ptr_(filter_config) {
// Populate matching data with whatever is available.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are right. Although around 90-95% of the code is common for request and response, there's one part where they diverge. I'll keep that in mind in case that divergence becomes bigger but in principle, it would most probably not diverge as it's core job is to do scrubbing given a protobuf message. In case, the divergence becomes bigger, we might try to make it configurable instead.

Also, please note that it's not like request headers are only for request path, request headers can very well be utilized by response path.

public:
// Validates whether the input type for the matcher is in the list of supported input types.
// Currently, only CEL input type (i.e., HttpAttributesCelMatchInput) is supported.
// ProtoApiScrubber filter supports all types of data inputs and hence, it returns
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would result in a no-match. This is documented nicely in matching API documentation but I couldn't find it as of now. Right now, I can only find this: https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/advanced/matching/matching_api#inputs-and-matching-algorithms
I'll try to find the documentation which clearly stated that if you use response type inputs in the request flow, it would result in a no-match.
In essence, if someone is using matching API, we can be assured that they are aware of such nuances as it's clearly documented in envoy documentation.

FieldChecker(const ScrubberContext scrubber_context,
const Envoy::StreamInfo::StreamInfo* stream_info, const std::string& method_name,
const Envoy::StreamInfo::StreamInfo* stream_info,
const Http::RequestHeaderMap* request_headers,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use of pointers here was intended to handle the optional nature of the headers and trailers, as the matching_data_ setters require valid references (so I needed a way to check for existence before dereferencing). I used pointers as a mechanism for nullable checks.

However, I agree that passing OptRef directly is more idiomatic for Envoy and avoids converting between types. I have updated the constructor signature to accept OptRef instead of raw pointers.

Signed-off-by: sumitkmr2 <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>
Signed-off-by: Sumit Kumar <sumitkmr@google.com>
Signed-off-by: Sumit Kumar <sumitkmr@google.com>
@sumitkmr2
Copy link
Copy Markdown
Contributor Author

@sumitkmr2 gcc failure looks real (even if flaking)

@phlax Yes, they were real failures caused by improper test cleanup. I've fixed those now.

Copy link
Copy Markdown
Contributor

@adisuissa adisuissa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@adisuissa adisuissa merged commit a7d4e04 into envoyproxy:main Dec 17, 2025
25 checks passed
TAOXUY pushed a commit to TAOXUY/envoy that referenced this pull request Dec 18, 2025
…cker (envoyproxy#42293)

Signed-off-by: Sumit Kumar <sumitkmr@google.com>
Signed-off-by: sumitkmr2 <sumitkmr@google.com>
Signed-off-by: Xuyang Tao <taoxuy@google.com>
grnmeira pushed a commit to grnmeira/envoy that referenced this pull request Mar 20, 2026
…cker (envoyproxy#42293)

Signed-off-by: Sumit Kumar <sumitkmr@google.com>
Signed-off-by: sumitkmr2 <sumitkmr@google.com>
Signed-off-by: Gustavo <grnmeira@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants