Skip to content

http: adding an option to preserve hop by hop headers - #17110

Merged
alyssawilk merged 11 commits into
envoyproxy:mainfrom
alyssawilk:hop-by-hop
Jul 15, 2021
Merged

alyssawilk merged 11 commits into
envoyproxy:mainfrom
alyssawilk:hop-by-hop

Conversation

@alyssawilk

Copy link
Copy Markdown
Contributor

Risk Level: low (config guarded code)
Testing: new unit tests
Docs Changes: n/a
Release Notes: intentionally not added
Platform Specific Features: n/a
Part of envoyproxy/envoy-mobile#1540

@repokitteh-read-only

Copy link
Copy Markdown

CC @envoyproxy/api-shepherds: Your approval is needed for changes made to api/envoy/.
envoyproxy/api-shepherds assignee is @adisuissa
CC @envoyproxy/api-watchers: FYI only for changes made to api/envoy/.

🐱

Caused by: #17110 was opened by alyssawilk.

see: more, trace.

Signed-off-by: Alyssa Wilk <[email protected]>

@adisuissa adisuissa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got a question about this.
/wait-any

// By default, Envoy removes hop by hop headers. For envoy-mobile
// they should be passed up to the caller. This should not be used by server
// side Envoy as it expects hop by hop headers to be cleared.
bool preserve_hop_by_hop_response_headers = 48;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking out loud here, are there going to be more mobile-only fields? If so, should this be part of a sub message that makes it clear that this is only for envoy-mobile instances?
This way we can also reject a config that has this sub-message in non-envoy-mobile instances.

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.

Also for consideration, can we make HCM aware of, in some general sense, the fact that it's linked into a client and not another hop? I think to reject and validate this field on Envoy-proper, we would need this kind of awareness anyway.

Signed-off-by: Alyssa Wilk <[email protected]>
Signed-off-by: Alyssa Wilk <[email protected]>
@alyssawilk

Copy link
Copy Markdown
Contributor Author

@mattklein123 @goaway will need unit tests but WDYT of this vs explicit control knob?

@mattklein123 mattklein123 left a comment

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.

Yup this is exactly what I had in mind. Thank you!

Comment on lines +227 to +251
const envoy::extensions::filters::network::http_connection_manager::v3::
EnvoyMobileHttpConnectionManager& mobile_config,
Server::Configuration::FactoryContext& context) {
const envoy::extensions::filters::network::http_connection_manager::v3::HttpConnectionManager&
proto_config = mobile_config.config();

Utility::Singletons singletons = Utility::createSingletons(context);

auto filter_config = Utility::createConfig(
proto_config, context, *singletons.date_provider_, *singletons.route_config_provider_manager_,
*singletons.scoped_routes_config_provider_manager_, *singletons.http_tracer_manager_,
*singletons.filter_config_provider_manager_);

// This lambda captures the shared_ptrs created above, thus preserving the
// reference count.
// Keep in mind the lambda capture list **doesn't** determine the destruction order, but it's fine
// as these captured objects are also global singletons.
return [singletons, filter_config, &context](Network::FilterManager& filter_manager) -> void {
auto hcm = new Http::ConnectionManagerImpl(
*filter_config, context.drainDecision(), context.api().randomGenerator(),
context.httpContext(), context.runtime(), context.localInfo(), context.clusterManager(),
context.overloadManager(), context.dispatcher().timeSource());
hcm->setClearHopByHopResponseHeaders(false);
filter_manager.addReadFilter(Network::ReadFilterSharedPtr{hcm});
};

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.

nit: I think you can probably share this code in a utility function with above.

Signed-off-by: Alyssa Wilk <[email protected]>
Signed-off-by: Alyssa Wilk <[email protected]>
@alyssawilk

Copy link
Copy Markdown
Contributor Author

I think macos failure is spurious, PTAL!

Signed-off-by: Alyssa Wilk <[email protected]>

@adisuissa adisuissa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm api

@alyssawilk

Copy link
Copy Markdown
Contributor Author

@snowp any requests here? I think I addressed all @mattklein123's comments

@snowp snowp left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few small comments, otherwise this LG!

Comment on lines +440 to +454
if (clear_hop_by_hop) {
response_headers.removeConnection();
response_headers.removeUpgrade();
}
}

response_headers.removeTransferEncoding();

if (request_headers != nullptr &&
(config.alwaysSetRequestIdInResponse() || request_headers->EnvoyForceTrace())) {
config.requestIDExtension()->setInResponse(response_headers, *request_headers);
}
response_headers.removeKeepAlive();
response_headers.removeProxyConnection();

if (clear_hop_by_hop) {
response_headers.removeTransferEncoding();
response_headers.removeKeepAlive();
response_headers.removeProxyConnection();
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to not do this within one if block?

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 prefer having the upgrade / not-upgrade logic colocated ratehr than having the hop by hop code colocated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wfm!

filter_manager.addReadFilter(Network::ReadFilterSharedPtr{new Http::ConnectionManagerImpl(
return [singletons, filter_config, &context,
clear_hop_by_hop_headers](Network::FilterManager& filter_manager) -> void {
auto hcm = new Http::ConnectionManagerImpl(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make_shared?

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.

We could make the shared readfiltersharedptr but then would need to cast it back for the call to setClearHopByHopResponseHeaders (which isn't in the interface). I chose raw pointer and making shared at addReadFilter but lmk if you prefer casts.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't you just make a shared_ptr<Http::ConnectionManagerImpl> and then implicit casting will handle the upcast?

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.

good call, on it!

Signed-off-by: Alyssa Wilk <[email protected]>
Signed-off-by: Alyssa Wilk <[email protected]>

@snowp snowp left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@adisuissa adisuissa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm api

@alyssawilk
alyssawilk merged commit 8589ca8 into envoyproxy:main Jul 15, 2021
@alyssawilk

Copy link
Copy Markdown
Contributor Author

ugh, so this doesn't work as advertised, because Envoy mobile sets up its config via ApiListener, and ApiListener is hard-coded to only read v3::HttpConnectionManager

I assume I'll need to do a follow-up to allow it to also parse EnvoyMobileHttpConnectionManager, but I'm also 1600+ diff patches into the envoy-mobile change to move from HttpConnectionManager to EnvoyMobileHttpConnectionManager and if anyone is willing to revisit a knob in the base HCM I'd love to not add more scut work here....

@mattklein123

Copy link
Copy Markdown
Member

I assume I'll need to do a follow-up to allow it to also parse EnvoyMobileHttpConnectionManager, but I'm also 1600+ diff patches into the envoy-mobile change to move from HttpConnectionManager to EnvoyMobileHttpConnectionManager and if anyone is willing to revisit a knob in the base HCM I'd love to not add more scut work here....

I'm really surprised it's this much of a diff? In general I think it's worth doing this work as I think we are going to need more options passed through that we don't necessarily want to be Envoy proxy side visible.

@alyssawilk

Copy link
Copy Markdown
Contributor Author

It's mostly whitespace: they have many hard-coded configs, and along with adding the new type becasue no-proto-subclass one has to add config: and add 2 spaces to all the HCM config. I've already done it so no skin off my back if we continue but it's a lot of churn I didn't anticipate.

alyssawilk added a commit that referenced this pull request Jul 21, 2021
#17110 the EnvoyMobileHttpConnectionManager but it turns out it's instantiated either as a standard network filter (needs a name) or as an API listener (which only accepted HttpConnectionManager)

Fixing both issues.

Risk Level: low
Testing: unit tests
Docs Changes: n/a
Release Notes: n/a
Part of envoyproxy/envoy-mobile#1540

Signed-off-by: Alyssa Wilk <[email protected]>
leyao-daily pushed a commit to leyao-daily/envoy that referenced this pull request Sep 30, 2021
Risk Level: low (config guarded code)
Testing: new unit tests
Docs Changes: n/a
Release Notes: intentionally not added
Platform Specific Features: n/a
Part of envoyproxy/envoy-mobile#1540
Signed-off-by: Alyssa Wilk <[email protected]>
leyao-daily pushed a commit to leyao-daily/envoy that referenced this pull request Sep 30, 2021
…xy#17407)

envoyproxy#17110 the EnvoyMobileHttpConnectionManager but it turns out it's instantiated either as a standard network filter (needs a name) or as an API listener (which only accepted HttpConnectionManager)

Fixing both issues.

Risk Level: low
Testing: unit tests
Docs Changes: n/a
Release Notes: n/a
Part of envoyproxy/envoy-mobile#1540

Signed-off-by: Alyssa Wilk <[email protected]>
@alyssawilk
alyssawilk deleted the hop-by-hop branch February 28, 2022 21:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants