Skip to content
18 changes: 17 additions & 1 deletion api/envoy/extensions/filters/http/ext_authz/v3/ext_authz.proto
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ option (udpa.annotations.file_status).package_version_status = ACTIVE;
// External Authorization :ref:`configuration overview <config_http_filters_ext_authz>`.
// [#extension: envoy.filters.http.ext_authz]

// [#next-free-field: 13]
// [#next-free-field: 14]
message ExtAuthz {
option (udpa.annotations.versioning).previous_message_type =
"envoy.config.filter.http.ext_authz.v2.ExtAuthz";
Expand Down Expand Up @@ -65,6 +65,11 @@ message ExtAuthz {
// request message indicating if the body data is partial.
BufferSettings with_request_body = 5;

// Dictates how request body is sent to the external the external authorization service. This is
// effective when :ref:`with_request_body <envoy_v3_api_field_extensions.filters.http.ext_authz.v3.ExtAuthz.with_request_body>`
// is set to buffer request body.
RequestBodyOptions request_body_options = 13;
Comment thread
htuch marked this conversation as resolved.
Outdated

// Clears route cache in order to allow the external authorization service to correctly affect
// routing decisions. Filter clears all cached routes when:
//
Expand Down Expand Up @@ -134,6 +139,17 @@ message BufferSettings {
// The authorization request will be dispatched and no 413 HTTP error will be returned by the
// filter.
bool allow_partial_message = 2;

// If true, the body sent to the external authorization service is set with raw bytes, instead of
// UTF-8 string.
Comment thread
dio marked this conversation as resolved.
Outdated
bool pack_as_bytes = 3;
Comment thread
dio marked this conversation as resolved.
}

// Configuration for request body.
message RequestBodyOptions {
// If true, the body sent to the external authorization service is set with raw bytes, instead of
// UTF-8 string.
bool pack_as_bytes = 1;
}

// HttpService is used for raw HTTP communication between the filter and the authorization service.
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 12 additions & 2 deletions api/envoy/service/auth/v3/attribute_context.proto
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ message AttributeContext {

// This message defines attributes for an HTTP request.
// HTTP/1.x, HTTP/2, gRPC are all considered as HTTP requests.
// [#next-free-field: 12]
// [#next-free-field: 14]
message HttpRequest {
option (udpa.annotations.versioning).previous_message_type =
"envoy.service.auth.v2.AttributeContext.HttpRequest";
Expand Down Expand Up @@ -144,7 +144,17 @@ message AttributeContext {
string protocol = 10;

// The HTTP request body.
string body = 11;
string body = 11 [deprecated = true];

// The HTTP request body.
oneof request_body {
// The HTTP request body in bytes.
bytes raw_body = 12;

// [#not-implemented-hide:] The HTTP request body in UTF-8 string.
// [#comment:TODO(dio): Use this instead of field body to set request body with UTF-8 string].
Comment thread
dio marked this conversation as resolved.
Outdated
string utf8_body = 13;
}
}

// The source of a network activity, such as starting a TCP connection.
Expand Down
15 changes: 13 additions & 2 deletions api/envoy/service/auth/v4alpha/attribute_context.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions docs/root/version_history/current.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ New Features
* dynamic_forward_proxy: added :ref:`use_tcp_for_dns_lookups<envoy_v3_api_field_extensions.common.dynamic_forward_proxy.v3.DnsCacheConfig.use_tcp_for_dns_lookups>` option to use TCP for DNS lookups in order to match the DNS options for :ref:`Clusters<envoy_v3_api_msg_config.cluster.v3.Cluster>`.
* ext_authz filter: added support for emitting dynamic metadata for both :ref:`HTTP <config_http_filters_ext_authz_dynamic_metadata>` and :ref:`network <config_network_filters_ext_authz_dynamic_metadata>` filters.
The emitted dynamic metadata is set by :ref:`dynamic metadata <envoy_v3_api_field_service.auth.v3.CheckResponse.dynamic_metadata>` field in a returned :ref:`CheckResponse <envoy_v3_api_msg_service.auth.v3.CheckResponse>`.
* ext_authz filter: added support for sending raw bytes as request body of a check request.
Comment thread
dio marked this conversation as resolved.
Outdated
* grpc-json: support specifying `response_body` field in for `google.api.HttpBody` message.
* hds: added :ref:`cluster_endpoints_health <envoy_v3_api_field_service.health.v3.EndpointHealthResponse.cluster_endpoints_health>` to HDS responses, keeping endpoints in the same groupings as they were configured in the HDS specifier by cluster and locality instead of as a flat list.
* hds: added :ref:`transport_socket_matches <envoy_v3_api_field_service.health.v3.ClusterHealthCheck.transport_socket_matches>` to HDS cluster health check specifier, so the existing match filter :ref:`transport_socket_match_criteria <envoy_v3_api_field_config.core.v3.HealthCheck.transport_socket_match_criteria>` in the repeated field :ref:`health_checks <envoy_v3_api_field_service.health.v3.ClusterHealthCheck.health_checks>` has context to match against. This unblocks support for health checks over HTTPS and HTTP/2.
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 12 additions & 2 deletions generated_api_shadow/envoy/service/auth/v3/attribute_context.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 16 additions & 7 deletions source/extensions/filters/common/ext_authz/check_request_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void CheckRequestUtils::setRequestTime(envoy::service::auth::v3::AttributeContex
void CheckRequestUtils::setHttpRequest(
envoy::service::auth::v3::AttributeContext::HttpRequest& httpreq, uint64_t stream_id,
const StreamInfo::StreamInfo& stream_info, const Buffer::Instance* decoding_buffer,
const Envoy::Http::RequestHeaderMap& headers, uint64_t max_request_bytes) {
const Envoy::Http::RequestHeaderMap& headers, uint64_t max_request_bytes, bool pack_as_bytes) {
httpreq.set_id(std::to_string(stream_id));
httpreq.set_method(getHeaderStr(headers.Method()));
httpreq.set_path(getHeaderStr(headers.Path()));
Expand Down Expand Up @@ -130,7 +130,16 @@ void CheckRequestUtils::setHttpRequest(
const uint64_t length = std::min(decoding_buffer->length(), max_request_bytes);
std::string data(length, 0);
decoding_buffer->copyOut(0, length, &data[0]);
httpreq.set_body(std::move(data));

// This pack_as_bytes flag allows us to switch the content type (bytes or string) of "body" to
// be sent to the external authorization server without doing string encoding check (in this
// case UTF-8 check).
if (pack_as_bytes) {
httpreq.set_raw_body(std::move(data));
} else {
// TODO(dio): Replace the following with set_utf8_body when set_body is removed.
httpreq.set_body(std::move(data));
}

// Add in a header to detect when a partial body is used.
(*mutable_headers)[Http::Headers::get().EnvoyAuthPartialBody.get()] =
Expand All @@ -141,18 +150,18 @@ void CheckRequestUtils::setHttpRequest(
void CheckRequestUtils::setAttrContextRequest(
envoy::service::auth::v3::AttributeContext::Request& req, const uint64_t stream_id,
const StreamInfo::StreamInfo& stream_info, const Buffer::Instance* decoding_buffer,
const Envoy::Http::RequestHeaderMap& headers, uint64_t max_request_bytes) {
const Envoy::Http::RequestHeaderMap& headers, uint64_t max_request_bytes, bool pack_as_bytes) {
setRequestTime(req, stream_info);
setHttpRequest(*req.mutable_http(), stream_id, stream_info, decoding_buffer, headers,
max_request_bytes);
max_request_bytes, pack_as_bytes);
}

void CheckRequestUtils::createHttpCheck(
const Envoy::Http::StreamDecoderFilterCallbacks* callbacks,
const Envoy::Http::RequestHeaderMap& headers,
Protobuf::Map<std::string, std::string>&& context_extensions,
envoy::config::core::v3::Metadata&& metadata_context,
envoy::service::auth::v3::CheckRequest& request, uint64_t max_request_bytes,
envoy::service::auth::v3::CheckRequest& request, uint64_t max_request_bytes, bool pack_as_bytes,
bool include_peer_certificate) {

auto attrs = request.mutable_attributes();
Expand All @@ -163,10 +172,10 @@ void CheckRequestUtils::createHttpCheck(
auto* cb = const_cast<Envoy::Http::StreamDecoderFilterCallbacks*>(callbacks);
setAttrContextPeer(*attrs->mutable_source(), *cb->connection(), service, false,
include_peer_certificate);
setAttrContextPeer(*attrs->mutable_destination(), *cb->connection(), "", true,
setAttrContextPeer(*attrs->mutable_destination(), *cb->connection(), EMPTY_STRING, true,
include_peer_certificate);
setAttrContextRequest(*attrs->mutable_request(), cb->streamId(), cb->streamInfo(),
cb->decodingBuffer(), headers, max_request_bytes);
cb->decodingBuffer(), headers, max_request_bytes, pack_as_bytes);

// Fill in the context extensions and metadata context.
(*attrs->mutable_context_extensions()) = std::move(context_extensions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,16 @@ class CheckRequestUtils {
* check request.
* @param request is the reference to the check request that will be filled up.
* @param with_request_body when true, will add the request body to the check request.
* @param pack_as_bytes when true, will set the check request body as bytes.
* @param include_peer_certificate whether to include the peer certificate in the check request.
*/
static void createHttpCheck(const Envoy::Http::StreamDecoderFilterCallbacks* callbacks,
const Envoy::Http::RequestHeaderMap& headers,
Protobuf::Map<std::string, std::string>&& context_extensions,
envoy::config::core::v3::Metadata&& metadata_context,
envoy::service::auth::v3::CheckRequest& request,
uint64_t max_request_bytes, bool include_peer_certificate);
uint64_t max_request_bytes, bool pack_as_bytes,
bool include_peer_certificate);

/**
* createTcpCheck is used to extract the attributes from the network layer and fill them up
Expand All @@ -76,13 +78,13 @@ class CheckRequestUtils {
const uint64_t stream_id, const StreamInfo::StreamInfo& stream_info,
const Buffer::Instance* decoding_buffer,
const Envoy::Http::RequestHeaderMap& headers,
uint64_t max_request_bytes);
uint64_t max_request_bytes, bool pack_as_bytes);
static void setAttrContextRequest(envoy::service::auth::v3::AttributeContext::Request& req,
const uint64_t stream_id,
const StreamInfo::StreamInfo& stream_info,
const Buffer::Instance* decoding_buffer,
const Envoy::Http::RequestHeaderMap& headers,
uint64_t max_request_bytes);
uint64_t max_request_bytes, bool pack_as_bytes);
static std::string getHeaderStr(const Envoy::Http::HeaderEntry* entry);
static Envoy::Http::HeaderMap::Iterate fillHttpHeaders(const Envoy::Http::HeaderEntry&, void*);
};
Expand Down
3 changes: 2 additions & 1 deletion source/extensions/filters/http/ext_authz/ext_authz.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ void Filter::initiateCall(const Http::RequestHeaderMap& headers,

Filters::Common::ExtAuthz::CheckRequestUtils::createHttpCheck(
callbacks_, headers, std::move(context_extensions), std::move(metadata_context),
check_request_, config_->maxRequestBytes(), config_->includePeerCertificate());
check_request_, config_->maxRequestBytes(), config_->packAsBytes(),
config_->includePeerCertificate());

ENVOY_STREAM_LOG(trace, "ext_authz filter calling authorization server", *callbacks_);
state_ = State::Calling;
Expand Down
Loading