-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
matching: add support for generic inputs and add environment variable…
… input (#15410) Adds support for a "generic input" extension point that allows specifying inputs that are not dependent on protocol data. Adds an environment variable generic input that allows matching on the value of an environment variable. Signed-off-by: Snow Pettersen <[email protected]>
- Loading branch information
Showing
26 changed files
with
442 additions
and
4 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
9 changes: 9 additions & 0 deletions
9
api/envoy/extensions/matching/common_inputs/environment_variable/v3/BUILD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"], | ||
) |
22 changes: 22 additions & 0 deletions
22
api/envoy/extensions/matching/common_inputs/environment_variable/v3/input.proto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
syntax = "proto3"; | ||
|
||
package envoy.extensions.matching.common_inputs.environment_variable.v3; | ||
|
||
import "udpa/annotations/migrate.proto"; | ||
import "udpa/annotations/status.proto"; | ||
import "udpa/annotations/versioning.proto"; | ||
import "validate/validate.proto"; | ||
|
||
option java_package = "io.envoyproxy.envoy.extensions.matching.common_inputs.environment_variable.v3"; | ||
option java_outer_classname = "InputProto"; | ||
option java_multiple_files = true; | ||
option (udpa.annotations.file_status).package_version_status = ACTIVE; | ||
|
||
// [#protodoc-title: Environment Variable Input] | ||
// [#extension: envoy.matching.common_inputs.environment_variable] | ||
|
||
// Reads an environment variable to provide an input for matching. | ||
message Config { | ||
// Name of the environment variable to read from. | ||
string name = 1 [(validate.rules).string = {min_len: 1}]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
generated_api_shadow/envoy/config/common/matcher/v3/matcher.proto
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
generated_api_shadow/envoy/config/common/matcher/v4alpha/matcher.proto
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
9 changes: 9 additions & 0 deletions
9
generated_api_shadow/envoy/extensions/matching/common_inputs/environment_variable/v3/BUILD
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
22 changes: 22 additions & 0 deletions
22
...ed_api_shadow/envoy/extensions/matching/common_inputs/environment_variable/v3/input.proto
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
source/extensions/matching/common_inputs/environment_variable/BUILD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
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 = "input_lib", | ||
hdrs = ["input.h"], | ||
deps = [ | ||
"//include/envoy/matcher:matcher_interface", | ||
"//source/common/common:hash_lib", | ||
], | ||
) | ||
|
||
envoy_cc_extension( | ||
name = "config", | ||
srcs = ["config.cc"], | ||
hdrs = ["config.h"], | ||
category = "envoy.matching.common_inputs", | ||
security_posture = "robust_to_untrusted_downstream", | ||
deps = [ | ||
":input_lib", | ||
"//include/envoy/matcher:matcher_interface", | ||
"//include/envoy/registry", | ||
"//include/envoy/server:factory_context_interface", | ||
"@envoy_api//envoy/extensions/matching/common_inputs/environment_variable/v3:pkg_cc_proto", | ||
], | ||
) |
39 changes: 39 additions & 0 deletions
39
source/extensions/matching/common_inputs/environment_variable/config.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#include "extensions/matching/common_inputs/environment_variable/config.h" | ||
|
||
#include <memory> | ||
|
||
#include "envoy/matcher/matcher.h" | ||
|
||
namespace Envoy { | ||
namespace Extensions { | ||
namespace Matching { | ||
namespace CommonInputs { | ||
namespace EnvironmentVariable { | ||
|
||
Envoy::Matcher::CommonProtocolInputPtr | ||
Config::createCommonProtocolInput(const Protobuf::Message& config, | ||
Server::Configuration::FactoryContext& factory_context) { | ||
const auto& environment_config = MessageUtil::downcastAndValidate< | ||
const envoy::extensions::matching::common_inputs::environment_variable::v3::Config&>( | ||
config, factory_context.messageValidationVisitor()); | ||
|
||
// We read the env variable at construction time to avoid repeat lookups. | ||
// This assumes that the environment remains stable during the process lifetime. | ||
auto* value = getenv(environment_config.name().data()); | ||
if (value != nullptr) { | ||
return std::make_unique<Input>(std::string(value)); | ||
} | ||
|
||
return std::make_unique<Input>(absl::nullopt); | ||
} | ||
|
||
/** | ||
* Static registration for the environment data input. @see RegisterFactory. | ||
*/ | ||
REGISTER_FACTORY(Config, Envoy::Matcher::CommonProtocolInputFactory); | ||
|
||
} // namespace EnvironmentVariable | ||
} // namespace CommonInputs | ||
} // namespace Matching | ||
} // namespace Extensions | ||
} // namespace Envoy |
35 changes: 35 additions & 0 deletions
35
source/extensions/matching/common_inputs/environment_variable/config.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#pragma once | ||
|
||
#include "envoy/extensions/matching/common_inputs/environment_variable/v3/input.pb.h" | ||
#include "envoy/extensions/matching/common_inputs/environment_variable/v3/input.pb.validate.h" | ||
#include "envoy/matcher/matcher.h" | ||
#include "envoy/server/factory_context.h" | ||
|
||
#include "common/protobuf/utility.h" | ||
|
||
#include "extensions/matching/common_inputs/environment_variable/input.h" | ||
|
||
namespace Envoy { | ||
namespace Extensions { | ||
namespace Matching { | ||
namespace CommonInputs { | ||
namespace EnvironmentVariable { | ||
|
||
class Config : public Envoy::Matcher::CommonProtocolInputFactory { | ||
public: | ||
Envoy::Matcher::CommonProtocolInputPtr | ||
createCommonProtocolInput(const Protobuf::Message& config, | ||
Server::Configuration::FactoryContext& factory_context) override; | ||
|
||
std::string name() const override { return "envoy.matching.common_inputs.environment_variable"; } | ||
|
||
ProtobufTypes::MessagePtr createEmptyConfigProto() override { | ||
return std::make_unique< | ||
envoy::extensions::matching::common_inputs::environment_variable::v3::Config>(); | ||
} | ||
}; | ||
} // namespace EnvironmentVariable | ||
} // namespace CommonInputs | ||
} // namespace Matching | ||
} // namespace Extensions | ||
} // namespace Envoy |
24 changes: 24 additions & 0 deletions
24
source/extensions/matching/common_inputs/environment_variable/input.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#pragma once | ||
|
||
#include "envoy/matcher/matcher.h" | ||
|
||
namespace Envoy { | ||
namespace Extensions { | ||
namespace Matching { | ||
namespace CommonInputs { | ||
namespace EnvironmentVariable { | ||
|
||
class Input : public Matcher::CommonProtocolInput { | ||
public: | ||
explicit Input(absl::optional<std::string>&& value) : storage_(std::move(value)) {} | ||
|
||
absl::optional<absl::string_view> get() override { return storage_; } | ||
|
||
private: | ||
const absl::optional<std::string> storage_; | ||
}; | ||
} // namespace EnvironmentVariable | ||
} // namespace CommonInputs | ||
} // namespace Matching | ||
} // namespace Extensions | ||
} // namespace Envoy |
Oops, something went wrong.