From 90b4a8493bc445cb446a82671d8f7fc94fea1ed5 Mon Sep 17 00:00:00 2001 From: "data-plane-api(Azure Pipelines)" Date: Tue, 11 Oct 2022 08:41:41 +0000 Subject: [PATCH] stateful_session: add header based session state (#23145) * add the wireframe Signed-off-by: Pawan Bishnoi * Added bussiness logic. Working now Signed-off-by: Pawan Bishnoi * header name is read from config now instead of using a static one Signed-off-by: Pawan Bishnoi * fill more bussiness logic to achieve functional completeness Signed-off-by: Pawan Bishnoi * add unit and integration tests Signed-off-by: Pawan Bishnoi * added docs Signed-off-by: Pawan Bishnoi * add codeowners Signed-off-by: Pawan Bishnoi * remove header type inline the config instead Fix Intg test Signed-off-by: Pawan Bishnoi * remove path from HeaderBasedSessionState Signed-off-by: Pawan Bishnoi * fix build - attempt 1 Signed-off-by: Pawan Bishnoi * fix build - attempt 2 . Improve code coverage Signed-off-by: Pawan Bishnoi * improve doc format Signed-off-by: Pawan Bishnoi * retrigger CI to resolve a likely transient error Signed-off-by: Pawan Bishnoi * header replace instead of add. We have no usecase of keeping more than the value being set Signed-off-by: Pawan Bishnoi * address review comment to avoid unnecessary type conversion from string to HttpLowerCaseString Signed-off-by: Pawan Bishnoi * retrigger CI to resolve a likely transient error Signed-off-by: Pawan Bishnoi * review comments : avoid copy Signed-off-by: Pawan Bishnoi * add release note Signed-off-by: Pawan Bishnoi * remove extra newline Signed-off-by: Pawan Bishnoi * review comments. fix release note Signed-off-by: Pawan Bishnoi Signed-off-by: Pawan Bishnoi Mirrored from https://github.com/envoyproxy/envoy @ e2aa62acad2342cb7a84e8ad8d552e89d4c01b22 --- BUILD | 1 + .../http/stateful_session/header/v3/BUILD | 9 ++++ .../stateful_session/header/v3/header.proto | 42 +++++++++++++++++++ versioning/BUILD | 1 + 4 files changed, 53 insertions(+) create mode 100644 envoy/extensions/http/stateful_session/header/v3/BUILD create mode 100644 envoy/extensions/http/stateful_session/header/v3/header.proto diff --git a/BUILD b/BUILD index 48896d9d..f92cef4a 100644 --- a/BUILD +++ b/BUILD @@ -231,6 +231,7 @@ proto_library( "//envoy/extensions/http/original_ip_detection/custom_header/v3:pkg", "//envoy/extensions/http/original_ip_detection/xff/v3:pkg", "//envoy/extensions/http/stateful_session/cookie/v3:pkg", + "//envoy/extensions/http/stateful_session/header/v3:pkg", "//envoy/extensions/internal_redirect/allow_listed_routes/v3:pkg", "//envoy/extensions/internal_redirect/previous_routes/v3:pkg", "//envoy/extensions/internal_redirect/safe_cross_scheme/v3:pkg", diff --git a/envoy/extensions/http/stateful_session/header/v3/BUILD b/envoy/extensions/http/stateful_session/header/v3/BUILD new file mode 100644 index 00000000..ee92fb65 --- /dev/null +++ b/envoy/extensions/http/stateful_session/header/v3/BUILD @@ -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"], +) diff --git a/envoy/extensions/http/stateful_session/header/v3/header.proto b/envoy/extensions/http/stateful_session/header/v3/header.proto new file mode 100644 index 00000000..01b9381b --- /dev/null +++ b/envoy/extensions/http/stateful_session/header/v3/header.proto @@ -0,0 +1,42 @@ +syntax = "proto3"; + +package envoy.extensions.http.stateful_session.header.v3; + +import "udpa/annotations/status.proto"; +import "validate/validate.proto"; + +option java_package = "io.envoyproxy.envoy.extensions.http.stateful_session.header.v3"; +option java_outer_classname = "HeaderProto"; +option java_multiple_files = true; +option go_package = "github.com/envoyproxy/go-control-plane/envoy/extensions/http/stateful_session/header/v3;headerv3"; +option (udpa.annotations.file_status).package_version_status = ACTIVE; + +// [#protodoc-title: Header based stateful session extension] + +// This extension allows the session state to be tracked via request headers. +// +// This extension encodes the address of the upstream host selected by the load balancer +// into a response header with the :ref:`header configuration +// `. +// When new requests are incoming, this extension will try to parse the specific upstream host +// address by header name. If the address parsed from the header corresponds to a valid +// upstream host, this upstream host will be selected first. See :ref:`stateful session filter +// `. +// +// For example, if the header name is set to ``session-header``, envoy will prefer ``1.2.3.4:80`` +// as the upstream host when the request contains the following header: +// +// .. code-block:: none +// +// session-header: "MS4yLjMuNDo4MA==" +// +// When processing the upstream response, if ``1.2.3.4:80`` is indeed the final choice the extension +// does nothing. If ``1.2.3.4:80`` is not the final choice, the new selected host will be set to +// response headers (via the ``session-header`` response header). +// +// [#extension: envoy.http.stateful_session.header] +message HeaderBasedSessionState { + // The name that will be used to obtain header value from downstream HTTP request or generate + // new header for downstream. + string name = 1 [(validate.rules).string = {min_len: 1}]; +} diff --git a/versioning/BUILD b/versioning/BUILD index 475c4edd..49b23a8a 100644 --- a/versioning/BUILD +++ b/versioning/BUILD @@ -171,6 +171,7 @@ proto_library( "//envoy/extensions/http/original_ip_detection/custom_header/v3:pkg", "//envoy/extensions/http/original_ip_detection/xff/v3:pkg", "//envoy/extensions/http/stateful_session/cookie/v3:pkg", + "//envoy/extensions/http/stateful_session/header/v3:pkg", "//envoy/extensions/internal_redirect/allow_listed_routes/v3:pkg", "//envoy/extensions/internal_redirect/previous_routes/v3:pkg", "//envoy/extensions/internal_redirect/safe_cross_scheme/v3:pkg",