Skip to content

Tunneling outbound traffic #37968

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

Merged
merged 4 commits into from
Jun 15, 2022

Conversation

jewertow
Copy link
Member

@jewertow jewertow commented Mar 16, 2022

Background context

This change aims to enable tunneling outbound traffic via external tunnel proxies. I described the idea in detail in this RFC.

The implementation differs slightly from what I described in the document, but I decided to make it as close to Envoy API as possible.

Important to note that this implementation enables tunneling outbound traffic through an egress gateway as well as directly through a sidecar proxy.

Related API change: istio/api#2283

@istio-testing istio-testing added the do-not-merge/work-in-progress Block merging of a PR because it isn't ready yet. label Mar 16, 2022
@istio-testing istio-testing added needs-rebase Indicates a PR needs to be rebased before being merged size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Mar 16, 2022
@istio-testing
Copy link
Collaborator

Hi @jewertow. Thanks for your PR.

I'm waiting for a istio member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@jewertow jewertow changed the title Destination rule tunneling Tunneling outbound traffic Mar 16, 2022
@istio-testing istio-testing added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Mar 21, 2022
@jewertow jewertow marked this pull request as ready for review March 25, 2022 16:19
@istio-testing istio-testing removed the do-not-merge/work-in-progress Block merging of a PR because it isn't ready yet. label Mar 25, 2022
@dgn
Copy link
Contributor

dgn commented Mar 28, 2022

/ok-to-test

@istio-testing istio-testing added ok-to-test Set this label allow normal testing to take place for a PR not submitted by an Istio org member. and removed needs-ok-to-test labels Mar 28, 2022
@jewertow jewertow force-pushed the destination-rule-tunneling branch 2 times, most recently from e8041b6 to 2dfae53 Compare March 28, 2022 17:59
@jewertow
Copy link
Member Author

Normal behavior - if intended destination is target.com client should originate request for target.com, and sidecar/proxy handle that.

I totally agree with you and that's why I don't want to support applying tunnel settings to services without associated virtual services.

@howardjohn
Copy link
Member

IMO its not our problem. For example, I can have a VS that matches sni=google.com and sends to wikipedia.org. It will very likely fail in most cases, and that is fine - the user configured it. The same applies here. The config is doing what they have configured. Their clients may reject it, and if so - they should not apply that config.

Its far more confusing to have a valid config silently ignored vs having an invalid config give a clear TLS error.

Especially when we consider all of this only applies to TLS but we are applying it to TCP for consistency. Note that "TCP" can also be TLS (if they do not configured it as TLS but actually send TLS).

@costinm
Copy link
Contributor

costinm commented May 28, 2022 via email

@jewertow jewertow force-pushed the destination-rule-tunneling branch from eb0d633 to 1dda4bb Compare June 2, 2022 18:41
@jewertow jewertow requested a review from howardjohn June 5, 2022 09:55
Signed-off-by: Jacek Ewertowski <jewertow@redhat.com>
@jewertow jewertow force-pushed the destination-rule-tunneling branch from e3b5bf9 to 94b396d Compare June 5, 2022 10:19
@@ -136,6 +138,9 @@ func buildOutboundNetworkFiltersWithWeightedClusters(node *model.Proxy, routes [

// For weighted clusters set hash policy if any of the upstream destinations have sourceIP.
maybeSetHashPolicy(destinationRule, tcpProxy, "")
// In case of weighted clusters, tunneling config for a subset is ignored,
// because it is set on listener, not on a cluster.
tunnelingconfig.Apply(tcpProxy, destinationRule, "")
Copy link
Member

Choose a reason for hiding this comment

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

this is pretty unexpected since we are basically saying ij a weighted cluster, for some DR fields the first cluster applies to all of them. However, this behavior was introduced in #35014 and is only extended here...

if tunnel == nil {
return
}
if tunnel.Protocol == "" {
Copy link
Member

Choose a reason for hiding this comment

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

Should default to connect, we can change the API

@@ -0,0 +1,25 @@
apiVersion: apps/v1
Copy link
Member

Choose a reason for hiding this comment

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

fwiw for unrelated reasons I have been working on adding CONNECT support in the echo app. So we could probably replace this long term. No problem for short term

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, I will get back to it once the CONNECT in echo is ready.

@@ -0,0 +1,35 @@
apiVersion: networking.istio.io/v1alpha3
Copy link
Member

Choose a reason for hiding this comment

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

these types of files should likely be under testdata/ which go has some special handling for

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

jewertow added 2 commits June 15, 2022 22:56
Signed-off-by: Jacek Ewertowski <jewertow@redhat.com>
Signed-off-by: Jacek Ewertowski <jewertow@redhat.com>
@jewertow
Copy link
Member Author

/test integ-security-multicluster_istio

Copy link
Member

@howardjohn howardjohn left a comment

Choose a reason for hiding this comment

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

Looks good!

})
}
if _, err := kubeClient.CoreV1().Services(externalNs).Create(context.TODO(), svc, metav1.CreateOptions{}); err != nil {
ctx.Fatalf("failed to create service external-forward-proxy: %s", err)
Copy link
Member

Choose a reason for hiding this comment

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

Its nice to be able to have things be idempotent since for local development running with no-cleanup is super super helpful (run tests in 1s instead of minutes). The following diff does it:

diff --git a/tests/integration/pilot/tunneling_test.go b/tests/integration/pilot/tunneling_test.go
index a21372b876..43d1c46162 100644
--- a/tests/integration/pilot/tunneling_test.go
+++ b/tests/integration/pilot/tunneling_test.go
@@ -27,6 +27,7 @@ import (
 	"time"
 
 	corev1 "k8s.io/api/core/v1"
+	kerrors "k8s.io/apimachinery/pkg/api/errors"
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 	"k8s.io/apimachinery/pkg/util/intstr"
 
@@ -230,7 +231,13 @@ func applyForwardProxyConfigMaps(ctx framework.TestContext, externalNs string) {
 		},
 	}
 	if _, err := kubeClient.CoreV1().ConfigMaps(externalNs).Create(context.TODO(), cfgMap, metav1.CreateOptions{}); err != nil {
-		ctx.Fatalf("failed to create config map external-forward-proxy-config: %s", err)
+		if kerrors.IsAlreadyExists(err) {
+			if _, err := kubeClient.CoreV1().ConfigMaps(externalNs).Update(context.TODO(), cfgMap, metav1.UpdateOptions{}); err != nil {
+				ctx.Fatalf("failed to update config map external-forward-proxy-config: %s", err)
+			}
+		} else {
+			ctx.Fatalf("failed to create config map external-forward-proxy-config: %s", err)
+		}
 	}
 }
 
@@ -257,7 +264,13 @@ func applyForwardProxyService(ctx framework.TestContext, externalNs string) {
 		})
 	}
 	if _, err := kubeClient.CoreV1().Services(externalNs).Create(context.TODO(), svc, metav1.CreateOptions{}); err != nil {
-		ctx.Fatalf("failed to create service external-forward-proxy: %s", err)
+		if kerrors.IsAlreadyExists(err) {
+			if _, err := kubeClient.CoreV1().Services(externalNs).Update(context.TODO(), svc, metav1.UpdateOptions{}); err != nil {
+				ctx.Fatalf("failed to update service external-forward-proxy: %s", err)
+			}
+		} else {
+			ctx.Fatalf("failed to create service external-forward-proxy: %s", err)
+		}
 	}
 }

Alternatively, the reason we don't have this code in 100 places is most of our tests are just doing YAML apply. I don't mind this way though, either works.

side note -I wish client-go had CreateOrUpdate...

Copy link
Member

Choose a reason for hiding this comment

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

Although since the deployment is already static it may make sense to do it all as YAML? it can be templated. Up to you, not sure how complex this logic ends up being in template logic, may be too much

externalNs := apps.External.Namespace.Name()

applyForwardProxyConfigMaps(ctx, externalNs)
ctx.ConfigIstio().File(externalNs, "testdata/external-forward-proxy-deployment.yaml").ApplyOrFail(ctx)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
ctx.ConfigIstio().File(externalNs, "testdata/external-forward-proxy-deployment.yaml").ApplyOrFail(ctx)
ctx.ConfigIstio().File(externalNs, "testdata/external-forward-proxy-deployment.yaml").ApplyOrFail(ctx, apply.CleanupConditionally)

For running locally, helpful. Also consistent with the fact we are not cleaning up the configmap/service

applyForwardProxyConfigMaps(ctx, externalNs)
ctx.ConfigIstio().File(externalNs, "testdata/external-forward-proxy-deployment.yaml").ApplyOrFail(ctx)
applyForwardProxyService(ctx, externalNs)
waitForPodsReadyOrFail(ctx, externalNs, "external-forward-proxy")
Copy link
Member

Choose a reason for hiding this comment

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

Do we need a readiness probe on the deployment to make this more reliable? The retries on the test may make this not a big issue as is though

Signed-off-by: Jacek Ewertowski <jewertow@redhat.com>
@jewertow
Copy link
Member Author

/retest

@howardjohn howardjohn removed the do-not-merge/hold Block automatic merging of a PR. label Jun 15, 2022
@istio-testing istio-testing merged commit 84461d6 into istio:master Jun 15, 2022
hemendrateli added a commit to hemendrateli/istio that referenced this pull request Sep 9, 2022
…evisions

We are adding min istio version for tests related to below PRs as this functionalities were not there in previous revisions :-
	a. gRPC fault
           injection(istio#39295)
	b. Ignore port number in domain
           matching(istio#40475)
	c. Tunneling outbound traffic :- new tunnel field got
           introduced(istio#37968)
	d. Fix consistent hash based on source IP for TCP
           proxy(istio#38438)
	e. Traffic policy load balancer API
           changes(istio#39742)
istio-testing pushed a commit that referenced this pull request Sep 12, 2022
…evisions (#40892)

We are adding min istio version for tests related to below PRs as this functionalities were not there in previous revisions :-
	a. gRPC fault
           injection(#39295)
	b. Ignore port number in domain
           matching(#40475)
	c. Tunneling outbound traffic :- new tunnel field got
           introduced(#37968)
	d. Fix consistent hash based on source IP for TCP
           proxy(#38438)
	e. Traffic policy load balancer API
           changes(#39742)
istio-testing pushed a commit to istio-testing/istio that referenced this pull request Sep 13, 2022
…evisions

We are adding min istio version for tests related to below PRs as this functionalities were not there in previous revisions :-
	a. gRPC fault
           injection(istio#39295)
	b. Ignore port number in domain
           matching(istio#40475)
	c. Tunneling outbound traffic :- new tunnel field got
           introduced(istio#37968)
	d. Fix consistent hash based on source IP for TCP
           proxy(istio#38438)
	e. Traffic policy load balancer API
           changes(istio#39742)
istio-testing added a commit that referenced this pull request Sep 13, 2022
…evisions (#40957)

We are adding min istio version for tests related to below PRs as this functionalities were not there in previous revisions :-
	a. gRPC fault
           injection(#39295)
	b. Ignore port number in domain
           matching(#40475)
	c. Tunneling outbound traffic :- new tunnel field got
           introduced(#37968)
	d. Fix consistent hash based on source IP for TCP
           proxy(#38438)
	e. Traffic policy load balancer API
           changes(#39742)

Co-authored-by: Hemendra Teli <hemendrat@google.com>
@costinm
Copy link
Contributor

costinm commented Oct 11, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/networking ok-to-test Set this label allow normal testing to take place for a PR not submitted by an Istio org member. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.