Skip to content

ext_authz: add dynamic_metadata_matchers and use them in the ext_authz HTTP implementation#14843

Closed
esmet wants to merge 13 commits intoenvoyproxy:mainfrom
esmet:ext-authz-http-metadata
Closed

ext_authz: add dynamic_metadata_matchers and use them in the ext_authz HTTP implementation#14843
esmet wants to merge 13 commits intoenvoyproxy:mainfrom
esmet:ext-authz-http-metadata

Conversation

@esmet
Copy link
Contributor

@esmet esmet commented Jan 27, 2021

Adds support for emitting dynamic metadata when using an HTTP authorization service. This is already possible when using a gRPC authorization service, so this change just connects the pipes on the HTTP side.

Commit Message: ext_authz: add dynamic_metadata_matchers and use them in the ext_authz HTTP implementation
Additional Description:
Risk Level: Low
Testing: New unit test
Docs Changes: Added documentation to API protos, similar to sibling fields.
Release Notes: ext_authz: added :ref:dynamic_metadata_from_headers <envoy_v3_api_field_extensions.filters.http.ext_authz.v3.AuthorizationResponse.dynamic_metadata_from_headers> to support emitting dynamic metadata from headers returned by an external authorization service via HTTP.
Fixes #14622

HTTP implementation

Signed-off-by: John Esmet <john.esmet@gmail.com>
@repokitteh-read-only
Copy link

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

🐱

Caused by: #14843 was opened by esmet.

see: more, trace.

@lizan
Copy link
Member

lizan commented Jan 27, 2021

/lgtm api

// *Status*, *Content-Length*, *WWWAuthenticate* and *Location* are automatically added.
type.matcher.v3.ListStringMatcher allowed_client_headers = 2;

// When this :ref:`list <envoy_api_msg_type.matcher.v3.ListStringMatcher>`. is set, authorization
Copy link
Contributor Author

Choose a reason for hiding this comment

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

typo near the .

Signed-off-by: John Esmet <john.esmet@gmail.com>
esmet added 4 commits January 28, 2021 16:27
Signed-off-by: John Esmet <john.esmet@gmail.com>
Signed-off-by: John Esmet <john.esmet@gmail.com>
Signed-off-by: John Esmet <john.esmet@gmail.com>
Signed-off-by: John Esmet <john.esmet@gmail.com>
@esmet esmet marked this pull request as ready for review January 29, 2021 20:25
@esmet esmet requested a review from dio as a code owner January 29, 2021 20:25
esmet added 2 commits January 29, 2021 20:33
Signed-off-by: John Esmet <john.esmet@gmail.com>
Signed-off-by: John Esmet <john.esmet@gmail.com>
@esmet
Copy link
Contributor Author

esmet commented Feb 2, 2021

/retest

@repokitteh-read-only
Copy link

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

🐱

Caused by: a #14843 (comment) was created by @esmet.

see: more, trace.

@lizan
Copy link
Member

lizan commented Feb 2, 2021

@dio can you do a first pass of review?

@dio dio self-assigned this Feb 7, 2021
Copy link
Member

@dio dio left a comment

Choose a reason for hiding this comment

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

Thank you for working on this! Looks good. Requesting for a better variable naming, and fixing some comments. Thank you!

const Http::HeaderMap& headers_;
const MatcherSharedPtr& matchers_;
const MatcherSharedPtr& append_matchers_;
const MatcherSharedPtr& dynamic_metadata_matchers_;
Copy link
Member

Choose a reason for hiding this comment

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

Sorry, can we rename this to to_dynamic_metadata_matchers_ or similar, headers_to_dynamic_metadata_matchers_? A bit confused if we look at only this. Probably add a comment that all of these matchers (matchers, append_matchers, ...) work against headers_.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good idea, this code is indeed getting hairy

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I went with to_dynamic_metadata_matchers

Comment on lines +70 to +71
std::string key{header.key().getStringView()};
std::string value{header.value().getStringView()};
Copy link
Member

Choose a reason for hiding this comment

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

Nit. const for both of it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

/**
* Returns a list of matchers used for selecting the headers to emit as dynamic metadata.
*/
const MatcherSharedPtr& dynamicMetadataMatchers() const { return dynamic_metadata_matchers_; }
Copy link
Member

Choose a reason for hiding this comment

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

The same as above, let's rename it to something more explicit (?).


const MatcherSharedPtr request_header_matchers_;
const MatcherSharedPtr client_header_matchers_;
const MatcherSharedPtr dynamic_metadata_matchers_;
Copy link
Member

Choose a reason for hiding this comment

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

Ditto with above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

(*metadata_fields)["x-metadata-header-2"] = ValueUtil::stringValue("4");

// When we call onSuccess() at the bottom of the test we expect that all the
// headers-to-remove in that http response to have been correctly extracted
Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I confused about this "headers-to-remove" comment. Do you mean all headers matched with the pattern defined by dynamic_metadata_from_headers?

Copy link
Member

Choose a reason for hiding this comment

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

s/http/HTTP.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this is bad copy paste. Let me fix it.

esmet added 5 commits February 9, 2021 16:26
…data

Signed-off-by: John Esmet <john.esmet@gmail.com>
Signed-off-by: John Esmet <john.esmet@gmail.com>
Signed-off-by: John Esmet <john.esmet@gmail.com>
Signed-off-by: John Esmet <john.esmet@gmail.com>
Signed-off-by: John Esmet <john.esmet@gmail.com>
@esmet
Copy link
Contributor Author

esmet commented Feb 22, 2021

@dio I addressed the code review feedback and I think this should be ready to go now.

@esmet
Copy link
Contributor Author

esmet commented Feb 22, 2021

@lizan friendly poke to take a pass and provide an API approval

Copy link
Member

@dio dio 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. Thank you!

@esmet
Copy link
Contributor Author

esmet commented Mar 9, 2021

@envoyproxy/api-shepherds sorry to bother, but can I ask for one more pass at the API portions and an approval if all looks good?

// response headers that have a correspondent match will be emitted as dynamic metadata, whose keys
// correspond to the name of the matched header and whose values are the respective values. When this
// list is *not* set, no additional dynamic metadata will be emitted. This metadata lives in a namespace
// specified by the canonical name of extension filter that requires it:
Copy link
Member

@htuch htuch Mar 10, 2021

Choose a reason for hiding this comment

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

@lizan @kyessenov I'm little concerned that we've moved to a model where type URL is the canonical name for extension filters but we continue to use these names in the API for other purposes. What exists in this PR is consistent with other places we do this, e.g. RLS, but curious what to do going forward. Do we need some API style guidance on which one to use where here?

CC @envoyproxy/api-shepherds @phlax

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, we need guidance what keys to use for metadata (and filter state). It's wild west right now. As long as the name is unique, it should be OK to use any name, but we need to phrase it this way and avoid canonical name.

Copy link
Member

Choose a reason for hiding this comment

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

+1 anything we can do here to centralize this in TypedExtensionConfig and have common documentation would be hugely helpful. This is incredibly confusing IMO.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, this PR uses the same metadata key name that is documented in the proto used by the gRPC authorization server. What can I do to help here, and is it something that should be addressed in this PR or in a followup PR?

Copy link
Member

Choose a reason for hiding this comment

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

For now can you potentially just add an example to these docs? It's pretty hard to understand for the casual user. Thank you!

/wait

@github-actions
Copy link

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 Apr 27, 2021
@github-actions
Copy link

github-actions bot commented May 4, 2021

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 May 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api stale stalebot believes this issue/PR has not been touched recently waiting

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FR - Ability to log headers from authorization response *without* forwarding to upstream service

6 participants