-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[ProtoApiScrubber] Add directory skeleton and basic logic for field checker #41713
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
cda8575
Add FieldChecker and ProtoScrubber
sumitkmr2 6d9b5c1
Fix code format
sumitkmr2 4110bfb
Merge branch 'main' into fchecker
sumitkmr2 c905df9
Try fixing asan error
sumitkmr2 8c4b62e
Add directory skeleton and basic logic for field checker
sumitkmr2 8f99dae
Removing filter changes
sumitkmr2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
source/extensions/filters/http/proto_api_scrubber/scrubbing_util_lib/BUILD
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| load( | ||
| "//bazel:envoy_build_system.bzl", | ||
| "envoy_cc_library", | ||
| "envoy_extension_package", | ||
| ) | ||
|
|
||
| licenses(["notice"]) # Apache 2 | ||
|
|
||
| envoy_extension_package() | ||
|
|
||
| envoy_cc_library( | ||
| name = "scrubbing_util_lib", | ||
| srcs = [ | ||
| "field_checker.cc", | ||
| ], | ||
| hdrs = [ | ||
| "field_checker.h", | ||
| ], | ||
| deps = [ | ||
| "//source/common/protobuf", | ||
| "@com_google_protoprocessinglib//proto_processing_lib/proto_scrubber", | ||
| ], | ||
| ) | ||
24 changes: 24 additions & 0 deletions
24
source/extensions/filters/http/proto_api_scrubber/scrubbing_util_lib/field_checker.cc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| #include "source/extensions/filters/http/proto_api_scrubber/scrubbing_util_lib/field_checker.h" | ||
|
|
||
| #include "source/common/protobuf/protobuf.h" | ||
|
|
||
| #include "proto_processing_lib/proto_scrubber/field_checker_interface.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Extensions { | ||
| namespace HttpFilters { | ||
| namespace ProtoApiScrubber { | ||
|
|
||
| FieldCheckResults FieldChecker::CheckField(const std::vector<std::string>&, | ||
| const Protobuf::Field*) const { | ||
| return FieldCheckResults::kInclude; | ||
| } | ||
|
|
||
| FieldCheckResults FieldChecker::CheckType(const Protobuf::Type*) const { | ||
| return FieldCheckResults::kInclude; | ||
| } | ||
|
|
||
| } // namespace ProtoApiScrubber | ||
| } // namespace HttpFilters | ||
| } // namespace Extensions | ||
| } // namespace Envoy |
60 changes: 60 additions & 0 deletions
60
source/extensions/filters/http/proto_api_scrubber/scrubbing_util_lib/field_checker.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| #pragma once | ||
|
|
||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| #include "source/common/protobuf/protobuf.h" | ||
|
|
||
| #include "proto_processing_lib/proto_scrubber/field_checker_interface.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Extensions { | ||
| namespace HttpFilters { | ||
| namespace ProtoApiScrubber { | ||
|
|
||
| using proto_processing_lib::proto_scrubber::FieldCheckerInterface; | ||
| using proto_processing_lib::proto_scrubber::FieldCheckResults; | ||
| using proto_processing_lib::proto_scrubber::FieldFilters; | ||
|
|
||
| /** | ||
| * FieldChecker class encapsulates the scrubbing logic of `ProtoApiScrubber` filter. | ||
| * This `FieldChecker` would be integrated with `proto_processing_lib::proto_scrubber` library for | ||
| * protobuf payload scrubbing. The `CheckField()` method declared in the parent class | ||
| * `FieldCheckerInterface` and defined in this class is called by the | ||
| * `proto_processing_lib::proto_scrubber` library for each field of the protobuf payload to decide | ||
| * whether to preserve, remove or traverse it further. | ||
| */ | ||
| class FieldChecker : public FieldCheckerInterface { | ||
| public: | ||
| FieldChecker() {} | ||
|
|
||
| // This type is neither copyable nor movable. | ||
| FieldChecker(const FieldChecker&) = delete; | ||
| FieldChecker& operator=(const FieldChecker&) = delete; | ||
| ~FieldChecker() override {} | ||
|
|
||
| /** | ||
| * Returns whether the `field` should be included (kInclude), excluded (kExclude) | ||
| * or traversed further (kPartial). | ||
| */ | ||
| FieldCheckResults CheckField(const std::vector<std::string>& path, | ||
| const Protobuf::Field* field) const override; | ||
|
|
||
| /** | ||
| * Returns false as it currently doesn't support `google.protobuf.Any` type. | ||
| */ | ||
| bool SupportAny() const override { return false; } | ||
|
|
||
| /** | ||
| * Returns whether the `type` should be included (kInclude), excluded (kExclude) | ||
| * or traversed further (kPartial). | ||
| */ | ||
| FieldCheckResults CheckType(const Protobuf::Type* type) const override; | ||
|
|
||
| FieldFilters FilterName() const override { return FieldFilters::FieldMaskFilter; } | ||
| }; | ||
|
|
||
| } // namespace ProtoApiScrubber | ||
| } // namespace HttpFilters | ||
| } // namespace Extensions | ||
| } // namespace Envoy |
21 changes: 21 additions & 0 deletions
21
test/extensions/filters/http/proto_api_scrubber/scrubbing_util_lib/BUILD
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| load( | ||
| "//bazel:envoy_build_system.bzl", | ||
| "envoy_cc_test", | ||
| "envoy_package", | ||
| ) | ||
|
|
||
| licenses(["notice"]) # Apache 2 | ||
|
|
||
| envoy_package() | ||
|
|
||
| envoy_cc_test( | ||
| name = "field_checker_test", | ||
| srcs = ["field_checker_test.cc"], | ||
| deps = [ | ||
| "//source/common/protobuf", | ||
| "//source/extensions/filters/http/proto_api_scrubber/scrubbing_util_lib", | ||
| "//test/test_common:environment_lib", | ||
| "//test/test_common:utility_lib", | ||
| "@com_google_protoprocessinglib//proto_processing_lib/proto_scrubber", | ||
| ], | ||
| ) |
51 changes: 51 additions & 0 deletions
51
test/extensions/filters/http/proto_api_scrubber/scrubbing_util_lib/field_checker_test.cc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| #include "source/common/protobuf/protobuf.h" | ||
| #include "source/extensions/filters/http/proto_api_scrubber/scrubbing_util_lib/field_checker.h" | ||
|
|
||
| #include "test/test_common/utility.h" | ||
|
|
||
| #include "gtest/gtest.h" | ||
| #include "proto_processing_lib/proto_scrubber/field_checker_interface.h" | ||
|
|
||
| using proto_processing_lib::proto_scrubber::FieldCheckResults; | ||
| using proto_processing_lib::proto_scrubber::FieldFilters; | ||
|
|
||
| namespace Envoy { | ||
| namespace Extensions { | ||
| namespace HttpFilters { | ||
| namespace ProtoApiScrubber { | ||
| namespace { | ||
|
|
||
| class FieldCheckerTest : public ::testing::Test {}; | ||
|
|
||
| // With the current basic implementation, all fields are included. This test | ||
| // verifies that behavior for a few different field paths. Once field mask | ||
| // logic is added, this test suite should be expanded to cover exclusion, | ||
| // wildcards, and other scenarios. | ||
| TEST_F(FieldCheckerTest, IncludesSimpleField) { | ||
| FieldChecker field_checker; | ||
| Protobuf::Field simple_field; | ||
| simple_field.set_name("name"); | ||
| EXPECT_EQ(field_checker.CheckField({"name"}, &simple_field), FieldCheckResults::kInclude); | ||
| } | ||
|
|
||
| TEST_F(FieldCheckerTest, IncludesType) { | ||
| FieldChecker field_checker; | ||
| Protobuf::Type type; | ||
| EXPECT_EQ(field_checker.CheckType(&type), FieldCheckResults::kInclude); | ||
| } | ||
|
|
||
| TEST_F(FieldCheckerTest, SupportAny) { | ||
| FieldChecker field_checker; | ||
| EXPECT_FALSE(field_checker.SupportAny()); | ||
| } | ||
|
|
||
| TEST_F(FieldCheckerTest, FilterName) { | ||
| FieldChecker field_checker; | ||
| EXPECT_EQ(field_checker.FilterName(), FieldFilters::FieldMaskFilter); | ||
| } | ||
|
|
||
| } // namespace | ||
| } // namespace ProtoApiScrubber | ||
| } // namespace HttpFilters | ||
| } // namespace Extensions | ||
| } // namespace Envoy |
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.
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.
This dependency is added for the classes
FieldCheckerInterface,FieldCheckResults, etc.