From 4b04ff76110299a1210c93ededfbcfd0fa9db616 Mon Sep 17 00:00:00 2001 From: "data-plane-api(CircleCI)" Date: Thu, 21 Jun 2018 15:38:28 +0000 Subject: [PATCH] Header to metadata filter (#2436) (#3633) Add support for extracting dynamic metadata from requests. This can then be used as static metadata would be used (e.g.: for subset load balancer metadata matches, logging, etc). Risk Level: Low Testing: unit-test Docs Changes: Basic docs. Release Notes: N/A Signed-off-by: Raul Gutierrez Segales Mirrored from https://github.com/envoyproxy/envoy @ 827c0a548ab38d55debe00587ee27253786befad --- docs/BUILD | 1 + .../filter/http/header_to_metadata/v2/BUILD | 9 +++ .../v2/header_to_metadata.proto | 69 +++++++++++++++++++ .../v2/http_connection_manager.proto | 1 + test/validate/BUILD | 1 + test/validate/pgv_test.cc | 1 + 6 files changed, 82 insertions(+) create mode 100644 envoy/config/filter/http/header_to_metadata/v2/BUILD create mode 100644 envoy/config/filter/http/header_to_metadata/v2/header_to_metadata.proto diff --git a/docs/BUILD b/docs/BUILD index 39359024..ffd68728 100644 --- a/docs/BUILD +++ b/docs/BUILD @@ -32,6 +32,7 @@ proto_library( "//envoy/config/filter/http/ext_authz/v2alpha:ext_authz", "//envoy/config/filter/http/fault/v2:fault", "//envoy/config/filter/http/gzip/v2:gzip", + "//envoy/config/filter/http/header_to_metadata/v2:header_to_metadata", "//envoy/config/filter/http/health_check/v2:health_check", "//envoy/config/filter/http/ip_tagging/v2:ip_tagging", "//envoy/config/filter/http/lua/v2:lua", diff --git a/envoy/config/filter/http/header_to_metadata/v2/BUILD b/envoy/config/filter/http/header_to_metadata/v2/BUILD new file mode 100644 index 00000000..102dd076 --- /dev/null +++ b/envoy/config/filter/http/header_to_metadata/v2/BUILD @@ -0,0 +1,9 @@ +load("//bazel:api_build_system.bzl", "api_proto_library") + +licenses(["notice"]) # Apache 2 + +api_proto_library( + name = "header_to_metadata", + srcs = ["header_to_metadata.proto"], + deps = [], +) diff --git a/envoy/config/filter/http/header_to_metadata/v2/header_to_metadata.proto b/envoy/config/filter/http/header_to_metadata/v2/header_to_metadata.proto new file mode 100644 index 00000000..813dacfd --- /dev/null +++ b/envoy/config/filter/http/header_to_metadata/v2/header_to_metadata.proto @@ -0,0 +1,69 @@ +syntax = "proto3"; + +package envoy.config.filter.http.header_to_metadata.v2; +option go_package = "v2"; + +import "validate/validate.proto"; + +// [#protodoc-title: Header-To-Metadata Filter] +// +// The configuration for transforming headers into metadata. This is useful +// for matching load balancer subsets, logging, etc. +// +// Header to Metadata :ref:`configuration overview `. + +message Config { + enum ValueType { + STRING = 0; + NUMBER = 1; + } + + message KeyValuePair { + // The namespace — if this is empty, the filter's namespace will be used. + string metadata_namespace = 1; + + // The key to use within the namespace. + string key = 2 [(validate.rules).string.min_bytes = 1]; + + // The value to pair with the given key. + // + // When used for a `on_header_present` case, if value is non-empty it'll be used + // instead of the header value. If both are empty, no metadata is added. + // + // When used for a `on_header_missing` case, a non-empty value must be provided + // otherwise no metadata is added. + string value = 3; + + // The value's type — defaults to string. + ValueType type = 4; + } + + // A Rule defines what metadata to apply when a header is present or missing. + message Rule { + // The header that triggers this rule — required. + string header = 1 [(validate.rules).string.min_bytes = 1]; + + // If the header is present, apply this metadata KeyValuePair. + // + // If the value in the KeyValuePair is non-empty, it'll be used instead + // of the header value. + KeyValuePair on_header_present = 2; + + // If the header is not present, apply this metadata KeyValuePair. + // + // The value in the KeyValuePair must be set, since it'll be used in lieu + // of the missing header value. + KeyValuePair on_header_missing = 3; + + // Whether or not to remove the header after a rule is applied. + // + // This prevents headers from leaking. + bool remove = 4; + } + + // The list of rules to apply to requests. + repeated Rule request_rules = 1; + + // The list of rules to apply to responses. + repeated Rule response_rules = 2; +} diff --git a/envoy/config/filter/network/http_connection_manager/v2/http_connection_manager.proto b/envoy/config/filter/network/http_connection_manager/v2/http_connection_manager.proto index 84bf1da9..a93c212b 100644 --- a/envoy/config/filter/network/http_connection_manager/v2/http_connection_manager.proto +++ b/envoy/config/filter/network/http_connection_manager/v2/http_connection_manager.proto @@ -298,6 +298,7 @@ message HttpFilter { // * :ref:`envoy.grpc_json_transcoder ` // * :ref:`envoy.grpc_web ` // * :ref:`envoy.health_check ` + // * :ref:`envoy.header_to_metadata ` // * :ref:`envoy.ip_tagging ` // * :ref:`envoy.lua ` // * :ref:`envoy.rate_limit ` diff --git a/test/validate/BUILD b/test/validate/BUILD index 467a3e74..2707e02c 100644 --- a/test/validate/BUILD +++ b/test/validate/BUILD @@ -18,6 +18,7 @@ api_cc_test( "//envoy/config/filter/http/buffer/v2:buffer", "//envoy/config/filter/http/fault/v2:fault", "//envoy/config/filter/http/gzip/v2:gzip", + "//envoy/config/filter/http/header_to_metadata/v2:header_to_metadata", "//envoy/config/filter/http/health_check/v2:health_check", "//envoy/config/filter/http/ip_tagging/v2:ip_tagging", "//envoy/config/filter/http/lua/v2:lua", diff --git a/test/validate/pgv_test.cc b/test/validate/pgv_test.cc index a8f0b3d6..f42718c2 100644 --- a/test/validate/pgv_test.cc +++ b/test/validate/pgv_test.cc @@ -15,6 +15,7 @@ #include "envoy/config/filter/http/fault/v2/fault.pb.validate.h" #include "envoy/config/filter/http/gzip/v2/gzip.pb.validate.h" #include "envoy/config/filter/http/health_check/v2/health_check.pb.validate.h" +#include "envoy/config/filter/http/header_to_metadata/v2/header_to_metadata.pb.validate.h" #include "envoy/config/filter/http/ip_tagging/v2/ip_tagging.pb.validate.h" #include "envoy/config/filter/http/lua/v2/lua.pb.validate.h" #include "envoy/config/filter/http/router/v2/router.pb.validate.h"