-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
router: Allow CORS to be configured using typed_per_filter_config #9324
Changes from 9 commits
9a0c494
1eca04c
53843ec
f3a2ef8
65db214
8829cc0
6f4e369
3f8ade3
7759da1
13d4d5d
532c882
ab9d7c7
d309b38
0248c95
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,12 @@ | ||
# DO NOT EDIT. This file is generated by tools/proto_sync.py. | ||
|
||
load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package") | ||
|
||
licenses(["notice"]) # Apache 2 | ||
|
||
api_proto_package( | ||
deps = [ | ||
"//envoy/api/v2/core:pkg", | ||
"//envoy/type/matcher:pkg", | ||
], | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
syntax = "proto3"; | ||
|
||
package envoy.config.filter.http.cors.v2; | ||
|
||
option java_package = "io.envoyproxy.envoy.config.filter.http.cors.v2"; | ||
option java_outer_classname = "CorsProto"; | ||
option java_multiple_files = true; | ||
|
||
import "envoy/api/v2/core/base.proto"; | ||
import "envoy/type/matcher/string.proto"; | ||
|
||
import "google/protobuf/wrappers.proto"; | ||
|
||
import "validate/validate.proto"; | ||
|
||
// [#protodoc-title: Cors] | ||
// Cors :ref:`configuration overview <config_http_filters_cors>`. | ||
// [#extension: envoy.filters.http.cors] | ||
|
||
// [#next-free-field: 9] | ||
message PerRouteCorsPolicy { | ||
// Specifies string patterns that match allowed origins. An origin is allowed if any of the | ||
// string matchers match. | ||
repeated type.matcher.StringMatcher allow_origin_string_match = 1; | ||
|
||
// Specifies the content for the *access-control-allow-methods* header. | ||
string allow_methods = 2; | ||
|
||
// Specifies the content for the *access-control-allow-headers* header. | ||
string allow_headers = 3; | ||
|
||
// Specifies the content for the *access-control-expose-headers* header. | ||
string expose_headers = 4; | ||
|
||
// Specifies the content for the *access-control-max-age* header. | ||
string max_age = 5; | ||
|
||
// Specifies whether the resource allows credentials. | ||
google.protobuf.BoolValue allow_credentials = 6; | ||
|
||
// Specifies the % of requests for which the CORS filter is enabled. | ||
// | ||
// If neither ``enabled``, ``filter_enabled``, nor ``shadow_enabled`` are specified, the CORS | ||
// filter will be enabled for 100% of the requests. | ||
// | ||
// If :ref:`runtime_key <envoy_api_field_core.runtimefractionalpercent.runtime_key>` is | ||
// specified, Envoy will lookup the runtime key to get the percentage of requests to filter. | ||
api.v2.core.RuntimeFractionalPercent filter_enabled = 7; | ||
|
||
// Specifies the % of requests for which the CORS policies will be evaluated and tracked, but not | ||
// enforced. | ||
// | ||
// This field is intended to be used when ``filter_enabled`` and ``enabled`` are off. One of those | ||
// fields have to explicitly disable the filter in order for this setting to take effect. | ||
// | ||
// If :ref:`runtime_key <envoy_api_field_core.runtimefractionalpercent.runtime_key>` is specified, | ||
// Envoy will lookup the runtime key to get the percentage of requests for which it will evaluate | ||
// and track the request's *Origin* to determine if it's valid but will not enforce any policies. | ||
api.v2.core.RuntimeFractionalPercent shadow_enabled = 8; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# DO NOT EDIT. This file is generated by tools/proto_sync.py. | ||
|
||
load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package") | ||
|
||
licenses(["notice"]) # Apache 2 | ||
|
||
api_proto_package( | ||
deps = [ | ||
"//envoy/api/v3alpha/core:pkg", | ||
"//envoy/config/filter/http/cors/v2:pkg", | ||
"//envoy/type/matcher/v3alpha:pkg", | ||
"@com_github_cncf_udpa//udpa/annotations:pkg", | ||
], | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
syntax = "proto3"; | ||
|
||
package envoy.config.filter.http.cors.v3alpha; | ||
|
||
option java_package = "io.envoyproxy.envoy.config.filter.http.cors.v3alpha"; | ||
option java_outer_classname = "CorsProto"; | ||
option java_multiple_files = true; | ||
|
||
import "envoy/api/v3alpha/core/base.proto"; | ||
import "envoy/type/matcher/v3alpha/string.proto"; | ||
|
||
import "google/protobuf/wrappers.proto"; | ||
|
||
import "udpa/annotations/versioning.proto"; | ||
|
||
import "validate/validate.proto"; | ||
|
||
// [#protodoc-title: Cors] | ||
// Cors :ref:`configuration overview <config_http_filters_cors>`. | ||
// [#extension: envoy.filters.http.cors] | ||
|
||
// [#next-free-field: 9] | ||
message PerRouteCorsPolicy { | ||
option (udpa.annotations.versioning).previous_message_type = | ||
"envoy.config.filter.http.cors.v2.PerRouteCorsPolicy"; | ||
|
||
// Specifies string patterns that match allowed origins. An origin is allowed if any of the | ||
// string matchers match. | ||
repeated type.matcher.v3alpha.StringMatcher allow_origin_string_match = 1; | ||
|
||
// Specifies the content for the *access-control-allow-methods* header. | ||
string allow_methods = 2; | ||
|
||
// Specifies the content for the *access-control-allow-headers* header. | ||
string allow_headers = 3; | ||
|
||
// Specifies the content for the *access-control-expose-headers* header. | ||
string expose_headers = 4; | ||
|
||
// Specifies the content for the *access-control-max-age* header. | ||
string max_age = 5; | ||
|
||
// Specifies whether the resource allows credentials. | ||
google.protobuf.BoolValue allow_credentials = 6; | ||
|
||
// Specifies the % of requests for which the CORS filter is enabled. | ||
// | ||
// If neither ``enabled``, ``filter_enabled``, nor ``shadow_enabled`` are specified, the CORS | ||
// filter will be enabled for 100% of the requests. | ||
// | ||
// If :ref:`runtime_key <envoy_api_field_core.runtimefractionalpercent.runtime_key>` is | ||
// specified, Envoy will lookup the runtime key to get the percentage of requests to filter. | ||
api.v3alpha.core.RuntimeFractionalPercent filter_enabled = 7; | ||
|
||
// Specifies the % of requests for which the CORS policies will be evaluated and tracked, but not | ||
// enforced. | ||
// | ||
// This field is intended to be used when ``filter_enabled`` and ``enabled`` are off. One of those | ||
// fields have to explicitly disable the filter in order for this setting to take effect. | ||
// | ||
// If :ref:`runtime_key <envoy_api_field_core.runtimefractionalpercent.runtime_key>` is specified, | ||
// Envoy will lookup the runtime key to get the percentage of requests for which it will evaluate | ||
// and track the request's *Origin* to determine if it's valid but will not enforce any policies. | ||
api.v3alpha.core.RuntimeFractionalPercent shadow_enabled = 8; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -657,6 +657,16 @@ Utility::resolveMostSpecificPerFilterConfigGeneric(const std::string& filter_nam | |
return maybe_filter_config; | ||
} | ||
|
||
std::vector<const Router::RouteSpecificFilterConfig*> | ||
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. perf nit: you might consider either an std::array of size 3 here, given that I think we know there can be a max of 3 entries? Or potentially for easier programming an absl::InlineVector of size 3 default storage? 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. ooh, 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. still need to finish addressing this before final review |
||
Utility::resolveAllPerFilterConfigGeneric(const std::string& filter_name, | ||
const Router::RouteConstSharedPtr& route) { | ||
std::vector<const Router::RouteSpecificFilterConfig*> configs{}; | ||
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. nit: {} not needed |
||
traversePerFilterConfigGeneric( | ||
filter_name, route, | ||
[&configs](const Router::RouteSpecificFilterConfig& cfg) { configs.push_back(&cfg); }); | ||
return configs; | ||
} | ||
|
||
void Utility::traversePerFilterConfigGeneric( | ||
const std::string& filter_name, const Router::RouteConstSharedPtr& route, | ||
std::function<void(const Router::RouteSpecificFilterConfig&)> cb) { | ||
|
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.
Needs a note in deprecated.rst, same below