Skip to content
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

ext_authz: support modifying and removing query string parameters when using a gRPC authorization server #18009

Merged
merged 34 commits into from
Oct 11, 2021

Conversation

esmet
Copy link
Contributor

@esmet esmet commented Sep 6, 2021

This PR currently only implements query string modifications when using a gRPC authorization server.

Commit Message: ext_authz: support modifying and removing query string parameters when using a gRPC authorization server
Additional Description:
Risk Level: low, new opt-in feature to an extension
Testing: new unit tests
Docs Changes: Proto spec documented
Release Notes: ext_authz: added :ref:query_parameters_to_set <envoy_v3_api_field_service.auth.v3.CheckResponse.query_parameters_to_set> and :ref:query_parameters_to_remove <envoy_v3_api_field_service.auth.v3.CheckResponse.query_parameters_to_remove> for adding and removing query string parameters when using a gRPC authorization server.
Platform Specific Features:
Fixes #3266

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>
@repokitteh-read-only
Copy link

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: #18009 was opened by esmet.

see: more, trace.

@repokitteh-read-only
Copy link

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: #18009 was opened by esmet.

see: more, trace.

Signed-off-by: John Esmet <john.esmet@gmail.com>
@@ -60,8 +60,20 @@ message DeniedHttpResponse {
string body = 3;
}

// TODO: Should this be in the core API?
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is an open question. I feel like it could be valuable alongside HeaderValueOption.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, that would be a good location, but I think the remove semantics are a bit weird. Would it be cleaner to structure this similar to headers, with query_parameters_to_add, query_parameter_to_remove?

Copy link
Member

Choose a reason for hiding this comment

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

I think I agree with @htuch, though with introducing a new structure the same as HeaderValue? But with the QueryParameter (?) as its name. We can do that via what is suggested (adding query_parameters_to_add, query_parameter_to_remove) by Harvey.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do

Signed-off-by: John Esmet <john.esmet@gmail.com>
const auto path_without_query =
Http::Utility::stripQueryString(request_headers_->Path()->value());
// TODO: These two lines should probably be abstracted as
// Http::Utility::formatPathAndQueryParams
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 still need to do this.

for (const auto& [key, value] : response->query_parameters_to_set) {
ENVOY_STREAM_LOG(trace, "'{}={}'", *decoder_callbacks_, key, value);
// TODO(esmet): Sanitize key/value and/or declare the security posture that we trust the
// authorization server.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Trusting the auth server seems obvious but I still need to circle back to this TODO

Copy link
Member

@dio dio Sep 13, 2021

Choose a reason for hiding this comment

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

File an issue and link it here will be better I think?

Signed-off-by: John Esmet <john.esmet@gmail.com>
Signed-off-by: John Esmet <john.esmet@gmail.com>
@esmet esmet changed the title ext_authz: support modifying and removing query string parameters ext_authz: support modifying and removing query string parameters when using a gRPC authorization server Sep 10, 2021
@esmet esmet marked this pull request as ready for review September 10, 2021 01:04
@esmet esmet requested a review from dio as a code owner September 10, 2021 01:04
Signed-off-by: John Esmet <john.esmet@gmail.com>
Signed-off-by: John Esmet <john.esmet@gmail.com>
@htuch
Copy link
Member

htuch commented Sep 10, 2021

/assign-from @envoyproxy/first-pass-reviewers

@repokitteh-read-only
Copy link

@envoyproxy/first-pass-reviewers assignee is @jmarantz

🐱

Caused by: a #18009 (comment) was created by @htuch.

see: more, trace.

Comment on lines 62 to 63
// TODO(esmet): It might make more sense to store query_parameters_to_set as a vector
// instead of a map since we will likely only ever iterate them linearly.
Copy link
Member

Choose a reason for hiding this comment

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

I agree with this, should we go ahead with this PR?

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'll work on adding QueryParamsVector for this.

@@ -213,12 +213,13 @@ void Filter::onComplete(Filters::Common::ExtAuthz::ResponsePtr&& response) {

switch (response->status) {
case CheckStatus::OK: {
// Any changes to request headers can affect how the request is going to be
// Any changes to request headers or query parameters can affect how the request is going to be
Copy link
Member

@dio dio Sep 13, 2021

Choose a reason for hiding this comment

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

Thanks for this. I totally forgot that we have a route matcher to match query params.

// [#next-free-field: 7]
message QueryParameterMatcher {
option (udpa.annotations.versioning).previous_message_type =
"envoy.api.v2.route.QueryParameterMatcher";
.

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>
@jmarantz
Copy link
Contributor

Looks like dio is on this; I'lll drop off this one.

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

esmet commented Sep 29, 2021

@rojkov thanks! I ended up needing to specify envoy_v3_field_service. which I think means "a field type" in the "service." namespace, since the qualified name is service.auth.v3... etc

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

htuch commented Sep 30, 2021

/lgtm api

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

Needs a main merge. @rojkov can you do a final pass on this please?

/wait

esmet added 2 commits October 6, 2021 15:38
Signed-off-by: John Esmet <john.esmet@gmail.com>
Signed-off-by: John Esmet <john.esmet@gmail.com>
@repokitteh-read-only repokitteh-read-only bot added api and removed waiting labels Oct 6, 2021
esmet added 3 commits October 6, 2021 19:52
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>
@rojkov rojkov self-assigned this Oct 7, 2021
@rojkov
Copy link
Member

rojkov commented Oct 7, 2021

Sorry, needs a merge again.

/wait

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

esmet commented Oct 7, 2021

@rojkov done!

rojkov
rojkov previously approved these changes Oct 8, 2021
Copy link
Member

@rojkov rojkov left a comment

Choose a reason for hiding this comment

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

Thanks! Looks perfect to me.

@htuch could you please reinstate your API approval?

Comment on lines 97 to 101
EXPECT_EQ(Utility::stripQueryString(HeaderString("/?x=1")), "/");
EXPECT_EQ(Utility::stripQueryString(HeaderString("/foo")), "/foo");
EXPECT_EQ(Utility::stripQueryString(HeaderString("/foo?")), "/foo");
EXPECT_EQ(Utility::stripQueryString(HeaderString("/foo?hello=there")), "/foo");
EXPECT_EQ(Utility::stripQueryString(HeaderString("/foo/?")), "/foo/");
Copy link
Member

Choose a reason for hiding this comment

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

Nit: I know it's too pedantic, but I feel incompleteness without having these two lines added

  EXPECT_EQ(Utility::stripQueryString(HeaderString("/?x=1&y=2")), "/");
  EXPECT_EQ(Utility::stripQueryString(HeaderString("/foo?hello=there&good=bye")), "/foo");

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that's fair - will add them

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

@rojkov rojkov left a comment

Choose a reason for hiding this comment

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

LGTM!

@htuch
Copy link
Member

htuch commented Oct 8, 2021

/lgtm api

@repokitteh-read-only repokitteh-read-only bot removed the api label Oct 8, 2021
@rojkov rojkov merged commit c42a018 into envoyproxy:main Oct 11, 2021
@esmet esmet deleted the ext-authz-query-string branch October 11, 2021 13:44
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.

Ext_Authz: Allow extension to append or modify original query string params
8 participants