Skip to content

Add tcp and http filters for external authorization service.#2359

Closed
saumoh wants to merge 1 commit intoenvoyproxy:masterfrom
colabsaumoh:ext-auth-review
Closed

Add tcp and http filters for external authorization service.#2359
saumoh wants to merge 1 commit intoenvoyproxy:masterfrom
colabsaumoh:ext-auth-review

Conversation

@saumoh
Copy link
Copy Markdown
Contributor

@saumoh saumoh commented Jan 12, 2018

Title
Support TCP and HTTP filter for external authorization service.

Description
Add support for filters for authorization by an external gRPC based authorization service. This PR implements the discussing we had in #2291.

Testing
I have tested this on my local setup with an external gRPC authorization server. I have also added UT's for both the http and tcp filters.

Risk
Low: Because only the users of this filter will be impacted. It should not impact general stability of Envoy it self.

Caveats

  • I did not test with a Google gRPC service configuration.
  • The v1 to v2 conversion of the configuration does not directly map to the way gRPC services protobuf is defined. I can make that change either as a follow up PR or within this PR if we feel that is important to cover here.
  • There may be a change required to data-plane-api accesslog. Once there is general aggrement on the change set here then I can submit a PR to make the changes to data-plane-api repo.

Notes to Reviewer

  • I'd really appreciate a closer look at how filter_config is being used in the file server/config/http/ext_auth.cc

Signed-off-by: Saurabh Mohan <saurabh+github@tigera.io>
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 for this very significant contribution. I'd like to ask two things to make the review work better:

  1. Can you apply the general style feedback (and (re)read the Envoy style guide at https://github.com/envoyproxy/envoy/blob/master/STYLE.md) to the entire set of files?

  2. Is it possible to break up this into at least 2 PRs? One for the gRPC client, and another for the auth filter? In general, we try to discourage such large PRs. Thanks.

*proto_config.mutable_ip_white_list());
}

void FilterJson::translateTcpExtAuthzFilter(
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.

Do you need v1 configuration support? If not, please drop this as we're trying to deprecate v1.

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 am happy to remove it. It's useful in ut's though, like here
What it the recommended way of filling out the protobuf in UT's?

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.

There are some examples, e.g. see https://github.com/envoyproxy/envoy/blob/master/test/common/access_log/grpc_access_log_impl_test.cc for an example of a unit test that takes protobuf config. I don't think it's worth keeping just for unit tests, although admittedly a lot of the legacy examples do still use v1 JSON. Protobufs are easy to build programatticaly or via JSON/YAML parsing.

]
for t in sub_bind_targets:
native.bind(
name = "envoy_api_sub_" + t[0],
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.

What is the goal here?

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.

This is for config(s) under directory auth in data-plane-api
Need to be able to specify dependency on the proto's in that directory. for example here
I'll re-write it using the idioms already in place for filters.

"//bazel:envoy_build_system.bzl",
"envoy_cc_library",
"envoy_package",
"envoy_proto_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.

Not used.

namespace Envoy {
namespace ExtAuthz {

using envoy::api::v2::auth::CheckRequest;
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.

using isn't allowed in headers by the style guide. It's also more readable IMHO to have the envoy::api::v2:: prefix in the type, indicating that this is a proto.

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.

+1

/**
* An interface for creating ext_authz.proto (authorization) request.
*/
class CheckRequestGenIntf {
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.

Hard to understand what this is from either the comment or type name. Please avoid abbreviations like Intf as they make readability more difficult.

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.

will rename

Ssl::Connection* ssl =
const_cast<Ssl::Connection*>(connection->ssl());
if (ssl != nullptr) {
if (local == false) {
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.

!local

Envoy::Http::StreamDecoderFilterCallbacks *sdfc = const_cast<Envoy::Http::StreamDecoderFilterCallbacks *>(callbacks);
httpreq->set_id(std::to_string(sdfc->streamId()));

#define SET_HDR_IN_HTTPREQ(_hq, _api, mname) \
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 there no other way to do this? Not a huge fan of macro magic (but it's OK if there's really no other way).

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.

Let me try to make it a function call.

httpreq->set_protocol(proto2str(sdfc->requestInfo().protocol().value()));

// Fill in the headers
::google::protobuf::Map< ::std::string, ::std::string >* mhdrs = httpreq->mutable_headers();
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.

auto* hdrs =



AttributeContext_Request *req = new AttributeContext_Request();
ASSERT(req);
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.

Same here with ownership.

void Instance::setCheckReqGen(CheckRequestGenIntf *crg)
{
ASSERT(crg_ == nullptr);
crg_ = CheckRequestGenIntfPtr{std::move(crg)};
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.

Please use meaningful field names.

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.

+1

@saumoh
Copy link
Copy Markdown
Contributor Author

saumoh commented Jan 12, 2018

@htuch thanks for the quick turn around. I'll followup on the style guide. Still learning and coming up to speed on the Envoy way.
Let me try to see how to break it into two pr's.

@mattklein123
Copy link
Copy Markdown
Member

@saumoh please break into 3 PRs:

  1. client
  2. HTTP filter
  3. TCP filter

Thank you!

@saumoh
Copy link
Copy Markdown
Contributor Author

saumoh commented Jan 12, 2018

sounds good. Will break it into 3. thx

@saumoh
Copy link
Copy Markdown
Contributor Author

saumoh commented Jan 17, 2018

@htuch As i am breaking this into three pr's can u confirm if naming files ext_authz is fine? thx

@htuch
Copy link
Copy Markdown
Member

htuch commented Jan 17, 2018

@saumoh FYI, you'll need to adapt this PR to work with the new pattern in #2393 once that merges.

@saumoh
Copy link
Copy Markdown
Contributor Author

saumoh commented Jan 19, 2018

Closing this PR and broken down the change set into three PR's:
#2415 (gRPC client)
#2416 (TCP filter)
#2417 (HTTP filter)

PS: Have incorporated the feedback here into the new PR's.
cc: @htuch @mattklein123

@saumoh saumoh closed this Jan 19, 2018
@devdinu
Copy link
Copy Markdown

devdinu commented Feb 8, 2018

@saumoh Thanks for the contribution. we want to use this to authenticate the request with another gRPC server. could you share the documentation or steps to use this filter,

  • service proto definition for authentication server
  • how do we configure envoy to use this (Is it part of filters in http_connection_manager?) or sample config if you've.
  • can we customise what we want to do by extending this? eg: custom errors

@saumoh
Copy link
Copy Markdown
Contributor Author

saumoh commented Feb 8, 2018

@Dineshkumar-cse The proto definitions for the auth server, the tcp filter and http filter are defined in the data-plane-api repo.
The protobuf for gRPC server is at:
https://github.com/envoyproxy/data-plane-api/tree/master/envoy/service/auth/v2
For the tcp filter config see:
https://github.com/envoyproxy/data-plane-api/tree/master/envoy/config/filter/network/ext_authz/v2
And for the http filter config see:
https://github.com/envoyproxy/data-plane-api/tree/master/envoy/config/filter/http/ext_authz/v2

The http filters are configured under the http_connection_manager.
hope this helps.

@devdinu
Copy link
Copy Markdown

devdinu commented Feb 12, 2018

@saumoh we've built the new envoy binary from master branch, and used the following config (v1), we just wanted to test whether it loads the filter.

{
"listeners": [
....
 "filters": [
 { "name": "http_connetion_manager", ... },
 {
   "name": "ext_authz",
   "config": {} 
 }] ...
]

But it errors out with the following,

envoy_bin.sh[8884]: [2018-02-12 20:32:03.100][8886][debug][config] source/server/config/network/http_connection_manager.cc:238]     filter #0
 envoy_bin.sh[8884]: [2018-02-12 20:32:03.101][8886][debug][config] source/server/config/network/http_connection_manager.cc:239]       name: envoy.router
 envoy_bin.sh[8884]: [2018-02-12 20:32:03.101][8886][debug][config] source/server/config/network/http_connection_manager.cc:243]     config: {"value":{},"deprecated_v1":true}
 envoy_bin.sh[8884]: [2018-02-12 20:32:03.101][8886][debug][config] source/server/listener_manager_impl.cc:29]   filter #1:
 envoy_bin.sh[8884]: [2018-02-12 20:32:03.101][8886][debug][config] source/server/listener_manager_impl.cc:30]     name: envoy.ext_authz
 envoy_bin.sh[8884]: [2018-02-12 20:32:03.101][8886][debug][config] source/server/listener_manager_impl.cc:33]   config: {"value":{},"deprecated_v1":true}
 envoy_bin.sh[8884]: [2018-02-12 20:32:03.102][8886][critical][main] source/server/server.cc:71] error initializing configuration '/etc/default/envoy.json': Didn't find a registered implementation for name
: 'envoy.ext_authz'
 envoy_bin.sh[8884]: [2018-02-12 20:32:03.102][8886][debug][upstream] source/common/upstream/cluster_manager_impl.cc:582] shutting down thread local cluster manager

Is there anything else we're missing?

@saumoh
Copy link
Copy Markdown
Contributor Author

saumoh commented Feb 13, 2018

@Dineshkumar-cse the filter's are under review still.
u can follow them and try it out once they are merged.
#2416
and
#2417

htuch pushed a commit that referenced this pull request Feb 20, 2018
As per the feedback on #2359 I am breaking it up into three PR's.

The patch in this PR adds support for the TCP filter.
This PR implements the discussing we had in #2291.

Testing
I have tested this on my local setup with an external gRPC authorization server. I have also added UT's for the TCP filter.

Risk
Low: Because only the users of this filter will be impacted. It should not impact general stability of Envoy it self.

Signed-off-by: Saurabh Mohan <saurabh+github@tigera.io>
htuch pushed a commit that referenced this pull request Mar 6, 2018
Authorization TCP and HTTP filters using an external gRPC service.
Patch 2 of 3: HTTP filter.

Description
As per the feedback on #2359 I am breaking it up into three PR's.

The patch in this PR adds support for the HTTP filter.
This PR implements the discussing we had in #2291.

Testing
I have tested this on my local setup with an external gRPC authorization server. I have also added UT's for the HTTP filter.

Risk
Low: Because only the users of this filter will be impacted. It should not impact general stability of Envoy it self.

Signed-off-by: Saurabh Mohan <saurabh+github@tigera.io>
Shikugawa pushed a commit to Shikugawa/envoy that referenced this pull request Mar 28, 2020
* metric record and integration test

* make test run

* make circle pass

* update go path

* try fix prow

* update sd filter and test

* clean

* remove direction from stackdriver config

* cleanup comment

* address comment

* fix build

* recover fake sd server

* add test prefix to field name

* update test config
jpsim pushed a commit that referenced this pull request Nov 28, 2022
Signed-off-by: Mike Schore <mike.schore@gmail.com>
Signed-off-by: JP Simard <jp@jpsim.com>
jpsim pushed a commit that referenced this pull request Nov 29, 2022
Signed-off-by: Mike Schore <mike.schore@gmail.com>
Signed-off-by: JP Simard <jp@jpsim.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.

4 participants