-
Notifications
You must be signed in to change notification settings - Fork 5.3k
filter: add conditions to access control filter #7716
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
43 commits
Select commit
Hold shift + click to select a range
3d4f7aa
Initial ABAC filter
kyessenov beb197c
typos
kyessenov e914f46
Merge remote-tracking branch 'upstream/master' into abac_filter_needs…
kyessenov ec74571
review
kyessenov 97efd6d
spelling
kyessenov f3668b2
undo watermark
kyessenov dca0933
Merge remote-tracking branch 'upstream/master' into abac_filter_needs…
kyessenov 8e80999
review feedback
kyessenov 970b361
review feedback
kyessenov ebf4c4a
review feedback
kyessenov d1fd462
add code owners
kyessenov 1235c7d
Merge remote-tracking branch 'upstream/master' into abac_filter_needs…
kyessenov 41220da
update cel-cpp
kyessenov 982e3fd
combine engines
kyessenov c31b4a7
make arena explicit
kyessenov e309dd8
more attributes
kyessenov 6cdbe8e
build fix
kyessenov f934dda
refactor
kyessenov bf99900
fix unit tests
kyessenov 6861b98
Merge remote-tracking branch 'upstream/master' into abac_filter_needs…
kyessenov b27790a
unit tests
kyessenov 9393ca9
fix api
kyessenov 5d44fea
add metadata test
kyessenov 784a970
release note
kyessenov c081695
typo
kyessenov 9f812b5
Merge remote-tracking branch 'upstream/master' into abac_filter_needs…
kyessenov 184fe6b
add constant folding; use unique_ptr to avoid copying the engine
kyessenov 811fba6
merge fix
kyessenov 64c9201
merge fix
kyessenov 684d473
apply a patch for gcc
kyessenov 08fe702
more specific patch
kyessenov 580a79f
fix the macro specializer
kyessenov 8f72a50
oops, reverse the patch
kyessenov a2a9a7f
Merge remote-tracking branch 'upstream/master' into abac_filter_needs…
kyessenov f86eadf
update re2 import
kyessenov b9c755c
Merge remote-tracking branch 'upstream/master' into abac_filter_needs…
kyessenov 532ed67
align with ext_authz by using source and destination
kyessenov c1f1890
bump up coverage
kyessenov aed67b6
Merge remote-tracking branch 'upstream/master' into abac_filter_needs…
kyessenov 76b6788
update cel-cpp
kyessenov a0daefa
Merge remote-tracking branch 'upstream/master' into abac_filter_needs…
kyessenov 753b352
merge fix
kyessenov 8df3414
bump up coverage
kyessenov 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
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
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
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
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
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
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
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
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,34 @@ | ||
| licenses(["notice"]) # Apache 2 | ||
|
|
||
| load( | ||
| "//bazel:envoy_build_system.bzl", | ||
| "envoy_cc_library", | ||
| "envoy_package", | ||
| ) | ||
|
|
||
| envoy_package() | ||
|
|
||
| envoy_cc_library( | ||
| name = "evaluator_lib", | ||
| srcs = ["evaluator.cc"], | ||
| hdrs = ["evaluator.h"], | ||
| deps = [ | ||
| ":context_lib", | ||
| "//source/common/http:utility_lib", | ||
| "//source/common/protobuf", | ||
| "@com_google_cel_cpp//eval/public:builtin_func_registrar", | ||
| "@com_google_cel_cpp//eval/public:cel_expr_builder_factory", | ||
| "@com_google_cel_cpp//eval/public:cel_expression", | ||
| "@com_google_cel_cpp//eval/public:cel_value", | ||
| ], | ||
| ) | ||
|
|
||
| envoy_cc_library( | ||
| name = "context_lib", | ||
| srcs = ["context.cc"], | ||
| hdrs = ["context.h"], | ||
| deps = [ | ||
| "//source/common/http:utility_lib", | ||
| "@com_google_cel_cpp//eval/public:cel_value", | ||
| ], | ||
| ) |
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,164 @@ | ||
| #include "extensions/filters/common/expr/context.h" | ||
|
|
||
| #include "absl/strings/numbers.h" | ||
| #include "absl/time/time.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Extensions { | ||
| namespace Filters { | ||
| namespace Common { | ||
| namespace Expr { | ||
|
|
||
| namespace { | ||
|
|
||
| absl::optional<CelValue> convertHeaderEntry(const Http::HeaderEntry* header) { | ||
| if (header == nullptr) { | ||
| return {}; | ||
| } | ||
| return CelValue::CreateString(header->value().getStringView()); | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
| absl::optional<CelValue> HeadersWrapper::operator[](CelValue key) const { | ||
| if (value_ == nullptr || !key.IsString()) { | ||
| return {}; | ||
| } | ||
| auto out = value_->get(Http::LowerCaseString(std::string(key.StringOrDie().value()))); | ||
| return convertHeaderEntry(out); | ||
| } | ||
|
|
||
| absl::optional<CelValue> RequestWrapper::operator[](CelValue key) const { | ||
| if (!key.IsString()) { | ||
| return {}; | ||
| } | ||
| auto value = key.StringOrDie().value(); | ||
|
|
||
| if (value == Headers) { | ||
| return CelValue::CreateMap(&headers_); | ||
| } else if (value == Time) { | ||
| return CelValue::CreateTimestamp(absl::FromChrono(info_.startTime())); | ||
| } else if (value == Size) { | ||
kyessenov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // it is important to make a choice whether to rely on content-length vs stream info | ||
| // (which is not available at the time of the request headers) | ||
| if (headers_.value_ != nullptr && headers_.value_->ContentLength() != nullptr) { | ||
| int64_t length; | ||
| if (absl::SimpleAtoi(headers_.value_->ContentLength()->value().getStringView(), &length)) { | ||
| return CelValue::CreateInt64(length); | ||
| } | ||
| } else { | ||
| return CelValue::CreateInt64(info_.bytesReceived()); | ||
| } | ||
| } else if (value == Duration) { | ||
| auto duration = info_.requestComplete(); | ||
| if (duration.has_value()) { | ||
| return CelValue::CreateDuration(absl::FromChrono(duration.value())); | ||
| } | ||
| } | ||
|
|
||
| if (headers_.value_ != nullptr) { | ||
| if (value == Path) { | ||
| return convertHeaderEntry(headers_.value_->Path()); | ||
| } else if (value == UrlPath) { | ||
| absl::string_view path = headers_.value_->Path()->value().getStringView(); | ||
| size_t query_offset = path.find('?'); | ||
| if (query_offset == absl::string_view::npos) { | ||
| return CelValue::CreateString(path); | ||
| } | ||
| return CelValue::CreateString(path.substr(0, query_offset)); | ||
| } else if (value == Host) { | ||
| return convertHeaderEntry(headers_.value_->Host()); | ||
| } else if (value == Scheme) { | ||
| return convertHeaderEntry(headers_.value_->Scheme()); | ||
| } else if (value == Method) { | ||
| return convertHeaderEntry(headers_.value_->Method()); | ||
| } else if (value == Referer) { | ||
| return convertHeaderEntry(headers_.value_->Referer()); | ||
| } else if (value == ID) { | ||
| return convertHeaderEntry(headers_.value_->RequestId()); | ||
| } else if (value == UserAgent) { | ||
| return convertHeaderEntry(headers_.value_->UserAgent()); | ||
| } else if (value == TotalSize) { | ||
| return CelValue::CreateInt64(info_.bytesReceived() + headers_.value_->byteSize()); | ||
| } | ||
| } | ||
| return {}; | ||
| } | ||
|
|
||
| absl::optional<CelValue> ResponseWrapper::operator[](CelValue key) const { | ||
| if (!key.IsString()) { | ||
| return {}; | ||
| } | ||
| auto value = key.StringOrDie().value(); | ||
| if (value == Code) { | ||
| auto code = info_.responseCode(); | ||
| if (code.has_value()) { | ||
| return CelValue::CreateInt64(code.value()); | ||
| } | ||
| } else if (value == Size) { | ||
| return CelValue::CreateInt64(info_.bytesSent()); | ||
| } else if (value == Headers) { | ||
| return CelValue::CreateMap(&headers_); | ||
| } else if (value == Trailers) { | ||
| return CelValue::CreateMap(&trailers_); | ||
| } | ||
| return {}; | ||
| } | ||
|
|
||
| absl::optional<CelValue> ConnectionWrapper::operator[](CelValue key) const { | ||
| if (!key.IsString()) { | ||
| return {}; | ||
| } | ||
| auto value = key.StringOrDie().value(); | ||
| if (value == UpstreamAddress) { | ||
| auto upstream_host = info_.upstreamHost(); | ||
| if (upstream_host != nullptr && upstream_host->address() != nullptr) { | ||
| return CelValue::CreateString(upstream_host->address()->asStringView()); | ||
| } | ||
| } else if (value == UpstreamPort) { | ||
| auto upstream_host = info_.upstreamHost(); | ||
| if (upstream_host != nullptr && upstream_host->address() != nullptr && | ||
| upstream_host->address()->ip() != nullptr) { | ||
| return CelValue::CreateInt64(upstream_host->address()->ip()->port()); | ||
| } | ||
| } else if (value == MTLS) { | ||
| return CelValue::CreateBool(info_.downstreamSslConnection() != nullptr && | ||
| info_.downstreamSslConnection()->peerCertificatePresented()); | ||
| } else if (value == RequestedServerName) { | ||
| return CelValue::CreateString(info_.requestedServerName()); | ||
| } | ||
|
|
||
| return {}; | ||
| } | ||
|
|
||
| absl::optional<CelValue> PeerWrapper::operator[](CelValue key) const { | ||
| if (!key.IsString()) { | ||
| return {}; | ||
| } | ||
| auto value = key.StringOrDie().value(); | ||
| if (value == Address) { | ||
| if (local_) { | ||
| return CelValue::CreateString(info_.downstreamLocalAddress()->asStringView()); | ||
| } else { | ||
| return CelValue::CreateString(info_.downstreamRemoteAddress()->asStringView()); | ||
| } | ||
| } else if (value == Port) { | ||
| if (local_) { | ||
| if (info_.downstreamLocalAddress()->ip() != nullptr) { | ||
| return CelValue::CreateInt64(info_.downstreamLocalAddress()->ip()->port()); | ||
| } | ||
| } else { | ||
| if (info_.downstreamRemoteAddress()->ip() != nullptr) { | ||
| return CelValue::CreateInt64(info_.downstreamRemoteAddress()->ip()->port()); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return {}; | ||
| } | ||
|
|
||
| } // namespace Expr | ||
| } // namespace Common | ||
| } // namespace Filters | ||
| } // namespace Extensions | ||
| } // namespace Envoy | ||
Oops, something went wrong.
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.
@kyessenov qq: does cel-cpp rely on specific commit of re2? Asking because it might conflict with #7878, or latest release (2019-08-01) is fine? cc @mattklein123
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.
There should be no difference between which version is used. I think I chose the latest version which I started this PR.
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.
OK that's fine.
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 was going to ask the same question. I'll switch this back a release version of re2 on a subsequent dependency PR.
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 will just fix this when I merge master.
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.
Thanks. Happy to help if necessary. Google3 doesn't really have versions for its repositories, and the upstream cel-cpp is continuously tested against head.