forked from openservicemesh/osm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
e2e_grpc_insecure_origination_test.go
169 lines (135 loc) · 5.44 KB
/
e2e_grpc_insecure_origination_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
package e2e
import (
"context"
"fmt"
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/openservicemesh/osm/tests/framework"
. "github.com/openservicemesh/osm/tests/framework"
)
const grpcbinInsecurePort = 9000
// This test originates insecure (plaintext) gRPC traffic between a client and server and
// verifies that the traffic is routable within the service mesh using HTTP routes.
// <Client app plaintext request> --> <local proxy> -- |mTLS over HTTP routes| --> <remote proxy> -- <server app plaintext request>
var _ = OSMDescribe("gRPC insecure traffic origination for client pod -> server pod usint HTTP routes",
OSMDescribeInfo{
Tier: 1,
Bucket: 3,
},
func() {
Context("gRPC insecure traffic origination over HTTP2 with SMI HTTP routes", func() {
testGRPCTraffic()
})
})
func testGRPCTraffic() {
var (
sourceNs = framework.RandomNameWithPrefix("client")
destNs = framework.RandomNameWithPrefix("server")
ns = []string{sourceNs, destNs}
)
It("Tests insecure gRPC traffic origination for client pod -> server pod using HTTP routes", func() {
// Install OSM
Expect(Td.InstallOSM(Td.GetOSMInstallOpts())).To(Succeed())
// Create Test NS
for _, n := range ns {
Expect(Td.CreateNs(n, nil)).To(Succeed())
Expect(Td.AddNsToMesh(true, n)).To(Succeed())
}
// Get simple pod definitions for the gRPC server
svcAccDef, podDef, svcDef, err := Td.SimplePodApp(
SimplePodAppDef{
PodName: framework.RandomNameWithPrefix("pod"),
Namespace: destNs,
Image: "moul/grpcbin",
Ports: []int{grpcbinInsecurePort},
AppProtocol: "grpc",
OS: Td.ClusterOS,
})
Expect(err).NotTo(HaveOccurred())
_, err = Td.CreateServiceAccount(destNs, &svcAccDef)
Expect(err).NotTo(HaveOccurred())
_, err = Td.CreatePod(destNs, podDef)
Expect(err).NotTo(HaveOccurred())
dstSvc, err := Td.CreateService(destNs, svcDef)
Expect(err).NotTo(HaveOccurred())
// Expect it to be up and running in it's receiver namespace
Expect(Td.WaitForPodsRunningReady(destNs, 90*time.Second, 1, nil)).To(Succeed())
srcPod := setupGRPCClient(sourceNs)
trafficTargetName := "test-target" //nolint: goconst
trafficRouteName := "routes" //nolint: goconst
By("Creating SMI policies")
// Deploy allow rule client->server
httpRG, trafficTarget := Td.CreateSimpleAllowPolicy(
SimpleAllowPolicy{
RouteGroupName: trafficRouteName,
TrafficTargetName: trafficTargetName,
SourceNamespace: sourceNs,
SourceSVCAccountName: srcPod.Spec.ServiceAccountName,
DestinationNamespace: destNs,
DestinationSvcAccountName: svcAccDef.Name,
})
// Configs have to be put into a monitored NS
_, err = Td.CreateHTTPRouteGroup(destNs, httpRG)
Expect(err).NotTo(HaveOccurred())
_, err = Td.CreateTrafficTarget(destNs, trafficTarget)
Expect(err).NotTo(HaveOccurred())
// All ready. Expect client to reach server
clientToServer := GRPCRequestDef{
SourceNs: sourceNs,
SourcePod: srcPod.Name,
SourceContainer: srcPod.Name,
Destination: fmt.Sprintf("%s.%s:%d", dstSvc.Name, dstSvc.Namespace, grpcbinInsecurePort),
JSONRequest: "{\"greeting\": \"client\"}",
Symbol: "hello.HelloService/SayHello",
UseTLS: false, // insecure gRPC, service mesh will upgrade connection to mTLS
}
srcToDestStr := fmt.Sprintf("%s/%s -> %s",
clientToServer.SourceNs, clientToServer.SourcePod, clientToServer.Destination)
cond := Td.WaitForRepeatedSuccess(func() bool {
result := Td.GRPCRequest(clientToServer)
if result.Err != nil {
Td.T.Logf("> (%s) gRPC req failed, response: %s, err: %s",
srcToDestStr, result.Response, result.Err)
return false
}
Td.T.Logf("> (%s) gRPC req succeeded, response: %s", srcToDestStr, result.Response)
return true
}, 5, 90*time.Second)
Expect(cond).To(BeTrue(), "Failed testing gRPC traffic for: %s", srcToDestStr)
By("Deleting SMI policies")
Expect(Td.SmiClients.AccessClient.AccessV1alpha3().TrafficTargets(destNs).Delete(context.TODO(), trafficTargetName, metav1.DeleteOptions{})).To(Succeed())
Expect(Td.SmiClients.SpecClient.SpecsV1alpha4().HTTPRouteGroups(destNs).Delete(context.TODO(), trafficRouteName, metav1.DeleteOptions{})).To(Succeed())
// Expect client not to reach server
cond = Td.WaitForRepeatedSuccess(func() bool {
result := Td.GRPCRequest(clientToServer)
if result.Err == nil {
Td.T.Logf("> (%s) gRPC req did not fail, expected it to fail, response: %s", srcToDestStr, result.Response)
return false
}
Td.T.Logf("> (%s) gRPC req failed correctly, response: %s, err: %s", srcToDestStr, result.Response, result.Err)
return true
}, 5, 150*time.Second)
Expect(cond).To(BeTrue())
})
}
func setupGRPCClient(sourceName string) *corev1.Pod {
// Get simple Pod definitions for the client
svcAccDef, podDef, _, err := Td.SimplePodApp(SimplePodAppDef{
PodName: sourceName,
Namespace: sourceName,
Command: []string{"sleep", "365d"},
Image: "networld/grpcurl",
OS: Td.ClusterOS,
})
Expect(err).NotTo(HaveOccurred())
_, err = Td.CreateServiceAccount(sourceName, &svcAccDef)
Expect(err).NotTo(HaveOccurred())
srcPod, err := Td.CreatePod(sourceName, podDef)
Expect(err).NotTo(HaveOccurred())
// Expect it to be up and running in it's receiver namespace
Expect(Td.WaitForPodsRunningReady(sourceName, 90*time.Second, 1, nil)).To(Succeed())
return srcPod
}