Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
a3f46c0
http namespace ext_authz dynamic metadata done
llu94 Dec 18, 2021
8399867
ext_authz for network namespace ready
llu94 Dec 19, 2021
e3c90d3
code formatter changes
llu94 Dec 19, 2021
f178ebd
respond to PR feedback
llu94 Dec 22, 2021
ad0727d
respond to PR feedback and apply fix format diff
llu94 Dec 22, 2021
9911284
remove unnecessary function
llu94 Dec 22, 2021
14ab553
apply formatting fix
llu94 Dec 22, 2021
530ad73
make changes in line with PR feedback
llu94 Dec 30, 2021
b4345a0
add formatter fix
llu94 Dec 30, 2021
7b72fd7
changes in response to PR feedback
llu94 Jan 10, 2022
fcffd56
remove extra artifact
llu94 Jan 5, 2022
cb957ab
format fix
llu94 Jan 10, 2022
7eb5f24
Refactoring in response to PR feedback
llu94 Jan 11, 2022
07e0c49
removed unneccessary code
llu94 Jan 12, 2022
f7e45d5
fix formatting issue
llu94 Jan 12, 2022
a333bd0
adjust test coverage
llu94 Jan 15, 2022
940c82b
adjust test coverage
llu94 Jan 15, 2022
9806b91
formatting changes
llu94 Jan 15, 2022
f874200
Adjust test coverage for network ext_authz
llu94 Jan 15, 2022
bd15dd1
remove helper methods
llu94 Jan 18, 2022
c51a383
Documentation and timing implementation changes
llu94 Jan 23, 2022
e3f576e
formatting changes
llu94 Jan 23, 2022
c40a796
renaming/refactoring http ext_authz
llu94 Jan 27, 2022
4427dda
add tests to http ext authz
llu94 Jan 28, 2022
a6ece49
reformatted ext_authz functions
llu94 Jan 28, 2022
370b958
add timing tests for network ext_authz. Reformatting
llu94 Jan 28, 2022
e2a202a
ext_authz filter tests adjusted; public time methods removed
llu94 Feb 2, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ from the authorization server that match the configured
:ref:`dynamic_metadata_from_headers <envoy_v3_api_field_extensions.filters.http.ext_authz.v3.AuthorizationResponse.dynamic_metadata_from_headers>`,
if set. For every response header that matches, the filter will emit dynamic metadata whose key is the name of the matched header and whose value is the value of the matched header.

Both the HTTP and gRPC external authorization filters support a dynamic metadata field called ``ext_authz_duration`` which records the time it takes to complete an authorization request in milliseconds.
This field will not be populated if the request does not complete.

Runtime
-------
The fraction of requests for which the filter is enabled can be configured via the :ref:`runtime_key
Expand Down
15 changes: 15 additions & 0 deletions source/extensions/filters/http/ext_authz/ext_authz.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "source/extensions/filters/http/ext_authz/ext_authz.h"

#include <chrono>

#include "envoy/config/core/v3/base.pb.h"

#include "source/common/common/assert.h"
Expand Down Expand Up @@ -58,6 +60,9 @@ void Filter::initiateCall(const Http::RequestHeaderMap& headers,
config_->includePeerCertificate(), config_->destinationLabels());

ENVOY_STREAM_LOG(trace, "ext_authz filter calling authorization server", *decoder_callbacks_);
// Store start time of ext_authz filter call
start_time_ = decoder_callbacks_->dispatcher().timeSource().monotonicTime();

state_ = State::Calling;
filter_return_ = FilterReturn::StopDecoding; // Don't let the filter chain continue as we are
// going to invoke check call.
Expand Down Expand Up @@ -210,6 +215,16 @@ void Filter::onComplete(Filters::Common::ExtAuthz::ResponsePtr&& response) {
Stats::StatName empty_stat_name;

if (!response->dynamic_metadata.fields().empty()) {
// Add duration of call to dynamic metadata if applicable
if (start_time_.has_value() && response->status == CheckStatus::OK) {
ProtobufWkt::Value ext_authz_duration_value;
auto duration =
decoder_callbacks_->dispatcher().timeSource().monotonicTime() - start_time_.value();
ext_authz_duration_value.set_number_value(
std::chrono::duration_cast<std::chrono::milliseconds>(duration).count());
(*response->dynamic_metadata.mutable_fields())["ext_authz_duration"] =
ext_authz_duration_value;
}
decoder_callbacks_->streamInfo().setDynamicMetadata("envoy.filters.http.ext_authz",
response->dynamic_metadata);
}
Expand Down
1 change: 1 addition & 0 deletions source/extensions/filters/http/ext_authz/ext_authz.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ class Filter : public Logger::Loggable<Logger::Id::filter>,
void onComplete(Filters::Common::ExtAuthz::ResponsePtr&&) override;

private:
absl::optional<MonotonicTime> start_time_;
void addResponseHeaders(Http::HeaderMap& header_map, const Http::HeaderVector& headers);
void initiateCall(const Http::RequestHeaderMap& headers,
const Router::RouteConstSharedPtr& route);
Expand Down
15 changes: 14 additions & 1 deletion source/extensions/filters/network/ext_authz/ext_authz.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "source/extensions/filters/network/ext_authz/ext_authz.h"

#include <chrono>
#include <cstdint>
#include <string>

Expand All @@ -24,7 +25,8 @@ void Filter::callCheck() {
Filters::Common::ExtAuthz::CheckRequestUtils::createTcpCheck(filter_callbacks_, check_request_,
config_->includePeerCertificate(),
config_->destinationLabels());

// Store start time of ext_authz filter call
start_time_ = filter_callbacks_->connection().dispatcher().timeSource().monotonicTime();
status_ = Status::Calling;
config_->stats().active_.inc();
config_->stats().total_.inc();
Expand Down Expand Up @@ -74,6 +76,16 @@ void Filter::onComplete(Filters::Common::ExtAuthz::ResponsePtr&& response) {
switch (response->status) {
case Filters::Common::ExtAuthz::CheckStatus::OK:
config_->stats().ok_.inc();
// Add duration of call to dynamic metadata if applicable
if (start_time_.has_value()) {
ProtobufWkt::Value ext_authz_duration_value;
auto duration = filter_callbacks_->connection().dispatcher().timeSource().monotonicTime() -
start_time_.value();
ext_authz_duration_value.set_number_value(
std::chrono::duration_cast<std::chrono::milliseconds>(duration).count());
(*response->dynamic_metadata.mutable_fields())["ext_authz_duration"] =
ext_authz_duration_value;
}
break;
case Filters::Common::ExtAuthz::CheckStatus::Error:
config_->stats().error_.inc();
Expand All @@ -84,6 +96,7 @@ void Filter::onComplete(Filters::Common::ExtAuthz::ResponsePtr&& response) {
}

if (!response->dynamic_metadata.fields().empty()) {

filter_callbacks_->connection().streamInfo().setDynamicMetadata(
NetworkFilterNames::get().ExtAuthorization, response->dynamic_metadata);
}
Expand Down
1 change: 1 addition & 0 deletions source/extensions/filters/network/ext_authz/ext_authz.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ class Filter : public Network::ReadFilter,
bool filterEnabled(const envoy::config::core::v3::Metadata& metadata) {
return config_->filterEnabledMetadata(metadata);
}
absl::optional<MonotonicTime> start_time_;

ConfigSharedPtr config_;
Filters::Common::ExtAuthz::ClientPtr client_;
Expand Down
Loading