Skip to content

Set-Metadata HTTP filter#16400

Merged
htuch merged 14 commits intoenvoyproxy:mainfrom
curiefense:feature/ext_add_metadata
May 25, 2021
Merged

Set-Metadata HTTP filter#16400
htuch merged 14 commits intoenvoyproxy:mainfrom
curiefense:feature/ext_add_metadata

Conversation

@aguinet
Copy link
Copy Markdown
Contributor

@aguinet aguinet commented May 9, 2021

Commit Message: HTTP filter that can set or update dynamic metadata.

Additional Description:

This extension simply allows to add user-defined dynamic metadata. This is intended to be used with matchers, so that the "result" of a matching process can imply specific metadata.

See issue #16266

Risk Level: Medium
Testing: Unit tests for the extension are added
Docs Changes: A small documentation for the extension is added in docs/root/configuration/http/http_filters
Release Notes: N/A
Platform Specific Features: N/A
[Optional Runtime guard:]
[Optional Fixes #Issue]
[Optional Deprecated:]
[Optional API Considerations:]

HTTP filter that can set or update dynamic metadata.

Signed-off-by: Adrien Guinet <adrien@reblaze.com>
@repokitteh-read-only
Copy link
Copy Markdown

CC @envoyproxy/api-shepherds: Your approval is needed for changes made to api/envoy/.
envoyproxy/api-shepherds assignee is @htuch
CC @envoyproxy/api-watchers: FYI only for changes made to api/envoy/.

🐱

Caused by: #16400 was opened by aguinet.

see: more, trace.

Copy link
Copy Markdown
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

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

Looks good generally, just want to verify the details around merge.

"//envoy/extensions/filters/http/ratelimit/v3:pkg",
"//envoy/extensions/filters/http/rbac/v3:pkg",
"//envoy/extensions/filters/http/router/v3:pkg",
"//envoy/extensions/filters/http/set_metadata/v3:pkg",
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.

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.

I tried to added myself, but it asked for a second maintainer. Who should I add? @snowp as he is sponsoring it :) ?

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.

Yes, Snow and you.

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.

Sorry missed this answer. Done in d139579 !

// The metadata namespace.
string metadata_namespace = 1 [(validate.rules).string = {min_len: 1}];

// The value to update the namespace with.
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.

RST link to docs providing details of the merge semantics.

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.

Should be fixed in 9d26ca2

aguinet added 5 commits May 10, 2021 19:52
@htuch review: coding style + cleanup + documentation improvements

Signed-off-by: Adrien Guinet <adrien@reblaze.com>
Implement a structure update algorithm that merges keys together, with a
"last-one-win" strategy for scalar values, and appending for lists.

Signed-off-by: Adrien Guinet <adrien@reblaze.com>
Use StructUtil::update, and update documentation about keys that have
different types between the original and new structure.

Signed-off-by: Adrien Guinet <adrien@reblaze.com>
Add documentation for StructUtil::update

Signed-off-by: Adrien Guinet <adrien@reblaze.com>
Signed-off-by: Adrien Guinet <adrien@reblaze.com>
review by @htuch

Signed-off-by: Adrien Guinet <adrien@reblaze.com>
@aguinet
Copy link
Copy Markdown
Contributor Author

aguinet commented May 14, 2021

@htuch it looks like this conflicts with main. Should I rebase on main and squash into two commits? (one for StructUtil::update and one for the extension)

@htuch
Copy link
Copy Markdown
Member

htuch commented May 14, 2021

@aguinet in general, you should have a flow that you never rebase after creating a PR. Instead do local merges from origin/main.

Copy link
Copy Markdown
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

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

Thanks. The merging now makes more sense. One question I have is how this extension relates to the header_to_metadata filter? https://github.com/envoyproxy/envoy/blob/main/api/envoy/extensions/filters/http/header_to_metadata/v3/header_to_metadata.proto

It seems that really we want both to behave similarly, and if we were designing from scratch they would be somewhat unified. We also have other filters, e.g. ext_authz, that set dynamic metadata base on return values from remote servers. Ideally these have aligned merge semantics.

We don't need to boil the ocean here, but having some explanation and game plan to get consistent behaviors would be helpful.

@aguinet
Copy link
Copy Markdown
Contributor Author

aguinet commented May 14, 2021

Thanks. The merging now makes more sense. One question I have is how this extension relates to the header_to_metadata filter? https://github.com/envoyproxy/envoy/blob/main/api/envoy/extensions/filters/http/header_to_metadata/v3/header_to_metadata.proto

It seems that really we want both to behave similarly, and if we were designing from scratch they would be somewhat unified. We also have other filters, e.g. ext_authz, that set dynamic metadata base on return values from remote servers. Ideally these have aligned merge semantics.

We don't need to boil the ocean here, but having some explanation and game plan to get consistent behaviors would be helpful.

These are good questions I tried to resolve before starting this. Let me first explain my use case. What we'd like to do is leverage the matching engine to add "tags", and log this tag and/or take decisions according to these tags. This is configurable by the user in the end, and would be transformed to an envoy configuration file.

As an example, I could add the tag "tag0" if the cookie "mycookie" matches a given regular expression, and another tag "tag1" if the IP comes from AS3215. I would like these two tags to be logged, and let's say block the request if the two of them are there.

In order to reuse the matching engine, we would configure HTTP filters like this:

# Wrapped into a first matcher
- filter0: 
    @type: set_metadata
    namespace: mynamespace
    value:
      tags:
       tag0: 1
#  Wrapped into a second matcher
- filter1:
    @type: set_metadata 
    namespace: mynamespace
    value:
      tags:
        tag1: 1

In order to get the two tags, I need the current merging strategy.

Now about header_to_metadata. From my understanding, it's just setting strings (potentially base64 ones) or integers values, taken from headers. There are no issue of potentially merging two different recursive structures. But I might be missing something here.

I just checked ext_authz, the only place I found it setting metadata is here:

if (!response->dynamic_metadata.fields().empty()) {
decoder_callbacks_->streamInfo().setDynamicMetadata(HttpFilterNames::get().ExtAuthorization,
response->dynamic_metadata);
}
. This looks like there are no merging strategy involved, but I don't know the use cases enough to know if that even makes sens!

Signed-off-by: Adrien Guinet <adrien@reblaze.com>
@aguinet
Copy link
Copy Markdown
Contributor Author

aguinet commented May 14, 2021

@aguinet in general, you should have a flow that you never rebase after creating a PR. Instead do local merges from origin/main.

Okay. So I'll end up with a merge commit, right? Should I squash all of this before merging?

@htuch
Copy link
Copy Markdown
Member

htuch commented May 16, 2021

Thanks for the explanation. I agree this makes sense. @envoyproxy/api-shepherds I'd like us to think about adopting this as the standard merge strategy going forward, so we don't have inconsistent merging when filters are performing dynamic metadata update.

Okay. So I'll end up with a merge commit, right? Should I squash all of this before merging?

Yes, add a merge commit. You can't squash (since this is a rebase) once a PR has started. We will squash everything prior to the main merge once approved.

Copy link
Copy Markdown
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

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

Thanks; a bunch of API and code comments to address, I think it's in the right shape.
/wait


This filters adds or updates dynamic metadata with static data.

Dynamic metadata values are updated with the following scheme. If a key
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.

@envoyproxy/api-shepherds this differs from MergeFrom in that it supports merging structs together, e.g. if you have a disjoint namespace things compose as expected. I think this makes sense, but flagging this for consideration in case there is some alternate merging preferences.

* add constness when relevant
* s/T const&/const T&/
* explicit some types
* add missing tests (factory + decodeData)

Signed-off-by: Adrien Guinet <adrien@reblaze.com>
Signed-off-by: Adrien Guinet <adrien@reblaze.com>

class StructUtilTest : public ProtobufUtilityTest {
protected:
ProtobufWkt::Struct updateSimpleStruct(ProtobufWkt::Value const& v0,
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.

More const issues. Sorry if this seems nit-picky, but this style of const is different to the Envoy code base and consistency is important. There are some rare exceptions and we should fix them.

Can you just grep for const& in your difference from main and fix them all? Thanks.

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.

I'm sorry I thought I had checked them all... I completely understand the style consistency. Will indeed recheck this properly!

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.

Fixed in 45ca933 .

$ git diff main...feature/ext_add_metadata |grep 'const&' |wc -l
0

Hopefully I should be fine!

@htuch
Copy link
Copy Markdown
Member

htuch commented May 18, 2021

LGTM modulo nits and a main merge for conflict.

Signed-off-by: Adrien Guinet <adrien@reblaze.com>
htuch
htuch previously approved these changes May 20, 2021
Copy link
Copy Markdown
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

Needs main merge.

Signed-off-by: Adrien Guinet <adrien@reblaze.com>
@aguinet
Copy link
Copy Markdown
Contributor Author

aguinet commented May 20, 2021

@htuch main merged into the branch! Is there something else I need to do?

Thanks for the time you took for all the reviews and remarks!

@htuch
Copy link
Copy Markdown
Member

htuch commented May 21, 2021

@phlax do you know what is going on with this glint failure?

@phlax
Copy link
Copy Markdown
Member

phlax commented May 21, 2021

Signed-off-by: Adrien Guinet <adrien@reblaze.com>
@aguinet
Copy link
Copy Markdown
Contributor Author

aguinet commented May 21, 2021

@phlax
Copy link
Copy Markdown
Member

phlax commented May 21, 2021

Added a configuration to my vim to highlight these...

i have my editor (emacs) automatically remove/fix on save

htuch
htuch previously approved these changes May 23, 2021
Copy link
Copy Markdown
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

Signed-off-by: Adrien Guinet <adrien@reblaze.com>
@htuch
Copy link
Copy Markdown
Member

htuch commented May 23, 2021

@aguinet
Copy link
Copy Markdown
Contributor Author

aguinet commented May 23, 2021

@htuch yep, I've just pushed d82b20a to fix it!

@htuch htuch merged commit cbe08bb into envoyproxy:main May 25, 2021
@aguinet aguinet deleted the feature/ext_add_metadata branch May 25, 2021 08:45
@aguinet
Copy link
Copy Markdown
Contributor Author

aguinet commented May 25, 2021

\o/ Thanks a lot for the merge @htuch !

leyao-daily pushed a commit to leyao-daily/envoy that referenced this pull request Sep 30, 2021
This extension simply allows to add user-defined dynamic metadata. This is intended to be used with matchers, so that the "result" of a matching process can imply specific metadata.

See issue envoyproxy#16266

Risk Level: Medium
Testing: Unit tests for the extension are added
Docs Changes: A small documentation for the extension is added in docs/root/configuration/http/http_filters

Signed-off-by: Adrien Guinet <adrien@reblaze.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