-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Add tcp and http filters for external authorization service. #2359
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| licenses(["notice"]) # Apache 2 | ||
|
|
||
| load( | ||
| "//bazel:envoy_build_system.bzl", | ||
| "envoy_cc_library", | ||
| "envoy_package", | ||
| "envoy_proto_library", | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not used. |
||
| ) | ||
|
|
||
| envoy_package() | ||
|
|
||
| envoy_cc_library( | ||
| name = "ext_authz_interface", | ||
| hdrs = ["ext_authz.h"], | ||
| external_deps = ["envoy_api_sub_auth"], | ||
| deps = [ | ||
| "//include/envoy/common:optional", | ||
| "//include/envoy/http:filter_interface", | ||
| "//include/envoy/http:header_map_interface", | ||
| "//include/envoy/network:filter_interface", | ||
| "//include/envoy/tracing:http_tracer_interface", | ||
| ], | ||
| ) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| #pragma once | ||
|
|
||
| #include <chrono> | ||
| #include <memory> | ||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| #include "envoy/common/optional.h" | ||
| #include "envoy/common/pure.h" | ||
| #include "envoy/http/filter.h" | ||
| #include "envoy/http/header_map.h" | ||
| #include "envoy/network/filter.h" | ||
| #include "envoy/tracing/http_tracer.h" | ||
|
|
||
| #include "api/auth/external_auth.pb.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace ExtAuthz { | ||
|
|
||
| using envoy::api::v2::auth::CheckRequest; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 |
||
|
|
||
| /** | ||
| * Possible async results for a check call. | ||
| */ | ||
| enum class CheckStatus { | ||
| // The request is authorized. | ||
| OK, | ||
| // The authz service could not be queried. | ||
| Error, | ||
| // The request is denied. | ||
| Denied | ||
| }; | ||
|
|
||
| /** | ||
| * Async callbacks used during check() calls. | ||
| */ | ||
| class RequestCallbacks { | ||
| public: | ||
| virtual ~RequestCallbacks() {} | ||
|
|
||
| /** | ||
| * Called when a check request is complete. The resulting status is supplied. | ||
| */ | ||
| virtual void complete(CheckStatus status) PURE; | ||
| }; | ||
|
|
||
|
|
||
| class Client { | ||
| public: | ||
| // Destructor | ||
| virtual ~Client() {} | ||
|
|
||
| /** | ||
| * Cancel an inflight Check request. | ||
| */ | ||
| virtual void cancel() PURE; | ||
|
|
||
| // A check call. | ||
| virtual void check(RequestCallbacks &callback, const CheckRequest& request, | ||
| Tracing::Span& parent_span) PURE; | ||
|
|
||
| }; | ||
|
|
||
| typedef std::unique_ptr<Client> ClientPtr; | ||
|
|
||
| /** | ||
| * An interface for creating a external authorization client. | ||
| */ | ||
| class ClientFactory { | ||
| public: | ||
| virtual ~ClientFactory() {} | ||
|
|
||
| /** | ||
| * Return a new authz client. | ||
| */ | ||
| virtual ClientPtr create(const Optional<std::chrono::milliseconds>& timeout) PURE; | ||
| }; | ||
|
|
||
| typedef std::unique_ptr<ClientFactory> ClientFactoryPtr; | ||
|
|
||
|
|
||
| /** | ||
| * An interface for creating ext_authz.proto (authorization) request. | ||
| */ | ||
| class CheckRequestGenIntf { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will rename |
||
| public: | ||
| // Destructor | ||
| virtual ~CheckRequestGenIntf() {} | ||
|
|
||
| virtual void createHttpCheck(const Envoy::Http::StreamDecoderFilterCallbacks* callbacks, | ||
| const Envoy::Http::HeaderMap &headers, | ||
| envoy::api::v2::auth::CheckRequest& request) PURE; | ||
| virtual void createTcpCheck(const Network::ReadFilterCallbacks* callbacks, | ||
| envoy::api::v2::auth::CheckRequest& request) PURE; | ||
| }; | ||
|
|
||
| typedef std::unique_ptr<CheckRequestGenIntf> CheckRequestGenIntfPtr; | ||
|
|
||
| } // namespace ExtAuthz | ||
| } // namespace Envoy | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -82,7 +82,7 @@ void HttpGrpcAccessLog::responseFlagsToAccessLogResponseFlags( | |
| envoy::api::v2::filter::accesslog::AccessLogCommon& common_access_log, | ||
| const RequestInfo::RequestInfo& request_info) { | ||
|
|
||
| static_assert(RequestInfo::ResponseFlag::LastFlag == 0x800, | ||
| static_assert(RequestInfo::ResponseFlag::LastFlag == 0x1000, | ||
| "A flag has been added. Fix this code."); | ||
|
|
||
| if (request_info.getResponseFlag(RequestInfo::ResponseFlag::FailedLocalHealthCheck)) { | ||
|
|
@@ -132,6 +132,13 @@ void HttpGrpcAccessLog::responseFlagsToAccessLogResponseFlags( | |
| if (request_info.getResponseFlag(RequestInfo::ResponseFlag::RateLimited)) { | ||
| common_access_log.mutable_response_flags()->set_rate_limited(true); | ||
| } | ||
|
|
||
| // @saumoh: TBD To the accesslog.proto | ||
| // | ||
| // if (request_info.getResponseFlag(RequestInfo::ResponseFlag::Unauthorized)) { | ||
| // common_access_log.mutable_response_flags()->set_unauthorized(true); | ||
| // } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to add another flag for Will remove it here and add it once the change in protobuf is there. How do we track this kind of TBD? Thx.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| } | ||
|
|
||
| void HttpGrpcAccessLog::log(const Http::HeaderMap* request_headers, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -399,5 +399,36 @@ void FilterJson::translateClientSslAuthFilter( | |
| *proto_config.mutable_ip_white_list()); | ||
| } | ||
|
|
||
| void FilterJson::translateTcpExtAuthzFilter( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| const Json::Object& json_config, envoy::api::v2::filter::network::ExtAuthz& proto_config) { | ||
| json_config.validateSchema(Json::Schema::EXT_AUTHZ_NETWORK_FILTER_SCHEMA); | ||
|
|
||
| JSON_UTIL_SET_STRING(json_config, proto_config, stat_prefix); | ||
| proto_config.set_failure_mode_allow(json_config.getBoolean("failure_mode_allow", false)); | ||
|
|
||
| const auto &json_grpc_cluster = json_config.getObject("grpc_cluster", false); | ||
| auto *grpc_service = proto_config.mutable_grpc_service(); | ||
| JSON_UTIL_SET_DURATION(*json_grpc_cluster, *grpc_service, timeout); | ||
|
|
||
| auto *grpc_cluster = grpc_service->mutable_envoy_grpc(); | ||
| JSON_UTIL_SET_STRING(*json_grpc_cluster, *grpc_cluster, cluster_name); | ||
| } | ||
|
|
||
| void FilterJson::translateHttpExtAuthzFilter( | ||
| const Json::Object& json_config, envoy::api::v2::filter::http::ExtAuthz& proto_config) { | ||
| json_config.validateSchema(Json::Schema::EXT_AUTHZ_HTTP_FILTER_SCHEMA); | ||
|
|
||
| proto_config.set_failure_mode_allow(json_config.getBoolean("failure_mode_allow", false)); | ||
|
|
||
|
|
||
| const auto &json_grpc_cluster = json_config.getObject("grpc_cluster", false); | ||
| auto *grpc_service = proto_config.mutable_grpc_service(); | ||
| JSON_UTIL_SET_DURATION(*json_grpc_cluster, *grpc_service, timeout); | ||
|
|
||
| auto *grpc_cluster = grpc_service->mutable_envoy_grpc(); | ||
| JSON_UTIL_SET_STRING(*json_grpc_cluster, *grpc_cluster, cluster_name); | ||
| } | ||
|
|
||
|
|
||
| } // namespace Config | ||
| } // namespace Envoy | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| licenses(["notice"]) # Apache 2 | ||
|
|
||
| load( | ||
| "//bazel:envoy_build_system.bzl", | ||
| "envoy_cc_library", | ||
| "envoy_package", | ||
| ) | ||
|
|
||
| envoy_package() | ||
|
|
||
| envoy_cc_library( | ||
| name = "ext_authz_lib", | ||
| srcs = ["ext_authz_impl.cc"], | ||
| hdrs = ["ext_authz_impl.h"], | ||
| external_deps = ["envoy_bootstrap"], | ||
| deps = [ | ||
| "//include/envoy/ext_authz:ext_authz_interface", | ||
| "//include/envoy/grpc:async_client_interface", | ||
| "//include/envoy/http:protocol_interface", | ||
| "//include/envoy/network:address_interface", | ||
| "//include/envoy/network:connection_interface", | ||
| "//include/envoy/upstream:cluster_manager_interface", | ||
| "//include/envoy/ssl:connection_interface", | ||
| "//source/common/common:assert_lib", | ||
| "//source/common/grpc:async_client_lib", | ||
| "//source/common/http:headers_lib", | ||
| "//source/common/tracing:http_tracer_lib", | ||
| ], | ||
| ) | ||
|
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
authin data-plane-apiNeed 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.