Skip to content
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

Add flag for transparent proxies to dial individual instances #10329

Merged
merged 8 commits into from
Jun 9, 2021

Conversation

freddygv
Copy link
Contributor

@freddygv freddygv commented Jun 1, 2021

This PR adds a new flag to proxy definitions: Proxy.TransparentProxy.DialedDirectly.

When enabled, services can opt into allowing transparent proxies to dial individual instances.

Typically transparent proxies only dial virtual IPs representing a logical service name. Dialing individual instances can be helpful in cases like stateful services, like a database cluster with a leader.

xDS configuration:

  • There will be a passthrough original destination cluster for each upstream service name. The cluster name is prefixed with passthrough to distinguish from the non-passthrough cluster for the upstream.

  • For listeners we will add a filter chain for each logical upstream that routes to the passthrough clusters mentioned above.

Limitations:

  • The protocol and connection timeout of the upstream are not respected and default to tcp and 5s respectively.
  • L7 rules like RetryOnStatusCodes would likely not be able to be supported with this approach. See this comment

Main Commits:

  1. Adds the DialedDirectly option
  2. Updates proxycfg and xds handling

TODO:

  • Add proxycfg and xDS tests

@github-actions github-actions bot added theme/api Relating to the HTTP API interface theme/cli Flags and documentation for the CLI interface theme/config Relating to Consul Agent configuration, including reloading theme/envoy/xds Related to Envoy support labels Jun 1, 2021
@freddygv freddygv force-pushed the tproxy/support-dialing-instances branch from 2477b73 to 0f87c47 Compare June 7, 2021 20:17
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging June 7, 2021 20:17 Inactive
@vercel vercel bot temporarily deployed to Preview – consul June 7, 2021 20:17 Inactive
@freddygv freddygv marked this pull request as ready for review June 7, 2021 20:27
@freddygv freddygv force-pushed the tproxy/support-dialing-instances branch from 0f87c47 to dfcd192 Compare June 7, 2021 20:28
@vercel vercel bot temporarily deployed to Preview – consul June 7, 2021 20:28 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging June 7, 2021 20:28 Inactive
@freddygv freddygv requested a review from a team June 7, 2021 20:28
@@ -352,40 +352,41 @@ func resourceTagSpecifiers(omitDeprecatedTags bool) ([]string, error) {
// - cluster.f8f8f8f8~pong.default.dc2.internal.e5b08d03-bfc3-c870-1833-baddb116e648.consul.bind_errors: 0
// - cluster.v2.pong.default.dc2.internal.e5b08d03-bfc3-c870-1833-baddb116e648.consul.bind_errors: 0
// - cluster.f8f8f8f8~v2.pong.default.dc2.internal.e5b08d03-bfc3-c870-1833-baddb116e648.consul.bind_errors: 0
// - cluster.passthrough.pong.default.dc2.internal.e5b08d03-bfc3-c870-1833-baddb116e648.consul.bind_errors: 0
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was updated so we can continue to correctly label metrics for this upstream, in the presence of two distinct cluster names.

@vercel vercel bot temporarily deployed to Preview – consul-ui-staging June 7, 2021 20:42 Inactive
@vercel vercel bot temporarily deployed to Preview – consul June 7, 2021 20:42 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging June 7, 2021 20:46 Inactive
@vercel vercel bot temporarily deployed to Preview – consul June 7, 2021 20:46 Inactive
@vercel vercel bot temporarily deployed to Preview – consul June 7, 2021 20:59 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging June 7, 2021 20:59 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging June 7, 2021 21:31 Inactive
@vercel vercel bot temporarily deployed to Preview – consul June 7, 2021 22:21 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging June 7, 2021 22:21 Inactive
@vercel vercel bot temporarily deployed to Preview – consul June 7, 2021 22:35 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging June 7, 2021 22:35 Inactive
Comment on lines +166 to +168
Note that when dialing individual instances HTTP routing rules configured with config entries
will **not** be considered. The transparent proxy acts as a TCP proxy to the original
destination IP address.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the main bit that gives me pause about the current implementation.

Configuration like retrying requests is applied on HTTP routes, and currently the network filter for passthrough is a TCP proxy. If we did attach an HTTP connection manager, what route config would it use? If it used the one for the upstream name, we would no longer route to the passthrough cluster and would instead load balance across the route destination endpoints.

I'm not sure that we can support L7 rules for headless services without creating a separate service registration for each upstream address. This seems really limiting.

@mikemorris mikemorris added this to the 1.10.0 milestone Jun 8, 2021
agent/xds/clusters.go Outdated Show resolved Hide resolved
agent/xds/clusters.go Outdated Show resolved Hide resolved
@freddygv freddygv force-pushed the tproxy/support-dialing-instances branch from f86f841 to 97559dc Compare June 8, 2021 19:29
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging June 8, 2021 19:29 Inactive
@vercel vercel bot temporarily deployed to Preview – consul June 8, 2021 19:29 Inactive
@vercel vercel bot temporarily deployed to Preview – consul June 8, 2021 20:46 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging June 8, 2021 20:46 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging June 8, 2021 21:37 Inactive
@vercel vercel bot temporarily deployed to Preview – consul June 8, 2021 21:37 Inactive
}

// Only create the outbound listener when there are upstreams and filter chains are present
if outboundListener != nil && hasFilterChains {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If no chains with matches on virtual IPs were created above then we would skip the block below, which was unintended.

@vercel vercel bot temporarily deployed to Preview – consul June 8, 2021 22:05 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging June 8, 2021 22:05 Inactive
We don't name filter chains, so the existing sort was a no-op. Sorting
on the match addresses is reasonable because each address is guaranteed
to be unique. If not unique, Envoy will reject the config.
@freddygv freddygv force-pushed the tproxy/support-dialing-instances branch from fb157e8 to ef2f6f7 Compare June 9, 2021 00:03
@vercel vercel bot temporarily deployed to Preview – consul June 9, 2021 00:03 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging June 9, 2021 00:03 Inactive
@@ -197,7 +197,8 @@ func (s *ResourceGenerator) listenersFromSnapshotConnectProxy(cfgSnap *proxycfg.

// Filter chains are stable sorted to avoid draining if the list is provided out of order
sort.SliceStable(outboundListener.FilterChains, func(i, j int) bool {
return outboundListener.FilterChains[i].Name < outboundListener.FilterChains[j].Name
return outboundListener.FilterChains[i].FilterChainMatch.PrefixRanges[0].AddressPrefix <
Copy link
Member

Choose a reason for hiding this comment

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

And this makes sense because the PrefixRanges slice is already sorted stably by AddressPrefix, so taking the zeroth element to compare on is fine.

// the destination service, so that remains intact.
if node.Service.Kind == structs.ServiceKindConnectProxy {
dst := node.Service.Proxy.DestinationServiceName
if dst == "" {
Copy link
Member

Choose a reason for hiding this comment

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

isn't this backwards? I thought IDs were more specific than Names

Copy link
Contributor Author

@freddygv freddygv Jun 9, 2021

Choose a reason for hiding this comment

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

I think we want to prefer the name for the SNI, and only fall back if it doesn't exist. (which shouldn't happen ™️ )

Follows this: https://github.com/hashicorp/consul/blob/master/agent/structs/structs.go#L952

Copy link
Member

@rboyer rboyer left a comment

Choose a reason for hiding this comment

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

LGTM again with one small question

@freddygv freddygv merged commit 429f9d8 into master Jun 9, 2021
@freddygv freddygv deleted the tproxy/support-dialing-instances branch June 9, 2021 20:34
@hc-github-team-consul-core
Copy link
Contributor

🍒 If backport labels were added before merging, cherry-picking will start automatically.

To retroactively trigger a backport after merging, add backport labels and re-run https://circleci.com/gh/hashicorp/consul/383864.

@hc-github-team-consul-core
Copy link
Contributor

🍒✅ Cherry pick of commit 429f9d8 onto release/1.10.x succeeded!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme/api Relating to the HTTP API interface theme/cli Flags and documentation for the CLI interface theme/config Relating to Consul Agent configuration, including reloading theme/envoy/xds Related to Envoy support
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants