Repository navigation
Conversation
Signed-off-by: Ambika Shankar <[email protected]>
Signed-off-by: Ambika Shankar <[email protected]>
Signed-off-by: Ambika Shankar <[email protected]>
Signed-off-by: Ambika Shankar <[email protected]>
Signed-off-by: Ambika Shankar <[email protected]>
|
CC @envoyproxy/api-shepherds: Your approval is needed for changes made to |
Signed-off-by: Ambika Shankar <[email protected]>
Signed-off-by: Ambika Shankar <[email protected]>
…common/expr from CODEOWNERS Signed-off-by: Ambika Shankar <[email protected]>
add more lazily evaluated cel functions Signed-off-by: Ambika Shankar <[email protected]>
Signed-off-by: Ambika Shankar <[email protected]>
Signed-off-by: Ambika Shankar <[email protected]>
Signed-off-by: Ambika Shankar <[email protected]>
Signed-off-by: Ambika Shankar <[email protected]>
… extensions/extensions_metadata Signed-off-by: Ambika Shankar <[email protected]>
Signed-off-by: Ambika Shankar <[email protected]>
|
/assign @RyanTheOptimist |
Signed-off-by: Ambika Shankar <[email protected]>
wjtracey
left a comment
There was a problem hiding this comment.
Overall looks good, @htuch to review from an Envoy-consistency perspective.
Another note: we may want to make the custom_vocabulary and related files explicitly have 'example' in their name, since they are reference implementations and not production code.
|
|
||
| // [#protodoc-title: RBAC CEL Custom Library] | ||
|
|
||
| // [#extension: envoy.rbac.custom_library_config.custom_library] |
There was a problem hiding this comment.
I think the custom CEL library isn't restricted to RBAC usage, so we should name it envoy.expr.custom_library_config.custom_library or similar (whatever is appropriate based on convention). e.g. the CEL matcher for the filter in #18064 will support extensible CEL as well.
| absl::StrCat("failed to register built-in functions: ", register_status.message())); | ||
| } | ||
|
|
||
| if (custom_library) { |
There was a problem hiding this comment.
Do we need to account for 'replace_default_library' here? if not, may want to add a comment about why.
There was a problem hiding this comment.
Why do we even have the replace_default_library option then?
There was a problem hiding this comment.
There are functions which are built-in to CEL (https://github.com/google/cel-spec/blob/master/doc/langdef.md#standard-definitions). I don't think anyone would want to replace those.
Then are envoy attributes (https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/advanced/attributes) which someone could potentially want to override with custom definitions.
I think I see what you're saying. Remove replace_default_library and always replace the the default library in the event of overlap?
There was a problem hiding this comment.
This seems good to me! (may be my fault for suggesting the idea of a knob to tweak this in the first place, some months back)
There was a problem hiding this comment.
Ah, right, that makes sense. Maybe this can be resolved if you share this explanation of the distinction between CEL and Envoy built-ins in the proto documentation for replace_default_library_in_case_of_overlap.
| Protobuf::Arena* arena) const { | ||
| // using arena so that it will not be unused | ||
| arena->SpaceUsed(); | ||
| if (args[0].type() == CelValue::Type::kInt64 && args[1].type() == CelValue::Type::kInt64) { |
There was a problem hiding this comment.
Here and below check args size as well?
There was a problem hiding this comment.
It seems this checking (number of args and their types) is done for us.
| CustomVocabularyName, std::make_unique<CustomVocabularyWrapper>( | ||
| arena, info, request_headers, response_headers, response_trailers)); | ||
| // functions | ||
| absl::Status status; |
There was a problem hiding this comment.
Perhaps explicitly call this out as lazy functions, and mention that the real benefit here is that they can be built be constructed at evaluation time, and so can be, e.g. influenced by the input params (headers etc).
| : arena_(arena), info_(info) { | ||
| request_headers_ = request_headers; | ||
| response_headers_ = response_headers; | ||
| response_trailers_ = response_trailers; |
There was a problem hiding this comment.
Can we consistently use the initializer list here?
| if (policy.second.has_condition()) { | ||
| builder_ = Expr::createBuilder(&constant_arena_); | ||
| builder_ = | ||
| Expr::createBuilder(&constant_arena_, custom_library_ ? custom_library_.get() : nullptr); |
There was a problem hiding this comment.
I believe this is equivalent to:
| Expr::createBuilder(&constant_arena_, custom_library_ ? custom_library_.get() : nullptr); | |
| Expr::createBuilder(&constant_arena_, custom_library_.get()); |
| for (const auto& policy : policies_) { | ||
| if (policy.second->matches(connection, headers, info)) { | ||
| if (policy.second->matches(connection, headers, info, | ||
| (custom_library_) ? custom_library_.get() : nullptr)) { |
There was a problem hiding this comment.
Same as above, I think the simpler version works:
| (custom_library_) ? custom_library_.get() : nullptr)) { | |
| custom_library_.get())) { |
use initializer list in CustomVocabularyWrapper constructor remove unnecessary type checks from custom_functions Signed-off-by: Ambika Shankar <[email protected]>
Signed-off-by: Ambika Shankar <[email protected]>
RyanTheOptimist
left a comment
There was a problem hiding this comment.
Good progress! Please add tests to cover the new codepaths.
| // [#protodoc-title: RBAC CEL Custom Library] | ||
|
|
||
| // [#extension: envoy.rbac.custom_library_config.custom_library] | ||
| message CustomLibraryConfig { |
There was a problem hiding this comment.
Please add a comment which describes the purpose of this message, and another for the field below.
There was a problem hiding this comment.
"CustomLibraryConfig" is a rather generic sounding name. Is "Custom Library" a term of art in this space?
There was a problem hiding this comment.
(related to the long comment I just added in custom_library.h) For both this comment and my one above, likely what we want is to rename this class and file for something like 'ExampleCustomCELVocabularyConfig' then in rbac.proto rename the field 'custom_library_config' to 'custom_cel_vocabulary_config' and there and elsewhere (in the Base factory) name the category of extensions something rbac-agnostic, like 'envoy.expr.custom_cel_vocabluary' or similar.
There was a problem hiding this comment.
Vocabulary or attribute. Whatever is most native to CEL.
| rules: | ||
| action: DENY | ||
| policies: | ||
| # "deny-admin-clusters-endpoint-policy": |
There was a problem hiding this comment.
I wouldn't have expected to see commented-out content in these files. Can you say more about this?
| bool matches(const Expression& expr, const StreamInfo::StreamInfo& info, | ||
| const Http::RequestHeaderMap& headers); | ||
|
|
||
| bool matches(const Expression& expr, const StreamInfo::StreamInfo& info, |
There was a problem hiding this comment.
nit: Please add a brief comment which describes this method. In particular, it would be good to explain how custom_library is used (as opposed to the previous method).
| namespace Expr { | ||
| namespace Library { | ||
|
|
||
| class CustomVocabularyWrapper : public BaseWrapper { |
There was a problem hiding this comment.
nit: class comments, please.
| rules.custom_library_config()); | ||
| custom_library_ = factory.createLibrary(rules.custom_library_config(), validation_visitor); | ||
| } else { | ||
| custom_library_ = nullptr; |
There was a problem hiding this comment.
nit: custom_library_ is a unique_ptr which is default initialized to nullptr, so this else clause it not needed.
| bool matches(const Network::Connection& connection, const Envoy::Http::RequestHeaderMap& headers, | ||
| const StreamInfo::StreamInfo&) const override; | ||
|
|
||
| bool matches(const Network::Connection& connection, const Envoy::Http::RequestHeaderMap& headers, |
There was a problem hiding this comment.
I notice that we have one matches() method which overrides a method and another matches() method which does not override a method. I think this might be slightly confusing. Can we rename the non-override method to something else? matchesCustom? customMatch? matchesWithCustomLibrary?
|
/retest |
|
Retrying Azure Pipelines: |
|
/retest |
|
Retrying Azure Pipelines: |
| constexpr absl::string_view EagerEvalFuncNameGetNextInt = "GetNextInt"; | ||
| constexpr absl::string_view EagerEvalFuncNameGetSquareOf = "GetSquareOf"; | ||
|
|
||
| class CustomLibrary { |
There was a problem hiding this comment.
Slightly related to my comment about adding 'example' to the reference implementation files (custom_vocabulary.h and others) - I realize now that this class/file is a mix of production code and example implementation code: I think really what we want is the following: (note I'm also suggesting renaming per @RyanTheOptimist's other comment about 'Custom Library' being ambiguous)
Split CustomLibrary into two classes
- 'CustomCELVocabulary' that is a pure interface which defines the methods that custom vocabularies must implement, and is the type used by RBAC and other filters (in the future)
- And 'ExampleCustomCELVocabulary' or similar that inherits from 'CustomCELVocabulary' and exists in its own file(s). This class would be the reference implementation that has member variables etc, and its files would define the play/example functions and their names 'LazyEvalFuncNameGetDouble' etc. We'd rename 'CustomLibraryFactory' to 'ExampleCustomCELVocabularyFactory' as well.
htuch
left a comment
There was a problem hiding this comment.
Really cool to see this coming together @ashankar1, I think this will be a very powerful extension capability. I gather this is still draft, so left a few high level comments and nits.
| // The policies are evaluated in lexicographic order of the policy name. | ||
| map<string, Policy> policies = 2; | ||
|
|
||
| // [#extension-category: envoy.rbac.custom_library_config] |
There was a problem hiding this comment.
Regarding naming, I prefer not to use "library" here, it's a bit too generic. "Custom attributes" is what I think is being added.
|
|
||
| // [#protodoc-title: RBAC CEL Custom Library] | ||
|
|
||
| // [#extension: envoy.rbac.custom_library_config.custom_library] |
| // [#protodoc-title: RBAC CEL Custom Library] | ||
|
|
||
| // [#extension: envoy.rbac.custom_library_config.custom_library] | ||
| message CustomLibraryConfig { |
There was a problem hiding this comment.
Vocabulary or attribute. Whatever is most native to CEL.
| custom_library_config: | ||
| name: envoy.rbac.custom_library_config.custom_library | ||
| typed_config: | ||
| "@type": type.googleapis.com/envoy.extensions.rbac.custom_library_config.v3.CustomLibraryConfig |
There was a problem hiding this comment.
Is this an example CEL extension? I'm wondering what its intent is given it has a field governing its replacement semantics but not anything else.
|
|
||
| "envoy.formatter.metadata": "//source/extensions/formatter/metadata:config", | ||
| "envoy.formatter.req_without_query": "//source/extensions/formatter/req_without_query:config", | ||
| "envoy.formatter.metadata": "//source/extensions/formatter/metadata:config", |
There was a problem hiding this comment.
Nit: looks like the format changes in this file should be undone.
| const auto& typed_config = | ||
| MessageUtil::downcastAndValidate<const envoy::config::core::v3::TypedExtensionConfig&>( | ||
| config, validation_visitor); | ||
| const auto custom_library_config = MessageUtil::anyConvertAndValidate<CustomLibraryConfig>( |
There was a problem hiding this comment.
I don't think individual extensions should need to do this kind of conversion. Instead, their factories should follow similar patterns as in other extensions. Maybe take a look at the templating that happens in various factory_base.h.
| absl::StrCat("failed to register built-in functions: ", register_status.message())); | ||
| } | ||
|
|
||
| if (custom_library) { |
There was a problem hiding this comment.
Why do we even have the replace_default_library option then?
| option java_multiple_files = true; | ||
| option (udpa.annotations.file_status).package_version_status = ACTIVE; | ||
|
|
||
| // [#protodoc-title: RBAC CEL Custom Library] |
There was a problem hiding this comment.
This comes up in other comments, but being clear on the distinction between the extension type and the example instance we are providing to show the use of this extension type will help reduce ambiguity. Right now, both the extension type and the extension instance have the same name.
|
This pull request has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in 7 days if no further activity occurs. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions! |
|
This pull request has been automatically closed because it has not had activity in the last 37 days. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions! |
Extensible CEL Vocabulary 18063
Commit Message:
Additional Description:
Risk Level:
Testing:
Docs Changes:
Release Notes:
Platform Specific Features:
[Optional Runtime guard:]
[Optional Fixes #Issue]
[Optional Fixes commit #PR or SHA]
[Optional Deprecated:]
[Optional API Considerations:]