Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
1 change: 1 addition & 0 deletions api/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ proto_library(
"//envoy/extensions/filters/http/ratelimit/v3:pkg",
"//envoy/extensions/filters/http/rbac/v3:pkg",
"//envoy/extensions/filters/http/router/v3:pkg",
"//envoy/extensions/filters/http/set_metadata/v3:pkg",

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.

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 tried to added myself, but it asked for a second maintainer. Who should I add? @snowp as he is sponsoring it :) ?

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.

Yes, Snow and you.

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.

Sorry missed this answer. Done in d139579 !

"//envoy/extensions/filters/http/squash/v3:pkg",
"//envoy/extensions/filters/http/tap/v3:pkg",
"//envoy/extensions/filters/http/wasm/v3:pkg",
Expand Down
9 changes: 9 additions & 0 deletions api/envoy/extensions/filters/http/set_metadata/v3/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# DO NOT EDIT. This file is generated by tools/proto_format/proto_sync.py.

load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package")

licenses(["notice"]) # Apache 2

api_proto_package(
deps = ["@com_github_cncf_udpa//udpa/annotations:pkg"],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
syntax = "proto3";

package envoy.extensions.filters.http.set_metadata.v3;

import "google/protobuf/struct.proto";

import "udpa/annotations/migrate.proto";
Comment thread
aguinet marked this conversation as resolved.
Outdated
import "udpa/annotations/status.proto";
import "udpa/annotations/versioning.proto";
import "validate/validate.proto";

option java_package = "io.envoyproxy.envoy.extensions.filters.http.set_metadata.v3";
option java_outer_classname = "SetMetadataProto";
option java_multiple_files = true;
option (udpa.annotations.file_status).package_version_status = ACTIVE;

// [#protodoc-title: Set-Metadata Filter]
//
// This filters adds or updates dynamic metadata with static data.
//
// [#extension: envoy.filters.http.set_metadata]

message Config {
// The metadata namespace.
string metadata_namespace = 1 [(validate.rules).string = {min_len: 1}];

// The value to update the namespace with.

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.

RST link to docs providing details of the merge semantics.

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.

Should be fixed in 9d26ca2

google.protobuf.Struct value = 2;
}
1 change: 1 addition & 0 deletions api/versioning/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ proto_library(
"//envoy/extensions/filters/http/ratelimit/v3:pkg",
"//envoy/extensions/filters/http/rbac/v3:pkg",
"//envoy/extensions/filters/http/router/v3:pkg",
"//envoy/extensions/filters/http/set_metadata/v3:pkg",
"//envoy/extensions/filters/http/squash/v3:pkg",
"//envoy/extensions/filters/http/tap/v3:pkg",
"//envoy/extensions/filters/http/wasm/v3:pkg",
Expand Down
126 changes: 126 additions & 0 deletions configs/waf/waf_matchers.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
admin:
address:
socket_address:
protocol: TCP
address: 0.0.0.0
port_value: 9901
static_resources:
listeners:
- name: listener_0
address:
socket_address:
protocol: TCP
address: 0.0.0.0
port_value: 10000
filter_chains:
- filters:
- name: envoy.filters.network.http_connection_manager
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
stat_prefix: ingress_http
access_log:
- name: envoy.access_loggers.file
typed_config:
"@type": type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog
path: /dev/stdout
log_format:
text_format_source:
inline_string: |
[%START_TIME%] "%REQ(:METHOD)% %REQ(X-ENVOY-ORIGINAL-PATH?:PATH)% %PROTOCOL%" %RESPONSE_CODE% %RESPONSE_FLAGS% %BYTES_RECEIVED% %BYTES_SENT% %DURATION% %RESP(X-ENVOY-UPSTREAM-SERVICE-TIME)% "%REQ(X-FORWARDED-FOR)%" "%REQ(USER-AGENT)%" "%REQ(X-REQUEST-ID)%" "%REQ(:AUTHORITY)%" '%DYNAMIC_METADATA(curiefense)%' "%UPSTREAM_HOST%"\n
route_config:
name: local_route
virtual_hosts:
- name: local_service
domains: ["*"]
routes:
- match:
prefix: "/"
route:
host_rewrite_literal: localhost
cluster: service_envoyproxy_io
http_filters:
- name: mytag0
typed_config:
"@type": type.googleapis.com/envoy.extensions.common.matching.v3.ExtensionWithMatcher
extension_config:
name: envoy.filters.http.set_metadata
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.set_metadata.v3.Config
metadata_namespace: curiefense
value:
tags:
mytag0: 0
matcher:
matcher_list:
matchers:
- predicate:
not_matcher:
or_matcher:
predicate:
- single_predicate:
input:
name: request-headers
typed_config:
"@type": type.googleapis.com/envoy.type.matcher.v3.HttpRequestHeaderMatchInput
header_name: myheader
value_match:
exact: foo
- single_predicate:
input:
name: request-headers
typed_config:
"@type": type.googleapis.com/envoy.type.matcher.v3.HttpRequestHeaderMatchInput
header_name: myheader
value_match:
exact: bar
on_match:
action:
name: skip
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.common.matcher.action.v3.SkipFilter
- name: mytag1
typed_config:
"@type": type.googleapis.com/envoy.extensions.common.matching.v3.ExtensionWithMatcher
extension_config:
name: envoy.filters.http.set_metadata
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.set_metadata.v3.Config
metadata_namespace: curiefense
value:
tags:
mytag1: 1
matcher:
matcher_list:
matchers:
- predicate:
not_matcher:
single_predicate:
input:
name: request-headers
typed_config:
"@type": type.googleapis.com/envoy.type.matcher.v3.HttpRequestHeaderMatchInput
header_name: header2
value_match:
exact: toto
on_match:
action:
name: skip
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.common.matcher.action.v3.SkipFilter
- name: envoy.filters.http.router
clusters:
- name: service_envoyproxy_io
connect_timeout: 30s
type: LOGICAL_DNS
# Comment out the following line to test on v6 networks
dns_lookup_family: V4_ONLY
lb_policy: ROUND_ROBIN
load_assignment:
cluster_name: service_envoyproxy_io
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: 127.0.0.1
port_value: 5555
1 change: 1 addition & 0 deletions docs/root/configuration/http/http_filters/http_filters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ HTTP filters
rate_limit_filter
rbac_filter
router_filter
set_metadata_filter
squash_filter
tap_filter
wasm_filter
Expand Down
48 changes: 48 additions & 0 deletions docs/root/configuration/http/http_filters/set_metadata_filter.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
.. _config_http_filters_set_metadata:

Set Metadata
============
* :ref:`v3 API reference <envoy_v3_api_msg_extensions.filters.http.set_metadata.v3.Config>`
* This filter should be configured with the name *envoy.filters.http.set_metadata*.

This filters adds or updates dynamic metadata with static data.

Dynamic metadata values are updated with the following scheme. If a key

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.

@envoyproxy/api-shepherds this differs from MergeFrom in that it supports merging structs together, e.g. if you have a disjoint namespace things compose as expected. I think this makes sense, but flagging this for consideration in case there is some alternate merging preferences.

does not exists, it's just copied into the current metadata. Otherwise:

* scalar values (null, string, number, boolean) are replaced with the new value
* list: new values are added to the current list
* structure: recursively apply this scheme

For instance, if the namespace already contains this structure:

.. code-block:: yaml

myint: 1
mylist: ["a"]
mytags:
tag0: 1

and the value to set is:

.. code-block:: yaml

myint: 2
mylist: ["b","c"]
mytags:
tag1: 1

After applying this filter, the namespace will contain:

.. code-block:: yaml

myint: 2
mylist: ["a","b","c"]
mytags:
tag0: 1
tag1: 1

Statistics
----------

Currently, this filter generates no statistics.
1 change: 1 addition & 0 deletions generated_api_shadow/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ proto_library(
"//envoy/extensions/filters/http/ratelimit/v3:pkg",
"//envoy/extensions/filters/http/rbac/v3:pkg",
"//envoy/extensions/filters/http/router/v3:pkg",
"//envoy/extensions/filters/http/set_metadata/v3:pkg",
"//envoy/extensions/filters/http/squash/v3:pkg",
"//envoy/extensions/filters/http/tap/v3:pkg",
"//envoy/extensions/filters/http/wasm/v3:pkg",
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.

1 change: 1 addition & 0 deletions source/extensions/extensions_build_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ EXTENSIONS = {
"envoy.filters.http.ratelimit": "//source/extensions/filters/http/ratelimit:config",
"envoy.filters.http.rbac": "//source/extensions/filters/http/rbac:config",
"envoy.filters.http.router": "//source/extensions/filters/http/router:config",
"envoy.filters.http.set_metadata": "//source/extensions/filters/http/set_metadata:config",
"envoy.filters.http.squash": "//source/extensions/filters/http/squash:config",
"envoy.filters.http.tap": "//source/extensions/filters/http/tap:config",
"envoy.filters.http.wasm": "//source/extensions/filters/http/wasm:config",
Expand Down
39 changes: 39 additions & 0 deletions source/extensions/filters/http/set_metadata/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
load(
"//bazel:envoy_build_system.bzl",
"envoy_cc_extension",
"envoy_cc_library",
"envoy_extension_package",
)

licenses(["notice"]) # Apache 2

envoy_extension_package()

envoy_cc_library(
name = "set_metadata_filter_lib",
srcs = ["set_metadata_filter.cc"],
hdrs = ["set_metadata_filter.h"],
deps = [
"//include/envoy/server:filter_config_interface",
"//source/common/http:utility_lib",
"//source/extensions/filters/http:well_known_names",
"//source/extensions/filters/http/common:pass_through_filter_lib",
"@envoy_api//envoy/extensions/filters/http/set_metadata/v3:pkg_cc_proto",
],
)

envoy_cc_extension(
name = "config",
srcs = ["config.cc"],
hdrs = ["config.h"],
category = "envoy.filters.http",
security_posture = "robust_to_untrusted_downstream_and_upstream",
deps = [
"//include/envoy/registry",
"//source/common/protobuf:utility_lib",
"//source/extensions/filters/http:well_known_names",
"//source/extensions/filters/http/common:factory_base_lib",
"//source/extensions/filters/http/set_metadata:set_metadata_filter_lib",
"@envoy_api//envoy/extensions/filters/http/set_metadata/v3:pkg_cc_proto",
],
)
34 changes: 34 additions & 0 deletions source/extensions/filters/http/set_metadata/config.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include "extensions/filters/http/set_metadata/config.h"

#include <string>

#include "envoy/extensions/filters/http/set_metadata/v3/set_metadata.pb.h"
#include "envoy/extensions/filters/http/set_metadata/v3/set_metadata.pb.validate.h"
#include "envoy/registry/registry.h"

#include "common/protobuf/utility.h"

#include "extensions/filters/http/set_metadata/set_metadata_filter.h"

namespace Envoy {
namespace Extensions {
namespace HttpFilters {
namespace SetMetadataFilter {

Http::FilterFactoryCb SetMetadataConfig::createFilterFactoryFromProtoTyped(
Comment thread
htuch marked this conversation as resolved.
const envoy::extensions::filters::http::set_metadata::v3::Config& proto_config,
const std::string&, Server::Configuration::FactoryContext&) {
ConfigSharedPtr filter_config(std::make_shared<Config>(proto_config));

return [filter_config](Http::FilterChainFactoryCallbacks& callbacks) -> void {
callbacks.addStreamDecoderFilter(
Http::StreamDecoderFilterSharedPtr{new SetMetadataFilter(filter_config)});
};
}

REGISTER_FACTORY(SetMetadataConfig, Server::Configuration::NamedHttpFilterConfigFactory);

} // namespace SetMetadataFilter
} // namespace HttpFilters
} // namespace Extensions
} // namespace Envoy
Loading