Skip to content

Ext cel - #19097

Closed
ashankar1 wants to merge 18 commits into
envoyproxy:mainfrom
ashankar1:ext-cel
Closed

Ext cel#19097
ashankar1 wants to merge 18 commits into
envoyproxy:mainfrom
ashankar1:ext-cel

Conversation

@ashankar1

@ashankar1 ashankar1 commented Nov 25, 2021 •

Copy link
Copy Markdown

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:]

@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: #19097 was opened by ashankar1.

see: more, trace.

@repokitteh-read-only repokitteh-read-only Bot added api deps Approval required for changes to Envoy's external dependencies labels Nov 25, 2021
@repokitteh-read-only

Copy link
Copy Markdown

CC @envoyproxy/api-shepherds: Your approval is needed for changes made to (api/envoy/|docs/root/api-docs/).
envoyproxy/api-shepherds assignee is @lizan
CC @envoyproxy/api-watchers: FYI only for changes made to (api/envoy/|docs/root/api-docs/).
CC @envoyproxy/dependency-shepherds: Your approval is needed for changes made to (bazel/.*repos.*\.bzl)|(bazel/dependency_imports\.bzl)|(api/bazel/.*\.bzl)|(.*/requirements\.txt)|(.*\.patch).
envoyproxy/dependency-shepherds assignee is @moderation

🐱

Caused by: #19097 was opened by ashankar1.

see: more, trace.

@ashankar1

Copy link
Copy Markdown
Author

/assign @RyanTheOptimist

@wjtracey wjtracey left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

+1

absl::StrCat("failed to register built-in functions: ", register_status.message()));
}

if (custom_library) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Do we need to account for 'replace_default_library' here? if not, may want to add a comment about why.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

will add a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why do we even have the replace_default_library option then?

@ashankar1 ashankar1 Dec 1, 2021 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Here and below check args size as well?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can we consistently use the initializer list here?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

ok

if (policy.second.has_condition()) {
builder_ = Expr::createBuilder(&constant_arena_);
builder_ =
Expr::createBuilder(&constant_arena_, custom_library_ ? custom_library_.get() : nullptr);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I believe this is equivalent to:

Suggested change
Expr::createBuilder(&constant_arena_, custom_library_ ? custom_library_.get() : nullptr);
Expr::createBuilder(&constant_arena_, custom_library_.get());

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

ok

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)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Same as above, I think the simpler version works:

Suggested change
(custom_library_) ? custom_library_.get() : nullptr)) {
custom_library_.get())) {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

ok

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 RyanTheOptimist left a comment

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.

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 {

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.

Please add a comment which describes the purpose of this message, and another for the field below.

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.

"CustomLibraryConfig" is a rather generic sounding name. Is "Custom Library" a term of art in this space?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

(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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Vocabulary or attribute. Whatever is most native to CEL.

Comment thread configs/rbac_cel.yaml
rules:
action: DENY
policies:
# "deny-admin-clusters-endpoint-policy":

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.

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,

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.

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 {

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.

nit: class comments, please.

rules.custom_library_config());
custom_library_ = factory.createLibrary(rules.custom_library_config(), validation_visitor);
} else {
custom_library_ = nullptr;

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.

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,

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.

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?

@phlax

phlax commented Nov 30, 2021

Copy link
Copy Markdown
Member

/retest

@repokitteh-read-only

Copy link
Copy Markdown

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #19097 (comment) was created by @phlax.

see: more, trace.

@phlax

phlax commented Nov 30, 2021

Copy link
Copy Markdown
Member

/retest

@repokitteh-read-only

Copy link
Copy Markdown

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #19097 (comment) was created by @phlax.

see: more, trace.

constexpr absl::string_view EagerEvalFuncNameGetNextInt = "GetNextInt";
constexpr absl::string_view EagerEvalFuncNameGetSquareOf = "GetSquareOf";

class CustomLibrary {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

ok

@htuch htuch self-assigned this Dec 1, 2021

@htuch htuch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

+1

// [#protodoc-title: RBAC CEL Custom Library]

// [#extension: envoy.rbac.custom_library_config.custom_library]
message CustomLibraryConfig {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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>(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

@yanavlasov yanavlasov self-assigned this Dec 1, 2021
@github-actions

github-actions Bot commented Jan 1, 2022

Copy link
Copy Markdown

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!

@github-actions github-actions Bot added the stale stalebot believes this issue/PR has not been touched recently label Jan 1, 2022
@github-actions

github-actions Bot commented Jan 8, 2022

Copy link
Copy Markdown

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!

@github-actions github-actions Bot closed this Jan 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api deps Approval required for changes to Envoy's external dependencies stale stalebot believes this issue/PR has not been touched recently

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants