Skip to content

Commit edcfb95

Browse files
authoredDec 18, 2024··
add support for udp routes (#1079)
1 parent e7aafbb commit edcfb95

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed
 

‎go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ require (
1717
github.com/iancoleman/strcase v0.3.0
1818
github.com/martinlindhe/base36 v1.1.1
1919
github.com/open-policy-agent/opa v0.70.0
20+
github.com/pomerium/csrf v1.7.0
2021
github.com/pomerium/pomerium v0.28.1-0.20241213191330-3d53f26d181c
2122
github.com/rs/zerolog v1.33.0
2223
github.com/sergi/go-diff v1.3.1
@@ -164,7 +165,6 @@ require (
164165
github.com/pkg/errors v0.9.1 // indirect
165166
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect
166167
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
167-
github.com/pomerium/csrf v1.7.0 // indirect
168168
github.com/pomerium/datasource v0.18.2-0.20221108160055-c6134b5ed524 // indirect
169169
github.com/pomerium/protoutil v0.0.0-20240813175624-47b7ac43ff46 // indirect
170170
github.com/pomerium/webauthn v0.0.0-20240603205124-0428df511172 // indirect

‎model/ingress_config.go

+7
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ const (
3232
UseServiceProxy = "service_proxy_upstream"
3333
// TCPUpstream indicates this route is a TCP service https://www.pomerium.com/docs/tcp/
3434
TCPUpstream = "tcp_upstream"
35+
// UDPUpstream indicates this route is a UDP service https://www.pomerium.com/docs/capabilities/udp/
36+
UDPUpstream = "udp_upstream"
3537
// SubtleAllowEmptyHost is a required annotation when creating an ingress containing
3638
// rules with an empty (catch-all) host, as it can cause unexpected behavior
3739
SubtleAllowEmptyHost = "subtle_allow_empty_host"
@@ -121,6 +123,11 @@ func (ic *IngressConfig) IsTCPUpstream() bool {
121123
return ic.IsAnnotationSet(TCPUpstream)
122124
}
123125

126+
// IsUDPUpstream returns true is this route represents a UDP service https://www.pomerium.com/docs/capabilities/tcp/
127+
func (ic *IngressConfig) IsUDPUpstream() bool {
128+
return ic.IsAnnotationSet(UDPUpstream)
129+
}
130+
124131
// IsPathRegex returns true if paths in the Ingress spec should be treated as regular expressions
125132
func (ic *IngressConfig) IsPathRegex() bool {
126133
return ic.IsAnnotationSet(PathRegex)

‎pomerium/ingress_annotations.go

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ var (
7070
model.PathRegex,
7171
model.SecureUpstream,
7272
model.TCPUpstream,
73+
model.UDPUpstream,
7374
model.UseServiceProxy,
7475
model.SubtleAllowEmptyHost,
7576
})

‎pomerium/ingress_to_route.go

+21
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,16 @@ func setRoutePath(r *pb.Route, p networkingv1.HTTPIngressPath, ic *model.Ingress
153153
return nil
154154
}
155155

156+
if ic.IsUDPUpstream() {
157+
if *p.PathType != networkingv1.PathTypeImplementationSpecific {
158+
return fmt.Errorf("udp services must have %s path type", networkingv1.PathTypeImplementationSpecific)
159+
}
160+
if p.Path != "" {
161+
return fmt.Errorf("udp services must not specify path, got %s", r.Path)
162+
}
163+
return nil
164+
}
165+
156166
switch *p.PathType {
157167
case networkingv1.PathTypeImplementationSpecific:
158168
if ic.IsPathRegex() {
@@ -187,6 +197,15 @@ func setRouteFrom(r *pb.Route, host string, p networkingv1.HTTPIngressPath, ic *
187197
u.Scheme = "tcp+https"
188198
}
189199

200+
if ic.IsUDPUpstream() {
201+
_, _, port, err := getServiceFromPath(p, ic)
202+
if err != nil {
203+
return err
204+
}
205+
u.Host = net.JoinHostPort(u.Host, fmt.Sprint(port))
206+
u.Scheme = "udp+https"
207+
}
208+
190209
r.From = u.String()
191210
return nil
192211
}
@@ -261,6 +280,8 @@ func getPathServiceHosts(r *pb.Route, p networkingv1.HTTPIngressPath, ic *model.
261280
func getUpstreamScheme(ic *model.IngressConfig) string {
262281
if ic.IsTCPUpstream() {
263282
return "tcp"
283+
} else if ic.IsUDPUpstream() {
284+
return "udp"
264285
} else if ic.IsSecureUpstream() {
265286
return "https"
266287
}

0 commit comments

Comments
 (0)
Please sign in to comment.