Skip to content

Commit

Permalink
Filter state: Add missing api to get filterstate format working (envo…
Browse files Browse the repository at this point in the history
…yproxy#35559)

Commit Message: Filter state: Add missing api to get filterstate format
working
Additional Description:
Consider the case where filter state is being set using the
`set_filter_state` filter:
```
- name: "envoy.filters.http.set_filter_state"
            typed_config:
              "@type": "type.googleapis.com/envoy.extensions.filters.http.set_filter_state.v3.Config"
              on_request_headers:
              - object_key: "envoy.network.upstream_server_name"
                format_string:
                  text_format_source:
                    inline_string: "%REQ(:AUTHORITY)%"
                shared_with_upstream: "TRANSITIVE"
```
Now if one try to use the value from the filter state, for example in
the tunneling config hostname:
```
- name: encap
    internal_listener: {}
    filter_chains:
    - filters:
      - name: tcp
        typed_config:
          "@type": type.googleapis.com/envoy.extensions.filters.network.tcp_proxy.v3.TcpProxy
          stat_prefix: tcp_stats
          cluster: cluster_0
          tunneling_config:
            hostname: "%FILTER_STATE(envoy.network.upstream_server_name:PLAIN)%"
```
Then filter state formatter fails to find the value because
[here](https://github.com/envoyproxy/envoy/blob/main/source/common/formatter/stream_info_formatter.cc#L239),
it invokes `serializeAsString()` on the stored filter state object,
which is `UpstreamServerName` instance in this case and it is missing
this function.

I think similar change would be required for other well-known name
objects as well like Upstream subject alt names and alpn application
protocols.

 related envoyproxy#30674

---------

Signed-off-by: Vikas Choudhary <[email protected]>
Signed-off-by: Vikas Choudhary (vikasc) <[email protected]>
  • Loading branch information
vikaschoudhary16 authored Aug 30, 2024
1 parent b661f52 commit b4d6c9a
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions source/common/network/upstream_server_name.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class UpstreamServerName : public StreamInfo::FilterState::Object {
public:
UpstreamServerName(absl::string_view server_name) : server_name_(server_name) {}
const std::string& value() const { return server_name_; }
absl::optional<std::string> serializeAsString() const override { return server_name_; }
static const std::string& key();

private:
Expand Down

0 comments on commit b4d6c9a

Please sign in to comment.