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

cli: Add new consul connect redirect-traffic command for applying traffic redirection rules when Transparent Proxy is enabled. #9910

Merged
merged 22 commits into from
Apr 9, 2021

Conversation

ishustava
Copy link
Contributor

@ishustava ishustava commented Mar 19, 2021

This PR proposes the following changes:

  • Add new consul connect redirect-traffic command for applying traffic redirection rules when Transparent Proxy is enabled.
  • Add new iptables package for applying traffic redirection rules with iptables.

@github-actions github-actions bot added pr/dependencies PR specifically updates dependencies of project theme/api Relating to the HTTP API interface theme/cli Flags and documentation for the CLI interface labels Mar 19, 2021
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging March 19, 2021 23:37 Inactive
@vercel vercel bot temporarily deployed to Preview – consul March 19, 2021 23:37 Inactive
@ishustava ishustava force-pushed the ishustava/tproxy-basic-iptables branch from 481cc7e to c4e3e7a Compare April 7, 2021 04:58
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging April 7, 2021 04:58 Inactive
@vercel vercel bot temporarily deployed to Preview – consul April 7, 2021 04:58 Inactive
@ishustava ishustava force-pushed the ishustava/tproxy-basic-iptables branch from c4e3e7a to b63ebe0 Compare April 7, 2021 05:19
@vercel vercel bot temporarily deployed to Preview – consul April 7, 2021 05:19 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging April 7, 2021 05:19 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging April 7, 2021 05:37 Inactive
@vercel vercel bot temporarily deployed to Preview – consul April 7, 2021 05:37 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging April 7, 2021 05:39 Inactive
@vercel vercel bot temporarily deployed to Preview – consul April 7, 2021 05:39 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging April 7, 2021 06:31 Inactive
@ishustava ishustava changed the title Add basic command for traffic redirection cli: Add new consul connect redirect-traffic command for applying traffic redirection rules when Transparent Proxy is enabled. Apr 7, 2021
@ishustava ishustava marked this pull request as ready for review April 7, 2021 15:08
@ishustava ishustava requested a review from freddygv April 7, 2021 15:08
Copy link
Contributor

@freddygv freddygv left a comment

Choose a reason for hiding this comment

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

This is looking good @ishustava, nice work! I added questions/comments in line.

cfg.ProxyInboundPort = svc.Port

// todo: change once it's configurable
cfg.ProxyOutboundPort = xds.TProxyOutboundPort
Copy link
Contributor

Choose a reason for hiding this comment

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

This is more of a note for myself, but looking at this maybe the TProxyOutboundPort constant should be moved to the SDK so that consul-k8s doesn't need to import the xds package. We won't default this value in proxy registrations.

Copy link
Member

Choose a reason for hiding this comment

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

I was just coming here to say that the command package probably shouldn't import agent/xds

Copy link
Contributor Author

Choose a reason for hiding this comment

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

💯 Agree. Sorry, I think misunderstood how defaulting should work and thought this const will go away eventually and so was using it temporarily. After syncing with Freddy, I've moved it to the iptables package instead.

command/connect/redirecttraffic/redirect_traffic.go Outdated Show resolved Hide resolved
// based on the configuration provided in cfg.
// This implementation was inspired by
// https://github.com/openservicemesh/osm/blob/650a1a1dcf081ae90825f3b5dba6f30a0e532725/pkg/injector/iptables.go
func Setup(cfg Config) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this idempotent? What happens if it's run twice? Either with the same or different Config.

Should we attempt to drop the chains before adding them?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, that's a great call-out. I've been thinking about your comment above about documenting that ApplyRules is not atomic, and I think it makes sense to make that one atomic and this one idempotent. I'm thinking to address it in a follow-up PR because most likely I'll switch to using iptables-save and iptables-restore to do that.

website/content/commands/connect/envoy.mdx Show resolved Hide resolved
Comment on lines 15 to 16
all traffic to go through the [Envoy proxy](https://envoyproxy.io) when using [Consul
Connect](/docs/connect/) in the Transparent Proxy mode.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
all traffic to go through the [Envoy proxy](https://envoyproxy.io) when using [Consul
Connect](/docs/connect/) in the Transparent Proxy mode.
all traffic to go through the [Envoy proxy](https://envoyproxy.io) when using [Consul
service mesh](/docs/connect/) in the Transparent Proxy mode.

sdk/iptables/iptables.go Show resolved Hide resolved
@vercel vercel bot temporarily deployed to Preview – consul April 8, 2021 23:22 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging April 8, 2021 23:22 Inactive
Co-authored-by: Freddy <freddygv@users.noreply.github.com>
@vercel vercel bot temporarily deployed to Preview – consul April 8, 2021 23:27 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging April 8, 2021 23:27 Inactive
@ishustava ishustava requested a review from freddygv April 8, 2021 23:28
@vercel vercel bot temporarily deployed to Preview – consul April 8, 2021 23:34 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging April 8, 2021 23:34 Inactive
@vercel vercel bot temporarily deployed to Preview – consul April 9, 2021 16:40 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging April 9, 2021 16:40 Inactive
@vercel vercel bot temporarily deployed to Preview – consul April 9, 2021 17:43 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging April 9, 2021 17:43 Inactive
Copy link
Contributor

@freddygv freddygv left a comment

Choose a reason for hiding this comment

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

🚀

@vercel vercel bot temporarily deployed to Preview – consul April 9, 2021 18:09 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging April 9, 2021 18:09 Inactive
@ishustava ishustava merged commit 5755c97 into master Apr 9, 2021
@ishustava ishustava deleted the ishustava/tproxy-basic-iptables branch April 9, 2021 18:48
@hashicorp-ci
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/347969.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr/dependencies PR specifically updates dependencies of project theme/api Relating to the HTTP API interface theme/cli Flags and documentation for the CLI interface
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants